I finally got some time to revisit this project this weekend. I figure automating Smashball video uploads would be a nice thing to crank out for our small-but-mighty community, and have the fun side effect of getting some more video content out there.
The workflow I’m building looks like this:
I was able to get a smoke-test of the ffmpeg bit and the Youtube API uploading bit working. I’m a bit stuck on the hl2.exe part since the default Smashball installation from Steam seems to dislike running from the command line these days. I’m reasonably sure it’s just a path thing that Valve broke with some recent update to hl2, as I’ve seen some bitching about this around other Source mods.
For ffmpeg, I’m running a command line like this:
ffmpeg.exe -r 30 -i "sbdemo%04d.tga" -i "sbdemo.wav" -vcodec libx264 sbdemtest.avi
That tells ffmpeg to use 30 fps instead of 29.997 fps, which slowly becomes desynced from the audio over the course of a smashball match. It also forces use of the libx264 codec, which looks the best after a bunch of testing. My last run was rendering at 37-40fps the whole time on my gaming rig, which was a nice surprise considering the quality of the output. ffmpeg was smart enough to grab the entire frame sequence from my test demo despite hl2.exe using inconsistent zero-padding (starts with sbdemo0000.tga, ends with sbdemo13975.tga). It was also smart enough to automatically grab the audio from the .wav once I specificed the audio file as an additional input file.
Here’s the bit of code that actually performs the upload:
# Call the API's videos.insert method to create and upload the video.
insert_request = youtube.videos().insert(
media_body=MediaFileUpload(options.file, chunksize=-1, resumable=True)
Hopefully, part 2 of this series will tell of my triumph in making hl2.exe behave correctly and automagically render Smashball server-side demo files into TGA frame sequences that ffmpeg can consume!