Skip to main content
ensure the presence of leading zeroes
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

It's simple math: the hour figure is $((i%3600), the minutes are $((i/60%60)), the seconds are $((i%60)). To add a leading zero where needed, a simple trick is to add 100, then strip the leading 1. Do the same with the file name if you want to avoid leading zeroes.

for i in $(seq 10); do
  ffmpeg -i video.mp4 -ss $((i%3600):$minutes=$((i /60%60)):$((i%60)) -t60 00:10:00% -c60 copy+ $100)); minutes=${iminutes#1}.mp4
done

If you want to have leading zeroes in the file name:

for i in $seconds=$(seq 10(i%60)); doseconds=${seconds#1}
  name=$i=$((i+100)); name=$i=${name#1i#1}
  ffmpeg -i video.mp4 -ss $((i%3600):$((i/60%60))$minutes:$((i%60))$seconds -t 00:10:00 -c copy $name${i}.mp4
done

It's simple math:

for i in $(seq 10); do
  ffmpeg -i video.mp4 -ss $((i%3600):$((i/60%60)):$((i%60)) -t 00:10:00 -c copy ${i}.mp4
done

If you want to have leading zeroes in the file name:

for i in $(seq 10); do
  name=$((i+100)); name=${name#1}
  ffmpeg -i video.mp4 -ss $((i%3600):$((i/60%60)):$((i%60)) -t 00:10:00 -c copy $name.mp4
done

It's simple math: the hour figure is $((i%3600), the minutes are $((i/60%60)), the seconds are $((i%60)). To add a leading zero where needed, a simple trick is to add 100, then strip the leading 1. Do the same with the file name if you want to avoid leading zeroes.

for i in $(seq 10); do
  minutes=$((i / 60 % 60 + 100)); minutes=${minutes#1}
  seconds=$((i%60)); seconds=${seconds#1}
  i=$((i+100)); i=${i#1}
  ffmpeg -i video.mp4 -ss $((i%3600):$minutes:$seconds -t 00:10:00 -c copy ${i}.mp4
done
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

It's simple math:

for i in $(seq 10); do
  ffmpeg -i video.mp4 -ss $((i%3600):$((i/60%60)):$((i%60)) -t 00:10:00 -c copy ${i}.mp4
done

If you want to have leading zeroes in the file name:

for i in $(seq 10); do
  name=$((i+100)); name=${name#1}
  ffmpeg -i video.mp4 -ss $((i%3600):$((i/60%60)):$((i%60)) -t 00:10:00 -c copy $name.mp4
done