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:

sb_demo_to_youtube_workflow_thumb

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.

For the YouTube API videos.insert part of the workflow, I ran across this handy Python script to upload videos using Google’s python api module, and only tweaked it a bit. I’ve never really done anything with Oauth2, but Google really made it braindead simple to authorize an application and download appropriate javascript containing the right credentials.

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(
part=",".join(body.keys()),
body=body,
media_body=MediaFileUpload(options.file, chunksize=-1, resumable=True)
)

Simple, huh?

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!