Add Video_Length field to Get-VideoInfo.ini mapping to frames_count for reading actual encoded frame count directly from ffprobe instead of JSON metadata, with duration calculation using real fps
This commit is contained in:
@@ -2,6 +2,7 @@ Text_Prompt=prompt
|
||||
Model=type
|
||||
Resolution=resolution
|
||||
Number_of_frames=video_length
|
||||
Video_Length=frames_count
|
||||
Seed=seed
|
||||
Frames_Positions=frames_positions
|
||||
Guidance=guidance_scale
|
||||
|
||||
+18
-1
@@ -9,7 +9,9 @@
|
||||
When present, outputs the parsed comment metadata as JSON.
|
||||
.DESCRIPTION
|
||||
This script uses ffprobe to extract video format metadata, parses the comment tag as JSON,
|
||||
and outputs the structured information with proper error handling.
|
||||
and outputs the structured information with proper error handling. Fields configured as
|
||||
'frames_count' in the INI file are read directly from ffprobe (actual encoded frame count)
|
||||
rather than from the JSON metadata.
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -148,6 +150,20 @@ try {
|
||||
|
||||
$displayNameFormatted = $displayName -replace '_', ' '
|
||||
|
||||
if ($jsonFieldName -eq 'frames_count') {
|
||||
# frames_count is read directly from ffprobe (actual encoded frame count)
|
||||
# rather than from the JSON comment metadata.
|
||||
$fps = if ($actualFps) { $actualFps } else { 24.0 }
|
||||
$ffFrames = & ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -of csv=p=0 -- "$VideoPath" 2>&1 | Select-Object -First 1
|
||||
if ($ffFrames -and $ffFrames -match '^\d+$') {
|
||||
$frames = [int]$ffFrames
|
||||
$durationSeconds = [Math]::Round($frames / $fps, 1)
|
||||
$valueDisplay = ('{0} frames ({1}s, {2} fps)' -f $frames, $durationSeconds, $fps)
|
||||
} else {
|
||||
$valueDisplay = 'Not found'
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fieldExists = $parsedComment.PSObject.Properties.Name -contains $jsonFieldName
|
||||
|
||||
if (-not $fieldExists) {
|
||||
@@ -208,6 +224,7 @@ try {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output ('{0}: {1}' -f $displayNameFormatted, $valueDisplay)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user