0

I have a server software that generates video thumbnails using ffmpeg in two steps like this:

Step 1

-ss 00:00:19.7500417 -i "S:\vids\main.mp4"
-ss 00:00:39.5000834 -i "S:\vids\main.mp4"
-ss 00:00:59.2501251 -i "S:\vids\main.mp4"
-y -threads 1 -frames:v 1 -vf "scale=-1:480" -map 0:v:0 "temp\temp0.jpg"
-y -threads 1 -frames:v 1 -vf "scale=-1:480" -map 1:v:0 "temp\temp1.jpg"
-y -threads 1 -frames:v 1 -vf "scale=-1:480" -map 2:v:0 "temp\temp2.jpg"

Step 2

-i "temp\temp%d.jpg" -y -filter_complex tile=1x3 "thumbnails\main.jpg"

This works fine when only a few thumbnails are needed, but when 50-100 thumbnails must be written to disk and then tiled separately, overall performance is very slow.

Is there some way I can combine these two commands into a single step?

UPDATE: @gyan's code results in:

PS C:\Users\Sam\Desktop> .\ffmpeg.exe  -ss 00:00:19.7500417 -i "S:\vids\main.mp4" -ss 00:00:39.5000834 -i "S:\vids\main.mp4" -ss 00:00:59.2501251 -i "S:\vids\main.mp4" -filter_complex "[0]trim=end_frame=1,scale=-1:480,setpts=N[a]; [1]trim=end_frame=1,scale=-1:480,setpts=N[b]; [2]trim=end_frame=1,scale=-1:480,setpts=N[c]; [a][b][c]vstack" "thumbnails\main.jpg"
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
  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-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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'S:\vids\main.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:01:19.95, start: 0.000000, bitrate: 529 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 406x720 [SAR 1:1 DAR 203:360], 424 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'S:\vids\main.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:01:19.95, start: 0.000000, bitrate: 529 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 406x720 [SAR 1:1 DAR 203:360], 424 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'S:\vids\main.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:01:19.95, start: 0.000000, bitrate: 529 kb/s
    Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 406x720 [SAR 1:1 DAR 203:360], 424 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[AVFilterGraph @ 000001dcaf4fef40] Too many inputs specified for the "vstack" filter.
Error initializing complex filters.
Invalid argument
0

Use

ffmpeg
 -ss 00:00:19.7500417 -i "S:\vids\main.mp4"
 -ss 00:00:39.5000834 -i "S:\vids\main.mp4"
 -ss 00:00:59.2501251 -i "S:\vids\main.mp4"
 -filter_complex
 "[0]trim=end_frame=1,scale=-1:480,setpts=N[a];
  [1]trim=end_frame=1,scale=-1:480,setpts=N[b];
  [2]trim=end_frame=1,scale=-1:480,setpts=N[c];
  [a][b][c]vstack=3"
"thumbnails\main.jpg"
  • Thanks for the answer, but this results in an error "Too many inputs specified for the "vstack" filter". I've included the full output in my question. – Sam Oct 4 at 4:18
  • Command edited. – Gyan Oct 4 at 4:29
  • Your solution works great, but takes as much RAM as the video size, which is excessive when the video size itself is 15G or more. Since I only need specific frames, is there any way I can avoid loading the entire video into memory? Perhaps by only using keyframes (or other easy to read approximations)? – Sam Oct 4 at 5:11
  • It won't load the entire video into memory. Add -benchmark to your cmd and share full log. – Gyan Oct 4 at 7:05
  • Sorry for the late response - loading the entire video seems to be an issue related to working with remote files. That issue is resolved. – Sam Oct 12 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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