Skip to content

Instantly share code, notes, and snippets.

@lwr
Forked from ckorn/ytdl
Last active August 29, 2015 14:01
Show Gist options
  • Save lwr/7b1e57ea5540d8b1af55 to your computer and use it in GitHub Desktop.
Save lwr/7b1e57ea5540d8b1af55 to your computer and use it in GitHub Desktop.
compatible with ffmpeg 2.2
#!/bin/bash
#Youtube-DL DASH Video and Audio merging script
#Written by QuidsUp
#Edited by Christoph Korn
#Edited by William Leung
File1New=video.mp4
File2New=audio.m4a
URL=$1
if [ -z $URL ]; then
echo "Usage: ytdl.sh url"
exit
fi
#Find what quality of videos are available
youtube-dl -F $URL
echo
echo -n "Qualtiy for Video (default 137): "
read Qual1
echo -n "Qualtiy for Audio (default 141): "
read Qual2
#Set values if user has just pressed Return without typing anything
if [ -z $Qual1 ]; then
Qual1="137"
fi
if [ -z $Qual2 ]; then
Qual2="141"
fi
#Set filenames from output of youtube-dl
File1=$(youtube-dl --get-filename -f $Qual1 $URL)
File2=$(youtube-dl --get-filename -f $Qual2 $URL)
echo $File1
echo $File2
Out=${File1:0:${#File1}-16}".mp4"
echo $Out
#Download Video file with First Quality Setting
youtube-dl -f $Qual1 $URL
if [[ ! -f $File1 ]]; then
echo
echo "Error video file not downloaded"
exit
fi
mv "$File1" "$File1New"
#Download Audio file with Second Quality Setting
youtube-dl -f $Qual2 $URL
if [[ ! -f $File2 ]]; then
echo
echo "Error audio file not downloaded"
exit
fi
mv "$File2" "$File2New"
File1=$File1New
File2=$File2New
#Merge Audio and Video with ffmpeg
#Delete -threads 0 if you have a Single Core CPU
echo
echo "Combining Audio and Video files with FFMpeg"
ffmpeg -i "$File1" -i "$File2" -q:v 0 -q:a 0 -strict -2 -threads 0 "$Out"
if [[ -f $Out ]]; then
echo
echo "File" $Out "created"
else
echo
echo "Error Unable to combine Audio and Video files with FFMpeg"
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment