d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Powershel Ffmpeg Combing Script Help
Add Reply New Topic New Poll
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 7 2024 12:55pm
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
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 9 2024 02:21pm
bump
Member
Posts: 30,959
Joined: Apr 13 2008
Gold: 11,786.69
Nov 10 2024 07:05am
do you want to concat all files in a single file, or in pairs or something different?
are they all in the same directory?
is there a specific ordering to maintain?
are there other files in that directory that should be ignored?

This post was edited by moutonguerrier on Nov 10 2024 07:06am
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 10 2024 09:50am
Want to read on MP4 files on the folder it's in , no order they are 30sec clips wanna combine 2 to make 1 minute videos and output to a new director inside folder "output" and combined MP4 files go inside those folder output#




Quote (moutonguerrier @ Nov 10 2024 07:05am)
do you want to concat all files in a single file, or in pairs or something different?
are they all in the same directory?
is there a specific ordering to maintain?
are there other files in that directory that should be ignored?




This post was edited by CyberGod on Nov 10 2024 09:50am
Member
Posts: 256
Joined: Sep 20 2023
Gold: 0.00
Warn: 10%
Nov 11 2024 11:47am
why powershell
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 11 2024 04:05pm
Quote (girly @ Nov 11 2024 11:47am)
why powershell


windows :shrug:
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 11 2024 05:32pm
Quote (girly @ Nov 11 2024 11:47am)
why powershell


closed! got it done in python
Member
Posts: 8,271
Joined: May 20 2006
Gold: 0.00
Dec 20 2024 05:09am
what is this in powershell i typed it in but what was it for?
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll