diff --git a/audiovideo.md b/audiovideo.md new file mode 100755 index 0000000..ca8be92 --- /dev/null +++ b/audiovideo.md @@ -0,0 +1,70 @@ +This script transcodes the audio to opus and changes the bitrate according to how many channels the audio has +========================== + +scripts that i might need later for transcoding + +Common Transcoding commands +--------------------------- + + +### Transcode input to av1 and transcode the audio to opus with bitrate correction (used for eureka) +``` +#!/bin/bash +#script written by logan but typed by zombie +#optimezed for teentitans +for i in *mkv; do + av1an -i "$i" -o av1/"$(basename "$i")" -e aom -c mkvmerge --passes=2 -v "--threads=2 --cpu-used=5 --end-usage=q --cq-level=24 --enable-fwd-kf=1 --aq-mode=1 --lag-in-frames=48 --bit-depth=10 --kf-max-dist=240 --kf-min-dist=12 --enable-qm=1 --sb-size=64 --enable-keyframe-filtering=2 --arnr-strength=2 --arnr-maxframes=3 --sharpness=1 --enable-dnl-denoising=0 --denoise-noise-level=5" -a "-c:a libopus -b:a:0 128k -af aformat=channel_layouts='7.1|5.1|stereo'" --chunk-order random -m lsmash -r +done +``` +For the file in question, all audio tracks will be transcoded to opus. It may be useful to delete unnecessary tracks before transcoding. For example, in the case of Eureka, there were multiple tracks with different channel layouts, one that opus doesnt really support so you might as well delete the one that opus doesnt support, but it still will transcode. +``` +for i in *mkv; do mkvmerge -o "$(basename "$i").balls" --audio-tracks 1 "$i"; done +``` +to delete the unwanted tracks +you can use the `mkvinfo` command to get the track you want to remove + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ball b/ball new file mode 100755 index 0000000..59a602c --- /dev/null +++ b/ball @@ -0,0 +1,155 @@ +This script transcodes the audio to opus and changes the bitrate according to how many channels the audio has +========================== + +scripts that i might need later for transcoding + +Common Transcoding commands +--------------------------- + + +### Transcode input to av1 and transcode the audio to opus with bitrate correction (used for eureka) +``` +#!/bin/bash + +# Set bitrate for different channels +BITRATE_1CHANNEL="64k" +BITRATE_2CHANNEL="135k" +BITRATE_6CHANNEL="265k" + +# Temporary directory for converted tracks +tmpdir=$(mktemp -d) +outputdir=av1/ + +mkdir -p $outputdir +echo "Temp dir $tmpdir" +echo "tmpdir\/file $tmpdir/$file" +echo "output dir $outputdir/$(basename "$file")" + +ulimit -n 10000 +for file in *.mkv; do + # Check if the file has already been processed + if [ -f "$outputdir/$(basename "$file")" ]; then + echo "$file has already been transcoded, skipping..." + continue + fi +############################################################################### +# audio wizard magic! # +# wont work on truehd or dolby atmos or anything with more than 6 channels :( # +############################################################################### + n_tracks=$(ffprobe -loglevel error -show_streams "$file" | grep -c 'codec_type=audio') + + # Transcode each audio track to Opus + input_files=(-i "$file") + map_args=(-map 0:v -map 0:s -c:v copy -c:s copy) + for ((i=0;i<$n_tracks;i++)); do + n_channels=$(ffprobe -loglevel error -show_streams -select_streams a:"$i" "$file" | grep 'channels=' | cut -f2 -d=) + output="$tmpdir/${file%.mkv}_track$i.opus" + + # Choose bitrate based on number of channels + case "$n_channels" in + 1) bitrate="$BITRATE_1CHANNEL";; + 2) bitrate="$BITRATE_2CHANNEL";; + 6) bitrate="$BITRATE_6CHANNEL";; + *) echo "Unsupported channel number: $n_channels"; continue ;; + esac + + echo "Transcoding audio track $i from $file ($n_channels channels) to Opus ($bitrate)..." + if [ "$n_channels" -eq 6 ]; then + ffmpeg -loglevel error -i "$file" -map 0:a:$i -af "channelmap=channel_layout=5.1" -c:a libopus -b:a "$bitrate" -mapping_family 1 "$output" + else + ffmpeg -loglevel error -i "$file" -map 0:a:$i -c:a libopus -b:a "$bitrate" "$output" + fi + + input_files+=(-i "$output") + map_args+=(-map $((i+1)):a -c:a:$(($i)) copy) + done + + # Merge the transcoded audio tracks, original video track, and original subtitle track back into an MKV file + + ffmpeg -loglevel error "${input_files[@]}" "${map_args[@]}" "$tmpdir/$file" + +############################ +# av1an # +############################ + + echo "Audio done! AV1 Time!" + echo "tmpdir\/file $tmpdir/$file" + echo "output dir $outputdir/$(basename "$file")" + av1an -i "$tmpdir/$file" -o "$outputdir/$(basename "$file")" -e aom -c mkvmerge --passes=2 -v "\ + --threads=2\ + --cpu-used=5\ + --end-usage=q\ + --cq-level=24\ + --enable-fwd-kf=1\ + --aq-mode=1\ + --lag-in-frames=48\ + --bit-depth=10\ + --kf-max-dist=240\ + --kf-min-dist=12\ + --enable-qm=1\ + --sb-size=64\ + --enable-keyframe-filtering=2\ + --arnr-strength=2\ + --arnr-maxframes=3\ + --sharpness=1\ + --enable-dnl-denoising=0\ + --denoise-noise-level=5\ + "\ + --chunk-order random -m lsmash -r +done + +# Clean up the temporary directory +rm -r "$tmpdir" +``` +For the file in question, all audio tracks will be transcoded to opus. It may be useful to delete unnecessary tracks before transcoding. For example, in the case of Eureka, there were multiple tracks with different channel layouts, one that opus doesnt really support so you might as well delete the one that opus doesnt support, but it still will transcode. +``` +for i in *mkv; do mkvmerge -o "$(basename "$i").balls" --audio-tracks 1 "$i"; done +``` +to delete the unwanted tracks +you can use the `mkvinfo` command to get the track you want to remove + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/researchscripts.md b/researchscripts.md new file mode 100755 index 0000000..4d76ca5 --- /dev/null +++ b/researchscripts.md @@ -0,0 +1,75 @@ +Neat comparison commands +------------------------ + + + + +this command will take a input video and transcode it for every crf value in a range + +crfleveltest.sh +``` +#!/bin/bash + +for i in {0..63} +do + echo da real time bro $i >> timetime + date >> timetime + ffmpeg -i originalencoding.mkv -c:a copy -c:v libsvtav1 -preset 8 -crf $i svtav1/crftest/svtav1_$i.mkv + #echo \n >> timetime +done +``` +this will take a specific frame out off all the videos in a folder which is useful for comparing the crf values on a specific frame +frameextractor.sh +``` +#!/bin/bash + +output_directory="png" + +for video in *mkv; do + filename=$(basename -- "$video") + filename_no_ext="${filename%.*}" + ffmpeg -ss 00:00:10 -i "$video" -vframes 1 "$output_directory/$filename_no_ext.png" +done +``` +this will take all the file names of the pngs and put them into subtitles so you cam see what video (crf value typically) the current frame was from +subtitles.py +``` +import os + +# Assuming files are in the current directory. +# Modify this path to the location of your PNG files if needed. +files = sorted([f for f in os.listdir('.') if f.endswith('.png')]) + +# Start time for each subtitle in seconds +start_time = 0.0 + +# The duration each subtitle is displayed for in seconds +duration = 0.1 + +with open('subtitles.srt', 'w') as f: + for i, filename in enumerate(files, start=1): + # Format start and end times + start_h = int(start_time // 3600) + start_m = int((start_time % 3600) // 60) + start_s = int(start_time % 60) + start_ms = int(round((start_time % 1) * 1000)) + start = "{:02d}:{:02d}:{:02d},{:03d}".format(start_h, start_m, start_s, start_ms) + + end_time = start_time + duration + end_h = int(end_time // 3600) + end_m = int((end_time % 3600) // 60) + end_s = int(end_time % 60) + end_ms = int(round((end_time % 1) * 1000)) + end = "{:02d}:{:02d}:{:02d},{:03d}".format(end_h, end_m, end_s, end_ms) + + # Write subtitle entry + f.write(f"{i}\n{start} --> {end}\n{filename}\n\n") + + # Update start time for next subtitle + start_time += duration +``` +this will combine all the pngs and subtitles to a video to be watched just make sure the framerates match between this command and rhe ones specified in the subtitle command +pngcombiner +``` +ffmpeg -framerate 10 -i svtav1_%02d.png -i subtitles.srt -c:v libx264 -crf 10 output.mkv +```