From b78bb07cefe637358196090c90f93fa1646c5ebf Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Sun, 12 Sep 2021 17:57:36 -0400 Subject: [PATCH] Add script to convert from flv to mp4 --- bin/{avi-to-mp4 => convert-video-avi-to-mp4} | 0 bin/convert-video-flv-to-mp4 | 64 ++++++++++++++++++++ 2 files changed, 64 insertions(+) rename bin/{avi-to-mp4 => convert-video-avi-to-mp4} (100%) create mode 100644 bin/convert-video-flv-to-mp4 diff --git a/bin/avi-to-mp4 b/bin/convert-video-avi-to-mp4 similarity index 100% rename from bin/avi-to-mp4 rename to bin/convert-video-avi-to-mp4 diff --git a/bin/convert-video-flv-to-mp4 b/bin/convert-video-flv-to-mp4 new file mode 100644 index 0000000..6074570 --- /dev/null +++ b/bin/convert-video-flv-to-mp4 @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# This is for reencoding an FLV video to mp4 using an mpeg4 encoder. +# Can optionally compress the video. + +if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) +fi +if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + MAGENTA="$(tput setaf 5)" + CYAN="$(tput setaf 6)" + BOLD="$(tput bold)" + NORMAL="$(tput sgr0)" +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + BOLD="" + NORMAL="" +fi + +if [[ $1 == "" || $2 == "" ]]; then + printf "${BOLD}${RED}Format: $0 ${NORMAL}\n" + exit 1 +fi + +compress="$1" + +filename=$(basename -- "$2") +extension="${filename##*.}" +filename="${filename%.*}" + +output="$3" +if [[ $output == "" ]]; then + output="${filename}_CONVERTED" +fi + +printf "\n${YELLOW}${BOLD}Encoding '$filename.$extension' | compress: $compress | output: $output.mp4${NORMAL}\n" + +if [[ $compress -eq 1 ]]; then + temp_output="temp_$output.mp4" +else + temp_output="$output.mp4" +fi + +# convert first. +# we convert then compress instead of compressing on first pass because this results in a slightly higher bitrate. +ffmpeg -y -stats -loglevel level+error -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i "$filename.$extension" -c:a aac -c:v h264_nvenc -b:v 5M "$temp_output" + +if [[ $compress -eq 1 ]]; then + compress-video 1 "$temp_output" "$output" + rm "$temp_output" +else + printf "\n" +fi + +printf "${GREEN}${BOLD}Done encoding '$filename.$extension' to '$output.mp4'${NORMAL}\n\n"