hey there fellow developers while I was browsing through Instagram I stumbled upon a real that sparked an idea in my mind this looks cool but I wonder if I could create something like this programmatically lately I've been diving into how AI tools can automate content creation setting up entire Instagram YouTube and Facebook pages with just a few clicks but as a developer I wanted to push the boundaries and see if we could achieve the same or even better results using python so I took on the challenge and developed a simple yet powerful app that does
exactly that with this app you just need to input a quote and some basic reel details and in no time the app generates a fully polished reel for you ready to be uploaded today I'm going to walk you through the entire process of building this app step by step and by the end you'll not only know how it works but also how you can leverage it to supercharge your content creation let's dive [Music] in all right let's dive into the Reel that initially caught my attention on Instagram which we'll try to recreate using python The
Reel is quite simple yet captivating it contains three main elements text sound and images our goal is to replicate this by programming it step by step the first thing we we need is a collection of images for that I used pixels a great resource for free highquality images and downloaded a bunch that fit the theme I was going for I then organized these images into a folder called images the next step is to combine these images to form a video I decided to set specific parameters for our video each video will consist of 30 images
with each image displayed for 0.15 seconds now the big question how do we achieve all of this using python to help guide me through the process I turned to chat GPT for some assistance and insights so I asked chat GPT how I could use Python to combine images into a video with each image shown for a specific duration chat GPT recommended a python Library called movie pie which makes this task straightforward now let me show you a snippet of the code that makes this possible here's a small part of the code that handles the video
creation process what this code does is it randomly selects a set number of images from a folder then it processes each image to fit the video size and finally it combines them all into a video clip with a specified duration for each image the movie Pi Library handles all the heavy lifting making it easy to create professionall look videos programmatically I won't go into every detail of the code here but the idea is to show you how powerful python can be for automating the creation of reels or shorts now let's go ahead and execute this
code to see the result we've already set up the images so when we run this script it will randomly pick 30 images from our folder each displayed for 0.15 seconds the code will combine these images into a single video adding a subtle black overlay for that cinematic look once the process is done we'll have a video file ready let's check out the video we just created with python now that we've got the video with images the next step is to add text over the video for this part I'm using the movie piie Library along with
the pill library to handle image and text manipulation the main idea here is that we're going to create an image with the text quote and author and then overlay it on top of our video let me walk you through the most important parts of the code text wrapping we're using a function to wrap the text properly so that it fits nicely in the video frame this is important because we want the text to look good without overflowing text overlay we generate the text as an image and then overlay it onto the video we can customize
the font color size and even add a nice border to the text for better visibility Watermark lastly we're adding a watermark at the bottom with the username this can be easily customized to display your social media handle the rest of the code handles placing the text at the center of the video and ensures everything looks balanced this keeps things clean and readable for the viewer now let's execute the code and see the result with the text overlay on the video now the last step is to add some background music to our video like with the
images I downloaded a collection of audio tracks and stored them in a folder called music we'll randomly pick one track sync it to the video and save the final output now let's run this and check out the final video complete with background music now that our real generation is complete the next step is to create a web application to make this process easier with an interface for that we need two parts the front end and the back end let's start with the front end where I decided to build a simple page using HTML and Tailwind
the page will include a simple header a form to input real info a button and an area for the generated video finally let's see how this interface looks here's a simple form with an area for the generated video now that we have our front end in place let's talk about the back end I decided to use fast API a modern web framework for building apis in Python but before we dive into that let me quick quickly explain what an API is an API application programming interface allows different software applications to communicate with each other in
this case our frontend the form where users input their data will send requests to the back end through the API the back end using fast API will process the data generate the video and then send the result back to the front end to achieve this I will use JavaScript on the front end to send HTTP requests to our fast API backend the backend will handle these requests generate the video as needed and respond with a link to the generated video which will then be displayed in the front-end interface so let's see how I built my
backend using fast API first I organized my HTML files in a folder called templates I use Ginga 2 to handle these templates which helps in rendering HTML files dynamically for the first endpoint I created a route for the root URL slash that responds with an HTML page when it user visits this URL fast API serves an HTML form from the templates folder the form is rendered using the index.html file and the request details are included to make the interaction more dynamic in summary this setup allows users to access an HTML form through the root URL
next I set up additional endpoints for handling video generation and file management one Tosh generate endpoint this endpoint is responsible for generating the video when a post request is made to this route it takes form data such as the quote author video size and Watermark it then starts a background task to handle the video creation process the background task is managed by fast API background tasks which allows the video generation to run asynchronously the endpoint responds with a unique task ID that can be used to check the progress of the video creation two SL progress
task ID endpoint this endpoint provides progress updates on the video generation task it reads the progress from a file associated with the given task ID and Returns the status as a Json response if the task ID does not exist or the task is still processing it returns an appropriate message three download SL file name endpoint finally this endpoint handles file downloads when a get request is made with a file name it checks if the file exists and returns it as a downloadable response if the file is not found it returns an error message these endpoints
work together to handle video generation track progress and provide access to the generated files in our setup JavaScript handles form submission by preventing the default action and validating input fields for quote author and Watermark it uses fetch to send form data to the fast API backend and starts a progress simulation with a loading spinner and disabled button the check progress function repeatedly queries the server for the video generation status updating the UI to display the video and a download button once complete this function also sets the video URL to allow playback and downloading ensuring a
seamless user experience while the backend processes the video our web app is now complete let's perform a quick test start the server and navigate to the specified URL to view our interface enter a quote author choose the video resolution and add a watermark then click generate and wait for the video to be Pro processed after a few moments the video will be generated successfully as shown it will be displayed on the page and you can either watch it directly or click the download button to save it this may seem simple but it demonstrates that we
can build more complex and advanced applications with this setup you can effortlessly create a multitude of videos and even post them programmatically to platforms like YouTube Instagram and Facebook in our next video we'll explore how to automate the posting of videos and how to generate multiple videos with a single click among other Advanced features if you're interested in the code leave a comment below this project is just the beginning and we have many more advanced ideas to explore if you enjoyed this video don't forget to like And subscribe for more