How to download video from phone (n Android) when it is being recorded

I am trying to write an application that downloads videos from Android phones as they are written by reading from a .mp4 file and loading bytes as they are written to the file. The problem is, as far as I can tell, the moov atom and some other diverse data do not seem to be written to the file until the video ends and the video file is closed. Is there a way to process the video file and add this metadata on the server side, assuming that

  • The full video file was uploaded (but without the moov atom or any other data that is not recorded in the first pass)
  • Only part of the video was uploaded (for example, the first 10 seconds), and I want to convert it to a valid mp4 file containing the downloaded video segment.

I saw links like http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system , but they obscure the problem by simply specifying

Thus, the received stream must be corrected after recording is completed, or raw video / audio frames must be processed by the server.

without explaining how to do it.

+6
source share
1 answer

As you noticed, the MP4 format can be difficult to use in such situations. I suspect that the related blog post does not go into the details of the “fix” because it can be quite complicated. In addition to writing the missing size field in the mdat field, you need to create the ftyp and moov fields. If you really need a complete MP4 solution, ISO 14496-12 and ISO 14496-14 will tell you more than you ever wanted to know about how to create these data structures.

However, you may find that a much more elegant solution is to use a format that is really suitable for real-time processing. In other words, on the Android side, convert the video stream to real-time and send it to the server. On the server side, you have great flexibility for processing video: you can transfer all the videos back to MP4, you can cut into cubes, do 10-second pieces, or something else. The open source Sipdroid project contains some code that demonstrates remixing live video in RTP. (You may prefer a reliable transmission format - RTP over TCP or something else - the principle is the same.)

+4
source

Source: https://habr.com/ru/post/913838/


All Articles