Outils pour utilisateurs

Outils du site


bash:youtube-dash

Ceci est une ancienne révision du document !


Youtube HD 1080 (DASH)

required: `youtube-dl` and `ffmpeg`

This script creates a folder in /tmp/ (which I have mounted as ramdisk), downloads the separate video and audio streams (see about DASH), copies them into a Matroska container, sets the modtime and moves the resulting file in the current directory.

I recommend putting an alias in <tt>.bashrc</tt> for easier use (I set it as <tt>ytd</tt>). example: `ytd https://www.youtube.com/watch?v=yVpbFMhOAwE`

youtube-dash.run
#!/bin/bash
hashfold=$(echo "$1" | md5sum)
outdir=$(pwd)
mkdir -p "/tmp/youtube-dash/$hashfold"
cd "/tmp/youtube-dash/$hashfold"
 
# downloading the video stream (MP4 1080p, else fallback 720p)
youtube-dl -f 137/136 -o "/tmp/youtube-dash/$hashfold/%(title)s.zvideo" "$1"
 
# downloading the audio stream (MP4A-AAC)
youtube-dl -f 140 -o "/tmp/youtube-dash/$hashfold/%(title)s.zaudio" "$1"
 
for file in *.zvideo; do
	filemtime=$(stat -c %Y "$file")
	ffmpeg -i "$file" -i "${file%.??????}.zaudio" -c:v copy -c:a copy "${file%.??????}.mkv"
	touch -d "@$filemtime" "${file%.??????}.mkv"
	mv "${file%.??????}.mkv" "$outdir/"
	rm -r "/tmp/youtube-dash/$hashfold"
done
bash/youtube-dash.1411165381.txt.gz · Dernière modification : 2014-09-19 22:23 (modification externe)