Skip to content

Instantly share code, notes, and snippets.

@rmathew
Created Sep 24, 2021
Embed
What would you like to do?
Convert Video-File To MP4 Using VLC CLI
#!/usr/bin/env bash
# vid2mp4.sh: Convert a video file into MP4 using the VLC Media Player CLI. See:
#
# https://wiki.videolan.org/VLC_command-line_help
#
# for the options available with VLC CLI and:
#
# https://wiki.videolan.org/VLC_Features_Formats
#
# for the supported video and audio codecs during encoding.
#
set -euo pipefail
VLC="/Applications/VLC.app/Contents/MacOS/VLC"
for VID in "$@"; do
if [[ ! -r "${VID}" ]]; then
echo "ERROR: Cannot read file \"${VID}\"."
exit 1
fi
case "${VID}" in
*.avi | *.flv) MP4=$(echo "${VID}" | sed s/...$/mp4/);;
*) echo "ERROR: Unsupported file-format for \"${VID}\"."; exit 1;;
esac
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
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment