2

Our client sends a request to download a movie file from a server. As the server receives the request, it will start a ffmpeg process to transcode the movie. The output of ffmpeg is temporarily saved to harddisk. We dont want to make client to wait to download the file after transcoding finish, so we send output data as its generated.

The problem is that ffmpeg seem to rewrite the output file header after finish transcoding, so the downloaded file (on client side) doesnt have correct file header, and player can not play it.

My question is that there is any way to make ffmpeg not to rewrite the header? What should be the solution for this?

EDIT: the command is to transcode to H264/AAC in mp4 container

jAckOdE
  • 2,402
  • 8
  • 37
  • 67
  • what is the output file format ? flv, mp4 ? – rajneesh Jan 11 '13 at 07:19
  • what is your ffmpeg command ? – rajneesh Jan 11 '13 at 07:48
  • 2
    For MP4, the moov atom is written at the end of the file. This can not be achieved until the file is done encoding. The client needs the moov atom for playback and therefore will need to download the complete file before playback: unless the moov atom is moved to the beginning (with `-movflags faststart` or equivalent). MP4 container is not a great choice for what I assume you're trying to do. – llogan Jan 11 '13 at 19:06
  • Thanks, it's good to know about moov atom, but I'm not trying to do streaming or progressive download. as i stated in the question, i want client to download file as it's transcoded on the fly. – jAckOdE Jan 14 '13 at 00:28

1 Answers1

1

Yes ffmpeg goes back to the beginning of the file and updates structures to indicate effective sizes that are only available when the file is being completed.

To be able to stream "live" you should consider passing payload video/audio using another method such as using RTSP protocol. Incomplete MP4 files are not well playable until fully complete.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • i'm not trying to make a live stream, i want enable users to download the movie as it's being transcoded. – jAckOdE Jan 14 '13 at 01:54
  • Look like i have to re-download the movie file header after ffmpeg finish transcoding. Is there any way to make ffmpeg to write the head er information at the end of file? – jAckOdE Jan 15 '13 at 02:01