8

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

rinofcan
  • 323
  • 1
  • 3
  • 9

2 Answers2

5

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

Gyan
  • 85,394
  • 9
  • 169
  • 201
2

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.

Chris
  • 3,184
  • 4
  • 26
  • 24