Can a Win10 GURU automate this solution for splitting videos upon resolution changes?

2

1

Can a Windows10 Guru help automate this?

I have failed at automating Lord Neckbeard's solution in the following post: How to split video files upon detected change in resolution? (ie. recorded streams containing multiple widths)

Ideally, I should either run the batch file on an entire directory of videos, or at least drop the video onto a batch file in file explorer.

EXAMPLE FILE (temporarily available): Example.flv

Failures:
I fell back on Powershell as a last resort, but that leads to code signing issues.
I tried extracting the unique changes using a batch file, but I couldn't get the variables to retain their values inside loops or subroutines. One of many attempts:

SETLOCAL ENABLEDELAYEDEXPANSION
SET lastres=none
FOR /F "eol=; tokens=1,2,3 delims=, " %%i in (allkeyframes.txt) do ( 
  if %j == %lastres% (echo "ignore") ELSE (
        set lastres=%%j
        echo %%j %%i %%k 
        echo !lastres!  
  ) 
) 

I tried extracting the contents of resolutionchanges.txt using SET /P segs=<resolutionchanges.txt but all I got were special characters and 0's.

SET /P segs=<resolutionchanges.txt
set filenam=%1
echo %segs%
echo %filenam%
echo S:\_sys\ffmpeg\bin\ffmpeg -i %1 -map 0 -c copy -segment_times %segs% -reset_timestamps 1 -f segment %filenam%_%%03d.flv
)
pause

Here is the currently working "manual" process:

drag video onto a batch file that contains:

ffprobe -v error -show_entries frame=pkt_pts_time,width,height -select_streams v -of csv=p=0 %1 > allkeyframes.txt

(allkeyframes.txt sample...)

13.652000,640,480
13.755000,640,480
13.597000,480,360
13.652000,480,360

paste this text in POWERSHELL:

$o=""
$n=0
foreach($line in (Get-Content allkeyframes.txt)){
  $nline = $line.Split(",")
  $nline2=($nline[1]+$nline[2])
  if ($nline2 -ne $preventry) {
    $n0=$nline[0]
    $o="$o,$n0"
    $n=$n0
}
  $preventry = $nline2
}
if ($o.length -gt 1){
echo $o.Remove(0,1) > resolutionchanges.txt
} else {
Write-Host "No resolution changes found" -ForegroundColor Red
}

(resolutionchanges.txt:)

13.597000,25.618000,33.628000,45.598000

enter the following in the command window, after pasting contents of resolutionchanges.txt and changing "input.flv" to the video name (Win10 refused my attempts at batching this):

ffmpeg -i input.flv -map 0 -c copy -segment_times 13.597000,25.618000,33.628000,45.598000 -reset_timestamps 1 -f segment output_%03d.flv

EverT

Posted 2018-02-28T23:25:50.967

Reputation: 61

Question was closed 2018-03-18T15:37:07.957

Because this is still about the same question as before, you should comment your issues on that other post so that Lord Neckbeard can improve his answer and get a fully working solution. – music2myear – 2018-02-28T23:55:25.080

@music2myear The original question was essentially two questions so I suggested it be broken up into two parts: 1) how to use ffmpeg to split videos based on when video width x height changes (which has been answered), and 2) how to implement this into a Windows script (which I know nothing of). – llogan – 2018-03-01T00:05:56.343

@EverT Would it be possible to upload a short sample video to play around with it? – nixda – 2018-03-01T00:13:54.700

@nixda I added a 3Meg example mixed resolution file in the post. – EverT – 2018-03-03T00:30:15.323

No answers