Skip to content

Instantly share code, notes, and snippets.

@AdySan
Created December 27, 2016 22:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AdySan/7a8aa6013008bb73bc77dc648ed98375 to your computer and use it in GitHub Desktop.
Save AdySan/7a8aa6013008bb73bc77dc648ed98375 to your computer and use it in GitHub Desktop.
Bash script to trim last few seconds of video files (.mp4) downloaded with you-get using ffmpeg
#!/bin/bash
for f in *.mp4; do
duration=$(ffmpeg -i "$f" 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//)
length=$(echo "$duration" | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }' )
trim_start=0
trim_end=$(echo "$length" - 18 - "$trim_start" | bc)
ffmpeg -ss "$trim_start" -i "$f" -c copy -map 0 -t "$trim_end" "${f%.mp4}-trimmed.mp4"
done
@AdySan
Copy link
Author

AdySan commented Dec 27, 2016

@sharonhe Check this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment