lav2mpeg

来自「Motion JPEG编解码器源代码」· 代码 · 共 588 行 · 第 1/2 页

TXT
588
字号
#!/bin/sh## A convenient front-end for the various mpeg encoding tools.# Allows "1 command" production of a video stream...# # Licensed under GPL (see http://www.fsf.org/licenses/gpl.html or contact# the Free Software Foundation for a copy)# Copyright Scott Moser# these can be changed with env variables, just set and export to overrideNICEVAL=${NICEVAL:-19}LAV2YUV=${LAV2YUV:-"lav2yuv"}YUVSCALER=${YUVSCALER:-"yuvscaler"}MPEG2ENC=${MPEG2ENC:-"mpeg2enc"}LAV2WAV=${LAV2WAV:-"lav2wav"}AUDIOENC=${AUDIOENC:-"mp2enc"}       # can be "toolame" or "mp2enc"MPLEX=${MPLEX:-"mplex"}YUVDENOISE=${YUVDENOISE:-"yuvdenoise"}LAVINFO=${LAVINFO:-"lavinfo"}NOISYLOGFILE=""                       # if not set, will be outputfilename.log -- only used if -L flag sentQUIETLOG=${QUIETLOG:-"lav2mpeg.log"}  # if set to not "" will log all normal messages to this file as well as stdoutLOGDATE=${LOGDATE:-1}                 # whether or not to output the date in log messagesLOGDATESTR=${LOGDATESTR:-"+%H:%M:%S"} # format for the date - only used if logdate!=0LOGCOMMANDS=${LOGCOMMANDS:-0};        # if non-zero, will output the commands it runs.  commands are always logged to NOISYLOGFILE if usedLOGONLY=${LOGONLY:-""}                # will only log the commands it would use if set  (for example useage/testing)LAV2MPEGRC=${LAV2MPEGRC:-"$HOME/.lav2mpegrc"}   # set this to contain your lav2mpeg rc file -- in bash sourceable syntax.                                      # it can modify any ENV vars in this script                                      # or set a "LAV2MPEG_OPTIONS" ENV to prepend default options that will be overridden by explicit command line options.if [ "$LOGONLY" != "" ]; then   LOGCOMMANDS=1fiVCD_MEDIUM_BR=${VCD_MEDIUM_BR:-1550}VCD_HIGH_BR=${VCD_HIGH_BR:-1800}SVCD_HIGH_BR=${SVCD_HIGH_BR:-3000}SVCD_HIGH_QUAL=${SVCD_HIGH_QUAL:-5}SVCD_HIGH_BUFFSIZE=${SVCD_HIGH_BUFFSIZE:-100}# extra flags for the encoders (will be the last thing on the line before file names)EXTRA_LAV2YUV=${EXTRA_LAV2YUV:-""}EXTRA_YUVSCALER=${EXTRA_YUVSCALER:-""}EXTRA_MPEG2ENC=${EXTRA_MPEG2ENC:-""}EXTRA_LAV2WAV=${EXTRA_LAV2WAV:-""}EXTRA_AUDIOENC=${EXTRA_AUDIOENC:-""}EXTRA_MPLEX=${EXTRA_MPLEX:-""}EXTRA_YUVDENOISE=${EXTRA_YUVDENOISE:-""}# things that can be changed with arguments# don't let an env override, to avoid confusionbitrate=1152quality=12saveraw=0mode="vcd"outputres=""encode_quality=2outfile=""stereo=1noisy=0logall=0aencbpr_stereo=224aencbpr_mono=112use_fifo=0# -- shouldn't have to change below hereNICE="nice -n $NICEVAL"# functionslogIt() {   if [ $LOGDATE -ne 0 ]; then      NOW=$(date $LOGDATESTR)      NOW="$NOW - "   fi   if [ "$logfile" = "" ]; then      echo "${NOW}$@"   else      echo "${NOW}$@" | tee -a $logfile   fi   if [ "$output_noisy" != ""  ]; then      echo "${NOW}$@" >> $noisylog    fi}cleanExit() {   # delete raw files if sawraw is 0 or exiting with non-zero   if [ $saveraw -eq 0 -a "$1" = "0" ]; then      rm -f $audio $video   fi   exit $1}getTimeDiff() {   if [ $# -lt 2 ]; then      return   fi   diff=$(expr $2 - $1)   hours=$(expr $diff / 3600)   temp=$(expr $hours \* 3600 )   diff=$(expr $diff - $temp )   minutes=$(expr $diff / 60)   sec=$(expr $diff % 60)   printf "%i:%02d:%02d\n" "$hours" "$minutes" "$sec"}doStep() {   if [ "$LOGCOMMANDS" == "0" ]; then      echo "COMMAND=${step[$count]}"   fi   if [ "$LOGONLY" == "" ]; then      eval ${step[$count]}   fi}usage(){  name=`basename $0`  cat << ENDUsage: $name [ -s/S -k/K -f/F -l/L -n/N -y/Y ] [ -m mode ] [ -e 0|1|2 ] [ -o outputFile ] [ -b vidbitrate ] [ -a audbitrate ] [ -q 0-30 ] [ -d XxY ] srcfile...  s/S - stereo : -s=off -S=on                                    (default auto)  k/K - keep raw output files (.m1v, .m2v, .mp2) : -k=no -K=yes  (default no)  f/F - use fifos : -f=no -F=yes                                 (default no)  l/L - log all encoding : -l=no -L=yes                          (default no)  n/N - be noisy (don't hide output of tools) : -n=no -N=yes     (default no)  y/Y - yuvdenoise : -y=don't use -Y=use           (default e=1|2 use e=0 dont)  m - one of MODES (see below)                                   (default $mode)  e - encoding quality : 0, 1, or 2                              (default $encode_quality)  o - output file ( defaults to firstInputFileName.mpg )  b - video bitrate in kbps  ( only used when -o is "mpeg1" or "mpeg2" )  a - audio bitrate in kpbs  ( only used when -o is not "vcd*" )  q - quality for mpeg2enc   ( only used when -o is "mpeg1" or "mpeg2" )  d - dimensions XxY         ( only used when -o is "mpeg1" or "mpeg2" )                               defaults to same as input  MODES:      vcd          -- standard VCD                    (352x240 or 352x288)      vcd_medium   -- ${VCD_MEDIUM_BR}kbps video VCD              (352x240 or 352x288)      vcd_high     -- ${VCD_HIGH_BR}kbps video VCD              (352x240 or 352x288)      svcd         -- standard SVCD                   (480x480 or 480x576)      svcd_high    -- ${SVCD_HIGH_BR}kbps(max) vbr @qual=${SVCD_HIGH_QUAL}       (480x480 or 480x576)      mpeg1        -- honor -a -b -q -d flags default resolution same as input      mpeg2        -- honor -a -b -q -d flags default resolution same as input   EXAMPLE:      VCD:  $name file.avi              - will create a VCD compatible mpeg named file.mpg      mpeg2: $name -m mpeg2 -o output.mpg file.edl              - will create a mpeg2 with default bitrate in same res as input      mpeg1: $name -a 160 -b 2110 -d 320x240 -m mpeg1 -o output.mpg file.edl              - will create a mpeg2 with videobitrate=2110 and audio=160              - and resolution 320x240      debug: export LOGONLY=1; $name -m mpeg2 -o output.mpg file.edl              - will print out the commands it would use to do this, but              - not do anything   please see the script for more info and environment variables set/usedENDexit 1}printDebugInfo() {   logIt "going from ${video_width}x${video_height} ($video_norm) to ${output_width}x${output_height} in $mode with quality=$quality, bitrate=$bitrate and encodequal=${encode_quality}"   logIt "outfile=$outfile audio=$audio video=$video"   logIt "lav2yuv_flags=$lav2yuv_flags"   logIt "yuscaler_flags=$yuvscaler_flags"   logIt "mpeg2enc_flags=$mpeg2enc_flags"   logIt "lav2wav_flags=$lav2wav_flags"   logIt "audioenc_flags=$audioenc_flags"   logIt "mplex_flags=$mplex_flags"   logIt "need_scale=$needscale"   logIt "downscale=$downscaling"}if [ $# -eq 0 -o "$1" == "--help" -o "$1" = "-h" ]; then   usage;   exit 1fiLAVRC_COUNT=0if [ -e $LAV2MPEGRC ]; then   logIt "Sourcing lav2mpgrc file $LAV2MPEGRC (this can change defaults!)"   . $LAV2MPEGRC   LAVRC_COUNT=$(echo $LAV2MPEG_OPTIONS | wc -w )fiinfostr=""while getopts "sSkKfFlLnNyYb:a:q:d:m:e:o:" opt  $LAV2MPEG_OPTIONS $@do   case $opt in      s) userstereo=0         infostr="${infostr} using mono -"         ;;      S) userstereo=1         infostr="${infostr} using stereo -"         ;;      k) saveraw=0         infostr="${infostr} not saving raw files -"         ;;      K) saveraw=1         infostr="${infostr} saving raw files -"         ;;      f) use_fifo=0         infostr="${infostr} not using fifos-"         ;;      F) use_fifo=1         infostr="${infostr} using fifos-"         ;;      l) logall=0         infostr="${infostr} not logging all -"         ;;      L) logall=1         infostr="${infostr} logging all -"         ;;      n) noisy=0         infostr="${infostr} not being noisy -"         ;;      N) noisy=1         infostr="${infostr} being noisy -"         ;;      y) userdenoise=0         infostr="${infostr} not using yuvdenoise -"         ;;      Y) userdenoise=1         infostr="${infostr} using yuvdenoise -"         ;;      b) bitrate=$OPTARG         infostr="${infostr} using video bitrate=$bitrate -"         ;;      a) useraencbpr=$OPTARG         infostr="${infostr} using audio bitrate=$useraencbpr"         ;;      q) quality=$OPTARG         infostr="${infostr} using quality=$quality -"         ;;      d) outputres=$OPTARG         infostr="${infostr} using outputres=$outputres -"         ;;      m) mode=$OPTARG         infostr="${infostr} mode=$mode -"         ;;      e) encode_quality=$OPTARG         infostr="${infostr} encode_quality=$encode_quality -"         ;;      o) outfile=$OPTARG         infostr="${infostr} outfile=$outfile -"         ;;      ?)         usage         ;;    esacdonelet MOPTIND=OPTIND-LAVRC_COUNTshift `expr $MOPTIND-1`if [ "${QUIETLOG}" != "" ]; then   logfile=${QUIETLOG}else   logfile="/dev/null"fi#uncomment to blank logfile#echo "" > $logfilelogIt "$infostr"# lavinfo should set up video_frames, video_width# video_height, video_inter, video_norm, audio_chanseval $($LAVINFO $@ | grep "=")  # grep for = to remove Warningsif [ "$video_frames" == "" ]; then   logIt "'lavinfo $@' died! exiting"   logIt " maybe you don't have lavinfo. or your input flags were wrong"   logIt " input files must be the last input on the command line"   exit 1ficase $mode in    vcd*)      case $video_norm in         NTSC)  output_width=352; output_height=240 ;;         PAL)   output_width=352; output_height=288 ;;         SECAM) output_width="SECAM_VCD_WIDTH???"; output_height="SECAM_VCD_HEIGHT";;      esac      ;;   svcd*)      case $video_norm in         NTSC)  output_width=480; output_height=480 ;;         PAL)   output_width=480; output_height=576;;         SECAM) output_width="SECAM_SVCD_WIDTH???"; output_height="SECAM_SVCD_HEIGHT" ;;      esac      ;;   mpeg*)      if [ "$outputres" != "" ]; then

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?