View Full Version : Bash: Batch convert webm VP9 to webm VP8 using ffmpeg
rhagelstrom
June 26th, 2023, 01: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, 23:45
Thanks!
Lo Zeno
June 27th, 2023, 11: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, 17: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, 19: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, 21: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, 12: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.
Farratto
August 16th, 2024, 03:54
I updated the bash script slightly for myself to add an additional option to rotate the tokens 90 degrees clockwise. The script still does everything it did before. Just one new command line option available.
It may sound wierd, but the reason I did it is because I have a lot of spell tokens originally intended for Foundry and for what ever reason they're token graphics default shooting to the right and B9 Spell Tokens extension uses shooting downward. For the most part this doesn't cause a problem but if you're using the B9 Spell Tokens to target, it becomes an issue for cone shaped spells only (i.e. dragon breath & what-not).
If you want to make use of these tokens in this manner, you separate out the cone spells (or any token you want to rotate 90 degrees clockwise) in a different directory. Run the script normally with the tokens you don't want to rotate. Then run the script again on your separated directy, this time, adding the "-t" argument. You don't have to remember that. If you do a help on the script, it will tell you all the available arguments and it is there.
Hope it's helpful to someone. Helped me a lot.
P.S. don't forget to rename the file to .sh and give it execute permission.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.