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.
Using -ss
after -i
in ffmpeg
takes ages!
This is because you are seeking to a point in the output, not the input. Per the ffmpeg
manual on seeking:
Input seeking
The
-ss
parameter needs to be specified somewhere before-i
:...The input will be parsed using keyframes, which is very fast...
as compared with:
Output Seeking
The
-ss
parameter needs to be specified after-i
:...This will be done very slowly, frame by frame...
in your question you specify the latter. It will be much faster if you use input seeking instead:
ffmpeg -ss 02:00:00 -i long.mkv -vcodec libvpx -b:v 1M -t 00:00:30 -threads 4 out.webm
But if you absolutely do need frame-accurate seeking, you can combine both:
ffmpeg -ss 01:59:30 -i long.mkv -ss 30 -vcodec libvpx -b:v 1M -t 00:00:30 -threads 4 out.webm
(fast seek to 01:59:30, then seek frame-by-frame to 02:00:00, which is +30)
You may already be aware, but if not this should illuminate that ffmpeg
is picky about the placement of options and switches!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments