Skip to content

Instantly share code, notes, and snippets.

@flibitijibibo
Created April 14, 2019 23:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flibitijibibo/c97bc14aab04b1277d8ef5e97fc9aeff to your computer and use it in GitHub Desktop.
Save flibitijibibo/c97bc14aab04b1277d8ef5e97fc9aeff to your computer and use it in GitHub Desktop.
Convert WMA/WMV to Vorbis/Theora, useful for XNA Windows games
#!/bin/bash
set -e
find -name "*.wma" -exec bash -c 'ffmpeg -i "{}" -q:a 10 "${0/.wma}.ogg"' {} \;
find -name "*.wmv" -exec bash -c 'ffmpeg -i "{}" -q:v 10 -q:a 10 "${0/.wmv}.ogv"' {} \;
@rfht
Copy link

rfht commented Jun 1, 2019

The following is an alternative implementation for the video part using gstreamer for potential use on platforms without ffmpeg, or where ffmpeg exists without compiled-in support for Theora/VP3. Because of the gst-launch syntax, it is a little more involved. The resulting script runs on OpenBSD's ksh and may even be completely Bourne shell compatible (unlike the above ${0/.wmv} which is a bashism).

Tested with the .wmv files of Cthulhu Saves the World and Cloudberry Kingdom.

for vfile in $(find . -name "*.wmv"); do
        gst-launch-1.0 filesrc location="$vfile" ! \
                decodebin name=demux ! \
                queue ! videoconvert ! theoraenc ! oggmux name=mux ! \
                filesink location="$(echo "$vfile" | rev | \
                cut -d. -f2-$(($(echo "$vfile" | tr -dc '.' | wc -c) + 1)) \
                | rev).ogv" demux. ! queue ! audioconvert ! audioresample ! vorbisenc ! mux. 
done

PS: I tried adding a progressreport, but that lead to file conversions never finishing, so no progress report in this version...

@rfht
Copy link

rfht commented Jun 1, 2019

PPS: credit to Bryan Steele from OpenBSD and our OpenBSD gaming group who came up with the gst-launch syntax. The subshell acrobatics are mine...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment