Add script to convert from flv to mp4
This commit is contained in:
parent
5d3e60709b
commit
b78bb07cef
64
bin/convert-video-flv-to-mp4
Normal file
64
bin/convert-video-flv-to-mp4
Normal file
|
@ -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 <compress 1|0> <filename> <optional output name>${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"
|
Loading…
Reference in New Issue
Block a user