MP4 to GIF Converter

Help with space by converting MP4 into time elapse

Origin

The idea came from a very weird situation. My friend was at the issue of getting in a small crash and he wanted to see if it was possible to get his dash camera feed. Personally, I didn't actually end up using the program for that but that is beside the point. I used test data of phone footage as it was the only thing that I could find that would be worth the time elapsed at the time.

Setting up

First of all, I created this to be command-line based with everything in the same folder to limit the amount of confusion that will be going on. I would love to make GUI but for a small project like this is it not worth it. So to start out you will need to grab the FFmpeg file as that is needed to read most video formats. Just go to this website and download it putting it in the same folder as the project.

The final part of the setup is having python installed. I used python because of my familiarity with the image processing class and written programs with it in the past.

This project was a beast and took a day and a half to write because of processing time and the number of issues I ran into. I will try and keep it brief but I had 8 versions if that tells you how many issues I had.

Step 1: The Overview

So I know the process overview of what the code was going to look like. At first, it was going to be efficient and take a lot of writing but I wanted to guarantee the highest possibility of testing without wasting a lot of resources. Another huge factor was I couldn't find how to do input and output at the same time for video files. I would take apart the video by specific frame times and then put them together into a gif. From there I could turn it back into an mp4 if wanted. Sounds so simple but in so many places it went wrong.

Step 2: The Starting Code

The process of writing the first version of the code. It has a lot of mistakes and the thought process was a little long because after my research not much was out there for a project like this. I might not have done good enough research but I guess it was ok with me so far.

Turning mp4 into photos

This is the easiest version. The issue is the GIF was massive

Turning Gif into mp4

Was hoping I could turn it back in hopes to be smaller but it was just as massive.

Creating Gif from photos

I got the photos and was hoping this would work. The timing was off and the gif was so slow.

Changing the framerate

I was hopeful that if I changed the framerate the issues would go away. It caused even more issues

Additional Info

Also, I used Tinify to make smaller images because the size was an issue, well that backfired a lot. It created horrible images and made me even doubt a gif would work at that point because looking up more it was limited in colors. It was based on the fact it would be better but had to rethink that when this came up.

Overall

Overall view of the first attempt, the code would need a lot of tweaking but I was onto something. It was coming together just inefficiently.

Step 3: Modifications

So at this point, I had a lot of parts of code, but nothing was really solid. I cleaned up the code and got a great main class.

Initial Main Method

The main method I strung together after my first attempt

Step 4: Cleaning Up

So I had a solid main class and all it took was modifications to this to get it how I wanted. I was going to do a better interface but after telling people about the program it was more of personal use than wide use. I modified it to work really well and the code was turning to be better

Second take of code

The code after my first day of starting the project

Other ideas

I came up with a few ideas at this point Create an input for the output folder Being able to do multiple folders in 1 project Start program with already taken images Simplify the modules even though it isn't that bad Making the software smaller

Final Conclusion

The program seemed better in my head but when putting it all together it didn't really live up to my expectations. It did get it done and could add the compression algorithm I already had made a while ago. The really big issue with this project is putting it into gif I thought would make a bigger deal than it did on the size.

Final Code

Final code that is released

Code exe

The exe file of the final code. It is in the git repository because I was unable to include all the classes and the size could not be less than 75 MB. It started out being 120 MB.

Last updated

Was this helpful?