Why don't some MP4 videos start showing until the whole file is downloaded?

I am working on an application where users upload a video and play it in a browser using jwplayer, jplayer, flowplayer, etc. Some videos play immediately, while others wait until the entire video file is downloaded.

I use ffmpeg to convert videos to mp4 format.

Here are some details about one of the video files I tried.

General Complete name : 429183132058337290450_AutoFF.mp4 Format : MPEG-4 Format profile : Base Media Codec ID : isom File size : 10.2 MiB Duration : 24s 333ms Overall bit rate : 3 501 Kbps Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.1 Format settings, CABAC : Yes Format settings, ReFrames : 3 frames Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 24s 333ms Bit rate mode : Variable Bit rate : 3 351 Kbps Width : 1 024 pixels Height : 560 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 30.000 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.195 Stream size : 9.72 MiB (96%) Language : Japanese 
+6
source share
3 answers

I had this problem with some MP4 videos. I converted downloaded videos to mp4 (h.264 + aac) and they do not buffer. The reason is that this format contains some important metadata necessary for playback at the end of the file, so the entire file must be downloaded before playback starts. The solution was to use a tiny program called qt-faststart ( https://github.com/danielgtaylor/qtfaststart ) as a result of the conversion. This program transfers this metadata to the beginning of the file, making progressive loading possible.

+6
source

Use ffmpeg with the -movflags +faststart option. This will move the moov atom to the beginning of the file, allowing you to start playback from the client without having to fully download the file first.

You can use it in your encoding command, or you can use it with an existing file and just re-mux:

 ffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4 
+5
source

I had the same problem for the longest time when ffmpeg was creating an MP4 video - which eventually worked, just adding preload = "metadata" to the html5 tag:

 <video preload="metadata"><source src="..." /></video> 
0
source

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


All Articles