Skip to content

Instantly share code, notes, and snippets.

Created Sep 24, 2021
What would you like to do?
Convert Video-File To MP4 Using VLC CLI
#!/usr/bin/env bash
# Convert a video file into MP4 using the VLC Media Player CLI. See:
# for the options available with VLC CLI and:
# for the supported video and audio codecs during encoding.
set -euo pipefail
for VID in "$@"; do
if [[ ! -r "${VID}" ]]; then
echo "ERROR: Cannot read file \"${VID}\"."
exit 1
case "${VID}" in
*.avi | *.flv) MP4=$(echo "${VID}" | sed s/...$/mp4/);;
*) echo "ERROR: Unsupported file-format for \"${VID}\"."; exit 1;;
echo "INFO: Converting \"${VID}\" to \"${MP4}\"..."
"${VLC}" -I dummy -v \
'--sout=#transcode{vcodec=h264,acodec=mp4a,deinterlace}' \
'--sout=#standard{access=file,mux=mp4}' \
--sout-standard-dst="${MP4}" --play-and-exit "${VID}" || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment