1

I want to stream my webcam in linux with VLC to the iPod. From what I've seen on the web, the easiest way is to use a web server and then access to it from the iPod like this:

NSString *url = @"http://www.example.com/path/to/movie.mp4";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];

I have never used web services before and would like to know how i can achieve this whole process. Thank you

EDIT: After setting up the linux/vlc/segmenter, this is what i get in the terminal after running the comment from Warren and exiting vlc:

VLC media player 1.1.4 The Luggage (revision exported)
Blocked: call to unsetenv("DBUS_ACTIVATION_ADDRESS")
Blocked: call to unsetenv("DBUS_ACTIVATION_BUS_TYPE")
[0x87bc914] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Blocked: call to setlocale(6, "")
Blocked: call to sigaction(17, 0xb71840d4, 0xb7184048)
Warning: call to signal(13, 0x1)
Warning: call to signal(13, 0x1)
Warning: call to srand(1309581991)
Warning: call to rand()
Blocked: call to setlocale(6, "")

(process:4398): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.
Warning: call to signal(13, 0x1)
Warning: call to signal(13, 0x1)
Blocked: call to setlocale(6, "")
Could not open input file, make sure it is an mpegts file: -1

Help me understanding all this? thks!

StinkyCat
  • 1,236
  • 1
  • 17
  • 31
  • Partial duplicate of [this question](http://stackoverflow.com/questions/1093667/http-live-streaming-ffmpeg-ffserver-and-iphone-os-3), but differs in that it covers the Cocoa Touch angle and uses VLC as the video capture and encoding piece instead of ffmpeg. – Warren Young Jun 23 '11 at 13:28

1 Answers1

4

The URL you show assumes the video is prerecorded.

For live HTTP streaming to an iOS device, the URL will instead end in .m3u or .m3u8, which is a common playlist format type. (It is an extended version of the Icecast playlist format, documented in this IETF draft.) This playlist tells the iOS device how to find the other files it will retrieve, in series, in order to stream the video.

The first tricky bit is producing the video stream. Unlike all other iOS compatible media files, live HTTP streaming requires an MPEG-2 transport stream (.ts) container, rather than an MPEG-4 part 14 container (.mp4, .m4v). The video codec is still H.264 and the audio AAC, as you might expect.

A command something like this should work:

$ vlc /dev/camera –intf=dummy –sout-transcode-audio-sync –sout='#transcode{\
        vcodec=h264,venc=x264{\
            aud,profile=baseline,level=30,keyint=30,bframes=0,ref=1,nocabac\
        },\
        acodec=mp4a,ab=56,deinterlace\
    }:\
    duplicate{dst=std{access=file,mux=ts,dst=-}}' > test.ts

This is all one long command. I've just broken it up for clarity, and to work around SO's formatting style limits. You can remove the backslashes and whitespace to make it a single long line, if you prefer. See the VLC Streaming HOWTO for help on figuring out what all that means, and how to adjust it.

The /dev/camera bit will probably have to be adjusted, and you may want to fiddle with the A/V encoding parameters based on Apple's best practices tech note (#TN 2224) to suit your target iOS device capabilites.

The next tricky bit is producing this playlist file and the video segment files from the live video feed.

Apple offers a program called mediastreamsgementer which does this, but it's not open source, it only runs on OS X, and it isn't even freely downloadable. (It comes as part of Snow Leopard, but otherwise, you have to be in Apple's developer program to download a copy.)

Chase Douglas has produced a basic segmenter which builds against libavformat from ffmpeg. There is a newer variant here which has various improvments.

To combine this with the vlc camera capture and encoding command above, replace the > test.ts part with something like this:

| segmenter - 10 test test.m3u8 http://www.example.com/path/to/

This pipes VLC's video output through the segmenter, which breaks the TS up into 10 second chunks and maintains the test.m3u8 playlist file that tells the iOS device how to find the segment files. The - argument tells the segmenter that the video stream is being piped into its standard input, rather than coming from a file. The URL fragment at the end gets prepended onto the file names mentioned in the M3U file.

Having done all that, the only adjustment that should be needed for your Cocoa Touch code is that it should be accessing test.m3u8 instead of movie.mp4.

Community
  • 1
  • 1
Warren Young
  • 40,875
  • 8
  • 85
  • 101
  • hum.. i've seen some stuff like that on the web, but hoped there was a more straightforward way to do.. well, gonna try all those steps now :) thks for ALL that info! – StinkyCat Jun 23 '11 at 14:54
  • i tried the first command, but gave me lots of errors and didn't show my image. I looked around on the internet and changed `$ vlc /dev/camera` to `$ vlc v4l2:///dev/video0`. Now it shows the video and no errors on the terminal. Is it ok? can i proceed? – StinkyCat Jun 23 '11 at 15:35
  • Yes, you've figured out how to get VLC to see your particular camera, so now it should be down to fairly generic commands like I show. – Warren Young Jun 23 '11 at 15:45
  • @warren i'm sorry but i'm very noob at linux stuff.. i downloaded the segmenter and extracted it to a folder, but now i don't know where to put it, since after running the complete command, the terminal said it didn't find the segmenter.. – StinkyCat Jun 23 '11 at 16:08
  • What you downloaded is source code. You have to build it. This is not the place to get such basic help. On SO, we expect that you already know how to build programs for your platform. – Warren Young Jun 23 '11 at 16:25
  • in the first link of the segmenter u find a .c and makefile. There u have to build it sure, but on the other website, i downloaded a .7z that when extracted had 3x .dll, segmenter.exe and a start.bat. I thought that it was ready to be used, guess not, gonna search on the web then. thks – StinkyCat Jun 23 '11 at 16:33
  • alright. Done. And re-run the terminal command with the segmenter part, runs the video with no errors. But on the iPod side, no change. nothing happens. I even tried the MoviePlayer example from Apple with `http://www.example.com/path/to/test.m3u8` and nothing :s – StinkyCat Jun 23 '11 at 17:31
  • No luck with this solution. chose to send the frames via tcp and works. thks for all the help – StinkyCat Jul 02 '11 at 15:38