2

I've been exploring the documentation and examples at http://bigflake.com/mediacodec/ by Fadden, and applied patch http://bigflake.com/mediacodec/0001-Record-game-into-.mp4.patch to the breakout game. Unfortunately, after compiling the code, I realized it doesn't work, producing video files that aren't streamable.

I see the following error: "The mp4 file will not be streamable."

According to Fadden, this should be fixed by checking the mBufferInfo.flags (https://stackoverflow.com/questions/23934087/non-streamable-video-file-created-with-mediamuxer), which is already done in his code, so I'm at a complete loss. Did anyone else get the video recording patch to work?

Community
  • 1
  • 1
matt snider
  • 4,013
  • 4
  • 24
  • 39
  • The message comes from line 913 of MPEG4Writer.cpp (https://android.googlesource.com/platform/frameworks/av/+/lollipop-release/media/libstagefright/MPEG4Writer.cpp). It's emitted if `mWriteMoovBoxToMemory` is not set. Line 642 has a long comment explaining what that's all about. The short version is that there's a chunk of data that can be written to the front of the file or the end, and if it's not written to the front then the file is not streamable because the recipient of the stream can't seek to the end to read it. I don't actually know what causes it to fail to write to the front. – fadden Nov 07 '14 at 05:09
  • I should probably add: there are more complete examples in Grafika (https://github.com/google/grafika), e.g. "record GL app". – fadden Nov 07 '14 at 05:12

2 Answers2

4

The warning you're seeing is just a warning, nothing more. MP4 files aren't streamable anyway in most cases, in the sense that you would be able to pass the written MP4 over a pipe and have the other end play it back (unless you resort to a lot of extra trickery, or use fragmented MP4 which the android MP4 muxer doesn't write normally). What streamable means here is that once you have the final MP4 file, you can start playing it back without having to seek to the end of the file (which playback over HTTP can do e.g. with HTTP byte range requests).

To write a streamable MP4, the muxer tries to guess how large your file will be, and reserves a correspondingly large area at the start of the file to write the file index to. If the file turns out to be larger so the index doesn't fit into the reserved area, it needs to be written at the end of the file. See lines 506-519 in https://android.googlesource.com/platform/frameworks/av/+/lollipop-release/media/libstagefright/MPEG4Writer.cpp for more info about this guess. Basically the guess seems to boil down to: "The default MAX _MOOV_BOX_SIZE value is based on about 3 minute video recording with a bit rate about 3 Mbps, because statistics also show that most of the video captured are going to be less than 3 minutes."

If you want to turn such a non-streamable MP4 file into a streamable one, you can use the qt-faststart tool from libav/ffmpeg, which just reorders the blocks in the file.

mstorsjo
  • 12,983
  • 2
  • 39
  • 62