rinofcan
rinofcan

Reputation: 343

Cut video with ffmpeg.

This is my idea.

I want to cut the first 10s of video and the last 10s of video

Thank for help

enter image description here

Upvotes: 8

Views: 9166

Answers (2)

Chris
Chris

Reputation: 3354

this is a bit nicer.

ffmpeg -i "<FILE>" -ss 00:00:10 -to  $( echo "$(ffprobe -v 0 -show_entries format=duration -of compact=p=0:nk=1 "<FILE>") - 35"  | bc) -c copy  "trimmed-output.mp4"

this uses ffprobe to get the duration: ffprobe -v 0 -show_entries format=duration -of compact=p=0:nk=1 "<FILE>"

and then pipes <duration> - 10 to bc to subtract 10 from duration, which is then used in -to param on ffmpeg.

Upvotes: 2

Gyan
Gyan

Reputation: 93329

With re-encoding:

ffmpeg -ss 10 -i video.mp4 -filter_complex "[0]trim=10,setpts=PTS-STARTPTS[b];[b][0]overlay=shortest=1" -shortest -c:a copy out.mp4

-ss 10 sets the the amount to cut from beginning. trim=10 sets amount to cut from end. Caveat here is that due to a current bug with shortest=1, this may not work on ffmpeg builds from 2017.


A bit of a hack method, which skips transcoding:

ffmpeg -ss 10 -i video.mp4 -ss 20 -i video.mp4 -c copy -map 1:0 -map 0 -shortest -f nut - | ffmpeg -f nut -i - -map 0 -map -0:0 -c copy out.mp4

Depending on the location keyframes, the trims at start and end won't be perfect. First ss is starting trim. Second ss is starting + ending trim

Upvotes: 5

Related Questions