encode2mpeglight

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· 代码 · 共 1,545 行 · 第 1/5 页

TXT
1,545
字号
status_bit () {    local a    case $1 in        avi) bit=0 ;;        mpv) bit=1 ;;        mpa) bit=2 ;;        mpg) bit=3 ;;        img) bit=4 ;;        sub) bit=5 ;;        ach) bit=6 ;;        fno) bit=7 ;;        ch0) bit=8 ;;        sbm) bit=9 ;;        spl) bit=10 ;;    esac    if [[ $2 = set ]]; then        skip=$((skip|1<<bit))    else        return $(((skip&1<<bit) && 1))    fi}###############################################################################file_size () { #fsize,fint,ffrac,fpre    local -a PRE=([1]=K M G T)    local i=0    fsize=$(ls -l "$1" | awk '{print $5}')    fint=$fsize    ffrac=0    while ((fint>=1024)) ; do        ((fint/1024 < 1024)) && ffrac=$((( fint+=51 )%1024))        i=$((++i))        fint=$((fint/1024))    done    ffrac=$((ffrac*10/1024))    fpre=${PRE[i]}}###############################################################################show_file_info () {    file_size "$2"    echo "   $1: $2 is $fsize bytes, $fint.$ffrac ${fpre}B" >>"$output".log}###############################################################################show_finalvideo_info () {    local codec TYPE i VIDEO OUT ASPECT CH FAAC SUBST    SUBST=    VIDEO="$(mplayer -nocache -frames 0 -vo null -nosound "$2" 2>/dev/null | grep "^VIDEO:")"    if [[ ! $VIDEO ]]; then        # MPEGs with MPEG-4 video do not show all the video informations in one line,        # assebmling the informations (kbps is missing):        OUT="$(mplayer -nocache -frames 1 -vo null -nosound -v "$2" 2>/dev/null)"        if echo "$OUT" | grep -q '^\[V].*fourcc:0x10000004' ; then            VIDEO="VIDEO:  MPEG-4  $(echo "$OUT" | awk '$1=="VO:"&&$2=="[null]"{print $3}')"            ASPECT=$(echo "$OUT" | awk '$1=="Movie-Aspect"{print $3}')            case $ASPECT in                undefined) VIDEO="$VIDEO  (aspect 1)" ;;                1.33:1) VIDEO="$VIDEO  (aspect 2)" ;;                1.78:1) VIDEO="$VIDEO  (aspect 3)" ;;                2.21:1) VIDEO="$VIDEO  (aspect 4)" ;;                *) VIDEO="$VIDEO  (aspect $ASPECT)" ;;            esac            VIDEO="$VIDEO  $(echo "$OUT" | awk '$1=="[V]"{print $5}')"        fi    fi    echo "   $1: $VIDEO" >>"$output".log    #### removed -vc dummy    for i in $(mplayer -vo null -ao null -nocache -frames 1 -v "$2" 2>/dev/null | awk '/==> Found audio str/{print $NF}' | sort -n) ; do        echo -n "   $1: AUDIO[$i]: " >>"$output".log        codec=$(mplayer -ac mp3, -nocache -frames 0 -v -ao null -vo null "$2" -aid $i 2>/dev/null | \          sed '/Selected audio codec:/!d;s/[^(]*(//;s/).*//;s/AAC.*/& AAC/;s/.* //')        #### AAC info are insufficient/incorrect        if [[ $codec = AAC ]]; then            CH=$(mplayer -nocache -frames 0 -v -ao null -vo null "$2" -aid $i 2>/dev/null | awk '/FAAD: Negotiated samplerate:/{print $NF}')            if type &>/dev/null faad ; then                mplayer -dumpaudio -dumpfile "$output".audio -aid $i "$2" 2>/dev/null                FAAC=$(faad -i "$output".audio 2>&1 | tail -2 | head -n 1)                #ADTS, 4.087 sec, 103 kbps, 44100 Hz                rm -f "$output".audio                SUBST="s/AAC.*/AAC:$(echo "$FAAC" | sed 's/.*,\([^,]*Hz\).*/\1/'), "                SUBST="${SUBST}$CH ch, $(echo "$FAAC" | sed 's/,.*//'),"                SUBST="${SUBST}$(echo "$FAAC" | sed 's/.*,\([^,]*kbps\).*/\1/')"                SUBST="${SUBST}/;"            else                SUBST="s/2 ch,/$CH ch,/;"            fi        fi        mplayer -ac mp3, -nocache -frames 0 -v -ao null -vo null "$2" -aid $i 2>/dev/null | sed '/^Opening audio decode/,/^AUDIO:/!d;s/\r//g' | \          grep -e '^AC3:' -e '^MPEG' -e '^AUDIO:' | sed 's/AUDIO/'"$codec"'/;'"$SUBST"'q' >>"$output".log    done    TYPE=$1    shift    for i ; do        show_file_info "$TYPE" "$i"    done}###############################################################################video_duration () {    mencoder "$@" -ovc copy -nosound -o /dev/null -quiet 2>&1 | awk '/^Video stream:/{print $10+$10/$12}'}###############################################################################job_exit () {    EXIT=$?        status_bit mpg || [[ ! -f ${output}.mpg && ! -f ${output}01.mpg ]] || show_finalvideo_info  "MPEG" "${output}"*.mpg        [[ $usesbr ]] && ((DEBUG && usesbr>6)) && awk -v u=$usesbr -v f=$fsize \          'BEGIN{b=u*1024*1024;printf("--DEBUG: [usesbr] target: %dMB (%d bytes), error: %f%%\n",u,b,(b-f)*100/b)}' >>"$output".log    sec=$(($(pr_time)-STARTTIME))    echo " JOBEND: $output $(pr_date) ($((sec/3600))h$((sec/60%60))m$((sec%60))s)" >>"$output".log    rm -f "${CLEAN[@]}" psnr_??????.log    ((DEBUG)) && exec >&1- >&2- && exec >&3    if [[ -f $output.yuvscaler.log || -f $output.mpeg2enc.log ]]; then        echo    else        ((!EXIT)) && [[ ! $quiet ]] && cat "$output".log    fi    ((DEBUG)) && rm -f "$output".debug.fifo && kill $PROCTEE}###############################################################################me_log () {    rm -f "$output".fifo    mkfifo "$output".fifo    tee -a /dev/stderr <"$output".fifo | sed 's/.*\r//' | \      awk '/^PSNR:|^M[EP][ln]|^There are |^\[open]|^audio stream:|^number of|^subtitle|^==> |^Recommended video bitrate/{sub(/^/,"   INFO: [mencoder] ");        print}' >>"$output".log &}###############################################################################me_bit_log () {    rm -f "$output".fifo    mkfifo "$output".fifo    tee -a /dev/stderr <"$output".fifo | sed 's/.*\r//;/^Recommended video bitrate/!d;s/^/   INFO: [mencoder] /' >>"$output".log &}###############################################################################check_abr () {        # abr permitted:        # ac3: ( 8000/11025/12000)  8 16 24 32 40 48 56 64 80 96 112 128 144 160        # ac3: (16000/22050/24000)    16 24 32 40 48 56 64 80 96 112 128     160     192 224 256 288 320        # ac3: (32000/44100/48000)          32 40 48 56 64 80 96 112 128     160     192 224 256     320     384     448 512 576 640        # mp3: ( 8000/11025/12000)  8 16 24 32 40 48 56 64 80 96 112 128 144 160        # mp3: (16000/22050/24000)  8 16 24 32 40 48 56 64 80 96 112 128 144 160        # mp3: (32000/44100/48000)          32 40 48 56 64 80 96 112 128     160     192 224 256     320        # mp2: ( 8000/11025/12000)        # mp2: (16000/22050/24000)  8 16 24 32 40 48 56 64 80 96 112 128 144 160        # mp2: (32000/44100/48000)          32    48 56 64 80 96 112 128     160     192 224 256     320     384        # mp1: ( 8000/11025/12000)        # mp1: (16000/22050/24000)          32    48 56 64 80 96 112 128 144 160 176 192 224 256        # mp1: (32000/44100/48000)          32          64    96     128     160     192 224 256 288 320 352 384 416 448    case $1 in        ac3)            case $2 in                8000|11025|12000)                    case $3 in                        8|16|24|32|40|48|56|64|80|96|112|128|144|160) : ;;                        *) return 1 ;;                    esac                    ;;                16000|22050|24000)                    case $3 in                        16|24|32|40|48|56|64|80|96|112|128|160|192|224|256|288|320) : ;;                        *) return 1 ;;                    esac                    ;;                32000|44100|48000)                    case $3 in                        32|40|48|56|64|80|96|112|128|160|192|224|256|320|384|448|512|576|640) : ;;                        *) return 1 ;;                    esac                    ;;                *) return 1 ;;            esac            ;;        mp3)            case $2 in                8000|11025|12000|16000|22050|24000)                    case $3 in                        8|16|24|32|40|48|56|64|80|96|112|128|144|160) : ;;                        *) return 1 ;;                    esac                    ;;                32000|44100|48000)                    case $3 in                        32|40|48|56|64|80|96|112|128|160|192|224|256|320) : ;;                        *) return 1 ;;                    esac                    ;;                *) return 1 ;;            esac            ;;        mp2)            case $2 in                16000|22050|24000)                    case $3 in                        8|16|24|32|40|48|56|64|80|96|112|128|144|160) : ;;                        *) return 1 ;;                    esac                    ;;                32000|44100|48000)                    case $3 in                        32|48|56|64|80|96|112|128|160|192|224|256|320|384) : ;;                        *) return 1 ;;                    esac                    ;;                *) return 1 ;;            esac            ;;        mp1)            case $2 in                16000|22050|24000)                    case $3 in                        32|48|56|64|80|96|112|128|144|160|176|192|224|256) : ;;                        *) return 1 ;;                    esac                    ;;                32000|44100|48000)                    case $3 in                        32|64|96|128|160|192|224|256|288|320|352|384|416|448) : ;;                        *) return 1 ;;                    esac                    ;;                *) return 1 ;;            esac            ;;        *) return 1 ;;    esac}###############################################################################debug_line () {    echo "--DEBUG: [$PROGNAME] $2($1) $(eval echo $(sed -n $1p "$PROGFILE" | sed 's/ |.*//;s/.>.*//;s/</\\\</'))" >>"$output".log}###############################################################################error_line () {    echo "--DEBUG: [$PROGNAME] $1"    echo "**ERROR: [$PROGNAME] there has been an error during the execution of the previous line, this should not happen"    echo "possible causes:"    echo "  0) missing or misspelled input stream"    echo "  1) the input stream is corrupted"    echo "       -> try a different input stream"    echo "  2) one of the options used has triggered a bug present only on your combination of architecture/compiler/distribution"    echo "       -> try to recompile MPlayer with a different compiler version or try another distribution"    if ((SVN)); then        echo "  3) one of the options used is not valid or is buggy for your SVN/unsupported version of MPlayer/MEncoder"        echo "       -> check MPlayer's man page and/or try a supported release of MPlayer"    fi    echo    echo "submit a bugreport if you think this is a bug in $PROGNAME"    exit $ret}###############################################################################check_mencoder_abr () {    local codec lib ASR    codec=([4]=mp2 mp3 ac3 mp2 aac)    lib=([4]=libavcodec libavcodec libavcodec lib${TOOLAME} libfaac)    ASR=${encode%%:*}    check_abr ${codec[ASR]} $1 $2 || ! echo "**ERROR: [$PROGNAME] ${lib[ASR]} does not support $2 kbps / $1 Hz for ${codec[ASR]}" || exit 1}###############################################################################is_film2pal () {    local a    a=$(mplayer -nocache "$@" -vo null -nosound -benchmark -frames 60 -noquiet 2>/dev/null | tr '\015' '\012' | tail | \      awk -F/ '$1~/^V:/{s=$1;t=$2}END{match(s,/ [0-9]+$/);n=substr(s,RSTART+1);match(t,/[0-9]+ /);m=substr(t,1,RLENGTH-1);r=n/m;if(r>1.02)print "24"}')    [[ $a ]] && a=$(mplayer -nocache "$@" -vo null -nosound -benchmark -frames 1500 -noquiet 2>/dev/null | tr '\015' '\012' | tail | \      awk -F/ '$1~/^V:/{s=$1;t=$2}END{match(s,/ [0-9]+$/);n=substr(s,RSTART+1);match(t,/[0-9]+ /);m=substr(t,1,RLENGTH-1);r=n/m;      if(r>1.042)print "24000/1001fps";if(r<1.042&&r>1.041)print "24fps"}')    echo "$a"}################################################################################### ERROR if some options conflict is detected part 2/2################################################################################### libavcodec codec/asr/abr#### libtoolame asr/abr#### libmp3lame asr#### no check is done on the other channel in case of multiaudioif [[ $encode == [2-8]:?:? ]]; then    if [[ $srate ]]; then        r=$srate    else        r=$(id_find ID_AUDIO_RATE "${MPLAYERINFO[@]}")        if [[ ! $r ]]; then            do_log "++ WARN: [$PROGNAME] failure to detect the audio sample rate of the input stream"            [[ ! $multiaudio && ! $audioid ]] && do_log "++ WARN: [$PROGNAME] if your source video does not have audio use -encode 0:${encode#*:}" || \              do_log "++ WARN: [$PROGNAME] probably is incorrect the audio stream selected with -${audioid:+aid}${multiaudio:+multiaudio}"        fi        if [[ $mpeg && ! $usespeed ]]; then            case $frameformat in                *VCD) ((r != 44100)) && do_log "++ WARN: [$PROGNAME] $frameformat standard requires 44100kHz audio, add -srate 44100" ;;                DVD)  ((r != 48000)) && do_log "++ WARN: [$PROGNAME] $frameformat standard requires 48000kHz audio, add -srate 48000" ;;            esac        fi    fi    if [[ $encode == [4-7]:?:? ]]; then        check_mencoder_abr "$r" ${AUDIOPASS##*=}    elif [[ $encode == 8:?:? ]]; then        case $r in            8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000) : ;;            *) echo "**ERROR: [$PROGNAME] libfaac does not support $r Hz sample rate" ; exit 1 ;;        esac    else        case $r in            8000|11025|12000|16000|22050|24000|32000|44100|48000) : ;;            *) echo "**ERROR: [$PROGNAME] libmp3lame does not support $r Hz sample rate" ; exit 1 ;;        esac    fifi#### copy of non-MPEG audio in a VCDif [[ $step -gt 1 && $frameformat = VCD && $encode == 0:?:? && ( $mpeg || ${!audioformat} = copy ) && ! $testmca && ! $pictsrc ]]; then    a=$(id_find ID_AUDIO_CODEC "${MPLAYERINFO[@]}")    [[ $a != mp3 ]] && echo "**ERROR: [$PROGNAME] you cannot copy $a audio in a $frameformat" && exit 1fi#### mpegchannels > 2 only with ac3 and aac[[ $mpeg && ${mpegchannels:-2} -gt 2 && $encode == [2-57]:?:? ]] && CODEC=([2]=mp3 mp3 mp2 mp3 [7]=mp2) && \  echo "**ERROR: [$PROG

⌨️ 快捷键说明

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