I'm new to FFmpeg and trying to figure this out. I found this for Batch processing and this answer for rotation of video but I need to put them together.
Could someone please explain how to create a script for this action, on Windows?
I'm new to FFmpeg and trying to figure this out. I found this for Batch processing and this answer for rotation of video but I need to put them together.
Could someone please explain how to create a script for this action, on Windows?
Basically, you just need to look the files up, (store them in a variable,) and then feed those looked up files into FFmpeg.
Of course, Windows's Batch-language would be sufficient for that. But since I have zero proficiency with that, here's a PowerShell-Script:
# Searching for files with the Get-ChildItem cmdlet and saving their relevant properties in an array:
# NOTE: -File will only work with PowerShell-versions >= 3.
[array]$FilesToRotate = Get-ChildItem -Path "C:\PATH_TO_FILES" ((-Filter *.mp4)) ((-Recurse)) -File | ForEach-Object {
# NOTE: This part is a bit tricky - I just added it so I'm able to save the parent-path of each file in an object.
# NOTE: One could also omit the whole ForEach-Object and use the Split-Path cmdlet inside the output-file's specification in FFmpeg's code.
[PSCustomObject]@{
InFullName = $_.FullName
# Will put the output-file in the same folder as the input-file and add "_ROTATION" as suffix in its name.
OutFullName = "$(Split-Path -Parent -Path $($_.FullName))\$($_.BaseName)_ROTATE$($_.Extension)"
}
}
# Processing the files with FFmpeg using PowerShell's Start-Process cmdlet:
for($i=0; $i -lt $FilesToRotate.Length; $i++){
Start-Process -FilePath "C:\PATH_TO_FFMPEG\ffmpeg.exe" -Argumentlist " -i `"$($FilesToRotate[$i].InFullName)`" -c copy -metadata:s:v:0 rotate=<x> `"$($FilesToRotate[$i].OutFullName )`" " ((-Wait)) ((-NoNewWindow))
}
This script will run FFmpeg with the code you provided (I did not check it, but you can easily replace it anyway) and save the resulting file into the same folder with the name-suffix "_ROTATE" - so "MyMovie2017.mov" will become "MyMovie2017_ROTATE.mov". (If you want to render them to a whole new folder, replace $($FilesToRotate[$i].ParentPath) with the path you like.)
Notes: things in doubled parentheses (( )) are optional:
-Filter will only adress (one) specific type of files, e.g. *.mp4 will only find MP4-Files. If you have more than one file-type, but many files you do not need to convert (like text-files), you could either -Exclude all formats you don't want to convert or -Include only those which should be converted (-Include is like -Filter - it is slower, but can include more than one format.)-Recurse will also look into subfolders. You could also use -Depthwith PowerShell v 5+.-Wait will open one ffmpeg-instance at a time - without it, all instances will be opened parallel.-NoNewWindow will show the output of your ffmpeg-instance at the PowerShell-Console, while without it, every instance of ffmpeg will open in a new console-window. Makes sense only with -Wait.You will have to delete all doubled parentheses (and the content of them if you don't want it) before starting the script.
Also, these things need to be adapted:
C:\PATH_TO_FILES Path to your files, obviously.C:\PATH_TO_FFMPEG\ffmpeg.exe Path to your ffmpeg.exe, obviously.rotate=<x> - you need to replace the <x> with either 90, 180, or 270. (As explained at the code's source)If anything needs more explanation, I'm happy to help.
npx rotate-video --source=source_path --destination=destination_path --extension=MP4 --angel=270
Note: You need to install FFMPEG CLI first install