Reputation: 1
I have no history with ffmpeg, but I am assuming this would be the right tool for the job. I am trying to cut a folder of videos with different lengths. I want to cut them all to be 12 seconds from the end. That is: on a 30 second video I would be left with 00:18 - 00:30. 00:00-00:17 would be deleted.
I am on mac OS Mojave. It seems that ffmpeg is the right tool for the job to batch edit these videos. Can someone walk me through this? I have some basic understanding but will need the code/script explained so that I can apply it to my own use. Thank you very much.
Upvotes: 0
Views: 992
Reputation: 1074
Get duration from input. Calc time position with bc utility: $(echo "$DUR" -12 | bc -l)
#!/bin/bash
for f in *.mkv; do
DUR="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$f")"
ffmpeg -ss $(echo "$DUR" -12 | bc -l) -i "$f" -map 0 -c copy "${f%.*}_trim.mkv"
done
will copy from key frame, so will not equal 12 sec. for accuracy you will have to convert, replace "-c copy" with something like "-c:v h264_nvenc -cq 18 -c:a aac -q:a 4" or what you want.
#!/bin/bash
for f in *.mkv; do
ffmpeg -sseof -12 -i "$f" -map 0 -c:v h264_nvenc -cq 18 -c:a aac -q:a 4 "${f%.*}_trim.mkv"
done
Thanks to Gyan
[add info]
Create the above script in folder with videos. Or run one string, edit for every file:
ffmpeg -sseof -12 -i "input.mp4" -map 0 -c:v libx264 -b:v 3M -c:a aac -b:a 320k "output.mkv"
Upvotes: 2