0

Let's say we have an FLV-wrapped video (under the container, it's h.264 and aac)

The goal is to read it and, on the fly, send it out* as MP4 in a way that can be streamed in Safari/iOS

Are there any libs out there that can help with this? I'm looking into ffmpeg, but I haven't figured it out yet, and I'm not sure if it's really what I need (if I needed a utility to go file->file it's perfect, no doubt, but as a library to use on a chunk by chunk basis, not sure yet if it's the right place to break my teeth over or not)

EDIT: Assume we're talking on-demand, i.e. duration is known and all headers can be scanned before initial read/write

davidkomer
  • 3,020
  • 2
  • 23
  • 58

1 Answers1

1

What you are asking is not possible. There is no way to stream an mp4. It is not a streaming format. An mp4 has (at least) two partitions. MDAT and MOOV. MDAT contains the raw audio/video frames. But there are simply concatenated with no start codes or timing information. So without the MOOV it is gibberish. the MOOV contains offset, sizes and timestamp for each frame in the MDAT. But it can not be calculated until all frames are recorded.

The only format supported on iOS for on the fly conversion is HLS.

EDIT: This will work only because flv internally uses the same elementary stream format as mp4. You can scan the flv, extract the sequence headers, and make a note of all the flv tags payload file offset and size. Also remember what frames are keyframes. Construct a fake moov atom that uses byte offsets into the flv (plus a number of bytes larger than the MOOV will be , say 100 MB) Write these values to the stbl sub atoms. Using the data from the sequence header to populate the tkhd. Pad out the MOOV with a FREE atom plus the header for a MDAT atom to make it exactly 100MB. Finally have your webserver map range requests larger than 100MB to the flv instead of the MDAT.

szatmary
  • 29,969
  • 8
  • 44
  • 57