AutoMotion: How I Automated My Video Editing Process 
Tags: kotlin, productivity, showdev, opensource
Published: 2020-03-12 11:43:50

---
title: AutoMotion: How I Automated My Video Editing Process 
published: true
description: 
tags: kotlin, productivity, showdev, opensource
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/b1ntird764ndairnxjy1.png
---

Hey DEV community! This is my first post, and I'm thrilled to share this with you!

## The Dream

While streaming YouTube videos, I would often dream about becoming a YouTuber, as I'm sure many of us do. I feel like I have a wealth of knowledge I'd like to share with the world. Small tutorial videos, talking about how I develop my hobby projects, and providing developers some productivity tips. Just something, anything, even if on a small scale. But to do these things, 🙄 I'd have to:

- Learn the fundamentals of video editing and how to use various editing software 📔
- Spend a good portion of time editing my video projects 👨‍💻 
- Do the usual, and often repetitive, drop-crop-trim process ✂️ 
- Switch from Ubuntu, my primary OS that I love, as most of the professional video editing software works only on Windows/MacOS 😥
- Spend a lot of time waiting for the final output to render ⏳ 
- And many other reasons to push me away from my dream 🙄 

I know, I know. All these things make me sound like a really lazy person. That's because I AM! 😁 So what do I do?

## Moment of Inspiration 🌩️

"*I know some dumb programming. Would I be able to automate this process?*" I asked myself, and that was it. What did I have to lose? So I decided to try and automate this process.

## Research 🔍

I've heard that [ffmpeg](https://ffmpeg.org) is a good tool to process video frames. So I quickly browsed through the docs, and found that it's pretty straightforward even for a simpleton like me. 

## Core Feature 🤖

If the input video is a 10 minutes footage, and if it has 1 minute of non-talking area (the area where no one is talking) after every 2 minutes, 

![input](https://dev-to-uploads.s3.amazonaws.com/i/cnd67n5pu4d3c0zvppyx.png)

I want to timelapse those areas to 15 seconds of footage. So the total video length becomes 7 minutes and 45 seconds. 

Also, while running the timelapse, I want to replace the footage's raw audio with some cool BGM 🥁.

So this was the core feature I wanted to implement in the *thing*, for which I had not decided a name at that point.

## Initial Development ⚗️

I created a `shell script` to process a sample video I downloaded from YouTube. I wrote some basic stuff in it, like

- Adding intro
- Adding text to intro 
- Trimming video parts
- Timelapse video parts
- Adding background music
- Adding watermark
- Adding end credits

It took me 3 days to write it all by hand. I just wanted to check if `ffmpeg` has the potential to do what I want it to, and it really impressed me, going beyond my expectations.

Next thing I wanted to do was generate these `ffmpeg` commands dynamically. 💣

## Code Improvements ⌨️

It took me around 5 days to code the entire program. Then I proceeded to make some code improvements and made all possible input variables dynamic, which means you can control pretty much ***anything*** in it: Timelapse speed, intro title, watermark title, minimum timelapse duration, you name it. 

Here's the overview of the core stack:

 - Language : [Kotlin](https://kotlinlang.org) 🧠
 - Video Processing : [ffmpeg](https://ffmpeg.org) 🎞
 - Audio Processing : [autosub](https://github.com/agermanidis/autosub) 🎧
 - Command Line Parsing : [commons-cli](https://commons.apache.org/proper/commons-cli/)

At this stage, I also settled on a name for this project, **auto-motion**.

Now, let's run it! 🏃


## Input 🕹

Input is a 6 minutes video from [comma archive](https://www.youtube.com/channel/UCwgKmJM4ZJQRJ-U5NjvR2dg), captured by  [George Hotz](https://en.wikipedia.org/wiki/George_Hotz) in a recent hackathon they conducted.

{% youtube 0l_zU7XjWXo %}


## Execution 🖱️

{% youtube N0rORfltywU %}

It only took ~1 minute to edit and render the output, whereas a manual edit would have taken hours, perhaps even days, to accomplish it. 🤷


## Output 📺

The output, reduced to 4 minutes 43 seconds, is here. It includes 7 time-lapses of different lengths.

{% youtube t_vo1SYnMsg %}
 
I know the output is not as enjoyable as a manually edited one, but I believe I can improve this in due time 😇. You'll see more dynamic and interesting output in the near future on [my Youtube channel](https://www.youtube.com/channel/UCSLv4OdjaTUJlllQpHv7Ciw). If you like my work, please subscribe to be notified.  🤗

## Download 📩

You can view the source code as well as download the program from GitHub.

{% github teamxenox/auto-motion %}

If you have some videos, download the code and run it on them to check out the output for fun. 🤪

## Thanks for reading!

I'm really happy I wrote this and I'm excited to share more with you all. If you liked the post, do share it with your friends. Feel free to post your suggestions for future posts! Thank you for reading this. Ciao!

![man sending a flying kiss and saying "ciao"](https://media.giphy.com/media/l4Ki0UwC89tEUahnW/giphy.gif)

---

## P.S. Are you an Open-Source Enthusiast?

If *you* looking to build cool products in a collaborative environment and meet awesome people, I welcome you to join me in [XenoX Multiverse](http://bit.ly/xnxmltvrs) 🔥. Check out some of the [stuff we made](http://bit.ly/madebyxenox) last year.

![open arms join us gif](https://media.giphy.com/media/NZCnpj2c4qoE0/giphy.gif)

We are currently working on **Caligator**, one of the products we built last year which got great reception from you all and the good folks over at [ProductHunt](http://bit.ly/cali-ph).

{% link teamxenox/introducing-caligator-a-simple-yet-powerful-open-source-calculator-convertor-5f86 %}

Caligator got a lot of traction and feature requests from people. Help us fire this up and take Caligator to the next level. Join chat on [Gitter](https://gitter.im/Caligatorapp/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge).