0

I want to split multiple mp4 videos into smaller chunks of size 30-40 secs after many days I have found an answer which used ffmpeg i.e

ffmpeg -i /home/msz/Downloads/CartoonVideos/1.mp4 -ss 180 -t 30 /home/msz/Downloads/NewCartoonVideos/1-7.mp4

but this is single line command and it's taking too much, I have to change it every time.Can anybody tell me other methods or change this code in script/loop?

1 Answers1

0

Ummm,

#!/usr/bin/bash
N_FRAGS=$1
SEG_LEN=$2
shift 2
for $FILE in "$@" ; do
    SS=0
    for (( segment = 1; segment <= N_FRAGS; ++segment )) ; do
        OUTPUT=$(dirname $FILE)/(basename $FILE .mp4)-$segment.mp4
        ffmpeg -i "$FILE" -ss $SS -t "$SEG_LEN $OUTPUT"
        SS=$((SS + SEG_LEN))
    done
done

Save it, say, under massive_split.sh and call it as

./massive_split.sh 10 30 /home/msz/Downloads/CartoonVideos/*.mp4

Where 10 is the amount of fragments per each file and 30 is each fragment's length.

This probably needs some debugging (haven't tested it), and can be more sophisticated, like auto-detect each file's length (and, consequently, amount of fragments available), pad segment number with zeroes in output file name as needed, etc.

bipll
  • 11,747
  • 1
  • 18
  • 32