Skip to main content

Deploy an FFmpeg App on Leapcell

You can deploy a Flask Python app that uses FFmpeg to process videos or images on Leapcell in just a few steps. This guide demonstrates using Flask as an interface to handle FFmpeg operations by uploading files via Flask, which then processes them using FFmpeg.

This quickstart uses a sample Flask app that runs FFmpeg commands, which you can customize to fit your requirements.

1. Fork the Flask FFmpeg Example on GitHub.

Here’s a basic app.py file that runs an FFmpeg command to convert a video into a different format:

from flask import Flask, request, jsonify
import subprocess

app = Flask(__name__)

@app.route('/convert', methods=['POST'])
def convert_video():
# Get the video file from the request
file = request.files['file']
output_format = request.form['format']

# Save the input file, it must be in the '/tmp' folder
input_path = '/tmp/input_video.mp4'
file.save(input_path)

# Define the output path
output_path = f'/tmp/output_video.{output_format}'

# Run FFmpeg to convert the video
command = ['ffmpeg', '-i', input_path, output_path]
subprocess.run(command, check=True)

# Return the path to the converted file
return jsonify({"output_file": output_path})

if __name__ == '__main__':
app.run(debug=True)

This Flask app accepts a video file via a POST request and converts it to the desired format using FFmpeg.

You can test the API locally with the following command:

curl -F "file=@/path/to/video.mp4" -F "format=mp4" http://localhost:5000/convert

You may upload the result from /tmp/output_video.{output_format} to object storage or other services.

2. Create a Service in the Leapcell Dashboard and Connect Your New Repository

Go to the Leapcell Dashboard and click the New Service button.

Next, click Connect with GitHub and select the forked repository.

3. Provide the Following Values During Creation:

info

We need to manually install FFmpeg. Include the following in the build command:

apt-get update && apt-get install -y ffmpeg && pip install -r requirements.txt
FieldValue
RuntimePython (Any version)
Build Commandapt-get update && apt-get install -y ffmpeg && pip install -r requirements.txt
Start Commandgunicorn -w 1 -b :8080 app:app
Port8080

4. Access Your App

Once deployed, you’ll see a URL like foo-bar.leapcell.dev on the Deployment page. Use this domain to test your app.

Continuous Deployments

Every push to the linked branch automatically triggers a build and deployment. If a build fails, the current version remains live until the next successful deployment.

Learn more about Continuous Deployments.