Last active
November 14, 2021 13:35
-
-
Save sekaiwish/ae9f30661741fb92abf41aee57525948 to your computer and use it in GitHub Desktop.
Create YouTube MKVs from FLAC album
This file contains hidden or 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 | |
cover=./cover.jpg | |
if [ ! -f "$cover" ]; then | |
cover=./cover.png | |
fi | |
if [ ! -f "$cover" ]; then | |
echo "No cover image found." | |
exit | |
fi | |
for f in *.flac | |
do | |
time=$(date +%s) | |
duration=$(ffprobe -i "$f" -show_entries format=duration -of csv=p=0 -v quiet) | |
album=$(ffprobe -i "$f" -show_entries format_tags=album -of csv=p=0 -v quiet) | |
title=$(ffprobe -i "$f" -show_entries format_tags=title -of csv=p=0 -v quiet) | |
track=$(ffprobe -i "$f" -show_entries format_tags=track -of csv=p=0 -v quiet) | |
disc=$(ffprobe -i "$f" -show_entries format_tags=disc -of csv=p=0 -v quiet) | |
if [ -z "$disc" ]; then | |
final="$album — $track. $title" | |
else | |
final="$album — $disc.$track. $title" | |
fi | |
printf "Track data:\n\tfile: $f\n\ttitle: $title\n\talbum: $album\n\tduration: $duration\n\tdisc: $disc\n\ttrack: $track\n\tfinal title: $final\n" | |
echo "Transcoding $final..." | |
ffmpeg -i "$f" -loop 1 -t "$duration" -i $cover -c:a copy -c:v libvpx-vp9 -s 1080x1080 -v quiet "$final".mkv | |
time=$(($(date +%s)-time)) | |
echo "Took $time seconds." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As YouTube does not support lossless audio, I thought it would be best to demonstrate what I believe the best possible case for uploading a lossless format to YouTube, as a copy of the .flac file with a repeated image, ideally the album cover.
Matroska is NOT listed on the list of supported YouTube formats, though WebM, essentially a subset of the Matroska container, is listed. Even though this is the case, Matroska files CAN be uploaded to YouTube, including ones with FLAC encoded audio.