generative video
preface⌗
I’ve always liked programming. Ever since I was a kid, I’ve always liked tinkering and seeing what happens when I do this or that.
In school, I wouldn’t even take a look at the book I’d just experiment and follow my intuition. Of course, my grades were always horrible, I was always a dunce.
The way I work often reminds me of an old arabic folktale about a person named Juh’aa. People would ask Juh’aa about where his ear is, and Juh’aa would use his left hand to point at his right ear. The underlying meaning is that Juh’aa prefers to take the longer road.
I usually act like Juh’aa and make things harder for myself but today’s post won’t follow that. It’ll talk about, what is in my opinion, a more efficient way of editing videos than the conventional way of editing videos.
intro⌗
Programming is a craft that revolves around getting a specific result out of a program. Be it through computing new results, interfacing with real life and producing a physical item or through making human-like ideas about the real world.
Good programmers, however, aim to reduce their programs to more concise versions of the original version until they either cannot be anymore or they don’t bother to.
In contrast to other fields, such as wood work or carpentry, programming runs miles in terms of the amount of tools you have to work with. That’s because many of the tools that programmers use on a daily-basis are easily modifiable by other programmers.
Whilst a carpenter needs to become an engineer to create his own tool, the programmer just programs his own tools.
Evidence of this resides in the amount of operating system that are single-handedly created by programmers. A good example of that is the operating system Temple OS.
Temple OS was an operating system created by Terry Davis. He built the operating system because he had, or so claimed that he had, visions of angels talking to him. He spent 11 years creating his own operating system according to how he saw fit. Terry Davis is not a special programmer by any means, he was just like any other programmer but with enough time on his hands and dedication. Any other programmer could’ve done the same.
Finally, that leads me to the idea of generative video. Generative video is any video, with a specific pattern, that can be generated whilst modifying main data points.
But before I talk about generative video, I want to distill in your minds how powerful generation can be…
the power of generation⌗
No, not generation as in Millennials and Boomers, but generation as in you tell the computer something and it generates that something. I know, words can be so misleading.
I want you to think about this simple blog website. It has links, each link leading to a blog post or a page that I wrote. But I didn’t create these links by hands, I only created these pages via a program and now you have these links that connect them together.
With computers, you get to enjoy free labor that is fast and cost-free(not counting electricity). The more serendipity you have, the more efficient the use of this free labor becomes.
Now let’s think about how we could put the power of generation to good use for a business. Let’s say we have a beautiful restaurant on our hands, restaurants typically have a list of available dishes called a menu.
Menus can be written on a wall using a pen, printing a document containing a table of names and prices or a visual image for better effect. Usually good restaurants get a designer to design a picture of a menu to market their foods in a pleasant way.
Specifically in the case of restaurants, prices of dishes sometimes flauctate. The restaurant managers then have to contact that same designer to modify a part of the menu, such as the prices.
The main issue isn’t the currency but the amount of time it takes. It takes time for the designer to respond, change it, maybe change the font sizes since the width wouldn’t fit, et cetera. I almost forgot to mention how unoptimized some of these programs are for modifying and outputting images.
Now, if you tackle the idea of menus through generating them via a program that you wrote, things become easier. Sure, you would invest some time in writing the program and you might face some hurdles, but in the long run you’d have less and less trouble.
You can arrange for ways to dynamically modify the image such as lessening the font-size if the width overflows the container and so on. Re-usability is also another upside of generating content.
To summarize, generation saves times.
practical application: generative video⌗
Generative video can be done in a lot of different ways. The fastest and hardest would be to invoke the C api directly and generating pixels hand by hand. The slowest and easiest would be to download a video program and manually modifying data.
The sweet spot, at-least for me, comes in the form of web pages that are recorded and later transformed into video. You can easily accomplish this through loading up the page on a browser and taking a screen recording.
Web pages are a sweet spot for me because they have been developed over about 2 to 3 centuries till now and are still developing. Don’t forget that these web pages, due to high demand from companies and strong-willed individuals, have morphed into applications that feel like the real thing and into beautiful strong-telling devices among other things.
So, you’re provided with tons and tons of useful tools that can generate any idea you have into video. One tool automates the process I mentioned before, you know the one about screen recording, into a simple command.
The package is called timecut
and it can be installed via npm
:
npm install -g timecut
Later, it can be invoked to read the local index.html
file or to record any website through the protocols http
or https
.
# record local `index.html` file
timecut
# record http website
timecut http://google.com
# record https website
timecut https://google.com
By default timecut
records a video at 800x600 for only 5 seconds. These options are modifiable through the options -W -H -V
and -D
.
# record a video for 10 seconds @ 60 fps (by default, modifiable through -R)
# in a resolution of 1920x1080
timecut -W 1920 -H 1080 -V 1920,1080 -D 10 video.html
One thing, you’ll find useful to make generating the video faster is to modify the threads parameter. By setting the threads parameter -T
to amount of cores that you have, you can speed up the process.
This is because timecut
records videos as a series of screenshots that are then after merged into a video via ffmpeg. timecut
utilizes the library timesend
which utilizes the puppetter
utility to hook itself into the time functions of the browser so that every frame that is painted gets sent into timesend
, gets turned into png and then forwarded to timecut
to be converted into an mp4 file.
bonus: audio⌗
timecut
unfortunately does not record audio. However, with a little trickery you can achieve full on video+audio through two steps:
- record the audio
- merge it using ffmpeg
I am not going to go into the first step as it’s pretty self-explanatory. Second step is pretty easy to do.
ffmpeg -i "audiofile.mp3" -i "videofile.mp4" "final_result.mp4"
Or to extract audio from a video
ffmpeg -vn -i "video_with_audio.mp4" "audiofile.mp3"
conclusion⌗
Generative Video is, in my opinion, an extremely useful tool to create content. Nowadays, there is a need for content and timecut provides a good way to dynamically generate content without the mess of learning a video editor nor how to manually manipulate videos pixel by pixel. You simply use timecut
with your already existing web skills and voila, you have a video!
alternatives⌗
You can also use Open Broadcaster Software (OBS) to generate the content while recording it without any post-processing. Though it won’t look as professional as with a video editor, you can make it relatively polished without much effort.
Tons of plugins exist for OBS too, so that you don’t have to create everything yourself. Lastly, if you wanted to, you could still record a web page, transparentize it, and enjoy timecut
capabilities. You essentially trade scriptability for more manual labor but it’s not too bad.