Using ffmpeg to extract segment in the middle of long video

Alex

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.

bertieb

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Extract alpha from video ffmpeg

From Dev

Extract part of a video using ffmpeg_extract_subclip - black frames

From Dev

Using FFMPEG I get an error when trying to insert a fade after about 35 mins in a long video - is this possible?

From Dev

Check incomplete video segment with ffmpeg

From Dev

Extract video cover/thumbnail from file with embedded cover using ffmpeg

From Dev

Use ffmpeg to extract parts of video

From Dev

Video padding using ffmpeg

From Dev

How to extract a frame out of a video using ffmpeg

From Dev

Extract frames from video using ffmpeg -- frame accurate?

From Dev

How to extract images from video files using FFmpeg without blur?

From Dev

Using the ffmpeg to extract video stream

From Dev

How to automatically segment video using ffmpeg without re-encoding?

From Dev

when i extract an audio from video using ffmpeg, It appear an error

From Dev

Fill middle of video with repeating a single frame in ffmpeg

From Dev

How to generate m3u8 file and list of TS segment files using ffmpeg for wmv and avi video files

From Dev

crop, rearrange middle of video frame with ffmpeg

From Dev

FFMPEG: Reversing only a segment of a video file

From Dev

Extract Quantization Parameter for individual frames of h.26x video using ffmpeg

From Dev

Clip long video segment quickly

From Dev

Is it possible to extract the dialogue in a video track using the subtitles track with ffmpeg?

From Dev

Extract Yuv frames from mp4 video using ffmpeg

From Dev

Extract final frame from a video using ffmpeg

From Dev

How to generate a video by looping an image and then concat with another very long video without re-encoding using ffmpeg?

From Dev

Comparison of two ffmpeg commands for video segment

From Dev

Cannot extract audio tracks from video using ffmpeg

From Dev

Extract video without audio ffmpeg

From Dev

Extract 5th frame of video & merge into a video using ffmpeg C#

From Dev

How to extract all video frames using ffmpeg-kit with flutter

From Dev

Extract frames from a video (errors from using grabVideoStills and ffmpeg)

Related Related

  1. 1

    Extract alpha from video ffmpeg

  2. 2

    Extract part of a video using ffmpeg_extract_subclip - black frames

  3. 3

    Using FFMPEG I get an error when trying to insert a fade after about 35 mins in a long video - is this possible?

  4. 4

    Check incomplete video segment with ffmpeg

  5. 5

    Extract video cover/thumbnail from file with embedded cover using ffmpeg

  6. 6

    Use ffmpeg to extract parts of video

  7. 7

    Video padding using ffmpeg

  8. 8

    How to extract a frame out of a video using ffmpeg

  9. 9

    Extract frames from video using ffmpeg -- frame accurate?

  10. 10

    How to extract images from video files using FFmpeg without blur?

  11. 11

    Using the ffmpeg to extract video stream

  12. 12

    How to automatically segment video using ffmpeg without re-encoding?

  13. 13

    when i extract an audio from video using ffmpeg, It appear an error

  14. 14

    Fill middle of video with repeating a single frame in ffmpeg

  15. 15

    How to generate m3u8 file and list of TS segment files using ffmpeg for wmv and avi video files

  16. 16

    crop, rearrange middle of video frame with ffmpeg

  17. 17

    FFMPEG: Reversing only a segment of a video file

  18. 18

    Extract Quantization Parameter for individual frames of h.26x video using ffmpeg

  19. 19

    Clip long video segment quickly

  20. 20

    Is it possible to extract the dialogue in a video track using the subtitles track with ffmpeg?

  21. 21

    Extract Yuv frames from mp4 video using ffmpeg

  22. 22

    Extract final frame from a video using ffmpeg

  23. 23

    How to generate a video by looping an image and then concat with another very long video without re-encoding using ffmpeg?

  24. 24

    Comparison of two ffmpeg commands for video segment

  25. 25

    Cannot extract audio tracks from video using ffmpeg

  26. 26

    Extract video without audio ffmpeg

  27. 27

    Extract 5th frame of video & merge into a video using ffmpeg C#

  28. 28

    How to extract all video frames using ffmpeg-kit with flutter

  29. 29

    Extract frames from a video (errors from using grabVideoStills and ffmpeg)

HotTag

Archive