[FFmpeg-user] Trying to cut 5 sec of beginning and ending of mp4 files

Aidan Barrett aidan at 5stream.com
Tue Jan 19 04:51:38 CET 2016

Hi Thomas,

Here is a bash script I made to do something similar
I’ve converted is so that ffmpeg will cut 5 seconds from the start and 10 from the end.


#------>>>> Set the input video


#get fps of input video
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=duration $input)

# ------>>>> Round input to seconds and set as variable


# ------convertsecs converts seconds to hh:mm:ss

convertsecs() {
 printf "%02d:%02d:%02d\n" $h $m $s

echo $inputduration
echo $(convertsecs inputduration)
echo $(convertsecs $((inputduration - 10)))

# ------>>>> Set the in (file locations), -ss start encoding here (hh:mm:ss), -to end encoding here (hh:mm:ss - 10seconds)

ffmpeg -i $input -ss 00:00:05 -to $(convertsecs $((inputduration - 10))) -codec copy "VideoPath/VideoOutput1.mp4”

#------>>>> End of Bash Script!

It will run ffprobe and get the duration of the input video, convert it to seconds, convert that to hh:mm:ss then run ffmpeg and cut off 5 seconds from the start and 10 seconds from the end.

Good luck!


> On 19 Jan 2016, at 7:51 am, tsh at tshilton.com wrote:
> Hi
> I am been trying almost every combination of switches to be able to cut 5
> sec from the start and 5 sec from the ending of variable length mp4 files.
> I have not been successful at doing either.  I guess I really don't
> understand the usage.  I have more than 100 files to do.
> Can anyone suggest a command string that will work?
> Thanks
> Thomas
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

More information about the ffmpeg-user mailing list