Last active
January 9, 2017 12:42
-
-
Save fordaz/1aaf23ad7f9a5353b7090ec56c180f09 to your computer and use it in GitHub Desktop.
concat multiple mp4 into a single one, extract audio as mp3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# default group size (no grouping) | |
group_size=-1 | |
# required to deal with file names containing blanks | |
OIFS="$IFS" | |
IFS=$'\n' | |
# parsing the -g command line argument | |
for i in "$@" | |
do | |
case $i in | |
-g=*|--groups=*) | |
group_size="${i#*=}" | |
shift # past argument=value | |
;; | |
-h|--help) | |
echo "Usage: ffmpeg-concat.sh [-g=<n>|--groups=n] | |
The groups parameter allows to concatenate groups of n videos" | |
exit 0 | |
shift # past argument=value | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
done | |
# removing preexisting temporary files | |
rm -f list-a* | |
rm -f all.txt* | |
# ffmpeg input file containing all the .mp4 file names to be converted | |
for f in `ls *.mp4`; do echo "file '$f'"; done > all.txt | |
# default input file name | |
input_files='all.txt' | |
if [ "$group_size" -gt 0 ] | |
then | |
echo "Converting videos in groups of $group_size" | |
split -l 10 all.txt list- | |
input_files='list-*' | |
else | |
echo "Converting all the videos" | |
fi | |
echo "converting files from $input_files" | |
for l in `ls $input_files` | |
do | |
echo "concatenating files from $l"; | |
ffmpeg -f concat -y -loglevel error -safe 0 -i $l -c copy "$l.mp4" | |
echo "extracting audio files"; | |
ffmpeg -loglevel error -i "$l.mp4" -vn "$l.mp3" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment