2

I recently encountered some problems while using FFmpeg to cut videos. For certain videos, FFmpeg processes very slowly and sends multiple HTTP requests to file links. I suspect there's an issue with the video itself, but how can I identify the problem with the video?

Version

ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04)

Command

$ ffmpeg -i <url> -ss 23 -t 11.0 -y output.mp4 -loglevel trace -report

Log

https://gist.github.com/Hanaasagi/0a416e41b351fa8f62f8e7274a366a25

In trace-level logs, there will be a large number of HTTP Range requests appearing later on.

Video file

https://drive.google.com/file/d/1fyq_AGVY52pfNGRjk82flpRvKDVZVBwk/view?usp=sharing

When I use -i with a disk file directly, this issue doesn't occur. It processes very quickly.

2
  • 1
    Why don't you download the video first, and then process it?
    – DavidPostill
    Commented Jun 9 at 9:08
  • @DavidPostill The user's videos are uploaded to object storage, and then a service processes them in batches. Of course, I could download them locally, but using -i with the URL seems more convenient.
    – Hanaasagi
    Commented Jun 9 at 9:48

1 Answer 1

2

It looks like the MOOV atom of the MP4 video file is at the end of the file.

We may moov the MOOV atom to the beginning of the file as described here:

ffmpeg -i input.mp4 -c copy -movflags faststart input_faststart.mp4


When FFmpeg starts demuxing (parsing) an MP4 file, the first thing it does, is looking for the MOOV atom.
Sine HTTP video URL is uses streaming like protocol, FFmpeg can't start reading from the end of the file - it may take long time to reach the MOOV atom (it might not work at all).


We may check if the MOOV atom is at the beginning or the end of the file as described here:

ffmpeg -v trace -i input.mp4 2>&1 | grep -e type:'mdat' -e type:'moov'

Output:

[mov,mp4,m4a,3gp,3g2,mj2 @ 00000178f9cdf2c0] type:'mdat' parent:'root' sz: 23492883 48 23515923
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000178f9cdf2c0] type:'moov' parent:'root' sz: 23000 23492931 23515923

'moov' comes second, so the MOOV atom is at the end.


Checking for input_faststart.mp4:

ffmpeg -v trace -i input_faststart.mp4 2>&1 | grep -e type:'mdat' -e type:'moov'

Output:

[mov,mp4,m4a,3gp,3g2,mj2 @ 00000228cf22f300] type:'moov' parent:'root' sz: 29393 40 23522316
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000228cf22f300] type:'mdat' parent:'root' sz: 23492883 29441 23522316

'moov' comes first, so the MOOV atom is at the beginning.


Using your shared file as input:

ffmpeg -i "https://drive.usercontent.google.com/download?id=1fyq_AGVY52pfNGRjk82flpRvKDVZVBwk&export=download" -ss 23 -t 11.0 -y output.mp4 -loglevel trace -report

It looks like it's not working...


Using shared input_faststart.mp4 as input:

ffmpeg -i "https://drive.usercontent.google.com/download?id=11Zw-bSpKVEmQPBiimsdm0aa_e4Zu3eS8&export=download" -ss 23 -t 11.0 -y output.mp4 -loglevel trace -report

Takes about 20 seconds in my machine.

3
  • I noticed that FFmpeg initially sent two HTTP range requests: Range: bytes=0- and Range: bytes=23492923-. The second request should retrieve the moov information. However, FFmpeg sent another HTTP range request when it reached sample 69. I suspect there might be an issue with sample 69 or FFmpeg has a buffer limitation.
    – Hanaasagi
    Commented Jun 10 at 7:11
  • Can you tell if HTTP is working with other files with MOOV atom at the end? I assumed that it is not suppose to work with relatively large files, but I don't have enough experience with HTTP.
    – Rotem
    Commented Jun 10 at 14:10
  • I've created many test videos using FFmpeg, each around 30 MB in size. When the moov atom is located at the end of the file, I noticed from the logs that FFmpeg makes three requests. The second request uses Range to fetch the moov data. I currently suspect that this issue arises because FFmpeg is handling badly interleaved MP4 files.
    – Hanaasagi
    Commented Jun 13 at 5:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .