Created
April 23, 2024 07:10
-
-
Save apeckham/a3f93c87d3b742c2a7f8c79534d7d463 to your computer and use it in GitHub Desktop.
Merge MKV video files with a random OPUS audio file, creating new video files with varied background audio
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 | |
set -euo pipefail | |
# Define directories | |
video_dir="./video" | |
audio_dir="./audio" | |
# Create an array of all opus files | |
mapfile -t music_files < <(find "$audio_dir" -type f -name '*.opus') | |
# Loop over all mkv video files in the video directory | |
for video_file in "$video_dir"/*/*.mkv; do | |
# Select a random music file | |
random_idx=$((RANDOM % ${#music_files[@]})) | |
random_music="${music_files[$random_idx]}" | |
# Define the output file path | |
output_file="${video_file%.*}_new.mkv" | |
# Log the process | |
echo "Processing: $video_file with $random_music" | |
# Execute ffmpeg command | |
ffmpeg -i "$video_file" -i "$random_music" -map 0:v -map 1:a -c:v copy -c:a aac -shortest "$output_file" -y | |
done |
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
yt-dlp -x \ | |
"https://www.youtube.com/watch?v=fRg0K5rgXog&pp=ygUoQmVldGhvdmVuJ3MgU3ltcGhvbnkgTm8uIDYgKCJQYXN0b3JhbCIpIA%3D%3D" \ | |
"https://www.youtube.com/watch?v=ea2WoUtbzuw&pp=ygUfQ2xhdWRlIERlYnVzc3kncyAiQ2xhaXIgZGUgTHVuZQ%3D%3D" \ | |
"https://www.youtube.com/watch?v=FS6o3qFimsc&pp=ygUbRXJpayBTYXRpZSdzICJHeW1ub3DDqWRpZXMi" \ | |
"https://www.youtube.com/watch?v=Qut5e3OfCvg" \ | |
"https://www.youtube.com/watch?v=XOVndSdAq2Q&pp=ygUoUHlvdHIgSWx5aWNoIFRjaGFpa292c2t5J3MgIlRoZSBTZWFzb25zIg%3D%3D" \ | |
"https://www.youtube.com/watch?v=O7YZ9FQIO-8" \ | |
"https://www.youtube.com/watch?v=B0V24-WaYH0" \ | |
"https://www.youtube.com/watch?v=O7YZ9FQIO-8&pp=ygUXVGNoYWlrb3Zza3kncyBzd2FuIGxha2U%3D" \ | |
"https://www.youtube.com/watch?v=9IhmroynRtc" \ | |
"https://www.youtube.com/watch?v=36ofZvGldnU" \ | |
"https://www.youtube.com/watch?v=qVn2YGvIv0w" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment