Why won't some MP4 videos start streaming until the entire file is downloaded?

10,777

Solution 1

I had this problem with some MP4 videos as well. I was converting uploaded videos to mp4 (h.264 + aac) and they wouldn't buffer. The reason is that this format contains some important metadata required for the playback at the end of the file, hence the entire file has to be loaded before the playback can start. The solution was to use a tiny program called qt-faststart (https://github.com/danielgtaylor/qtfaststart) on the result of the conversion. This program relocates this metadata to the beginning of the file making progressive-download playback possible.

Solution 2

Use ffmpeg with the -movflags +faststart option. This will relocate the moov atom to the beginning of the file, thus allowing playback to begin by the client without the need to completely download the file first.

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

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

Solution 3

I had this same problem for the longest time when using ffmpeg to create MP4 videos - what eventually worked, was simply adding preload="metadata" to the html5 tag:

<video preload="metadata"><source src="..." /></video>
Share:
10,777
Sujeet
Author by

Sujeet

Full stack PHP developer at iQDesk working platforms: zend framework (zf) codeigniter pyrocms wordpress eZ publish HTML5 SQLite

Updated on July 30, 2022

Comments

  • Sujeet
    Sujeet almost 2 years

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

    I'm using ffmpeg to convert the video to mp4 format.

    Here is some detailed information 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                   : [email protected]
    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