IPhone, IPad, IPod: HTTP Streaming with segmenter and m3u8 on Windows
With the new Ipod touch, iPad, IPhone OS3 Apple implemented HTTP Streaming. A very tricky way but works very good without any flash usage. A file or a stream will split to several smaller parts that will put together in a playlist. On live streaming the playlist will updated automatically. To get this, videos must trancoded and chuked. On google you will find a open source filesegmenter.c and a apple tool mediastreamsegmenter for Mac OS only. So we must use segmenter.c and compile it. Since most users will do that on Linux we will not find any Windows files. So i have compiled a exe file for my home streaming.
Alternative: Air Video
You can also use the Air Video for streaming your files. There you get a server software for Windows and a patched ffmpeg. Some guys made a mod of this and patched that patched ffmpeg again :) so you can use streaming links (i.e from dbox, dreambox) in this software. Because this was too complex i decided to do something on my known.
Download
In the Sidebar you can find the Download archive link of the binary files for Windows. I host them now on Google Code (httpsegmenter). I tested in on Windows XP and Windows 7 and in works after patching arround in the source file (segmenter.c) (see above). The commandline syntax is similar to the orginal one but has an additional optional paramter at the end. But you can use all scripts and commandlines snippets without changing anything.
So my building system works very well now, i also put a Windows binary of live_segmenter into the download archive. You can upload the stream to Amazon S3, ftp, shh , .... Not tested yet.
In the download archive you will find a batch file for starting a stream. Some syntax as on Linux System, so Google for more information or look here if you need help.
ffmpeg -i C:\your\nice\video\source.avi -f mpegts -acodec libmp3lame -ab 64000 -s 480x320 -vcodec libx264 -b 480000 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 400k -maxrate 524288 -bufsize 524288 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 480:320 -g 30 -async 2 - | segmenter - 10 stream/stream stream/stream.m3u8 http://localhost/ 5 1
More Information
- Think of using Apache or any other Webserver to get the playlist open on your Ipod touch, iPad or IPhone. VLC should also open then m3u8 file but i have not tested yet.
- In the archive you can see a ffmpeg binary. Some ffmpeg Version doesnt implement the necessary codec, this does
Usage: c:\...\segmenter <input MPEG-TS file> <segment duration in seconds> <output MPEG-TS file prefix> <output m3u8 index file> <http prefix> [<segment window size>] [<search kill file>] Compiled by Daniel Espendiller - www.espend.de build on May 23 2010 16:55:37 with 3.4.5 (mingw-vista special r3) Took some code from: - source:http://svn.assembla.com/svn/legend/segmenter/ - iStreamdev:http://projects.vdr-developer.org/git/?p=istreamdev.git;a=tree;f=segmenter;hb=HEAD - live_segmenter:http://github.com/carsonmcdonald/HTTP-Live-Video-Stream-Segmenter-and-Distributor
For Experts only
Patched segmenter
To work in Windows i hade to patch the function write_index_file because the m3u8 playlist generator doesnt remove older files on a Windows System (does rename only). Furthermore i added several tweaks i a got from comments and user sites to clean up the code. Now a PID filewill generated and you can close a running streaming progress by putting a file with name kill in the same folder as the binary.
int write_index_file(const char [...] [...] remove(index); if (rename(tmp_index, index)) { fprintf(stderr, "Could not rename %s to %s\n", tmp_index, index); return -1; } return 0; }
Compile
First of all you need the mingw32 and mssys buliding system, simply use the setup files to install them on windows. Moreover you need the ffmpeg libraries. Its very tricky to get them compiled but you can find alot on the FFmpeg on Windows. If you installed the building system you must replace serveral binaries and implement new versions i.e. bash-3.1.17-2-msys-1.0.11, coreutils-5.97-MSYS-1.0.11, make-3.81-2-msys-1.0.11-bin some informationen you can find here: gooli.org - Building ffmpeg for Windows with MSYS and MinGW. I cannot tell that in detail here.
You dont need to build the full ffmpeg with libx264 and other codec, when you take a different ffmpeg binary (mostly static) use only configure --enable-memalign-hack to start your ffmpeg builing and then do a make.
After hopefully you get a working ffmpeg build process you can build segmenter.c with gcc. If you check out the orignal source you can find a makefile in that. Some people tweaks alot on that but we dont need this. To compile the file simply use this:
gcc -Wall -g segmenter.c -o segmenter.exe -L /usr/local/lib -lavformat -lavcodec -lavutil
It should work hopefully without any warning. Under mingw32 you can now run the exe binary. To use it in directly in windows put the ffmpeg dll files in the some folder as binary it should be:avcodec-xx.dll, avformat-xx.dll, avutil-xx.dll find them in ffmpeg source folder after ffmpeg build. A static build without the dlls didnt work for me right now.
Ready build-enviroment for you
After some requests i but a full working and patched mingw32 / mysys enviroment as mentioned above into the the Google Project Download list
VideoLAN (VLC)
The newest Version of VLC can also stream to IPhone, IPad and others with http segmentation (some solution mentioned above). Look at the wiki: Documentation:Streaming HowTo/Streaming for the iPhone