Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trim a large video with ffmpeg?

Tags:

video

ffmpeg

I am trying to trim a video that is 75 GB size and 1 hour and 28 minutes long

I only want to get 7 seconds out of it

When I try this

ffmpeg -i Replay.mp4 -ss 01:21:24.0000 -to 01:21:32.0000 -acodec copy -vcodec copy ShortReplay2.mp4

I get this

Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=-1.0 size=       0kB time=00:00:00.00 bitrate=N/A

It's stuck and nothing happens, have waited for about 30 minutes and is still stuck

However when I try trimming it from the beginning of the video

ffmpeg -i Replay.mp4 -ss 00:00:00.000 -to 00:20:00.000 -acodec copy -vcodec copy ShortReplay2.mp4

It works without issues

Is it because the file size is too big and the program takes too long to read it? What can I do?

like image 848
JonC Avatar asked Aug 04 '15 23:08

JonC


Video Answer


1 Answers

Option placement matters

You can try using -ss as an input option (before -i). This will immediately seek to the closest seek point before the declared -ss position. Note that when -ss is used as an input option the -to option behaves the same as the -t option.

If you find this is not accurate enough you may have to use -ss as an output option and/or re-encode instead of stream copy. As an output option it is slower, so it is possible you simply did not wait long enough for it to fully decode to your position.

Example

ffmpeg -ss 01:21:24 -i input.mp4 -t 7 -c copy output.mp4

Also see

  • ffmpeg tool documentation
  • FFmpeg Wiki: Seeking
like image 90
llogan Avatar answered Oct 08 '22 08:10

llogan