Skip to content

Instantly share code, notes, and snippets.

@Cyklan
Created June 8, 2020 15:24
Show Gist options
  • Save Cyklan/718538fe37a5702a39a24a5856558dd9 to your computer and use it in GitHub Desktop.
Save Cyklan/718538fe37a5702a39a24a5856558dd9 to your computer and use it in GitHub Desktop.
Stitch multiple video-files together in batches of n
param([int]$episodes_per_file)
$file_count = ( Get-ChildItem .\input | Measure-Object).Count;
$batches = $file_count / $episodes_per_file;
$files = Get-ChildItem .\input |
Foreach-Object {$_.Name}
for ($i = 0; $i -lt $batches; $i++) {
$file_text = 'ffmpeg -i "concat:'
for ($j = 0; $j -lt $episodes_per_file; $j++) {
$file = $files[$i * $episodes_per_file + $j]
$file_text += ".\input\$file|"
}
$file_text = $file_text.Substring(0, $file_text.Length - 1);
$file_text += "`"-c:a copy -c:v copy .\output\$i.mp4"
Invoke-Expression $file_text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment