If I want to keep processing h264 as it is now, but add hevc and process it another way, and process everything else just like it is now, how can I do it?
" If (Test-Path ffmpegLog) {
Try {
Remove-Item -LiteralPath ffmpegLog -Force
} Catch {
ErrorMessage=_.Exception.Message
LogWrite "Error while removing old FFMPEG Log: ffmpegLog"
Exit 1
}
}
# Determine the codec of the input file
$codecName = $(ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 "$fullName").Trim()
# Set hardware acceleration options based on codec
If ($codecName -eq "h264") {
$VideoEncoder = "h264_qsv"
$hwaccel_options = @("-hwaccel", "qsv", "-hwaccel_device", "auto")
}
Else {
$VideoEncoder = $global:VideoLibrary
$hwaccel_options = ""
}
# Scan the file with FFmpeg
If ($global:LimitCPU) {
ffmpeg.exe -v error $hwaccel_options -i $fullName -max_muxing_queue_size 1024 -f null -threads $global:CPULimit - >$ffmpegLog 2>&1
}
Else {
ffmpeg.exe -v error $hwaccel_options -i $fullName -max_muxing_queue_size 1024 -f null - >$ffmpegLog 2>&1
}
# Check to see if the ffmpeg error log was empty"
To process h264 files as you currently do, add special processing for hevc files, and handle all other codecs the same way you currently do, you need to adjust your conditional logic to include a separate case for hevc. Here’s how you can modify your script:
Add an ElseIf block for hevc: Insert an ElseIf statement to check if the codec is hevc.
Set the processing parameters for hevc: Within this new block, define how you want to process hevc files differently by setting the $VideoEncoder and $hwaccel_options variables accordingly.
Keep processing for other codecs the same: Ensure that the Else block remains as is so that all other codecs are processed the same way they have been.
Here's the updated code:
powershell
# Determine the codec of the input file
$codecName = $(ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 "$fullName").Trim()
# Set hardware acceleration options based on codec
If ($codecName -eq "h264") {
# Processing for h264 (same as before)
$VideoEncoder = "h264_qsv"
$hwaccel_options = @("-hwaccel", "qsv", "-hwaccel_device", "auto")
}
ElseIf ($codecName -eq "hevc") {
# Special processing for hevc
$VideoEncoder = "hevc_qsv"
$hwaccel_options = @("-hwaccel", "qsv", "-hwaccel_device", "auto")
# Add any additional options specific to hevc processing if needed
# For example:
# $additional_options = @("-some_hevc_specific_option")
}
Else {
# Processing for other codecs (same as before)
$VideoEncoder = $global:VideoLibrary
$hwaccel_options = ""
}
# Scan the file with FFmpeg
If ($global:LimitCPU) {
ffmpeg.exe -v error $hwaccel_options -i $fullName -max_muxing_queue_size 1024 -f null -threads $global:CPULimit - >$ffmpegLog 2>&1
}
Else {
ffmpeg.exe -v error $hwaccel_options -i $fullName -max_muxing_queue_size 1024 -f null - >$ffmpegLog 2>&1
}
# Continue with the rest of your script
Explanation:
If ($codecName -eq "h264"): This block remains unchanged and continues to process h264 files as before.
ElseIf ($codecName -eq "hevc"): This new block checks if the codec is hevc and sets the $VideoEncoder to "hevc_qsv" (assuming you want to use Intel Quick Sync Video for HEVC encoding) and defines the hardware acceleration options.
Else: This block remains the same and handles all other codecs as before.
Note:
Adjust the $VideoEncoder and $hwaccel_options values in the hevc block to suit how you want to process hevc files differently.
If the processing for hevc requires additional FFmpeg options, you can define them using a new variable (e.g., $additional_options) and include it in your FFmpeg command.
By modifying your script in this way, you can keep the processing for h264 files the same, introduce special handling for hevc files, and maintain the existing processing for all other codecs.