1

I have a video.mp4 which I need to convert losslessly into a sequence of images. I used ffmpeg -i input.mp4 $filename%05d.tiff but I get a lot (thousands) of duplicated frames. What are they? is it possible to avoid that ffmpeg exports them? I had to stop the operation because it was taking forever.


The video file:
codec: H265 – MPEG-4 AVC (part 10) (avc1)
Encoder: Lavf58.29.100
FPS: 70.476432
resolution: 1824 x 1216
Duration: 0m31s


Full output from ffmpeg (I use Linux):

$ ffmpeg -i input.mp4 $filename%05d.tiff

ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)

  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared

  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:31.88, start: 0.000000, bitrate: 746 kb/s
  Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1824x1216, 741 kb/s, 70.48 fps, 1k tbr, 90k tbn, 2k tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> tiff (native))
Press [q] to stop, [?] for help
Output #0, image2, to '%05d.tiff':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: tiff, yuv420p(progressive), 1824x1216, q=2-31, 200 kb/s, 1k fps, 1k tbn (default)
    Metadata:                                                                                                                                                                                
      handler_name    : VideoHandler                                                                                                                                                         
      vendor_id       : [0][0][0][0]                                                                                                                                                         
      encoder         : Lavc58.134.100 tiff                                                                                                                                                  
More than 1000 frames duplicatedN/A time=00:00:01.04 bitrate=N/A dup=976 drop=0 speed=0.0308x                                                                                                
More than 10000 frames duplicated/A time=00:00:10.74 bitrate=N/A dup=9989 drop=0 speed=0.0265x                                                                                               
frame=17673 fps= 26 q=-0.0 Lsize=N/A time=00:00:17.67 bitrate=N/A dup=16428 drop=0 speed=0.0262x                       

After trying different options, I found 3 alternatives that achieve the same results. I give details below.

Option 1 (source)
Comment: it uses variable frame-rate mode.
Command: ffmpeg -i input.mp4 -vf mpdecimate -vsync vfr $filename%05d.tiff
Result: it works. The video is exported as 2245 TIFF images (~6.2GB) and no messages about duplicate frames.

Option 2 (source)
Comment: it retimes the frames using the setpts filter.
Command: ffmpeg -i input.mp4 -vf mpdecimate,setpts=N/24/TB -vsync vfr $filename%05d.tiff
Result: it works. The video is exported as 2245 TIFF images (~6.2GB) and no messages about duplicate frames. According to the question in the source, the resulting framerate is 24 FPS (as requested by the OP), but this is not what I need. I need to respect the FPS of the original video (if possible).

Option 3 (source)
Comment: This keeps 1:1 correspondence between input and output frames.
Command: ffmpeg -i input.mp4 -vsync passthrough $filename%05d.tiff
Result: it works. The video is exported as 2246 TIFF images (~6.2GB) and no messages about duplicate frames.

The strange thing (to me anyway) is that all 3 options produce exactly the same TIFF files, each one with a size of 2.8 MiB (I even compared a couple of random pairs by contents, and the files are actually identical, except that option 3 generates 1 more file than options 1 and 2).

4
  • there are many similar questions on stack overflow, have you tried some of the answers? 1 2 3 4 5
    – Gantendo
    Commented Apr 27, 2023 at 21:42
  • Thank you. Yes, I've seen those posts and I thought they applied to video-to-video but after trying some more tests I was able to apply some of those things to my case. I will edit the original question.
    – terauser
    Commented Apr 28, 2023 at 9:34
  • By the way I used superuser and video because I was suggested that Sack Overflow is rather for software developers and my question did not fit there... ¯\_(ツ)_/¯
    – terauser
    Commented Apr 28, 2023 at 9:55
  • @terauser this is more or less the correct spot, although video.stackexchange.com could be even better. There are many old questions like this on SO because admins didn't think that moving them to more proper sites when changing rules would be a good idea ¯\_(ツ)_/¯ One of the biggest flaws of StackExchange, IMO, as people see similar questions there and ask there just to be redirected to other sites, sometimes in a rude way.
    – Destroy666
    Commented Apr 28, 2023 at 10:52

0

You must log in to answer this question.

Browse other questions tagged .