Reputation: 31
I use this command to convert files in batch plus crop and re-scale:
for i in $( ls *.mp4 ); do
ffmpeg -y -i "$i" -acodec libfaac -ab 128k -ar 44100 -vcodec libx264 -b 850k -threads 0 -vf [in]crop=in_w-112:in_h-63:56:0,scale=1280:720[out] "../../archive/${i/.mp4/}.mp4"
done
this command will start at second 15, and makes video 30 seconds long:
for i in $( ls *.mp4 ); do
ffmpeg -ss 00:00:15 -t 30 -y -i "$i" -acodec libfaac -ab 128k -ar 44100 -vcodec libx264 -b 850k -threads 0 -vf [in]crop=in_w-112:in_h-63:56:0,scale=1280:720[out] "${i/.mp4/}_test.mp4"
done
what I would like is a command that cuts off 15s from the beginning and 15s from the end of EACH video from the BATCH ... the trick is that each video has different duration, so "how long it is" must be a variable (duration minus 15s or minus 30s if I count 15s from the start as well)
video duration examples:
video 1 - 00:25:19
video 2 - 00:15:34
video 3 - 00:19:21
video 4 - 00:22:49
etc.
Upvotes: 0
Views: 2197
Reputation: 1426
Couldn't you do this with a simple bash script?
As stated here this command will retrieve the video duration in seconds:
ffprobe -i some_video -show_entries format=duration -v quiet -of csv="p=0"
So you can read that into a variable, then simply withdraw 30 seconds and you will now what duration to set in your ffmpeg command.
So, step 1 will be the first for-loop you have already posted in your question.
Step 2 will be to withdraw 30 seconds from the movies duration and save that in a variable.
Then in step 3, rewrite your second for-loop like this:
for i in $( ls *.mp4 ); do
ffmpeg -ss 00:00:15 -t $your_new_duration_variable -y -i "$i" -acodec libfaac -ab 128k -ar 44100 -vcodec libx264 -b 850k -threads 0 -vf [in]crop=in_w-112:in_h-63:56:0,scale=1280:720[out] "${i/.mp4/}_test.mp4"
done
Upvotes: 1