Live streaming through MP4

对着背影说爱祢 提交于 2019-11-27 11:07:28

Here's my thoughts guys some of it might be right on others way way off. I plead ignorance because no one have really documented this process fully, its all an educated guess.

AvAssetWriter only encodes to a file, there seems to be no way to get encoded video to memory. Reading the file while it is being written to from a background thread to say a socket results in an elementary stream, this is essentially an m4v, which its a container with h264/acc mdata, but no moov atoms. (in other words no header) No apple supplied player can play this stream, but a modified player based on ffplay should be able to decode and play the stream. This should work, because ffplay use libavformat which can decode elementary streams, one caveat since there is no file length info, some things have to be determined by the play, the DTS and PTS and also the player can't seek within the file.

Alternatively an the raw naul's from the m4v stream can be used to construct an rtmp stream.

If you want to discuss further you can contact me directly.

How you get at the data.

Since your going to have to rebuild the file on the receiving side anyway, I guess you could just kind of segment it, Steve Mcfarin wrote a little appleSegmentedEcorder you can find on his github page, this solves some of the issues for moov atoms since you have all the file info.

You may use fragmented MP4. A fragmented MP4 file is built a follows:

moov [moof mdat]+

The moov box then only contains basic information about the tracks (how many, their type , codec initialization and so on) but no information about the samples in the track. The information about sample locations and sample sizes is in the moof box, each moof box is followed by a mdat that contains the samples as described in the preceding moof box. Typically one would choose the length of a (moof, mdat)-pair to be around 2,4 or 8 seconds (there is no specification on that but these values seem to be reasonable for most usecases).

This is a way to construct a neverending MP4 stream.

No, it is not just the very long length.. you need to know exact size of every frame to create the header in a mp4. [which is why it gets created at the end by the various encoders].

Just looking at 2nd para of your question ("The videos are transcoded from ASF on a server by ffmpeg."), you mentioned you are using ffmpeg to transcode videos on server.

Use qt-faststart or MP4Box to place MOOV atom in the beginning of the file. (also you make sure that using H264 Video & AAC Audio codec for universal support)

Hope this helped you.

MP4 is a file format developed by MPEG (Moving Pictures Experts Group). This was created for the International Standards Organization and was made based upon QTFF. During the initial release, MP4 was very similar to QTFF. However, it developed and became a more advanced file container format. MP4 can be used within Apple devices for both iOS and macOS without the need to re-encode the entire video. The said file format has a great advantage over QTFF; it can be streamed over the net while the latter cannot. The MP4 file format is supported by most operating systems and video editing tools. For a file containing both video and audio, the usual extension is.MP4. However, audio files only use the extension .M4A. Audiobooks utilize the extension .M4B allowing bookmarking of the actual audio file because of the code variation. The extension .M4V is used for raw MPEG4 video bitstreams while mobile phones usually utilize the extension .3G2 and .3GP. Dumpmedia Video Converter is the best converter I ever used. It can support many video file formats, such as MP4, MOV, WMV, AVI, MKV, FLV, 3GP, MPEG and other regular video formats are available, here is an easy guide about how to convert MP4 to AVI, you can click it to learn more!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!