Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Created December 22, 2015 18:23
Show Gist options
  • Save jcefoli/6120283ad9cab40fffcc to your computer and use it in GitHub Desktop.
Save jcefoli/6120283ad9cab40fffcc to your computer and use it in GitHub Desktop.
Generate a WebM Video in PowerShell using open source tools
<#
Name: makewebm.ps1
Version: 1.0
Description: This script will take all image files in a folder and automagically generate a webm video file using some open source tools.
Usage:
powershell "& "C:\Scripts\makewebm.ps1"
Required Binaries:
- vpxenc.exe: https://github.com/balistof/NVP8/tree/master/vpx-vp8-debug-src-x86-win32mt-vs9-v1.0.0/bin/Win32
- jpeg2yuv.exe or png2yuv.exe: http://sourceforge.net/projects/mjpeg/files/mjpegtools/2.1.0/mjpegtools-2.1.0-mingw-bin.tar.bz2/download
- pthreadGC2.dll: ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip
- pcre.dll: http://gnuwin32.sourceforge.net/packages/pcre.htm
- Bulk Rename Command (brc64.exe): http://www.bulkrenameutility.co.uk/Downloads/BRC_Unicode_64.zip
#>
#In Powershell 2, $PSScriptRoot does not work on its own. Only added for backwards compatibility
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
#Copy Files to temporary working directory
Remove-Item $PSScriptRoot\Temp\* -recurse
Copy-Item $PSScriptRoot\Images\*.jpg $PSScriptRoot\Temp
#Rename Files to correct format for yuv generator
& $PSScriptRoot\brc64.exe /DIR:"$PSScriptRoot\Temp" /REMOVEFIRSTN:16 /AUTONUMBER:001:1:P:1:10:4 /REMOVELASTN:1 /EXECUTE
#Get number of pictures in folder. Use $picNumber.Count to display just the number
$picNumber = Get-ChildItem $PSScriptRoot\Temp | Measure-Object
$picNumberCount = $picNumber.Count
#Create YUV File
cmd /c "$PSScriptRoot\jpeg2yuv.exe -I p -f 24 -b 1 -n $picNumberCount -j $PSScriptRoot\Temp\%04d.jpg > $PSScriptRoot\Temp\vid.yuv"
#Create WebM File
cmd /c "$PSScriptRoot\vpxenc.exe --good --cpu-used=0 --auto-alt-ref=1 --lag-in-frames=16 --end-usage=vbr --passes=2 --threads=2 --target-bitrate=2000 --width=640 --height=480 -o $PSScriptRoot\Output\output.webm $PSScriptRoot\Temp\vid.yuv"
#Cleanup
Remove-Item $PSScriptRoot\Temp\* -recurse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment