# Set the input file path from the first argument param ( [string]$input_file ) # Override input file location # $input_file = "C:\your\override\here" # Get the directory of the input file $inputFileDirectory = Split-Path -Path $input_file -Parent # Define the debug log path in the same directory as the input file $debugLog = Join-Path -Path $inputFileDirectory -ChildPath "stacherPost_log.txt" # Debugging step: Log the input file path "Input file: $input_file" | Out-File -FilePath $debugLog -Append # Run ffprobe to detect codec and log output "Running ffprobe..." | Out-File -FilePath $debugLog -Append $ffprobeOutput = & ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 $input_file # Extract codec information from ffprobe $codec = $ffprobeOutput.Trim() # Log the codec detected "Detected codec: $codec" | Out-File -FilePath $debugLog -Append # If codec is empty or not detected properly, log it and exit if (-not $codec) { "Failed to detect codec or ffprobe error." | Out-File -FilePath $debugLog -Append exit 1 } # Check codec and process if VP9 or AV1. Alter ffmpeg command here if you wish to encode differently. if ($codec -ieq "vp9" -or $codec -ieq "av1") { "Codec is $codec. Proceeding with conversion..." | Out-File -FilePath $debugLog -Append & ffmpeg -hide_banner -threads 0 -hwaccel auto -i $input_file -c:v hevc_nvenc -b_ref_mode 0 -b:v 24000k -profile:v main -level 6.1 -map v:0 -c:a aac -ar 48k -b:a 256k -map a:0 -pix_fmt yuv420p -sws_flags bicubic -tag:v hvc1 -y "$($input_file.Substring(0, $input_file.LastIndexOf('.')))_converted.mp4" } else { "Codec is $codec. Conversion not needed." | Out-File -FilePath $debugLog -Append }