Created
December 27, 2016 22:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sharonhe Check this