HOME/bin/make_web_video2
frankdelange ecd79740fd Add ~/bin
2022-06-26 20:20:31 +02:00

131 lines
3.1 KiB
Bash
Executable file

#!/bin/bash
# make_flv - make flash movie from any video file
# tools
#MENCODER=/opt/APPmplayer/bin/mencoder
MENCODER=/usr/bin/mencoder
#MENCODER=/usr/bin/avconv
#FFMPEG=$(which ffmpeg)
FFMPEG=$(which avconv)
# defaults
extension="mp4"
vcodec="libx264"
acodec="aac"
suffix=""
output_dir=""
geometry="1280x720"
filter="scale=1280:720"
thumbsize="640x480"
vbitrate=800k
abitrate=64k
# actions
convert () {
# convert to requested format (default: flv)
#ffmpeg -i $inputfile -ar 22050 -ab ${abitrate}k -acodec libmp3lame -b ${vbitrate}k -s 320x240 ${outputfile}
# OR mencoder:
# $MENCODER -vf ${filter} -oac mp3lame -lameopts br=${abitrate} -ovc lavc -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -lavcopts vcodec=${vcodec}:vbitrate=${vbitrate}:autoaspect:v4mv:vmax_b_frames=0:vb_strategy=1:mbd=2:mv0:trell:cbp:sc_factor=6:cmp=2:subcmp=2:predia=2:dia=2:preme=2:turbo:acodec=mp3:abitrate=56 ${inputfile} -o ${outputfile}
$FFMPEG \
-i ${inputfile} \
${nosound} -ar 44100 \
-vf ${filter} \
-b:v ${vbitrate} \
-b:a ${abitrate} \
-codec:v ${vcodec} \
-codec:a ${acodec} \
${extra_options} ${outputfile}
# -r ${framerate} \
# $MENCODER \
# ${nosound} -srate 22050 \
# -oac lavc -ovc lavc -of lavf \
# -lavcopts vcodec=${vcodec}:vbitrate=${vbitrate}:acodec=libmp3lame:abitrate=${abitrate} \
# -vf ${filter} \
# ${inputfile} -o ${outputfile}
# add metadata for flash video
[ "$filetype" == ".flv" ] && flvtool2 -U ${outputfile}
# make thumbnail
ffmpeg -y -i $outputfile -vframes 1 -ss 00:00:02 -an -vcodec mjpeg -f rawvideo -s ${thumbsize} ${outputfile}.thumb
}
help () {
echo " "
echo "make_flv video file converter (defaults to flv - flash video)"
echo " "
echo " -i file Inputfile"
echo " -d dir [ outputDirectory (default: current directory) ]"
echo " -s suffix [ Suffix (default: none) ]"
echo " -x ext [ eXtension (default: ${extension}) ]"
echo " -c codec [ video Codec (default: ${vcodec}) ]"
echo " -L [ rotate video Left/counterclockwise ]"
echo " -R [ rotate video Right/clockwise ]"
echo " -v [ Video bitrate (default: ${vbitrate}) ]"
echo " -a [ Audio bitrate (default: ${abitrate}) ]"
echo " -A [ no sound in output video ]"
echo " -h this Help message"
echo " "
echo "final destination file is (outputdirectory/) (basename inputfile)(-suffix).(extension)"
}
# parameters
while getopts "hi:d:s:t:LRv:a:A" OPTION
do
case $OPTION in
h)
help
exit
;;
i)
inputfile="$OPTARG"
filename=$(basename $inputfile|sed -e 's#\..*##')
;;
d)
output_dir="${OPTARG}/"
;;
s)
suffix="-${OPTARG:-}"
;;
t)
extension="${OPTARG:-mp4}"
;;
c)
vcodec="${OPTARG:-libx264}"
;;
L)
filter=${filter:-}${filter:+,}transpose=2
thumbsize="480x640"
;;
R)
filter=${filter:-}${filter:+,}transpose=1
thumbsize="480x640"
;;
v)
vbitrate="${OPTARG:-$vbitrate}"
;;
a)
abitrate="${OPTARG:-$abitrate}"
;;
A)
nosound="-an "
;;
esac
done
# show help if called without options
[ $OPTIND = 1 ] && help && exit
outputfile=${output_dir}${filename}${suffix}.${extension}
if [ "${vcodec}" == "libx264" ]; then
extra_options="-strict -2 "
fi
echo $extra_options
echo filename: $filename
echo outputfile: $outputfile
convert
exit