0

I want to create one thumbnail consisting of the first frame of a video for arbitrary video files. I do it like this:

ffmpeg -i video.mkv -vf scale=w=300:h=300:force_original_aspect_ratio=decrease -frames:v 1 thumbnail.png

For performance considerations I was experimenting with only loading the first megabytes of a video instead of whole video files for this task.

In my experiments this works fine with some formats like mkv and mts and only sometimes with mp4 (I get errors - and no thumbnail, when the moov atom is not at the beginning of a file)

With what video file formats is it possible to generate thumbnails only from the first megabytes of a file, and with what formats is it not possible? Does it only depend on the container type or also on the codec? Can there be a reliable answer?

1 Answer 1

2

Can there be a reliable answer?

No.

As with almost everything is video. The real answer is: It depends.

With mp4, the moov must be at the beginning, AND the mdat must properly interleave tracks. For example, If the there more than one megabyte of audio before the video, Then it won't work even with the moov at the start.

For TS, there must be a SPS, a PPS and and IDR in the first megabyte. That is probable, but not guaranteed.

For Mkv Interleaving matters.

The codec, codec configuration, and even bitrate will also matter. If the first keyframe is over 1Mb, no container will work.

If the codec is using periodic inter fresh, it would probably take more that 1Mb, unless the video bitrate is very low.

Writing all the permutations would take a book.

2
  • I could extend the size of the fragment I use, it does not have to be 1MB. Everything that keeps me from having to deal with the video as a whole is a performance win. So a better question would have been probably: Under what circumstances does FFmpeg need access the end of a video file, just to produce a thumbnail of the first frame.
    – MartinW
    Commented Nov 17, 2020 at 16:05
  • Same answer. It depends on the container, the codec and encoding settings. There is not one size first all answer. Why not just give ffmpeg the URL, and let it figure it out?
    – m3u8
    Commented Nov 18, 2020 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.