3

I'm generating thumbnails for a videos that are available from s3 and need to minimize traffic. Frame is going to be from the first couple seconds of the video so the question: is there a way to get frame without passing the full file through network?

At the moment I'm passing video url to ffmpeg but seems like it downloads the whole file, not only first couple seconds.

ffmpeg -ss 0 -noaccurate_seek -i {srcPresignedUrl} -vframes 1 -q:v 2 {outputFileName}

I tried downloading first 10mb of the file and passing it, this works for some mp4 files, but fails on mov:

ffmpeg.exe -ss 0 -i source.mov -vframes 1 -q:v 2 thumb.jpg
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.1 (GCC) 20200726
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000017582ffff40] moov atom not found
source.mov: Invalid data found when processing input

servalex
  • 175
  • 2
  • 6

1 Answers1

1

That's true. Some mp4 files are streaming-ready, but often they are not. The trick is that the moov atom (in simple English, the table of contents of the video file) is normally prepared during the file encoding and attached to the end. There are different ways to move this information to the head of the stream (see Post processing in ffmpeg to move 'moov atom' in MP4 files (qt-faststart)), but this requires rebuilding the video.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I wonder if It's possible to fill only the beginning and the end of the file and leave middle with zeros or garbage. This would be a fun exercise but I don't think it can be a reliable solution. – servalex Aug 20 '20 at 13:53
  • what can you gain by adding zeros? – Alex Cohn Aug 20 '20 at 16:54
  • I just meant that I hope ffmpeg could read moov atom from the end without parsing the whole file and thus would be satisfied with real bytes only in beginning and end. – servalex Aug 20 '20 at 17:32
  • It's still not clear what you want to achieve. If you have control over the video production, make sure they are post-processed with `qt-faststart` and they will stream flawlessly. But *oh, you can easily generate thumbnail images at the same time and save them along the video files*. So, you probably have no control over the video production. Some server software could also help, e.g. [nginx](http://nginx.org/en/docs/http/ngx_http_mp4_module.html). – Alex Cohn Aug 21 '20 at 20:50