All posts
Video to MP4 via CLI
Re-encode any video to H.264 + AAC with ffmpeg.
Open online converterPackages to install
You need ffmpeg with libx264 and AAC. On Ubuntu that is the ffmpeg package.
ffmpeg
sudo apt-get update
sudo apt-get install -y ffmpegHow to run the command
ffmpeg -i input.mov -c:v libx264 -preset ultrafast -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4. The same profile works for MKV, AVI, and WebM.
ffmpeg -y -i input.mov -c:v libx264 -preset ultrafast -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4Dockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t video-to-mp4 .
docker run --rm -v "$PWD:/work" -w /work video-to-mp4 \
ffmpeg -y -i input.mov -c:v libx264 -preset ultrafast -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4Example commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
ffmpeg -y -i input.mov -c:v libx264 -preset ultrafast -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4ffmpeg -y -i input.mkv -c:v libx264 -preset ultrafast -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4