You may have noticed I work casually on semi-regular gaming videos with friends that I post around here and at the OHC subdomain. How do I have time for that? I definitely don’t. Gaming is an important hobby, it’s led me directly to anything I’ve been successful at, and I take it seriously. Still, I don’t have time after long play sessions to edit hours of video multiplied by the number of players I partied up with on any given night for something Google won’t let me profit from.
My solution? Better video editing through code.
I recently made the jump from iMovie video editing over to Blender. Blender is definitely a 3D modeling suite first, but their video editing component has been around for many years, and if you’ve already reached the top of the application’s learning curve, it has tons of potential. This is not just due to its core features–Blender supports Python scripting that will let you perform just about any repetitive task at the push of a button, if you can put together the right lines of code.
Let’s be real, doing any video editing in Blender is intimidating. The idea of trying to automate large portions of it by manipulating the program through code seemed even further out of reach, but I eventually realized I had to find a solution or give up the activity altogether.
Scripting Just About Anything in Blender
As I mentioned previously, Blender is scripted using Python. Python is a surprisingly friendly scripting language that can mostly be learned by doing, but if you’re new to programming or nervous about it in general, you should check out the internet’s wide variety of Python primers to get a feel for the language and its vast capabilities.
If you’re familiar with Python already–or you’re just adventurous–you can dive straight into its applications in Blender. I had great success digging into the Blender Python API documentation, particularly this Addon Tutorial which taught me the important mechanics of extending Blender by registering scripts, installing them permanently from saved script files, etc., most of which I understand now (most). If you’re coding along at home, I’d really urge you to follow their examples, run their scripts, and get to know how it works. After that, there was nothing left but to start experimenting.
Automating Our Workflow
We’ve had positive feedback about our video editing, but the process is kind of a bitch. During most sessions, at least three of us play a game of our choosing, which we record on Elgato capture devices, everyone uploads their footage to YouTube as an unlisted video, they send me the link, I download each of them, then I put them together in Blender as a single video featuring perspective switches, multi-view shots, and gamertag overlays. You can see this in action in our recent Overwatch video.
The biggest problem, as you might have already guessed if you edit anything like this, is several minutes’ worth of adjustments to individual clips and their properties at the beginning of each new shot. Not to mention some shots you set up just don’t work the way you’d hoped, requiring you to do something else. There’s no doubt in my mind that this is why you don’t see a lot of videos like ours. iMovie–though you can fudge it to some degree–really doesn’t support shots like this at all, much less let you do anything to make life easy. But Good Guy Blender will let you do just about anything you want.
When I decided to take a swing at Blender scripting, I went straight for the hard stuff. If I could set up our “quad view” shots with the push of a button, I could automate everything and it would breathe new life into the editing process. If not, I was honestly about ready to hang it up.
I had it done in about two hours.
There are a couple of things I’m trying to get better about, now that I’m pushing 15 years of programming. One is watching videos. When I was getting started, programming videos just weren’t out there. Video on the web was barely out there. I had a tendency to try to read a book about everything I had any questions about at all. That helped, don’t get me wrong, but I can get my questions answered a lot faster on YouTube in many situations. The other is a willingness to dig through other people’s code. That’s the sort of thing I normally like to get paid for. But I’m an all-arounder. I may use three or more languages on a given workday. Languages are all tools in a belt for me, helping me build whatever it is, but that means most developers who have a well-defined focus area know more about it than I do. That’s only bad news for me if I fail to leverage that for the benefit of my projects.
In this case, to the latter point, I found over 1500 lines of extremely useful code at GitHub in kgeogeo’s VSE_Transform_Tools project. This is a killer Addon for Blender that lets you perform all kinds of useful transformations on a strip right in the preview area. Without a doubt, kgeogeo’s code and the Blender/Python API tutorials answered every significant question I had about how scripting worked for Blender’s video tools and very subtle changes to their code had my scripts working almost immediately. Though the complete script has a good deal more boilerplate code used to register the script with the application, here’s a taste of the important part:
stripCount = 1 selection = [seq for seq in context.scene.sequence_editor.sequences if seq.select and seq.type not in ['SOUND','TRANSFORM']] for seq in selection: bpy.ops.sequencer.select_all(action='DESELECT') context.scene.sequence_editor.active_strip = seq bpy.ops.sequencer.effect_strip_add(type = "TRANSFORM") active_seq = context.scene.sequence_editor.active_strip active_seq.scale_start_x = .5 active_seq.scale_start_y = .5 active_seq.blend_type = "OVER_DROP" if stripCount == 1: active_seq.name = "TopLeftScreen" active_seq.translate_start_x = -25 active_seq.translate_start_y = 25 elif stripCount == 2: active_seq.name = "TopRightScreen" active_seq.translate_start_x = 25 active_seq.translate_start_y = 25 elif stripCount == 3: active_seq.name = "BottomLeftScreen" active_seq.translate_start_x = -25 active_seq.translate_start_y = -25 if stripCount == 4: active_seq.name = "TopLeftCard" active_seq.translate_start_x = -25 active_seq.translate_start_y = 25 elif stripCount == 5: active_seq.name = "TopRightCard" active_seq.translate_start_x = 25 active_seq.translate_start_y = 25 elif stripCount == 6: active_seq.name = "BottomLeftCard" active_seq.translate_start_x = -25 active_seq.translate_start_y = -25 stripCount += 1
That left more than the necessary code to implement my “Dual View” and “Single Player” shot scripts. I was done with all of it minutes later.
Once I saved and installed my scripts from file (also detailed in the Blender Python API tutorial), the entire video editing process was brand new. Now I make start and end cuts for a shot, hit the space bar, type a few letters of the kind of shot I want, and click on it. The rest is done for me.
If you’ve accomplished great editing OR scripting feats in Blender, I’d definitely be interested to hear about them. If you’re into the videos we’re doing, drop us a Like and a Sub at YouTube.
Most importantly, I hope the scripting insight helps. Let me know!