I have a video file, and I need to encode it as H264/AVC and feed to client via HTTP. What i need is that i player at client side can play back the video as it is being encoded.
AFAIK, To enable player to play as the video is downloading, "moov atom" have to be placed at the begnning of the video file. However, encoders (ex: ffmpeg) always write "moov atom" at the end of file after it completes encoding.
Is there any way encoder can put "moov atom" at beginning of encode's output? Or play video without moov atom presence?
Thank in advances
LR
Yes, this is possible, but only in some container formats. It is NOT possible with a QuickTime/MP4 container. In these formats, the moov atom contains sample offsets (the locations of the samples in the mdat atom). These are not known until after the video has been encoded. With VOD (video on demand) you can take the finished file, and move the moov atom to the front, to make streaming work better. But there is no way to do this if you are encoding on the fly. To make that work, you'll need to use a stream-oriented transport format. Something like FLV or MPEG-TS would work. If you pass video into ffmpeg and tell it to produce H.264 video in an FLV container, you can then serve that data to a player as it's encoded, and it will work. Of course, if you want to serve it over HTTP, you'll probably have to write your own server (or module for an existing server). Nothing that I know of supports serving a file as it is written (an issue is that the file size is not known when the content-length header is sent). If you serve the video over RTMP or RTSP, however, you can make this work with existing software.
You can move the MOOV Atom to the beginning of a file by rewriting the file using a tool in ffmpeg called qt-faststart. You will need to compile it yourself from source code (but is quite easy at least in Linux / Mac OS). Just download the source of libavcodec, for example:
http://libav.org/releases/libav-0.8.tar.xz
Untar it and go the tools directory, there is a file called qt-faststart.c, just build it with:
make qt-faststart
you can now reallocate MOOV Atom by calling it like this: qt-faststart input.mp4 output.mp4
I also tried this same thing earlier with ffmpeg, but could not succeed. But with vlc I was able to download, transcode and stream on Android simultaneously, though with rtsp. I did not try with http progressive method. I used mpeg4 video codec, mpega audio codec in vlc.