PDA

View Full Version : Bash: Batch convert webm VP9 to webm VP8 using ffmpeg



rhagelstrom
June 26th, 2023, 00:19
Bash script to batch convert animated assets VP9 to VP8 for FG using ffmpeg.
Linux/OSX Bash Script (https://www.fantasygrounds.com/forums/attachment.php?attachmentid=57952&d=1687734452)
Windows Powershell - By Lo Zeno (https://www.fantasygrounds.com/forums/attachment.php?attachmentid=58109&d=1688552119)

Will recursively batch convert animated assets. Works well for large amounts of assets such as https://jb2a.com
It will copy over existing VP8 assets to the new destination and convert VP9 to VP8. There is option to re-encode VP8 if you wish. You can also adjust some of the encoding settings I have if you don't like them. It will also not copy over anything that isn't a webm file so it cleans out any text files or webp files that may also be there.

Instructions OSX/Linux

Install ffmepg
Download attached convert-vp9.txt and rename it convert-vp9
Make it executable. chmod +x convert-vp9
Run it ./convert-vp9 -i input-folder -o images


Windows should also be possible but it may have to get converted to a powershell script. Someone who has more knowledge than I may be able to do that pretty quickly

Jiminimonka
June 26th, 2023, 22:45
Thanks!

Lo Zeno
June 27th, 2023, 10:52
Bash script to batch convert animated assets VP9 to VP8 for FG using ffmpeg.

Will recursively batch convert animated assets. Works well for large amounts of assets such as https://jb2a.com
It will copy over existing VP8 assets to the new destination and convert VP9 to VP8. There is option to re-encode VP8 if you wish. You can also adjust some of the encoding settings I have if you don't like them. It will also not copy over anything that isn't a webm file so it cleans out any text files or webp files that may also be there.

Instructions OSX/Linux

Install ffmepg
Download attached convert-vp9.txt and rename it convert-vp9
Make it executable. chmod +x convert-vp9
Run it ./convert-vp9 -i input-folder -o images


Windows should also be possible but it may have to get converted to a powershell script. Someone who has more knowledge than I may be able to do that pretty quickly

I have made a powershell conversion of it - very hasted, very brutal and absolutely ugly looking in terms of code and Powershell best practices - I basically converted your bash line-by-line. Ugly, but works fine for what I tested so far.
If I'll have time I'll clean it up.
Once downloaded, the file needs to be renamed from convert-vp9.txt to convert-vp9.ps1

For windows users, the best way to install ffmpeg is to use a package manager:
if you have chocolatey (https://chocolatey.org/) from powershell with admin rights type:

choco install ffmpeg
if you have scoop (https://scoop.sh/), from powershell without admin rights type:

scoop install ffmpeg
if you prefer WinGet, which comes included in Windows 11, from powershell with or without admin rights type:

winget install ffmpeg

EDIT: I've removed the old version of the script, the post just below this has the latest version.

Lo Zeno
June 27th, 2023, 16:49
I've made a better version with some small cleanup to the code and a fix to the parameters passed to ffmpeg which were not passing the transparency correctly.

The instructions to use it are similar to the ones for the bash file, except the commands are run in Powershell:

Install ffmpeg (refer to the post above for ways to do it on Windows)
Download the file and rename it to convert-vp9.ps1
Set your powershell execution policy to allow the script to be run: Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
Run it: convert-vp9.ps1 -i input-folder -o output-folder

Farnaby
June 27th, 2023, 18:09
I am not versed in Powershell.

So I installed ffmpeg with winget, I ran powershell as admin, ran the set-executionpolicy and then ran your script and I get the following error:


ffprobe : The term 'ffprobe' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\RPG\convert-vp9.ps1:43 char:28
+ $vp8 = ffprobe -show_streams -hide_banner -logle ...
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (ffprobe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Any ideas?

[UPDATE]
Uninstalled ffmpeg and then reinstalled using powershell with admin rights and it works now.

Lo Zeno
June 27th, 2023, 20:30
I am not versed in Powershell.

So I installed ffmpeg with winget, I ran powershell as admin, ran the set-executionpolicy and then ran your script and I get the following error:



Any ideas?

[UPDATE]
Uninstalled ffmpeg and then reinstalled using powershell with admin rights and it works now.

You don't need to use powershell with admin rights in order to install ffmpeg - actually you don't need to run powershell with admin rights at all for this script to work. I think your issue was that winget, unlike scoop and chocolatey, does not automatically refresh the PATH and environment variable of your powershell session, so after installing ffmpeg with winget what you needed to do was close powershell, wait a few seconds, and reopen it (without admin rights) for it to work. Your uninstalling and reinstalling achieved probably the same thing.

Lo Zeno
July 5th, 2023, 11:16
One more small fix to the Powershell version: the script was failing to copy files or folders that included wildcard characters (square brackets in particular), so I changed the relevant commandlets to use -LiteralPath instead of -Path

As usual, rename the file to convert-vp9.ps1 to use.