Skip to content

Instantly share code, notes, and snippets.

@namnv609
Last active November 20, 2023 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namnv609/8e2892a6578ec4faa5a8ac612590444d to your computer and use it in GitHub Desktop.
Save namnv609/8e2892a6578ec4faa5a8ac612590444d to your computer and use it in GitHub Desktop.
[MacOS] Convert Movie to MP4 using FFMPEG

[MacOS] Convert Movie to MP4 using FFMPEG

For terminal

Install

chmod +x <path/to/movie2mp4.sh>

ln -s <path/to/movie2mp4.sh> /usr/local/bin/movie2mp4

Usage

movie2mp4 /path_to_movie_file

For context menu

convert-movie-to-mp4

  1. Open Automator
  2. Choose Quick Action
  3. Actions -> Library -> Run Shell Script
  4. Workflow receives current -> movie files -> in Finder
  5. Pass input -> as arguments
  6. Paste code to Shell section
  7. Save Quick Action by press Cmd+S then enter your context menu title (i.e: Movie2MP4)

Enjoy 😄

convert-movie2mp4.mp4
#!/usr/bin/env bash
file_path=$(printf "%q" "$1")
src_folder=$(dirname "$file_path")
src_file=$(basename "$file_path")
src_name="${src_file%.*}"
file_ext="${src_file##*.}"
dest_file="$src_folder/$src_name.mp4"
ffpmeg_params=""
case "$file_ext" in
mov)
ffpmeg_params="-vcodec h264 -acodec mp2"
;;
webm)
ffpmeg_params="-fflags +genpts -r 24"
;;
*)
;;
esac
if [ ! -z "$ffpmeg_params" ]; then
convert_cmd="/usr/local/bin/ffmpeg -i $file_path $ffpmeg_params $dest_file"
/usr/bin/env bash -c "$convert_cmd"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment