Saturday, September 27, 2014

Download and merge multiple video files (from twitch or youtube)

Last year I posted how to download and merge clips manually, recently I threw together a script that takes a twitch video, downloads the mp4 files, and them merges them all.

You'll have to download and compile ffmpeg which is a hassle, but since I use this script often it's worth the trouble.

#!/bin/bash
tempfolder=$(mktemp -d --tmpdir=./)

pushd $tempfolder
read -p "Input the date (YYYY-MM-DD): " date
echo "files:"
youtube-dl -e $@    # lists the file titles
echo "choosing one"
default_name=$(youtube-dl -e $@ 2>&1| head -1)
read -p "Name is $default_name. Override?: " name
if [ -z "$name" ]; then
    name=$default_name
fi

youtube-dl $@
file=$(mktemp --tmpdir=./)
for i in *.flv; do
    echo "file '$i'";
done > $file
ffmpeg -f concat -i $file -c copy "$date - $name.mp4"
mv "$date - $name.mp4" ..

popd
rm -r $tempfolder

The script will actually take multiple links as well, and concat them in order according to the twitch IDs.

No comments:

Post a Comment