I've read again the answer you linked, and I think it actually is a better answer than mine to your question. The only difference is that you need to execute the command ffmpeg
twice in the code that's written there.
This answer on SuperUser shows you how to use the -t
and -ss
options of ffmpeg
, and gives some useful info about it.
I've tried it myself, but the second part of the video is not good, as I hear the sound with a steady photogram. As I'm not expert of video encoding/deconding, I really can't help you further.
I've update my original answer below to include the two commands I referred to earlier, plus some comments.
Maybe there's an easier way to get it done, but you can write a bash
script to do what you want.
You can start with something like this:
#!/bin/bash
file=$1
filename=${1%.*}
extension=${1##*.}
splitTime=$(ffmpeg -i $file 2>&1 \
| sed -n 's/^ *Duration: *\([^,]*\).*$/\1/p' \
| awk -F: '{ print $1*3600 + $2*60 + $3 - 2.24 }')
ffmpeg -t $splitTime -i $file -c copy $filename.part1.$extension
ffmpeg -ss $splitTime -i $file -c copy $filename.part2.$extension
which stores the duration of the video, reduced by 2.24 seconds, in the variable splitTime
, and then uses it for two ffmpeg
commands.
Note that ffmpeg
accepts duration
s in 2 formats for both the -t
and -ss
options (look at man ffmpeg
, which references man ffmpeg-utils
).
They script the way I've set it up is meant to be used with a single file, whose name is in the format basename.extension
. You can clearly call it from something like this:
for f in *.mp4; do
that_script $f
done
or you can wrap the original into the for
loop and adapt it to your needs.