Created
September 24, 2021 07:06
-
-
Save rmathew/2448850fa3d3b9654377e8d52ef759ac to your computer and use it in GitHub Desktop.
Convert Video-File To MP4 Using VLC CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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