I have a bunch of mp4 clips from my switch and wanna combine them into 1minute videos.
Code
# Clear previous filelist.txt if it exists
if (Test-Path filelist.txt) {
Remove-Item filelist.txt
}
# Create a filelist.txt for pairing
$count = 0
$fileList = Get-ChildItem *.mp4 | Select-Object -ExpandProperty FullName
# Check if there are enough files to pair
if ($fileList.Count -lt 2) {
Write-Warning "Not enough MP4 files to combine."
exit
}
# Combine every two files
$outputDir = "C:\Users\cyber\Videos\combined"
$logFile = "ffmpeg_log.txt"
for ($i = 0; $i -lt $fileList.Count; $i += 2) {
# Create pairlist.txt
$pairList = @($fileList[$i], $fileList[$i+1])
Add-Content pairlist.txt $pairList
# Log the pairlist content for debugging
Write-Host "Creating pairlist.txt with:"
$pairList | ForEach-Object { Write-Host $_ }
# Combine the pair using FFmpeg
$outputFile = "$outputDir\output_$(($i / 2) + 1).mp4"
$result = & ffmpeg -f concat -safe 0 -i pairlist.txt -c copy $outputFile 2>&1 | Out-File -FilePath $logFile -Append
if ($result.ExitCode -ne 0) {
Write-Warning "FFmpeg failed to combine files. Check the log file $logFile for details."
# You can add more specific error handling here, e.g., reading the log file and extracting error messages.
}
# Remove the pairlist.txt and the processed files from the filelist
Remove-Item pairlist.txt
$fileList = $fileList | Select-Object -Skip 2
}
Write-Host "Combining complete. Output files are in: $outputDir"
file names are: 2024103015292500_s.mp4, 2024103015352500_s.mp4
working script will be paid some FG