1

I'm looking a way to create a MOOV atom that would allow an user to reproduce an MP4 file while it is still transcoding (for example the transcoding of an endless stream like a the one from a security camera)

I think that the only way I could do that is to have each chunk and sample have exactly the same size so I can declare in advance its format in the st* tables. The problem is that I'm not able to transcode a mp4 with this characteristics using vlc (I don't know if that is even possible) and therefore I can't test if such approach would work.

Is there a way to transcode a file so its frames and chunks have the same size? And if that is possible do you think I could create a MOOV atom that would allow to start the reproduction while the file is still transcoding?

Gerard Garcia
  • 125
  • 1
  • 10
  • 1
    I would comment that what you are asking is "possible". But not recommended. It would be very wasteful, and every frame would need to be padded out to the largest possible frame size. Pablo Montilla has the right idea below. – szatmary Jan 26 '15 at 19:08

1 Answers1

4

What you are looking for is to generate a fragmented MP4. I only know how to do that with ffmpeg, but its probably doable with VLC. You don't need to have same size chunks, but you will have same size segments with moof following mdat boxes.

As an example, using x264 You can use this command line with ffmpeg: ffmpeg -i input -c:v libx264 -preset medium -f mp4 -movflags empty_moov+omit_tfhd_offset+frag_keyframe -frag_duration 1000000 output.mp4

Pablo Montilla
  • 2,941
  • 1
  • 31
  • 35
  • That's great! Almost exactly what I was looking for. – Gerard Garcia Jan 26 '15 at 20:29
  • Just one more question. Do you now how I can fake the duration of the video so it won't stop playing? I mean, with these options when I start playing the file it stops after reaching the duration that it had when I started playing. I guess I would need to manually modify the duration of the track or the total duration so when somebody starts playing it will continue while there is still data. – Gerard Garcia Jan 26 '15 at 20:36
  • Umm...with the command line I gave you, you don't have a set length. If you wish to specify a duration, you'll have to set it on the moov header in a track box, but I'm not sure how...you'll have to investigate that yourself. :-( – Pablo Montilla Jan 26 '15 at 20:41
  • No problem, I'm okey patching ffmpeg. I'll try setting the duration on the moov header. thanks a lot! – Gerard Garcia Jan 26 '15 at 20:51
  • This is really great! Would you happen to also know of a way to just download the chunks you're currently watching instead of the whole file? I have tried this with a 4 minute file that's being written to, and my FFPLAY/VLC had to download the whole file before starting playback. – Boehmi Mar 16 '15 at 13:32
  • The problem you are experiencing is slightly different. You need to encode the file making the MOOV box go to the beginning of the file. This is usually known as 'qt-faststart'. FFmpeg supports that as an option, and I think VLC does too. – Pablo Montilla Mar 16 '15 at 13:37
  • Could you manage to figure it out how to set the duration to infinite? – Zsolt Aug 31 '15 at 12:52