Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 287
Sujeet Avatar asked Nov 24 '11 11:11

Sujeet


People also ask

Why do some MP4 files not play?

Reason 1: The media player you are using is not compatible with the format. Reason 2: There could be a codec issue. Reason 3: The MP4 file that you have downloaded could be broken. These are the most common reasons why you may end up looking for how to fix corrupt video files MP4 solutions.

How do I play an incomplete MP4 video?

Method 1 – VLC Media Player And another feature of VLC is that it can play incomplete video files. How to play partially downloaded MP4 with VLC? Just launch VLC Media Player, just drag your mp4. crdownload file to the interface, then it will automatically play the incomplete MP4 file.


2 Answers

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
like image 151
llogan Avatar answered Oct 22 '22 04:10

llogan


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.

like image 43
Aleks G Avatar answered Oct 22 '22 06:10

Aleks G