I'm trying to write an app that uploads videos from Android phones as they are being recorded by reading from .mp4 file and uploading the bytes as they are written to the file. The problem is that, as far as I can tell, the moov atom and some other assorted data do not seem to be written to file until the video recording has finished and the video file has been closed. Is there any way to process the video file and add these metadata on the server-side assuming either
I've seen links like http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system but they gloss over the problem by simply stating
So the received stream will have to be fixed up after the recording is finished, or the raw video / audio frames have to be processed by the server.
without explaining exactly how to go about doing that.
1) Select the video file from the gallery. Create a global int private static final int SELECT_VIDEO = 3; -- it doesn't matter what number you use, so long as that's to one you check for later on. Then, use an intent to select a video. Intent intent = new Intent(); intent.
To prevent your phone from overheating, higher resolution videos have a 10-minute recording limit, but you can choose a lower resolution to extend your recording time.
As you've noticed, the MP4 format can be difficult to use in such situations. I suspect the linked blog post doesn't go into detail about the "fixing up" because it can be quite involved. In addition to writing the missing size field of the mdat box, you'll need to generate the ftyp and moov boxes. If you really need an end-to-end MP4 solution, ISO 14496-12 and ISO 14496-14 will tell you more than you ever wanted to know about how to build these data structures.
However, you might find that a much more elegant solution is to use a format that is actually suited for real-time processing. In other words, on the Android side, remux the video stream into a real-time format and send that to the server. On the server side, you then have great flexibility for processing the video: You can remux the whole video back into MP4, you can slice-and-dice, make 10-second chunks, or whatever. The open-source Sipdroid project contains some code that demonstrates remuxing live video into RTP. (You may prefer a reliable transmission format -- RTP over TCP, or whatever -- the principle is the same.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With