I need to extract a 30 second interval from the middle of a video, while converting it to webm. ffmpeg seemed like the perfect one liner:
ffmpeg -i long.mkv -vcodec libvpx -b:v 1M -ss 02:00:00 -t 00:00:30 -threads 4 out.webm
To my surprise it almost immediately swallowed all available memory and things started to get swapped so I killed it. After not finding any obvious error - and bare in mind I rarely use ffmpeg - I tried avconv. It didn't report doing anything and memory usage was (slowly) growing in the same direction.
After a few tests with:
-ss 02:00:00 -t 00:00:01
-ss 00:00:01 -t 00:00:01
-ss 00:01:00 -t 00:00:01
It seems ffmpeg is loading the entire movie up to -ss
in memory, or something like that. Anyhow it doesn't seem fit for this kind of operation. My question is, am I doing something wrong and ffmpeg can in fact perform this operation with reasonable resource usage? In case ffmpeg is not meant for this or is just being silly on how to do it, are there any alternatives that don't involve dragging and dropping rectangles into a timeline and using little scissors and scrollbars?
debian@pc:~/ ffmpeg -version
ffmpeg version 0.8.16-6:0.8.16-1, Copyright (c) 2000-2014 the Libav developers
built on Sep 16 2014 23:10:48 with gcc 4.7.2
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
ffmpeg 0.8.16-6:0.8.16-1
libavutil 51. 22. 2 / 51. 22. 2
libavcodec 53. 35. 0 / 53. 35. 0
libavformat 53. 21. 1 / 53. 21. 1
libavdevice 53. 2. 0 / 53. 2. 0
libavfilter 2. 15. 0 / 2. 15. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 52. 0. 0 / 52. 0.100
I also tried with the latest version from ffmpeg's site and the results were the same as avconv's -- doesn't swallow my memory all at once, but doesn't seem to do anything:
frame= 0 fps=0.0 q=-1.0 size= 4kB time=00:00:00.00 bitrate=N/A
And steadily increases memory usage. For a one second clip it seems to me it should be instantaneous and barely use any memory.
ss
. I've never observed the memory usage doing things like this, but maybe you can memory-cap the process?-ss
as an input parameter instead ? Would avoid the delay of output seeking. IE:ffmpeg -ss 02:00:00 -i long.mkv -vcodec libvpx -b:v 1M -t 00:00:30 -threads 4 out.webm
. Leaving as a comment rather than answer in case you need frame-accurate seeking; if it works for you I'll write it up as an answer :)