" # Scan the file with FFMPEG
If (global:LimitCPU) {
ffmpeg.exe -v error -hwaccel qsv -hwaccel_device auto -i fullName -max_muxing_queue_size 1024 -f null -threads global:CPULimt−>ffmpegLog 2>&1
}
Else {
ffmpeg.exe -v error -hwaccel qsv -hwaccel_device auto -i ffmpegLog 2>&1
}"
Assistant
fullName−maxmuxingqueuesize1024−fnull−>
It uses Intel QSV, so any H264 files that are video stream format "AVC" runs perfectly, but any H264 files that are video stream format "VC-1" gives errors, as Intel QSV do not fully support it. How can I change that part of the script so that if it detects it's "AVC" it runs with hardware transcoding ("-hwaccel qsv -hwaccel_device auto"), but if it detects that it's "VC-1" then it runs without hardware transcoding?
Here is an exempt from the script where this part is located:
"# Function to check a supplied video object with ffmpeg.exe
Function CheckFile {
Param (
[Object]VideoFile,[switch]AutoRepaired,
[switch]$RescanVideo
)
# If the file is a new file being check, clear out the variables
If (!($AutoRepaired)) {
$global:RepairLength = $null
$global:RepairedFile = $null
$global:OrigLength = $null
$global:OriginalFile = $null
}
# Reset the Deleted value
$Deleted = $false
# Get the full name of the Video Object with path included
$fullName = $VideoFile.FullName
# Get only the name of the video file
$fileName = $VideoFile.Name
# Counter for the number of files that have been scanned
$global:VideoCount = $global:VideoCount + 1
# Save the length and object of the video file to make sure the repaired video file length matches original
If ($AutoRepaired) {
$global:RepairLength = GetLength $VideoFile
$global:RepairedFile = $VideoFile
}
Else {
$global:OrigLength = GetLength $VideoFile
$global:OriginalFile = $VideoFile
}
If ($RescanVideo) {
Update-VideoArray -VideoFile $VideoFile -Status "Re-Scanning"
} Else {
Update-VideoArray -VideoFile $VideoFile -Status "Scanning"
}
LogWrite "Scanning File: $fullName" -Log
Write-ScanOutput -Scanning
If (Test-Path $ffmpegLog) {
Try {
Remove-Item -LiteralPath $ffmpegLog -Force
} Catch {
$ErrorMessage = $_.Exception.Message
LogWrite "Error while removing old FFMPEG Log: $ErrorMessage" -Colour "Red"
LogWrite "Scan cannot continue without the ability to modify: $ffmpegLog"
Exit 1
}
}
# Scan the file with FFMPEG
If ($global:LimitCPU) {
ffmpeg.exe -v error -hwaccel qsv -hwaccel_device auto -i $fullName -max_muxing_queue_size 1024 -f null -threads $global:CPULimt - >$ffmpegLog 2>&1
}
Else {
ffmpeg.exe -v error -hwaccel qsv -hwaccel_device auto -i $fullName -max_muxing_queue_size 1024 -f null - >$ffmpegLog 2>&1
}
# Check to see if the ffmpeg error log was empty
If ($Null -eq (Get-Content $ffmpegLog)) {
# Get information to log to the CSV file
$FileSize = "{0:N2}" -f (($VideoFile | Measure-Object -property length -sum ).sum / 1MB)
$Date = $((Get-Date).ToString('yyyy-MM-dd'))"
You can modify your script to detect the video codec using ffprobe and adjust the ffmpeg command accordingly. Here's how you can do it:
Add Codec Detection Before the FFMPEG Scan:
Before you run the ffmpeg command, use ffprobe to detect the video codec of the file. You can do this by adding the following code to your script:
# Get codec_name using ffprobe
$codec_name = (ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 $fullName).Trim()
If ($codec_name -eq "h264") {
# Use hardware acceleration
$hwaccel_options = "-hwaccel qsv -hwaccel_device auto"
}
Else {
# Do not use hardware acceleration
$hwaccel_options = ""
}
This code runs ffprobe on the video file $fullName and retrieves the codec name of the first video stream. It then checks if the codec is h264 (which corresponds to AVC). If it is, it sets $hwaccel_options to include the hardware acceleration parameters. Otherwise, it leaves $hwaccel_options empty.
Adjust the FFMPEG Command to Include the Hardware Acceleration Options Conditionally:
Modify your ffmpeg command to include the $hwaccel_options variable:
This way, if the codec is h264, the hardware acceleration options (-hwaccel qsv -hwaccel_device auto) are included in the ffmpeg command. If the codec is vc1 or any other format, those options are omitted.
Complete Modified Section of Your Script:
Here is how the modified section of your script would look:
# ... [previous code] ...
# Get codec_name using ffprobe
$codec_name = (ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 $fullName).Trim()
If ($codec_name -eq "h264") {
# Use hardware acceleration
$hwaccel_options = "-hwaccel qsv -hwaccel_device auto"
}
Else {
# Do not use hardware acceleration
$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:CPULimt - >$ffmpegLog 2>&1
}
Else {
ffmpeg.exe -v error $hwaccel_options -i $fullName -max_muxing_queue_size 1024 -f null - >$ffmpegLog 2>&1
}
# ... [rest of your code] ...
Explanation:
ffprobe Command: This command extracts the codec name of the first video stream in the file. The options used are:
-v error: Suppresses all non-error messages.
-select_streams v:0: Selects the first video stream.
-show_entries stream=codec_name: Shows only the codec_name field from the stream.
-of default=noprint_wrappers=1:nokey=1: Formats the output to only show the value, without any keys or wrappers.
Checking the Codec Name:
If the codec name is h264, it sets $hwaccel_options to include the hardware acceleration options.
If the codec name is anything else (like vc1), it leaves $hwaccel_options empty.
Modifying the ffmpeg Command:
The $hwaccel_options variable is included in the ffmpeg command.
If $hwaccel_options is empty, it effectively removes the hardware acceleration options from the command.
Note:
Make sure you have ffprobe available in your environment (it's usually included with ffmpeg).
Test the modified script with both AVC and VC-1 files to ensure it behaves as expected.
This method can be extended to handle other codecs and hardware acceleration options if needed.
By making these changes, your script will now conditionally use hardware acceleration based on the video codec of the file, resolving the errors you encountered with VC-1 files.