0

I am extracting part of a large video using the following ffmpeg command and it works fine as long as the -ss X position is few seconds:

ffmpeg -i "test.mov" -ss 2 -t 3 -vf "scale=512x288,setdar=16/9" -r 30 -b:v 500k -b:a 96k -ar 44100 -preset slower "out.mp4"

The problem is, that the larger the X value is in -ss X, the longer it takes ffmpeg to start showing progress and processing the file, and the CPU usage spikes. So for example if the above command produces a video file in about a second, changing the -ss value to 3000 makes the system hang for good 2 minutes and the CPU is getting extremely hot.

While the process is stuck, here is the output:

ffmpeg version 2021-02-10-git-e0fd35d867-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 64.100 / 56. 64.100
  libavcodec     58.122.100 / 58.122.100
  libavformat    58. 67.100 / 58. 67.100
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7.103.100 /  7.103.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 85984000
    compatible_brands: qt
    creation_time   : 2021-09-14T12:19:57.000000Z
    timecode        : 08:19:57:28
  Duration: 01:50:36.53, start: 0.000000, bitrate: 3715 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 3535 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
    Metadata:
      handler_name    : Media Handler
      vendor_id       : appl
      encoder         : H264
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
    Metadata:
      handler_name    : Media Handler
      vendor_id       : [0][0][0][0]
  Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 1 kb/s (default)
    Metadata:
      handler_name    : Media Handler
      reel_name       : 1_2nd Floor
      timecode        : 08:19:57:28
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help

While it seems that "Stream mapping:" is the culprit I had no luck finding a solution. Any help in this matter would be greatly appreciated.

Razor
  • 359
  • 2
  • 11
  • 2
    Put the `-ss` before the `-i` to seek the input. The difference is explained here: https://trac.ffmpeg.org/wiki/Seeking – aergistal Sep 30 '21 at 13:53
  • if i seek the input, then I don't get an exact cut, because ffmpeg can only cut on key frames. – Razor Sep 30 '21 at 14:13
  • 1
    This should be frame accurate for your FFmpeg version when you transcode, is it not the case? – aergistal Sep 30 '21 at 14:22
  • I had many issues with input seeking and saw cases when output was longer than needed or first few seconds of the cut clip being blank. I will follow your recommendation and check again and then report back. I really hope this works, thanks for the help! – Razor Sep 30 '21 at 14:38
  • 1
    If you don't copy the original encoding it should go to the nearest keyframe before the requested position then ignore the decoded frames until it reaches the `-ss` timestamp. – aergistal Sep 30 '21 at 14:43
  • @aergistal that worked perfectly. you should post your comment as an answer. Thank you very much! – Razor Sep 30 '21 at 16:00

0 Answers0