FFmpeg Microservice is a scalable and efficient solution designed for processing video & audio files using FFmpeg. This microservice can input/output entirely via streaming - it does not need to store data in memory or on disk in order to function, ensuring robust performance with large files.
It supports various input methods, including direct HTTP streaming, file system input, and multipart form data, and can stream output directly to the client.
-
Clone the repository:
git clone https://github.com/EricFrancis12/ffmpeg-microservice.git
-
Navigate to the project directory:
cd ffmpeg-microservice
-
Build the application:
make build
This will create a binary file located at
/bin/ffmpeg-microservice
. -
Run the application:
make run
The service should now be running at http://localhost:3003 by default.
The service accepts input via HTTP Post request, or as Multipart Form Data.
Use -i -
if you are sending the input file in the request body:
curl -X POST \
-H "Content-Type: video/mkv" \
# Specify the command that will run:
-H "X-Command: ffmpeg -i - -vf scale=100:50 -c:a copy -c:v libx264 -f flv ./output-A.flv" \
# The path to the input file:
--data-binary @./video.mkv \
http://localhost:3003
Use -i [path/to/file]
if you are referencing an input file in the file system:
curl -X POST \
-H "X-Command: ffmpeg -i ./video.mkv -vf scale=100:50 -c:a copy -c:v libx264 -f flv ./output-B.flv" \
http://localhost:3003
Use the header "Accept": "application/octet-stream"
and pipe:
to stream stdout back to the client:
fetch("http://localhost:3003", {
method: "POST",
headers: {
"Accept": "application/octet-stream",
"X-Command": "ffmpeg -i ./video.mkv -vf scale=100:50 -c:a copy -c:v libx264 -f flv pipe:",
},
})
.then(res => res.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = url;
a.download = "output-C.flv";
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
});
Make sure to use ?form-data=1
to indicate you are sending multipart form data.
The input file needs to have the name file
.
The command needs to have the name command
.
<form
enctype="multipart/form-data"
method="POST"
action="http://localhost:3003?form-data=1"
>
<!-- File Input -->
<input
type="file"
name="file"
required
>
<!-- Command Input -->
<input
type="text"
name="command"
value="ffmpeg -i - -vf scale=100:50 -c:a copy -c:v libx264 -f flv ./output-D.flv"
required
>
<button type="submit">
Submit
</button>
</form>
-
Download the sample video:
make dl video
-
Run the test suite:
make test
If you found an issue or would like to submit an improvement to this project, please submit an issue using the issues tab above. If you would like to submit a PR with a fix, reference the issue you created.