Answers.Body: <blockquote>
  <p>Can there be a reliable answer?</p>
  </blockquote>
  <p>No.</p>
  <p>As with almost everything is video. The real answer is: It depends.</p>
  <p>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.</p>
  <p>For TS, there must be a SPS, a PPS and and IDR in the first megabyte. That is probable, but not guaranteed.</p>
  <p>For Mkv Interleaving matters.</p>
  <p>The codec, codec configuration, and even bitrate will also matter.
  If the first keyframe is over 1Mb, no container will work.</p>
  <p>If the codec is using periodic inter fresh, it would probably take more that 1Mb, unless the video bitrate is very low.</p>
  <p>Writing all the permutations would take a book.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-17T16:05:53.703Z
Answers.Text: 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.
Answers.UserDisplayName: MartinW
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-18T19:02:33.407Z
Answers.Text: 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?
Answers.UserDisplayName: m3u8
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-12T18:14:47.403Z
Answers.LastActivityDate: 2020-11-12T18:14:47.403Z
Answers.UserDisplayName: m3u8
Body: <p>I want to create one thumbnail consisting of the first frame of a video for arbitrary video files. I do it like this:</p>
  <pre><code>ffmpeg -i video.mkv -vf scale=w=300:h=300:force_original_aspect_ratio=decrease -frames:v 1 thumbnail.png
  </code></pre>
  <p>For performance considerations I was experimenting with only loading the first megabytes of a video instead of whole video files for this task.</p>
  <p>In my experiments this works fine with some formats like <code>mkv</code> and <code>mts</code> and only sometimes with <code>mp4</code> (I get errors - and no thumbnail, when the <code>moov atom</code> is not at the beginning of a file)</p>
  <p>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?</p>
  
Tags: <video><ffmpeg><thumbnails>
Title: Generating thumbnail from only the first megabytes of a video file
UserDisplayName: MartinW
ThreadText: # Generating thumbnail from only the first megabytes of a video file
  
  (Asked by: username_0 on 2020-11-12)
  
  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?
  
  **Tags:** video, ffmpeg, thumbnails
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-12. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_1**: 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?  
  
  ---
  
  