comparison TOOLS/encode2mpeglight @ 20858:4e8dbc741909

update to 0.6.2, patch by Giacomo Comes, comes naic edu
author diego
date Sun, 12 Nov 2006 23:38:35 +0000
parents 36589811e5d0
children 21b938300bf7
comparison
equal deleted inserted replaced
20857:f973dc7132a8 20858:4e8dbc741909
1 #!/bin/bash 1 #!/bin/bash
2 # 2 #
3 # Version: 0.5.5 3 # Version: 0.6.2
4 # 4 #
5 # Licence: GPL 5 # Licence: GPL
6 # 6 #
7 # 2004-05-22 Giacomo Comes <encode2mpeg at users.sourceforge.net> 7 # 2004-05-22 Giacomo Comes <encode2mpeg at users.sourceforge.net>
8 # 2006-01-14 <encode2mpeg at katamail.com> 8 # 2006-11-06 <encode2mpeg at email.it>
9 # 9 #
10 # Pourpose: Convert anything MPlayer can play to AVI/VCD/SVCD/DVD mpeg 10 # Purpose: Convert anything MPlayer can play to AVI/VCD/SVCD/DVD MPEG
11 # 11 #
12 # This program is free software; you can redistribute it and/or modify 12 # encode2mpeglight is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by 13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License. 14 # the Free Software Foundation; either version 2 of the License.
15 15
16 # This program is distributed in the hope that it will be useful, 16 # encode2mpeglight is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details. 19 # GNU General Public License for more details.
20 20
21 # You should have received a copy of the GNU General Public License 21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software 22 # along with encode2mpeglight; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 24
25 25
26 ############################################################################### 26 ###############################################################################
27 # encode2mpeglight is a program that can create VCD/SVCD/DVD mpegs 27 # encode2mpeglight is a program that can create VCD/SVCD/DVD MPEGs
28 # and eventually extract VobSub subtitles from a DVD using only 28 # and eventually extract VobSub subtitles from a DVD using only
29 # MEncoder/MPlayer. 29 # MEncoder/MPlayer.
30 # 30 #
31 # encode2mpeglight is a stripped release of encode2mpeg and therefore the 31 # encode2mpeglight is a stripped release of encode2mpeg and therefore the
32 # code is redundant in several places, with many variables defined and 32 # code is redundant in several places, with many variables defined and
41 # - creation, burn and verification of the disk image 41 # - creation, burn and verification of the disk image
42 # - creation of MPEG-4 avi and subtitles for a hardware player 42 # - creation of MPEG-4 avi and subtitles for a hardware player
43 # and more, consider to use the full release (http://encode2mpeg.sf.net) 43 # and more, consider to use the full release (http://encode2mpeg.sf.net)
44 # 44 #
45 # encode2mpeglight is mainly tested with the stable release of MPlayer, 45 # encode2mpeglight is mainly tested with the stable release of MPlayer,
46 # I try to make it work with CVS too, but due to the "instable" nature of 46 # I try to make it work with SVN too, but due to the "unstable" nature of
47 # CVS, bugs may suddenly appear. If you find any, please report it to me. 47 # SVN, bugs may suddenly appear. If you find any, please report them to me.
48 ############################################################################### 48 ###############################################################################
49 49
50 ############################################################################### 50 ###############################################################################
51 #### start 51 #### start
52 ############################################################################### 52 ###############################################################################
66 echo "Arguments enclosed in [ ] are optional" 66 echo "Arguments enclosed in [ ] are optional"
67 } 67 }
68 ############################################################################### 68 ###############################################################################
69 ModeText () { 69 ModeText () {
70 echo 70 echo
71 echo -e "$PROGNAME defaults to encode2mpeg's Mpeg Mode, the others mode are not" 71 echo "$PROGNAME defaults to encode2mpeg's MPEG Mode, the other modes are not"
72 echo -e "available" 72 echo "available."
73 } 73 }
74 ############################################################################### 74 ###############################################################################
75 usage () { 75 usage () {
76 echo -e "Usage: $PROGNAME options source\nOptions:" 76 echo -e "Usage: $PROGNAME options source\nOptions:"
77 sed -n '/^#### PARSING/,/^done/!d;/^done/q;/^[ ]*-[^)]*)/,/#-/!d;s/)$//;s/) *#/ /;s/#-/# /;s/ *#L.$//;s/#//;p' "$PROGFILE" 77 sed -n '/^#### PARSING/,/^done/!d;/^done/q;/^[ ]*-[^)]*)/,/#-/!d;s/)$//;s/) *#/ /;s/#-/# /;s/ *#L.$//;s/#//;p' "$PROGFILE"
90 sed -n '/^#### PARSING/,/^done/!d;/^done/q;/^[ ]*-[^)]*)/!d;s/)$//;s/) *#/ /;s/ *#L.$//;p' "$PROGFILE" 90 sed -n '/^#### PARSING/,/^done/!d;/^done/q;/^[ ]*-[^)]*)/!d;s/)$//;s/) *#/ /;s/ *#L.$//;p' "$PROGFILE"
91 OptionsText 91 OptionsText
92 } 92 }
93 ############################################################################### 93 ###############################################################################
94 mp_identify () { 94 mp_identify () {
95 mplayer -identify -vo null -ao null -nocache "$@" -frames 0 2>/dev/null 95 mplayer -msglevel identify=6 -vo md5sum:outfile=/dev/null -ao null -nocache -frames 0 "$@" 2>/dev/null
96 }
97 ###############################################################################
98 id_find () {
99 local ID=$1
100 shift
101 mp_identify "$@" | awk -v id=$ID -F= '$1==id{t=$2}END{print t}'
96 } 102 }
97 ############################################################################### 103 ###############################################################################
98 get_aspect () { 104 get_aspect () {
99 mplayer -vo null -ao null -nocache -frames 4 "$@" 2>/dev/null | sed '/^Movie-Aspect is/!d;s/.*Movie-Aspect is //;s/:.*//' 105 mplayer -vc -mpegpes, -vo null -ao null -nocache -frames 4 "$@" 2>/dev/null | sed '/^Movie-Aspect is/!d;s/.*Movie-Aspect is //;s/:.*//'
100 } 106 }
101 ############################################################################### 107 ###############################################################################
102 mlistopt () { 108 mlistopt () {
103 mplayer -list-options 2>&1 | awk '$1=="Name"{m=1}{if(m&&$1!="Name"&&$1!=""&&$1!="Total:")print "\""$1"\""}' 109 mplayer -list-options 2>&1 | awk '$1=="Name"{m=1}{if(m&&$1!="Name"&&$1!=""&&$1!="Total:")print "\""$1"\""}'
104 } 110 }
105 ############################################################################### 111 ###############################################################################
106 pre_log () { 112 do_log () {
107 echo "$1" 113 echo "$1"
108 WARN="$WARN${WARN:+\n}$1" 114 ((LG)) && echo "$1" >>"$output".log || WARN="$WARN${WARN:+\n}$1"
109 } 115 }
110 ############################################################################### 116 ###############################################################################
111 isarg () { 117 isarg () {
112 if [[ ${2:0:1} = - || ! $2 || $2 = help ]]; then 118 if [[ ${2:0:1} = - || ! $2 || $2 = help ]]; then
113 [[ ${2:0:1} = - ]] && echo "**ERROR: [$PROGNAME] invalid argument '$2' for option '$1'" 119 [[ ${2:0:1} = - ]] && echo "**ERROR: [$PROGNAME] invalid argument '$2' for option '$1'"
131 } 137 }
132 ############################################################################### 138 ###############################################################################
133 get_abr () { 139 get_abr () {
134 local INFO ABR 140 local INFO ABR
135 INFO=$(mp_identify "${MPLAYEROPT[@]}" ${dvddev:+-dvd-device "$dvddev"} "$@" | grep '^ID_') 141 INFO=$(mp_identify "${MPLAYEROPT[@]}" ${dvddev:+-dvd-device "$dvddev"} "$@" | grep '^ID_')
136 ABR=$(echo "$INFO" | grep '^ID_AUDIO_BITRATE' | cut -f2 -d=) 142 ABR=$(echo "$INFO" | grep '^ID_AUDIO_BITRATE' | tail -1 | cut -f2 -d=)
137 case $(echo "$INFO" | grep '^ID_AUDIO_CODEC' | cut -f2 -d=) in 143 case $(echo "$INFO" | grep '^ID_AUDIO_CODEC' | cut -f2 -d=) in
138 dvdpcm) abr=$((abr+ABR/1024)) ;; 144 dvdpcm) abr=$((abr+ABR/1024)) ;;
139 *) abr=$((abr+ABR/1000)) ;; 145 *) abr=$((abr+ABR/1000)) ;;
140 esac 146 esac
141 } 147 }
162 elif [[ -f $SRCDOCDIR/html/$1 ]]; then 168 elif [[ -f $SRCDOCDIR/html/$1 ]]; then
163 HTML=$(get_pwd "$SRCDOCDIR/html" $1) 169 HTML=$(get_pwd "$SRCDOCDIR/html" $1)
164 elif [[ $1 && ! -d $INSTDOCDIR/html && ! -d $SRCDOCDIR/html ]]; then 170 elif [[ $1 && ! -d $INSTDOCDIR/html && ! -d $SRCDOCDIR/html ]]; then
165 HTML="http://encode2mpeg.sourceforge.net/html/$1" 171 HTML="http://encode2mpeg.sourceforge.net/html/$1"
166 fi 172 fi
167 LIST=(mozilla firefox) 173 LIST=(mozilla seamonkey firefox)
168 [[ ${HTML:0:1} = / ]] && PREFIX=file:// || PREFIX= 174 [[ ${HTML:0:1} = / ]] && PREFIX=file:// || PREFIX=
169 for ((i=0;i<${#LIST[*]};i++)); do 175 for ((i=0;i<${#LIST[*]};i++)); do
170 type ${LIST[i]} &>/dev/null && ${LIST[i]} -remote 'openURL('"$PREFIX$HTML"',new-tab)' 2>/dev/null && return 176 type ${LIST[i]} &>/dev/null && ${LIST[i]} -remote 'openURL('"$PREFIX$HTML"',new-tab)' 2>/dev/null && return
171 done 177 done
172 LIST=(mozilla firefox opera konqueror epiphany galeon) 178 LIST=(mozilla firefox seamonkey opera konqueror epiphany galeon)
173 if [[ $BROWSER ]]; then 179 if [[ $BROWSER ]]; then
174 type "$BROWSER" &>/dev/null && LIST=("$BROWSER") || echo "++ WARN: default browser '$BROWSER' not found, using builtin browser list" 180 type "$BROWSER" &>/dev/null && LIST=("$BROWSER") || echo "++ WARN: default browser '$BROWSER' not found, using builtin browser list"
175 fi 181 fi
176 for ((i=0;i<${#LIST[*]};i++)); do 182 for ((i=0;i<${#LIST[*]};i++)); do
177 if type "${LIST[i]}" &>/dev/null; then 183 if type "${LIST[i]}" &>/dev/null; then
185 fi 191 fi
186 done 192 done
187 } 193 }
188 194
189 ############################################################################### 195 ###############################################################################
190 #### variables initialization 196 #### variable initialization
191 ############################################################################### 197 ###############################################################################
192 abr=;asr=;vbr=;vfr=;videonorm=;frameformat=;output=;audioformat=;mp1=;mp2=;mp3=;ac3=;dts=;lpcm=;normalize=;volume=;multiaudio=;mpegchannels=;quiet=;resume=;blank=;encode=;ofps=;mono=;usesbr=;sbr=;clear=;keep=;frames=;avisplit=;channels=;vcustom=;acustom=;cpu=;interlaced=;mpegaspect=;intra_matrix=;inter_matrix=;fixavi=;mpeg=;crop=;audioid=;dvdaudiolang=;bframes=;firstchap=;lastchap=;dvdtrack=;addchapter=;cdi=;mpegfixaspect=;nowait=;vf=;frameres=;trick=;autocrop=;ac=;afm=;cache=;removecache=;turbo=;dvddev=;srate=;endpos=;fourcc=;menu=;menubg=;dvdtitle=;rotate=;menuvtsbg=;autosync=;telecine=;AFMT=;telesrc=;vcodec=;vrfyumnt=;burniso=;verify=;fixasync=;removedir=;MPGRES=;GOP=;TXTSUBOPT=;usespeed=;testmca=;chconf=;noodml=;pictsrc=;slideaudio=;audioonly=;norc= 198 abr=;asr=;vbr=;vfr=;videonorm=;frameformat=;output=;audioformat=;mp1=;mp2=;mp3=;ac3=;dts=;lpcm=;aac=;normalize=;volume=;multiaudio=;mpegchannels=;quiet=;resume=;blank=;encode=;ofps=;mono=;usesbr=;sbr=;clear=;keep=;frames=;avisplit=;channels=;vcustom=;acustom=;cpu=;interlaced=;mpegaspect=;intra_matrix=;inter_matrix=;fixavi=;mpeg=;crop=;audioid=;dvdaudiolang=;bframes=;firstchap=;lastchap=;dvdtrack=;addchapter=;cdi=;mpegfixaspect=;nowait=;vf=;frameres=;trick=;autocrop=;afm=;cache=;removecache=;turbo=;dvddev=;srate=;endpos=;fourcc=;menu=;menubg=;dvdtitle=;rotate=;menuvtsbg=;autosync=;telecine=;AFMT=;telesrc=;vcodec=;vrfyumnt=;burniso=;verify=;fixasync=;removedir=;MPGRES=;GOP=;TXTSUBOPT=;usespeed=;testmca=;chconf=;noodml=;pictsrc=;slideaudio=;audioonly=;norc=;rawsub=;vobsubsrc=;af=;lavf=;subrender=;harddup=;overburn=
193 unset encsid encsdx encsla addsub addsdx addsla savecache txtsub txtsubopts 199 unset encsid encsdx encsla addsub addsdx addsla savecache txtsub txtsubopts
194 zoom=0 200 zoom=0
195 scale=1 201 scale=1
196 fast=1 202 fast=1
197 MAXSTEP=6 # burn is the default 203 MAXSTEP=6 # burn is the default
236 unset CLEAN 242 unset CLEAN
237 DEBUG=0 243 DEBUG=0
238 LAVC= 244 LAVC=
239 WARN= 245 WARN=
240 LOG= 246 LOG=
247 LG=0
248 SVN=0
241 MAXFIX=20 249 MAXFIX=20
242 timelen=0 250 timelen=0
243 ocrsub=0 251 ocrsub=0
244 slidefps=1 252 slidefps=1
245 default_intra=8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27 253 default_intra=8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27
280 if [[ -s ~/.encode2mpegrc ]]; then 288 if [[ -s ~/.encode2mpegrc ]]; then
281 for ((i=0;i<${#CMD[*]};i++)); do 289 for ((i=0;i<${#CMD[*]};i++)); do
282 [[ ${CMD[i]} = -norc ]] && norc=1 && break 290 [[ ${CMD[i]} = -norc ]] && norc=1 && break
283 done 291 done
284 if [[ ! $norc ]] && ! awk '{if($1~"^#")exit 1}' ~/.encode2mpegrc ; then 292 if [[ ! $norc ]] && ! awk '{if($1~"^#")exit 1}' ~/.encode2mpegrc ; then
285 WARN="$WARN${WARN:+\n}++ WARN: [$PROGNAME] ~/.encode2mpegrc appears to contain comments, ignoring it" 293 do_log "++ WARN: [$PROGNAME] ~/.encode2mpegrc appears to contain comments, ignoring it" >/dev/null
286 norc=1 294 norc=1
287 fi 295 fi
288 [[ ! $norc ]] && set -- $(<~/.encode2mpegrc) "$@" 296 [[ ! $norc ]] && set -- $(<~/.encode2mpegrc) "$@"
289 fi 297 fi
290 298
404 vfr=$2 412 vfr=$2
405 isarg $1 "$2" direct 413 isarg $1 "$2" direct
406 shift 414 shift
407 ;; 415 ;;
408 -n|-video-norm) #<n|p|s> 416 -n|-video-norm) #<n|p|s>
409 #-set the video norm of the VCD/SVCD/DVD 417 # set the video norm of the VCD/SVCD/DVD; NTSC is USA standard,
418 # PAL is European standard and SECAM is French standard; concerning
419 #-VCD/SVCD/DVD encoding, SECAM is equivalent to PAL
410 case $2 in 420 case $2 in
411 n|N|ntsc|NTSC) videonorm=n ;; 421 n|N|ntsc|NTSC) videonorm=n ;;
412 p|P|pal|PAL) videonorm=p ;; 422 p|P|pal|PAL) videonorm=p ;;
413 s|S|secam|SECAM) videonorm=s ;; 423 s|S|secam|SECAM) videonorm=s ;;
414 doc|help) isarg $1 $2 direct ;; 424 doc|help) isarg $1 $2 direct ;;
534 [[ $2 -eq 0 ]] && mpegmbr= 544 [[ $2 -eq 0 ]] && mpegmbr=
535 isarg $1 "$2" mpeg 545 isarg $1 "$2" mpeg
536 shift 546 shift
537 ;; 547 ;;
538 -mpegchannels) #<1-6> 548 -mpegchannels) #<1-6>
539 # number of channels of the mpeg audio stream, 1-6 for ac3 and lpcm; 549 # number of channels of the MPEG audio stream, 1-6 for ac3 and lpcm;
540 # 1-2 for mp1, mp2 and mp3; 3-6 for mp2 Multichannel Audio; for the 550 # 1-2 for mp1, mp2 and mp3; 3-6 for mp2 Multichannel Audio; for the
541 #-avi audio stream use MPlayer's option -channels 551 #-avi audio stream use MPlayer's option -channels
542 mpegchannels=2 552 mpegchannels=2
543 isarg $1 "$2" direct 553 isarg $1 "$2" direct
544 echo "$2" | grep -q '^[1-6]$' && mpegchannels=$2 554 echo "$2" | grep -q '^[1-6]$' && mpegchannels=$2
555 volume=$2 565 volume=$2
556 isarg $1 "$2" direct 566 isarg $1 "$2" direct
557 shift 567 shift
558 ;; 568 ;;
559 -noscale) # 569 -noscale) #
560 # encode2mpeg automatically scales the video according to the mpeg 570 # encode2mpeg automatically scales the video according to the MPEG
561 # profile chosen, this option disable this feature; used mainly 571 # profile chosen, this option disables this feature; used mainly
562 #-for debug purpose 572 # for debug purposes.
563 [[ $2 = doc || $2 = help ]] && isarg $1 $2 direct 573 [[ $2 = doc || $2 = help ]] && isarg $1 $2 direct
564 scale= 574 scale=
565 ;; 575 ;;
566 -monochrome) 576 -monochrome)
567 #-create B/W video or avoid color artifacts in B/W source streams 577 #-create B/W video or avoid color artifacts in B/W source streams
568 [[ $2 = doc || $2 = help ]] && isarg $1 $2 direct 578 [[ $2 = doc || $2 = help ]] && isarg $1 $2 direct
569 YUVSCALEROPT="$YUVSCALEROPT -O MONOCHROME" 579 YUVSCALEROPT="$YUVSCALEROPT -O MONOCHROME"
570 ;; 580 ;;
571 -split) #<n> 581 -split) #<n>
572 #-split the resulting mpeg stream in <n> MB chunks. 582 #-split the resulting MPEG stream in <n> MB chunks.
573 split=$2 583 split=$2
574 isarg $1 "$2" direct 584 isarg $1 "$2" direct
575 shift 585 shift
576 ;; 586 ;;
577 -encode) #<n:m:i[,b]> 587 -encode) #<n:m:i[,b]>
584 # 3 mp3lame/standard 3 as 1 + compression opts 594 # 3 mp3lame/standard 3 as 1 + compression opts
585 # 4 libavcodec/mp2 4 as 1 + quality opts 595 # 4 libavcodec/mp2 4 as 1 + quality opts
586 # 5 libavcodec/mp3 596 # 5 libavcodec/mp3
587 # 6 libavcodec/ac3 for m=[2-4] and i>1 turbo is on 597 # 6 libavcodec/ac3 for m=[2-4] and i>1 turbo is on
588 # 7 toolame/mp2 598 # 7 toolame/mp2
599 # 8 libfaac/aac
589 #- with n=[3-7] b specify the audio bit rate 600 #- with n=[3-7] b specify the audio bit rate
590 encode=5:3:2 601 encode=5:3:2
591 echo "$2" | grep -qE '^[0-7]:[0-4]:[1-9](,[0-9]+)?$' && encode=$2 602 echo "$2" | grep -qE '^[0-8]:[0-4]:[1-9](,[0-9]+)?$' && encode=$2
592 isarg $1 "$2" $([[ $mpeg ]] && echo mpeg || echo Avi) 603 isarg $1 "$2" $([[ $mpeg ]] && echo mpeg || echo Avi)
593 shift 604 shift
594 ;; 605 ;;
595 -telecinesrc) # 606 -telecinesrc) #
596 # if you use -encode n:0:i in Mpeg Mode, encode2mpeg needs to know 607 # if you use -encode n:0:i in MPEG Mode, encode2mpeg needs to know
597 # if the source NTSC mpeg is telecined, otherwise the stream copy may 608 # if the source NTSC MPEG is telecined, otherwise the stream copy may
598 # not work properly; normally encode2mpeg is able to detect telecined 609 # not work properly; normally encode2mpeg is able to detect telecined
599 # sources, but, if the source mpeg is mixed, part not telecined and 610 # sources, but, if the source MPEG is mixed, part not telecined and
600 # part telecined, encode2mpeg may fail to detect it. In such case, 611 # part telecined, encode2mpeg may fail to detect it. In such case,
601 #-you can use this option to specify a telecined source. 612 #-you can use this option to specify a telecined source.
602 [[ $2 = doc || $2 = help ]] && isarg $1 $2 mpeg 613 [[ $2 = doc || $2 = help ]] && isarg $1 $2 mpeg
603 telesrc=1 614 telesrc=1
604 ;; 615 ;;
611 ;; 622 ;;
612 -hispeed) # 623 -hispeed) #
613 # increase the encoding speed of 25-50% (with -encode n:1:1); the 624 # increase the encoding speed of 25-50% (with -encode n:1:1); the
614 # output video stream will be bigger and can have poor quality; this 625 # output video stream will be bigger and can have poor quality; this
615 # option is mainly intented for testing, but it can be used if you 626 # option is mainly intented for testing, but it can be used if you
616 #-want to create more quickly an mpeg4/avi or a DVD 627 #-want to create more quickly an MPEG-4/AVI or a DVD.
617 [[ $2 = doc || $2 = help ]] && isarg $1 $2 Avi 628 [[ $2 = doc || $2 = help ]] && isarg $1 $2 Avi
618 hispeed=1 629 hispeed=1
619 ;; 630 ;;
620 -bframes) #<0-4> 631 -bframes) #<0-4>
621 # specify the number of B frames; if -encode is n:3:i the default 2, 632 # specify the number of B frames; if -encode is n:3:i the default 2,
630 vcustom=$2 641 vcustom=$2
631 isarg $1 "$2" Avi 642 isarg $1 "$2" Avi
632 shift 643 shift
633 ;; 644 ;;
634 -acustom) #<mp3lame options> 645 -acustom) #<mp3lame options>
635 #-specify a custom set of lame options, use with -encode 2:m:i 646 # specify a custom set of lame options (with -encode 2:m:i) or faac
647 #-options (with -encode 8:m:i)
636 acustom=$2 648 acustom=$2
637 isarg $1 "$2" Avi 649 isarg $1 "$2" Avi
638 shift 650 shift
639 ;; 651 ;;
640 -encsid) #<sid0,sid1,...> 652 -encsid) #<sid0,sid1,...>
693 ;; 705 ;;
694 -slidefps) #<n> 706 -slidefps) #<n>
695 # fps to use when creating video from pictures, default is 1; if 707 # fps to use when creating video from pictures, default is 1; if
696 # there is a audio file associated with a picture, the duration of 708 # there is a audio file associated with a picture, the duration of
697 #-the audio file is used 709 #-the audio file is used
710 isarg $1 "$2" images
698 slidefps=$(awk -v a=$2 'BEGIN{printf("%.3f",1/a)}') 711 slidefps=$(awk -v a=$2 'BEGIN{printf("%.3f",1/a)}')
699 isarg $1 "$2" images
700 shift 712 shift
701 ;; 713 ;;
702 -slideaudio) #<audio file> 714 -slideaudio) #<audio file>
703 # use the content of <audio file> as audio stream when creating video 715 # use the content of <audio file> as audio stream when creating video
704 #-from pictures; it works correctly only if used with mf://singlepic 716 #-from pictures; it works correctly only if used with mf://singlepic
715 -debug) 727 -debug)
716 # make a more verbose log file and creates a debug file; if you are 728 # make a more verbose log file and creates a debug file; if you are
717 # submitting a bug report, use this option and compress and send the 729 # submitting a bug report, use this option and compress and send the
718 #-log file and the debug file 730 #-log file and the debug file
719 [[ $2 = doc || $2 = help ]] && isarg $1 $2 731 [[ $2 = doc || $2 = help ]] && isarg $1 $2
720 ((DEBUG)) && DEBUG=2 || DEBUG=1 732 echo "$2" | grep -q '^[0-7]$' && DEBUG=$2 && shift || DEBUG=3
721 ;; 733 ;;
722 (-frames) 734 (-frames)
723 frames=$2 735 frames=$2
724 isarg $1 $2 736 isarg $1 $2
725 shift 737 shift
744 MENCODEROPT=( "${MENCODEROPT[@]}" $1 ) 756 MENCODEROPT=( "${MENCODEROPT[@]}" $1 )
745 ;; 757 ;;
746 (-vf) 758 (-vf)
747 vf="-vf $2" 759 vf="-vf $2"
748 MPLAYEROPT=( "${MPLAYEROPT[@]}" $vf ) 760 MPLAYEROPT=( "${MPLAYEROPT[@]}" $vf )
761 isarg $1 $2
762 shift
763 ;;
764 (-af)
765 af="-af $2"
749 isarg $1 $2 766 isarg $1 $2
750 shift 767 shift
751 ;; 768 ;;
752 (-dvd-device) 769 (-dvd-device)
753 dvddev=$2 770 dvddev=$2
760 a=$IFS 777 a=$IFS
761 IFS=, 778 IFS=,
762 PICTSRC=( ${1#mf://} ) 779 PICTSRC=( ${1#mf://} )
763 IFS=$a 780 IFS=$a
764 srate=48000 781 srate=48000
782 ;;
783 (-sub)
784 [[ ! -f $2 ]] && echo "**ERROR: [$PROGNAME] subtitle file '$2' not found" && exit 1
785 MPLAYEROPT=( "${MPLAYEROPT[@]}" $1 "$2" )
786 subrender=1
787 shift
765 ;; 788 ;;
766 (-mpeg|-mpegonly|-nosplit) ;; 789 (-mpeg|-mpegonly|-nosplit) ;;
767 *) 790 *)
768 if [[ ! $TOOL ]]; then 791 if [[ ! $TOOL ]]; then
769 [[ ${1:0:1} = - ]] && ! echo "${MOPT[@]}" | grep -q "\"${1#-}\"" && \ 792 [[ ${1:0:1} = - ]] && ! echo "${MOPT[@]}" | grep -q "\"${1#-}\"" && \
779 ;; 802 ;;
780 esac 803 esac
781 shift 804 shift
782 done 805 done
783 806
784 [[ -s ~/.encode2mpegrc && ! $norc ]] && pre_log " INFO: [$PROGNAME] using .encode2mpegrc settings: '$(<~/.encode2mpegrc)'" 807 [[ -s ~/.encode2mpegrc && ! $norc ]] && do_log " INFO: [$PROGNAME] using .encode2mpegrc settings: '$(<~/.encode2mpegrc)'"
785 808 if [[ $subrender || $harddup ]]; then
786 ############################################################################### 809 if [[ $vf ]]; then
787 #### redirect stdout and stderr to the debug file 810 vf=$vf${subrender:+,expand=::::1}
811 [[ $harddup ]] && ! echo $vf | grep -q harddup && vf=$vf,harddup
812 for ((a=0;a<${#MPLAYEROPT[*]};a++)); do
813 [[ ${MPLAYEROPT[a]} = -vf ]] && MPLAYEROPT[a+1]=${vf#-vf }
814 done
815 else
816 vf="-vf ${subrender:+expand=::::1}${harddup:+${subrender:+,}harddup}"
817 MPLAYEROPT=( "${MPLAYEROPT[@]}" $vf )
818 fi
819 fi
820
821 ###############################################################################
822 #### debug part
788 ############################################################################### 823 ###############################################################################
789 if ((DEBUG)); then 824 if ((DEBUG)); then
825 if ((DEBUG & 1)); then
826 #### redirect stdout and stderr to the debug file
790 exec 3>&1 827 exec 3>&1
791 rm -f "$output".debug.fifo 828 rm -f "$output".debug.fifo
792 mkfifo "$output".debug.fifo 829 mkfifo "$output".debug.fifo
793 tee "$output".debug <"$output".debug.fifo >&3 & 830 tee "$output".debug <"$output".debug.fifo >&3 &
794 PROCTEE=$! 831 PROCTEE=$!
795 exec &>"$output".debug.fifo 832 exec &>"$output".debug.fifo
796 ((DEBUG==2)) && set -x 833 trap 'rm "$output".debug.fifo' 0
834 fi
835 if ((DEBUG & 2)); then
836 #### catch mplayer/mencoder errors
837 mplayer () {
838 command mplayer "$@"
839 ret=$? ; (( ret )) && error_line "$FUNCNAME $*" || true
840 }
841 mencoder () {
842 command mencoder "$@"
843 ret=$? ; (( ret )) && error_line "$FUNCNAME $*" || true
844 }
845 fi
846 ((DEBUG & 4)) && set -x
797 fi 847 fi
798 848
799 ############################################################################### 849 ###############################################################################
800 #### ERROR if some options conflict is detected part 1/2 850 #### ERROR if some options conflict is detected part 1/2
801 ############################################################################### 851 ###############################################################################
802 #### mplayer/mencoder 852 #### mplayer/mencoder
803 for a in mplayer mencoder ; do 853 for a in mplayer mencoder ; do
804 type $a &>/dev/null || ! echo "**ERROR: [$PROGNAME] $a missing, install $(echo ${a:0:2} | tr '[:lower:]' '[:upper:]')${a:2}" || exit 1 854 type -f $a &>/dev/null || ! echo "**ERROR: [$PROGNAME] $a missing, install $(echo ${a:0:2} | tr '[:lower:]' '[:upper:]')${a:2}" || exit 1
805 done 855 done
806 #### output stream name check 856 #### output stream name check
807 [[ ! $output ]] && echo "**ERROR: [$PROGNAME] name of the output stream missing (-o name)" && exit 1 857 [[ ! $output ]] && echo "**ERROR: [$PROGNAME] name of the output stream missing (-o name)" && exit 1
808 #### unspecified video norm 858 #### unspecified video norm
809 [[ ! $videonorm && step -gt 1 && ! ( $mpeg && ${encode%,*} == ?:0:? && ! $menu ) ]] && \ 859 [[ ! $videonorm && step -gt 1 && ! ( $mpeg && ${encode%,*} == ?:0:? && ! $menu ) && ${#TITLESET[*]} -eq 0 ]] && \
810 echo "**ERROR: [$PROGNAME] you must specify a video norm (-n n|p|s)" && exit 1 860 echo "**ERROR: [$PROGNAME] you must specify a video norm (-n n|p|s)" && exit 1
861 #### libfaac check
862 if [[ ${encode%,*} == 8:?:? ]]; then
863 ! mencoder -oac help 2>/dev/null | grep -q faac && echo "**ERROR: [$PROGNAME] missing libfaac support in mencoder [-encode 8:m:i]" && exit 1
864 fi
865 #### mpeg4
866 if [[ $vcodec = mpeg4 ]]; then
867 [[ $pictsrc && $step -gt 1 && $mpeg ]] && echo "**ERROR: [$PROGNAME] -vcodec mpeg4, -mpeg and mf://file are not compatible" && exit 1
868 fi
811 #### pictsrc 869 #### pictsrc
812 if [[ $pictsrc ]]; then 870 if [[ $pictsrc ]]; then
813 [[ $slideaudio != /dev/null && ${encode%,*} == 0:?:? && $mpeg ]] && \ 871 [[ $slideaudio != /dev/null && ${encode%,*} == 0:?:? && $mpeg ]] && \
814 echo "**ERROR: [$PROGNAME] -encode 0:m:i is not compatible with mf:// in Mpeg Mode" && exit 1 872 echo "**ERROR: [$PROGNAME] -encode 0:m:i is not compatible with mf:// in MPEG Mode" && exit 1
815 [[ $audioonly ]] && echo "**ERROR: [$PROGNAME] -audioonly does not work with mf://" && exit 1 873 [[ $audioonly ]] && echo "**ERROR: [$PROGNAME] -audioonly does not work with mf://" && exit 1
816 fi 874 fi
817 #### -encode 1:m:i is not allowed 875 #### -encode 1:m:i is not allowed
818 [[ ${encode%,*} == 1:?:? ]] && echo "**ERROR: [$PROGNAME] do not use -encode 1:m:i" && exit 1 876 [[ ${encode%,*} == 1:?:? ]] && echo "**ERROR: [$PROGNAME] do not use -encode 1:m:i" && exit 1
819 877
820 ############################################################################### 878 ###############################################################################
821 #### WARN if some options conflict is detected 879 #### WARN if some options conflict is detected
822 ############################################################################### 880 ###############################################################################
823 #### missing toolame support 881 #### missing toolame support
824 if [[ ${encode%,*} == 7:?:? ]]; then 882 if [[ ${encode%,*} == 7:?:? ]]; then
825 if ! mencoder -oac help 2>/dev/null | grep -q toolame ; then 883 if ! mencoder -oac help 2>/dev/null | grep -q t[wo]olame ; then
826 encode=4:${encode#?:} 884 encode=4:${encode#?:}
827 pre_log "++ WARN: [$PROGNAME] missing toolame support in mencoder, setting -encode $encode" 885 do_log "++ WARN: [$PROGNAME] missing toolame support in mencoder, setting -encode $encode"
886 else
887 mencoder -oac help 2>/dev/null | grep -q toolame && TOOLAME=toolame || TOOLAME=twolame
828 fi 888 fi
829 fi 889 fi
830 890
831 ############################################################################### 891 ###############################################################################
832 #### set default values for unspecified parameters 892 #### set default values for unspecified parameters
840 0) [[ ! $pictsrc ]] && 900 0) [[ ! $pictsrc ]] &&
841 AFMT=acopy ;; 901 AFMT=acopy ;;
842 2|3|5) AFMT=mp3 ;; 902 2|3|5) AFMT=mp3 ;;
843 4|7) AFMT=mp2 ;; 903 4|7) AFMT=mp2 ;;
844 6) AFMT=ac3 ;; 904 6) AFMT=ac3 ;;
905 8) AFMT=aac ;;
845 esac 906 esac
846 [[ $AFMT ]] && eval : ${audioformat:-\${$AFMT:=copy}} 907 [[ $AFMT ]] && eval : ${audioformat:-\${$AFMT:=copy\}}
847 fi 908 fi
848 : ${frameformat:=VCD} 909 : ${frameformat:=VCD}
849 : ${audioformat:=${AFMT:-mp2}} 910 : ${audioformat:=${AFMT:-mp2}}
850 : ${mp1:=mp2enc} 911 : ${mp1:=mp2enc}
851 ((${mpegchannels:-2}>2)) && : ${mp2:=musicin} || : ${mp2:=mp2enc} 912 ((${mpegchannels:-2}>2)) && : ${mp2:=musicin} || : ${mp2:=mp2enc}
852 : ${mp3:=lame} 913 : ${mp3:=lame}
853 : ${ac3:=mencoder} 914 : ${ac3:=mencoder}
854 : ${dts:=copy} 915 : ${dts:=copy}
916 : ${aac:=faac}
855 case $audioformat in 917 case $audioformat in
856 mp1) 918 mp1)
857 case ${mpegchannels:-2} in 919 case ${mpegchannels:-2} in
858 1) : ${abr:=192} ;; 920 1) : ${abr:=192} ;;
859 2) : ${abr:=384} ;; 921 2) : ${abr:=384} ;;
880 4) : ${abr:=384} ;; # to verify 942 4) : ${abr:=384} ;; # to verify
881 5) : ${abr:=448} ;; # to verify 943 5) : ${abr:=448} ;; # to verify
882 6) : ${abr:=448} ;; 944 6) : ${abr:=448} ;;
883 esac 945 esac
884 ;; 946 ;;
947 aac) : ${abr:=$((${mpegchannels:-2}*48))} ;;
885 #### mplex fails with asr != 48000 for lpcm 948 #### mplex fails with asr != 48000 for lpcm
886 lpcm) : ${asr:=48000} ${abr:=$((asr*16*${mpegchannels:-2}/1024))} ;; 949 lpcm) : ${asr:=48000} ${abr:=$((asr*16*${mpegchannels:-2}/1024))} ;;
887 esac 950 esac
888 if [[ ${encode%,*} == 0:?:? && ${!audioformat} = copy ]]; then 951 if [[ ${encode%,*} == 0:?:? && ${!audioformat} = copy ]]; then
889 abr=0 952 abr=0
890 if [[ ! $multiaudio ]]; then 953 if [[ ! $multiaudio ]]; then
891 get_abr 954 get_abr
892 fi 955 fi
893 fi 956 fi
894 [[ $mpeg && ${encode%,*} == ?:0:? ]] && \ 957 [[ $mpeg && ${encode%,*} == ?:0:? ]] && \
895 vbr=$(($(mp_identify "${MPLAYEROPT[@]}" ${dvddev:+-dvd-device "$dvddev"} "$@" | grep '^ID_VIDEO_BITRATE' | cut -f2 -d=)/1000)) 958 vbr=$(($(id_find ID_VIDEO_BITRATE "${MPLAYEROPT[@]}" ${dvddev:+-dvd-device "$dvddev"} "$@")/1000))
896 case $frameformat in 959 case $frameformat in
897 DVD) : ${asr:=48000} ;; 960 DVD) : ${asr:=48000} ;;
898 *) : ${asr:=44100} ;; 961 *) : ${asr:=44100} ;;
899 esac 962 esac
900 case $videonorm in 963 case $videonorm in
901 p|s) 964 p|s)
902 : ${vfr:=3} 965 : ${vfr:=3}
903 ;; 966 ;;
904 n) 967 n)
905 #FIXME remove the encode 3 check once the mpeg muxer is fixed 968 [[ $frameformat != VCD && ! $vfr && $hispeed -eq 0 && ! $testmca ]] && vfr=1 && telecine=1
906 [[ $frameformat != VCD && ! $vfr && $hispeed -eq 0 && ! $testmca && ${encode%,*} != ?:3:? ]] && vfr=1 && telecine=1
907 : ${vfr:=4} 969 : ${vfr:=4}
908 ;; 970 ;;
909 esac 971 esac
910 [[ $encode ]] && : ${vfr:=2} 972 [[ $encode && ${encode%,*} != ?:0:? ]] && : ${vfr:=2}
911 if [[ ! $ofps ]]; then 973 if [[ ! $ofps ]]; then
912 case $vfr in 974 case $vfr in
913 1) ofps=24000/1001 ;; 975 1) ofps=24000/1001 ;;
914 2) ofps=24 ;; 976 2) ofps=24 ;;
915 3) ofps=25 ;; 977 3) ofps=25 ;;
943 ((cpu<2)) && cpu= 1005 ((cpu<2)) && cpu=
944 1006
945 ############################################################################### 1007 ###############################################################################
946 #### -ao pcm arguments 1008 #### -ao pcm arguments
947 ############################################################################### 1009 ###############################################################################
948 PCM=(pcm:waveheader:file="$output".wav) 1010 PCMWAV=(pcm:waveheader:fast:file=%$((${#output}+4))%"$output".wav)
949 PCMTMP=(pcm:waveheader:file="$output".tmp) 1011 PCMTMP=(pcm:waveheader:fast:file=%$((${#output}+4))%"$output".tmp)
950 PCMNOWYUV=(pcm:nowaveheader:file=/dev/fd/4) 1012 PCMNOWYUV=(pcm:nowaveheader:fast:file=/dev/fd/4)
951 1013
952 [[ $dvddev ]] && MPLAYEROPT=( "${MPLAYEROPT[@]}" -dvd-device "$dvddev" ) 1014 [[ $dvddev ]] && MPLAYEROPT=( "${MPLAYEROPT[@]}" -dvd-device "$dvddev" )
953 1015
954 ############################################################################### 1016 ###############################################################################
955 #### mplayer/mencoder/mjpegtools options 1017 #### mplayer/mencoder/mjpegtools options
964 MPLAYERINFO=( "${MPLAYEROPT[@]}" ) 1026 MPLAYERINFO=( "${MPLAYEROPT[@]}" )
965 1027
966 #### mf:// case 1028 #### mf:// case
967 if [[ $pictsrc ]]; then 1029 if [[ $pictsrc ]]; then
968 if [[ $slideaudio && $slideaudio != /dev/null ]]; then 1030 if [[ $slideaudio && $slideaudio != /dev/null ]]; then
969 [[ $(mp_identify "$slideaudio" | grep ID_AUDIO_RATE | cut -f2 -d=) != $asr ]] && SRATE="-srate $asr -af-adv force=1" || SRATE= 1031 [[ $(id_find ID_AUDIO_RATE "$slideaudio") != $asr ]] && SRATE="-srate $asr -af-adv force=1" || SRATE=
970 CLEAN[${#CLEAN[*]}]="$output".wav 1032 CLEAN[${#CLEAN[*]}]="$output".wav
971 mplayer "$slideaudio" $SRATE -vo null -vc dummy -ao "${PCM[@]}" $VOL $ac $afm ${mpegchannels:+-channels $mpegchannels -af channels=$mpegchannels} 1033 mplayer "$slideaudio" $SRATE -vo null -vc dummy -ao "${PCMWAV[@]}" $afm ${mpegchannels:+-channels $mpegchannels -af channels=$mpegchannels}
972 MPLAYEROPT=( "${MPLAYEROPT[@]}" -fps 1/$(mp_identify "$output".wav | sed -n '/^ID_LENGTH=/s/.*=//p') -audiofile "$output".wav ) 1034 MPLAYEROPT=( "${MPLAYEROPT[@]}" -fps 1/$(id_find ID_LENGTH "$output".wav) -audiofile "$output".wav )
973 else 1035 else
974 if [[ $slideaudio == /dev/null ]]; then 1036 if [[ $slideaudio == /dev/null ]]; then
975 MPLAYEROPT=( "${MPLAYEROPT[@]}" -fps $slidefps ) 1037 MPLAYEROPT=( "${MPLAYEROPT[@]}" -fps $slidefps )
976 encode=0:${encode#?:} 1038 encode=0:${encode#?:}
977 else 1039 else
981 fi 1043 fi
982 1044
983 #### MENCODERARG is used for mencoding, vobsub dumping 1045 #### MENCODERARG is used for mencoding, vobsub dumping
984 MENCODERARG=( "${MPLAYEROPT[@]}" ${frames:+-frames $frames} ) 1046 MENCODERARG=( "${MPLAYEROPT[@]}" ${frames:+-frames $frames} )
985 1047
986 MENCODERARG=( "${MENCODERARG[@]}" "${MENCODEROPT[@]}" ${endpos:+-endpos $endpos} ) 1048 MENCODERARG=( "${MENCODERARG[@]}" "${MENCODEROPT[@]}" ${endpos:+-endpos $endpos} ${ofps:+-ofps $ofps} )
987 if [[ $mpeg && $mpegchannels ]]; then 1049 if [[ $mpeg && $mpegchannels ]]; then
988 MENCODERARG=( "${MENCODERARG[@]}" -channels $mpegchannels ) 1050 MENCODERARG=( "${MENCODERARG[@]}" -channels $mpegchannels )
989 else 1051 af=$(echo "${af:--af }${af:+,}" | sed 's/channels=[^,]*,//')channels=$mpegchannels
990 MENCODERARG=( "${MENCODERARG[@]}" ${channels:+-channels $channels} ) 1052 elif [[ $channels ]]; then
991 fi 1053 MENCODERARG=( "${MENCODERARG[@]}" -channels $channels )
992 #### if video copy then no ofps 1054 af=$(echo "${af:--af }${af:+,}" | sed 's/channels=[^,]*,//')channels=$channels
993 [[ ${encode%,*} != ?:0:? ]] && MENCODERARG=( "${MENCODERARG[@]}" ${ofps:+-ofps $ofps} ) 1055 fi
994 1056
995 YUVSCALEROPT="-v 1 -n $videonorm ${scale:+-O $frameformat} $YUVSCALEROPT" 1057 YUVSCALEROPT="-v 1 -n $videonorm ${scale:+-O $frameformat} $YUVSCALEROPT"
996 1058
997 MPEG2ENCOPT="${cpu:+-M $cpu }-v 1 -S ${split:-50000} -n $videonorm -F $vfr -s -r 16 ${telecine:+-p} $MPEG2ENCOPT" 1059 MPEG2ENCOPT="${cpu:+-M $cpu }-v 1 -S ${split:-50000} -n $videonorm -F $vfr -s -r 16 ${telecine:+-p} $MPEG2ENCOPT"
998 case $vfr in 1060 case $vfr in
1073 #### mencoder audio/video/pass options 1135 #### mencoder audio/video/pass options
1074 ############################################################################### 1136 ###############################################################################
1075 if [[ $encode ]]; then 1137 if [[ $encode ]]; then
1076 OPTIONS="-noskiplimit -sws $((hispeed?1:7))" 1138 OPTIONS="-noskiplimit -sws $((hispeed?1:7))"
1077 if [[ $mpeg ]]; then 1139 if [[ $mpeg ]]; then
1078 # mencoder can put in the mpeg container: 1140 # mencoder can put in the MPEG container:
1079 # video: mpeg1, mpeg2, mpeg4 1141 # video: mpeg1, mpeg2, mpeg4
1080 # audio: mp1, mp2, mp3, ac3, aac (not yet: lpcm, dts) 1142 # audio: mp1, mp2, mp3, ac3, aac (not yet: lpcm, dts)
1081 [[ ${encode%,*} != ?:0:? ]] && : ${mpegaspect:=2} 1143 [[ ${encode%,*} != ?:0:? ]] && : ${mpegaspect:=2}
1082 #MUX="-mpegopts ${mpegaspect:+vaspect=${ASPECT[mpegaspect]}:}:vbitrate=${vbr}" 1144 #MUX="-mpegopts ${mpegaspect:+vaspect=${ASPECT[mpegaspect]}:}:vbitrate=${vbr}"
1083 MUX="-mpegopts ${mpegaspect:+vaspect=${ASPECT[mpegaspect]}:}" 1145 MUX="-mpegopts "
1084 MUX2="${telecine:+:telecine}" 1146 if [[ $telecine ]]; then
1147 if [[ $vcodec = mpeg2video || ! $vcodec && $frameformat != VCD ]]; then
1148 if [[ $vfr == [12] ]]; then
1149 [[ $videonorm = n ]] && MUX2=":telecine" || MUX2=":film2pal"
1150 else
1151 do_log "++ WARN: [$PROGNAME] telecine only works with 24000/1001 or 24 fps, disabling it"
1152 fi
1153 else
1154 do_log "++ WARN: [$PROGNAME] telecine only works for MPEG-2, disabling it"
1155 fi
1156 fi
1085 case $frameformat in 1157 case $frameformat in
1086 VCD) MUX="${MUX}format=xvcd" LAVC="vcodec=${vcodec:-mpeg1video}${LAVC:-:vrc_buf_size=327:vrc_minrate=${vbr}:vrc_maxrate=${vbr}}" ;; 1158 VCD) MUX="${MUX}format=xvcd" LAVC="vcodec=${vcodec:-mpeg1video}${LAVC:-:vrc_buf_size=327:vrc_minrate=${vbr}:vrc_maxrate=${vbr}}" ;;
1087 SVCD) if [[ $trick ]]; then MUX="${MUX}format=xvcd" ; else 1159 SVCD) if [[ $trick ]]; then MUX="${MUX}format=xvcd" ; else
1088 MUX="${MUX}format=xsvcd" ; fi ; 1160 MUX="${MUX}format=xsvcd" ; fi ; LAVC="vcodec=${vcodec:-mpeg2video}:vrc_buf_size=917" ;;
1089 LAVC="vcodec=${vcodec:-mpeg2video}:vrc_buf_size=917" ;;
1090 DVD) MUX="${MUX}format=dvd" LAVC="vcodec=${vcodec:-mpeg2video}:vrc_buf_size=1835" ;; 1161 DVD) MUX="${MUX}format=dvd" LAVC="vcodec=${vcodec:-mpeg2video}:vrc_buf_size=1835" ;;
1091 esac 1162 esac
1092 case $vfr in 1163 case $vfr in
1093 1|2) LAVC="$LAVC:keyint=$((hispeed?1:${GOP:-12}))" ;; 1164 1|2) LAVC="$LAVC:keyint=$((hispeed?1:${GOP:-12}))" ;;
1094 3|6) LAVC="$LAVC:keyint=$((hispeed?1:${GOP:-15}))" ;; 1165 3|6) LAVC="$LAVC:keyint=$((hispeed?1:${GOP:-15}))" ;;
1095 4|5|7|8) LAVC="$LAVC:keyint=$((hispeed?1:${GOP:-18}))" ;; 1166 4|5|7|8) LAVC="$LAVC:keyint=$((hispeed?1:${GOP:-18}))" ;;
1096 esac 1167 esac
1097 [[ $frameformat = VCD && ! $bframes ]] && LAVC="$LAVC:vmax_b_frames=2" 1168 [[ $frameformat = VCD && ! $bframes ]] && LAVC="$LAVC:vmax_b_frames=2"
1098 [[ $mpegmbr ]] && [[ $mpegmbr -lt $vbr ]] && mpegmbr=$vbr 1169 [[ $mpegmbr ]] && [[ $mpegmbr -lt $vbr ]] && mpegmbr=$vbr
1099 #### -a 1 really means aspect undefined (do not scale), not aspect 1:1 1170 #### -a 1 is SAR=1 (do not scale), not DAR=1
1100 [[ $vcodec != mpeg4 || $mpegaspect != 1 ]] && LAVC="${LAVC}:aspect=${ASPECT[mpegaspect]}" 1171 [[ $mpegaspect != 1 ]] && LAVC="${LAVC}:aspect=${ASPECT[mpegaspect]}"
1101 LAVC="${LAVC}${mpegmbr:+:vrc_maxrate=$mpegmbr}${inter_matrix:+:inter_matrix=${inter_matrix}}${intra_matrix:+:intra_matrix=${intra_matrix}}" 1172 LAVC="${LAVC}${mpegmbr:+:vrc_maxrate=$mpegmbr}${inter_matrix:+:inter_matrix=${inter_matrix}}${intra_matrix:+:intra_matrix=${intra_matrix}}"
1102 OF="-of mpeg" 1173 OF="-of mpeg"
1103 NOSKIP=-noskip 1174 NOSKIP=-noskip
1104 vbitrate=$vbr 1175 vbitrate=$vbr
1105 if [[ ${encode%,*} != ?:0:? ]]; then 1176 if [[ ${encode%,*} != ?:0:? ]]; then
1136 2:?:?|2:?:?,*) AUDIOPASS="-oac mp3lame -lameopts ${acustom:-fast}" ;; 1207 2:?:?|2:?:?,*) AUDIOPASS="-oac mp3lame -lameopts ${acustom:-fast}" ;;
1137 3:?:?) AUDIOPASS="-oac mp3lame -lameopts preset=standard" ;; 1208 3:?:?) AUDIOPASS="-oac mp3lame -lameopts preset=standard" ;;
1138 4:?:?) AUDIOPASS="-oac lavc -lavcopts acodec=mp2:abitrate=$abr" ;; 1209 4:?:?) AUDIOPASS="-oac lavc -lavcopts acodec=mp2:abitrate=$abr" ;;
1139 5:?:?) AUDIOPASS="-oac lavc -lavcopts acodec=mp3:abitrate=$abr" ;; 1210 5:?:?) AUDIOPASS="-oac lavc -lavcopts acodec=mp3:abitrate=$abr" ;;
1140 6:?:?) AUDIOPASS="-oac lavc -lavcopts acodec=ac3:abitrate=$abr" ;; 1211 6:?:?) AUDIOPASS="-oac lavc -lavcopts acodec=ac3:abitrate=$abr" ;;
1141 7:?:?) AUDIOPASS="-oac toolame -toolameopts br=$abr" ;; 1212 7:?:?) AUDIOPASS="-oac $TOOLAME -${TOOLAME}opts br=$abr" ;;
1213 8:?:?) AUDIOPASS="-oac faac -faacopts ${acustom:-br=$abr}" ;;
1142 3:?:?,*) AUDIOPASS="-oac mp3lame -lameopts preset=${encode#*,}" ;; 1214 3:?:?,*) AUDIOPASS="-oac mp3lame -lameopts preset=${encode#*,}" ;;
1143 4:?:?,*) AUDIOPASS="-oac lavc -lavcopts acodec=mp2:abitrate=${encode#*,}" ;; 1215 4:?:?,*) AUDIOPASS="-oac lavc -lavcopts acodec=mp2:abitrate=${encode#*,}" ;;
1144 5:?:?,*) AUDIOPASS="-oac lavc -lavcopts acodec=mp3:abitrate=${encode#*,}" ;; 1216 5:?:?,*) AUDIOPASS="-oac lavc -lavcopts acodec=mp3:abitrate=${encode#*,}" ;;
1145 6:?:?,*) AUDIOPASS="-oac lavc -lavcopts acodec=ac3:abitrate=${encode#*,}" ;; 1217 6:?:?,*) AUDIOPASS="-oac lavc -lavcopts acodec=ac3:abitrate=${encode#*,}" ;;
1146 7:?:?,*) AUDIOPASS="-oac toolame -toolameopts br=${encode#*,}" ;; 1218 7:?:?,*) AUDIOPASS="-oac $TOOLAME -${TOOLAME}opts br=${encode#*,}" ;;
1219 8:?:?,*) AUDIOPASS="-oac faac -faacopts ${acustom:-br=${encode#*,}}" ;;
1147 esac 1220 esac
1148 encode=${encode%,*} 1221 encode=${encode%,*}
1149 case $encode in 1222 case $encode in
1150 ?:0:?) VIDEOPASS="$OF $MUX -ovc copy $NOSKIP" ; encode=${encode%%:*}:0:1 ; turbo=0 ;; # copy uses only one pass 1223 ?:0:?) VIDEOPASS="$OF $MUX -ovc copy $NOSKIP" ; encode=${encode%%:*}:0:1 ; turbo=0 ;; # copy uses only one pass
1151 ?:1:?) VIDEOPASS="$OF $MUX$MUX2 -ovc lavc -lavcopts ${BASIC}${vcustom:+:$vcustom}" ; : ${turbo:=0} ;; 1224 ?:1:?) VIDEOPASS="$OF $MUX$MUX2 -ovc lavc -lavcopts ${BASIC}${vcustom:+:$vcustom}" ; : ${turbo:=0} ;;
1153 ?:3:?) VIDEOPASS="$OF $MUX$MUX2 -ovc lavc -lavcopts ${BESTSIZE}" ; : ${turbo:=1} ;; 1226 ?:3:?) VIDEOPASS="$OF $MUX$MUX2 -ovc lavc -lavcopts ${BESTSIZE}" ; : ${turbo:=1} ;;
1154 ?:4:?) VIDEOPASS="$OF $MUX$MUX2 -ovc lavc -lavcopts ${BESTQUALITY}" ; : ${turbo:=1} ;; 1227 ?:4:?) VIDEOPASS="$OF $MUX$MUX2 -ovc lavc -lavcopts ${BESTQUALITY}" ; : ${turbo:=1} ;;
1155 esac 1228 esac
1156 ((turbo)) && turbo=:turbo || turbo= 1229 ((turbo)) && turbo=:turbo || turbo=
1157 PASS=${encode##*:} 1230 PASS=${encode##*:}
1158 [[ $normalize && $encode != 0:?:? ]] && AUDIOPASS="-af volnorm $AUDIOPASS" 1231 [[ $normalize && $encode != 0:?:? ]] && af=${af:--af }${af:+,}volnorm
1159 fi 1232 fi
1160 1233
1161 1234
1162 ############################################################################### 1235 ###############################################################################
1163 #### more functions 1236 #### more functions
1189 local i=0 1262 local i=0
1190 fsize=$(ls -l "$1" | awk '{print $5}') 1263 fsize=$(ls -l "$1" | awk '{print $5}')
1191 fint=$fsize 1264 fint=$fsize
1192 ffrac=0 1265 ffrac=0
1193 while ((fint>=1024)) ; do 1266 while ((fint>=1024)) ; do
1194 ((fint/1024 < 1024)) && fint=$((fint+51)) 1267 ((fint/1024 < 1024)) && ffrac=$((( fint+=51 )%1024))
1195 i=$((++i)) 1268 i=$((++i))
1196 ffrac=$((fint%1024))
1197 fint=$((fint/1024)) 1269 fint=$((fint/1024))
1198 done 1270 done
1199 ffrac=$((ffrac*10/1024)) 1271 ffrac=$((ffrac*10/1024))
1200 fpre=${PRE[i]} 1272 fpre=${PRE[i]}
1201 } 1273 }
1204 file_size "$2" 1276 file_size "$2"
1205 echo " $1: $2 is $fsize bytes, $fint.$ffrac ${fpre}B" >>"$output".log 1277 echo " $1: $2 is $fsize bytes, $fint.$ffrac ${fpre}B" >>"$output".log
1206 } 1278 }
1207 ############################################################################### 1279 ###############################################################################
1208 show_finalvideo_info () { 1280 show_finalvideo_info () {
1209 local codec TYPE i VIDEO OUT ASPECT 1281 local codec TYPE i VIDEO OUT ASPECT CH FAAC SUBST
1282 SUBST=
1210 VIDEO="$(mplayer -nocache -frames 0 -vo null -nosound "$2" 2>/dev/null | grep "^VIDEO:")" 1283 VIDEO="$(mplayer -nocache -frames 0 -vo null -nosound "$2" 2>/dev/null | grep "^VIDEO:")"
1211 if [[ ! $VIDEO ]]; then 1284 if [[ ! $VIDEO ]]; then
1212 # mpegs with mpeg4 video do not show all the video informations in one line, 1285 # MPEGs with MPEG-4 video do not show all the video informations in one line,
1213 # assebmling the informations (kbps is missing): 1286 # assebmling the informations (kbps is missing):
1214 OUT="$(mplayer -nocache -frames 1 -vo null -nosound -v "$2" 2>/dev/null)" 1287 OUT="$(mplayer -nocache -frames 1 -vo null -nosound -v "$2" 2>/dev/null)"
1215 if echo "$OUT" | grep -q '^\[V].*fourcc:0x10000004' ; then 1288 if echo "$OUT" | grep -q '^\[V].*fourcc:0x10000004' ; then
1216 VIDEO="VIDEO: MPEG4 $(echo "$OUT" | awk '$1=="VO:"&&$2=="[null]"{print $3}')" 1289 VIDEO="VIDEO: MPEG-4 $(echo "$OUT" | awk '$1=="VO:"&&$2=="[null]"{print $3}')"
1217 ASPECT=$(echo "$OUT" | awk '$1=="Movie-Aspect"{print $3}') 1290 ASPECT=$(echo "$OUT" | awk '$1=="Movie-Aspect"{print $3}')
1218 case $ASPECT in 1291 case $ASPECT in
1219 undefined) VIDEO="$VIDEO (aspect 1)" ;; 1292 undefined) VIDEO="$VIDEO (aspect 1)" ;;
1220 1.33:1) VIDEO="$VIDEO (aspect 2)" ;; 1293 1.33:1) VIDEO="$VIDEO (aspect 2)" ;;
1221 1.78:1) VIDEO="$VIDEO (aspect 3)" ;; 1294 1.78:1) VIDEO="$VIDEO (aspect 3)" ;;
1227 fi 1300 fi
1228 echo " $1: $VIDEO" >>"$output".log 1301 echo " $1: $VIDEO" >>"$output".log
1229 #### removed -vc dummy 1302 #### removed -vc dummy
1230 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 1303 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
1231 echo -n " $1: AUDIO[$i]: " >>"$output".log 1304 echo -n " $1: AUDIO[$i]: " >>"$output".log
1232 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/.* //') 1305 codec=$(mplayer -ac mp3, -nocache -frames 0 -v -ao null -vo null "$2" -aid $i 2>/dev/null | \
1306 sed '/Selected audio codec:/!d;s/[^(]*(//;s/).*//;s/AAC.*/& AAC/;s/.* //')
1307 #### AAC info are insufficient/incorrect
1308 if [[ $codec = AAC ]]; then
1309 CH=$(mplayer -nocache -frames 0 -v -ao null -vo null "$2" -aid $i 2>/dev/null | awk '/FAAD: Negotiated samplerate:/{print $NF}')
1310 if type &>/dev/null faad ; then
1311 mplayer -dumpaudio -dumpfile "$output".audio -aid $i "$2" 2>/dev/null
1312 FAAC=$(faad -i "$output".audio 2>&1 | tail -2 | head -n 1)
1313 #ADTS, 4.087 sec, 103 kbps, 44100 Hz
1314 rm -f "$output".audio
1315 SUBST="s/AAC.*/AAC:$(echo "$FAAC" | sed 's/.*,\([^,]*Hz\).*/\1/'), "
1316 SUBST="${SUBST}$CH ch, $(echo "$FAAC" | sed 's/,.*//'),"
1317 SUBST="${SUBST}$(echo "$FAAC" | sed 's/.*,\([^,]*kbps\).*/\1/')"
1318 SUBST="${SUBST}/;"
1319 else
1320 SUBST="s/2 ch,/$CH ch,/;"
1321 fi
1322 fi
1233 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' | \ 1323 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' | \
1234 grep -e '^AC3:' -e '^MPEG' -e '^AUDIO:' | sed 's/AUDIO/'"$codec"'/;q' >>"$output".log 1324 grep -e '^AC3:' -e '^MPEG' -e '^AUDIO:' | sed 's/AUDIO/'"$codec"'/;'"$SUBST"'q' >>"$output".log
1235 done 1325 done
1236 TYPE=$1 1326 TYPE=$1
1237 shift 1327 shift
1238 for i ; do 1328 for i ; do
1239 show_file_info "$TYPE" "$i" 1329 show_file_info "$TYPE" "$i"
1245 } 1335 }
1246 ############################################################################### 1336 ###############################################################################
1247 job_exit () { 1337 job_exit () {
1248 EXIT=$? 1338 EXIT=$?
1249 status_bit mpg || [[ ! -f ${output}.mpg && ! -f ${output}01.mpg ]] || show_finalvideo_info "MPEG" "${output}"*.mpg 1339 status_bit mpg || [[ ! -f ${output}.mpg && ! -f ${output}01.mpg ]] || show_finalvideo_info "MPEG" "${output}"*.mpg
1340 [[ $usesbr ]] && ((DEBUG && usesbr>6)) && awk -v u=$usesbr -v f=$fsize \
1341 'BEGIN{b=u*1024*1024;printf("--DEBUG: [usesbr] target: %dMB (%d bytes), error: %f%%\n",u,b,(b-f)*100/b)}' >>"$output".log
1250 sec=$(($(pr_time)-STARTTIME)) 1342 sec=$(($(pr_time)-STARTTIME))
1251 echo " JOBEND: $output $(pr_date) ($((sec/3600))h$((sec/60%60))m$((sec%60))s)" >>"$output".log 1343 echo " JOBEND: $output $(pr_date) ($((sec/3600))h$((sec/60%60))m$((sec%60))s)" >>"$output".log
1252 rm -f "${CLEAN[@]}" psnr_??????.log 1344 rm -f "${CLEAN[@]}" psnr_??????.log
1253 ((DEBUG)) && exec >&1- >&2- && exec >&3 1345 ((DEBUG)) && exec >&1- >&2- && exec >&3
1254 if [[ -f $output.yuvscaler.log || -f $output.mpeg2enc.log ]]; then 1346 if [[ -f $output.yuvscaler.log || -f $output.mpeg2enc.log ]]; then
1257 ((!EXIT)) && [[ ! $quiet ]] && cat "$output".log 1349 ((!EXIT)) && [[ ! $quiet ]] && cat "$output".log
1258 fi 1350 fi
1259 ((DEBUG)) && rm -f "$output".debug.fifo && kill $PROCTEE 1351 ((DEBUG)) && rm -f "$output".debug.fifo && kill $PROCTEE
1260 } 1352 }
1261 ############################################################################### 1353 ###############################################################################
1262 mplayer_log () { 1354 me_log () {
1263 tee -a /dev/stderr | sed 's/.*\r//' | \ 1355 rm -f "$output".fifo
1264 awk '/^PSNR:|^M[EP][ln]|^There are |^\[open]|^==> |^Recommended video bitrate/{sub(/^/," INFO: ['"$1"'] ");print}' >>"$output".log 1356 mkfifo "$output".fifo
1265 } 1357 tee -a /dev/stderr <"$output".fifo | sed 's/.*\r//' | \
1266 ############################################################################### 1358 awk '/^PSNR:|^M[EP][ln]|^There are |^\[open]|^audio stream:|^number of|^subtitle|^==> |^Recommended video bitrate/{sub(/^/," INFO: [mencoder] ");
1267 mp_single_log () { 1359 print}' >>"$output".log &
1268 tee -a /dev/stderr | sed 's/.*\r//;/'"$2"'/!d;s/^/ INFO: ['$1'] /' >>"$output".log 1360 }
1361 ###############################################################################
1362 me_bit_log () {
1363 rm -f "$output".fifo
1364 mkfifo "$output".fifo
1365 tee -a /dev/stderr <"$output".fifo | sed 's/.*\r//;/^Recommended video bitrate/!d;s/^/ INFO: [mencoder] /' >>"$output".log &
1269 } 1366 }
1270 ############################################################################### 1367 ###############################################################################
1271 check_abr () { 1368 check_abr () {
1272 # abr permitted: 1369 # abr permitted:
1273 # ac3: ( 8000/11025/12000) 8 16 24 32 40 48 56 64 80 96 112 128 144 160 1370 # ac3: ( 8000/11025/12000) 8 16 24 32 40 48 56 64 80 96 112 128 144 160
1363 ############################################################################### 1460 ###############################################################################
1364 debug_line () { 1461 debug_line () {
1365 echo "--DEBUG: [$PROGNAME] $2($1) $(eval echo $(sed -n $1p "$PROGFILE" | sed 's/ |.*//;s/.>.*//;s/</\\\</'))" >>"$output".log 1462 echo "--DEBUG: [$PROGNAME] $2($1) $(eval echo $(sed -n $1p "$PROGFILE" | sed 's/ |.*//;s/.>.*//;s/</\\\</'))" >>"$output".log
1366 } 1463 }
1367 ############################################################################### 1464 ###############################################################################
1465 error_line () {
1466 echo "--DEBUG: [$PROGNAME] $1"
1467 echo "**ERROR: [$PROGNAME] there has been an error during the execution of the previous line, this should not happen"
1468 echo "possible causes:"
1469 echo " 0) missing or misspelled input stream"
1470 echo " 1) the input stream is corrupted"
1471 echo " -> try a different input stream"
1472 echo " 2) one of the options used has triggered a bug present only on your combination of architecture/compiler/distribution"
1473 echo " -> try to recompile MPlayer with a different compiler version or try another distribution"
1474 if ((SVN)); then
1475 echo " 3) one of the options used is not valid or is buggy for your SVN/unsupported version of MPlayer/MEncoder"
1476 echo " -> check MPlayer's man page and/or try a supported release of MPlayer"
1477 fi
1478 echo
1479 echo "submit a bugreport if you think this is a bug in $PROGNAME"
1480 exit $ret
1481 }
1482 ###############################################################################
1368 check_mencoder_abr () { 1483 check_mencoder_abr () {
1369 local codec lib ASR 1484 local codec lib ASR
1370 codec=([4]=mp2 mp3 ac3 mp2) 1485 codec=([4]=mp2 mp3 ac3 mp2 aac)
1371 lib=([4]=libavcodec libavcodec libavcodec libtoolame) 1486 lib=([4]=libavcodec libavcodec libavcodec lib${TOOLAME} libfaac)
1372 ASR=${encode%%:*} 1487 ASR=${encode%%:*}
1373 check_abr ${codec[ASR]} $1 $2 || ! echo "**ERROR: [$PROGNAME] ${lib[ASR]} does not support $2 kbps / $1 Hz for ${codec[ASR]}" || exit 1 1488 check_abr ${codec[ASR]} $1 $2 || ! echo "**ERROR: [$PROGNAME] ${lib[ASR]} does not support $2 kbps / $1 Hz for ${codec[ASR]}" || exit 1
1489 }
1490 ###############################################################################
1491 is_film2pal () {
1492 local a
1493 a=$(mplayer -nocache "$@" -vo null -nosound -benchmark -frames 60 -noquiet 2>/dev/null | tr '\015' '\012' | tail | \
1494 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"}')
1495 [[ $a ]] && a=$(mplayer -nocache "$@" -vo null -nosound -benchmark -frames 1500 -noquiet 2>/dev/null | tr '\015' '\012' | tail | \
1496 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;
1497 if(r>1.042)print "24000/1001fps";if(r<1.042&&r>1.041)print "24fps"}')
1498 echo "$a"
1374 } 1499 }
1375 1500
1376 ############################################################################### 1501 ###############################################################################
1377 #### ERROR if some options conflict is detected part 2/2 1502 #### ERROR if some options conflict is detected part 2/2
1378 ############################################################################### 1503 ###############################################################################
1379 #### libavcodec codec/asr/abr 1504 #### libavcodec codec/asr/abr
1380 #### libtoolame asr/abr 1505 #### libtoolame asr/abr
1381 #### libmp3lame asr 1506 #### libmp3lame asr
1382 #### no check is done on the other channel in case of multiaudio 1507 #### no check is done on the other channel in case of multiaudio
1383 if [[ $encode == [2-7]:?:? ]]; then 1508 if [[ $encode == [2-8]:?:? ]]; then
1384 if [[ $srate ]]; then 1509 if [[ $srate ]]; then
1385 r=$srate 1510 r=$srate
1386 else 1511 else
1387 r=$(mp_identify "${MPLAYERINFO[@]}" | sed -n '/^ID_AUDIO_RATE=/s/.*=//p') 1512 r=$(id_find ID_AUDIO_RATE "${MPLAYERINFO[@]}")
1513 if [[ ! $r ]]; then
1514 do_log "++ WARN: [$PROGNAME] failure to detect the audio sample rate of the input stream"
1515 [[ ! $multiaudio && ! $audioid ]] && do_log "++ WARN: [$PROGNAME] if your source video does not have audio use -encode 0:${encode#*:}" || \
1516 do_log "++ WARN: [$PROGNAME] probably is incorrect the audio stream selected with -${audioid:+aid}${multiaudio:+multiaudio}"
1517 fi
1388 if [[ $mpeg && ! $usespeed ]]; then 1518 if [[ $mpeg && ! $usespeed ]]; then
1389 case $frameformat in 1519 case $frameformat in
1390 *VCD) ((r != 44100)) && pre_log "++ WARN: [$PROGNAME] $frameformat standard requires 44100kHz audio, add -srate 44100" ;; 1520 *VCD) ((r != 44100)) && do_log "++ WARN: [$PROGNAME] $frameformat standard requires 44100kHz audio, add -srate 44100" ;;
1391 DVD) ((r != 48000)) && pre_log "++ WARN: [$PROGNAME] $frameformat standard requires 48000kHz audio, add -srate 48000" ;; 1521 DVD) ((r != 48000)) && do_log "++ WARN: [$PROGNAME] $frameformat standard requires 48000kHz audio, add -srate 48000" ;;
1392 esac 1522 esac
1393 fi 1523 fi
1394 fi 1524 fi
1395 if [[ $encode == [4-7]:?:? ]]; then 1525 if [[ $encode == [4-7]:?:? ]]; then
1396 check_mencoder_abr $r ${AUDIOPASS##*=} 1526 check_mencoder_abr "$r" ${AUDIOPASS##*=}
1527 elif [[ $encode == 8:?:? ]]; then
1528 case $r in
1529 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000) : ;;
1530 *) echo "**ERROR: [$PROGNAME] libfaac does not support $r Hz sample rate" ; exit 1 ;;
1531 esac
1397 else 1532 else
1398 case $r in 1533 case $r in
1399 8000|11025|12000|16000|22050|24000|32000|44100|48000) : ;; 1534 8000|11025|12000|16000|22050|24000|32000|44100|48000) : ;;
1400 *) echo "**ERROR: [$PROGNAME] libmp3lame does not support $r Hz sample rate" ; exit 1 ;; 1535 *) echo "**ERROR: [$PROGNAME] libmp3lame does not support $r Hz sample rate" ; exit 1 ;;
1401 esac 1536 esac
1402 fi 1537 fi
1403 fi 1538 fi
1404 #### copy of non mpeg audio in a VCD 1539 #### copy of non-MPEG audio in a VCD
1405 if [[ $step -gt 1 && $frameformat = VCD && $encode == 0:?:? && ( $mpeg || ${!audioformat} = copy ) && ! $testmca && ! $pictsrc ]]; then 1540 if [[ $step -gt 1 && $frameformat = VCD && $encode == 0:?:? && ( $mpeg || ${!audioformat} = copy ) && ! $testmca && ! $pictsrc ]]; then
1406 a=$(mp_identify "${MPLAYERINFO[@]}" | sed -n '/^ID_AUDIO_CODEC=/s/.*=//p') 1541 a=$(id_find ID_AUDIO_CODEC "${MPLAYERINFO[@]}")
1407 [[ $a != mp3 ]] && echo "**ERROR: [$PROGNAME] you cannot copy $a audio in a $frameformat" && exit 1 1542 [[ $a != mp3 ]] && echo "**ERROR: [$PROGNAME] you cannot copy $a audio in a $frameformat" && exit 1
1408 fi 1543 fi
1409 #### mpegchannels > 2 only with ac3 1544 #### mpegchannels > 2 only with ac3 and aac
1410 [[ $mpeg && ${mpegchannels:-2} -gt 2 && $encode == [2-57]:?:? ]] && CODEC=([2]=mp3 mp3 mp2 mp3 [7]=mp2) && \ 1545 [[ $mpeg && ${mpegchannels:-2} -gt 2 && $encode == [2-57]:?:? ]] && CODEC=([2]=mp3 mp3 mp2 mp3 [7]=mp2) && \
1411 echo "**ERROR: [$PROGNAME] audio codec ${CODEC[${encode%%:*}]} selected with -encode $encode do not support more than 2 audio channels" && exit 1 1546 echo "**ERROR: [$PROGNAME] audio codec ${CODEC[${encode%%:*}]} selected with -encode $encode do not support more than 2 audio channels" && exit 1
1412 ############################################################################### 1547 ###############################################################################
1413 #### set cleanup 1548 #### set cleanup
1414 ############################################################################### 1549 ###############################################################################
1415 trap 'job_exit' 0 1550 trap 'job_exit' 0
1416 CLEAN[${#CLEAN[*]}]="$output".fifo 1551 CLEAN[${#CLEAN[*]}]="$output".fifo
1417 1552
1418 skip=0 1553 skip=0
1554 LG=1
1419 1555
1420 ############################################################################### 1556 ###############################################################################
1421 #### start the log file 1557 #### start the log file
1422 ############################################################################### 1558 ###############################################################################
1423 if [[ ! $resume ]] ; then 1559 if [[ ! $resume ]] ; then
1430 echo -n " INFO: [$PROGNAME] version $VERSION running in " 1566 echo -n " INFO: [$PROGNAME] version $VERSION running in "
1431 if ((${#TITLESET[*]})); then 1567 if ((${#TITLESET[*]})); then
1432 echo -n "Titleset Mode" 1568 echo -n "Titleset Mode"
1433 else 1569 else
1434 if [[ $mpeg ]]; then 1570 if [[ $mpeg ]]; then
1435 [[ $testmca ]] && echo -n "Testmca Mode" || echo -n "Mpeg Mode" 1571 [[ $testmca ]] && echo -n "Testmca Mode" || echo -n "MPEG Mode"
1436 fi 1572 fi
1437 fi 1573 fi
1438 echo "${cpu:+ (cpu=$cpu)}" 1574 echo "${cpu:+ (cpu=$cpu)}"
1439 echo " INFO: [$PROGNAME] command line: '${CMD[@]}'" 1575 echo " INFO: [$PROGNAME] command line: '${CMD[@]}'"
1440 } >"$output".log 1576 } >"$output".log
1448 echo -e "$WARN" >>"$output".log 1584 echo -e "$WARN" >>"$output".log
1449 fi 1585 fi
1450 #### volume and audio copy 1586 #### volume and audio copy
1451 if [[ $volume ]]; then 1587 if [[ $volume ]]; then
1452 [[ $encode == 0:?:? && ( ${!audioformat} = copy || $step -eq 1 || $mpeg ) || ${!audioformat} = copy && ! $encode ]] && \ 1588 [[ $encode == 0:?:? && ( ${!audioformat} = copy || $step -eq 1 || $mpeg ) || ${!audioformat} = copy && ! $encode ]] && \
1453 echo "++ WARN: [$PROGNAME] you cannot modify the volume of the output audio stream if you are making a copy the input audio stream" | \ 1589 do_log "++ WARN: [$PROGNAME] you cannot modify the volume of the output audio stream if you are making a copy the input audio stream"
1454 tee -a "$output".log
1455 fi 1590 fi
1456 #### cpu and bframes 1591 #### cpu and bframes
1457 if [[ $cpu && $bframes ]]; then 1592 if [[ $cpu && $bframes ]]; then
1458 ((bframes)) && echo "++ WARN: [$PROGNAME] with bframes>0 the encoding will be faster with cpu=1" | tee -a "$output".log 1593 ((bframes)) && do_log "++ WARN: [$PROGNAME] with bframes>0 the encoding will be faster with cpu=1"
1459 fi 1594 fi
1460 #### -usespeed 1595 #### -usespeed
1461 if [[ $usespeed && ( $encode == 0:?:? || $encode == ?:0:? ) ]]; then 1596 if [[ $usespeed && ( $encode == 0:?:? || $encode == ?:0:? ) ]]; then
1462 echo -en "++ WARN: [$PROGNAME] -usespeed may not work if you do not encode both audio and video.\nPress return to proceed" | tee -a "$output".log && read 1597 do_log "++ WARN: [$PROGNAME] -usespeed may not work if you do not encode both audio and video." && echo -n "Press return to proceed" && read
1463 fi 1598 fi
1464 #### total br 1599 #### total br
1465 [[ $encode != ?:0:? ]] && ((step>1&&abr*audiostream*1024/1000+vbr>MAXBR)) && \ 1600 [[ $encode != ?:0:? ]] && ((step>1&&abr*audiostream*1024/1000+vbr>MAXBR)) && \
1466 echo "++ WARN: [$PROGNAME] total video+audio bitrate ($vbr+$((abr*audiostream*1024/1000))kbps) exceed $frameformat specifications (${MAXBR}kbps)" | \ 1601 do_log "++ WARN: [$PROGNAME] total video+audio bitrate ($vbr+$((abr*audiostream*1024/1000))kbps) exceed $frameformat specifications (${MAXBR}kbps)"
1467 tee -a "$output".log
1468 #### -slideaudio/single picture 1602 #### -slideaudio/single picture
1469 if [[ $slideaudio && $slideaudio != /dev/null && $pictsrc ]]; then 1603 if [[ $slideaudio && $slideaudio != /dev/null && $pictsrc ]]; then
1470 ((${#PICTSRC[*]}!=1||$(ls ${PICTSRC[0]} | wc -l)!=1)) && \ 1604 ((${#PICTSRC[*]}!=1||$(ls ${PICTSRC[0]} | wc -l)!=1)) && \
1471 echo "++ WARN: [$PROGNAME] you should use only one source image if you use the option -slideaudio" | tee -a "$output".log 1605 do_log "++ WARN: [$PROGNAME] you should use only one source image if you use the option -slideaudio"
1472 fi
1473 #FIXME remove once the mpeg muxer is fixed
1474 #### NTSC telecined with B-frames
1475 if [[ $mpeg && $telecine && $videonorm = n && ( $frameformat = DVD || $frameformat = SVCD ) && ( $bframes -gt 0 || ! $bframes && $encode == ?:3:? ) ]]; then
1476 echo "++ WARN: [$PROGNAME] mpeg telecined and with B-frames are not created correctly by mencoder, do not use telecine or do not use B-frames" | \
1477 tee -a "$output".log
1478 echo -n "Press return to proceed" && read
1479 fi 1606 fi
1480 1607
1481 ############################################################################### 1608 ###############################################################################
1482 #### dump some info in the log file 1609 #### dump some info in the log file
1483 ############################################################################### 1610 ###############################################################################
1507 [[ $(echo $encode | cut -f 2 -d:) = 1 && $vcustom ]] && txt="libavcodec" 1634 [[ $(echo $encode | cut -f 2 -d:) = 1 && $vcustom ]] && txt="libavcodec"
1508 [[ ${encode%%:*} = 2 && $acustom ]] && txt=${txt:+${txt} and} && txt="$txt lame" 1635 [[ ${encode%%:*} = 2 && $acustom ]] && txt=${txt:+${txt} and} && txt="$txt lame"
1509 txt=${txt:+(custom ${txt} options)} 1636 txt=${txt:+(custom ${txt} options)}
1510 echo $txt 1637 echo $txt
1511 fi 1638 fi
1512 [[ ! $resume ]] && { [[ $audioonly ]] && mp_identify "$audioonly" || mp_identify "${MPLAYERINFO[@]}" ; } | sed -n '/^ID_/s/^/ INFO: [identify] /p' | uniq 1639 [[ ! $resume ]] && { [[ $audioonly ]] && mp_identify "$audioonly" || mp_identify "${MPLAYERINFO[@]}" -frames 1 ; } | \
1640 sed -n '/^ID_/s/^/ INFO: [identify] /p' | uniq
1513 VARS=(${encode:+MENCODERARG} MPLAYERYUVOPT) 1641 VARS=(${encode:+MENCODERARG} MPLAYERYUVOPT)
1514 VARS=(${encode:+MENCODERARG}) 1642 VARS=(${encode:+MENCODERARG})
1515 for ((i=0;i<${#VARS[*]};i++)) ; do 1643 for ((i=0;i<${#VARS[*]};i++)) ; do
1516 s="INFO: [${VARS[i]}] \${${VARS[i]}[*]}" 1644 s="INFO: \[${VARS[i]}] \${${VARS[i]}[*]}"
1517 eval echo "\ \ \ $s" 1645 eval echo "\ \ \ $s"
1518 done 1646 done
1519 } >>"$output".log 1647 } >>"$output".log
1520 h_res=$(grep ID_VIDEO_WIDTH "$output".log | tail -1 | cut -f2 -d=) 1648 h_res=$(grep ID_VIDEO_WIDTH "$output".log | tail -1 | cut -f2 -d=)
1521 v_res=$(grep ID_VIDEO_HEIGHT "$output".log | tail -1 | cut -f2 -d=) 1649 v_res=$(grep ID_VIDEO_HEIGHT "$output".log | tail -1 | cut -f2 -d=)
1527 [[ $mpeg && ${encode%,*} == ?:0:? ]] && H_RES=$h_res && V_RES=$v_res 1655 [[ $mpeg && ${encode%,*} == ?:0:? ]] && H_RES=$h_res && V_RES=$v_res
1528 1656
1529 ############################################################################### 1657 ###############################################################################
1530 #### put the volume in DB 1658 #### put the volume in DB
1531 ############################################################################### 1659 ###############################################################################
1532 [[ $volume ]] && volume="-af volume=$(awk -v a=$volume 'BEGIN{if(a>0) print 20*log(a)/log(10) ; else print 0}')" 1660 if [[ $volume ]]; then
1533 1661 volume=$(awk -v a=$volume 'BEGIN{if(a>0) print 20*log(a)/log(10) ; else print 0}')
1534 ############################################################################### 1662 af=${af:--af }${af:+,}volume=$volume
1535 #### NTSC telecined mpeg copy/speed encoding change 1663 fi
1664
1665 [[ ${mver:0:5} = 1.0rc ]] || SVN=1
1666
1667 ###############################################################################
1668 #### telecined (NTSC/PAL) MPEG copy/speed encoding change
1536 ############################################################################### 1669 ###############################################################################
1537 if [[ $mpeg && ( $encode == ?:0:? || $usespeed ) || $usespeed && ! $encode && $step -gt 1 ]]; then 1670 if [[ $mpeg && ( $encode == ?:0:? || $usespeed ) || $usespeed && ! $encode && $step -gt 1 ]]; then
1538 FPS=($(grep ID_VIDEO_FPS "$output".log | cut -f2 -d=) [1]=23.976 24.000 25.000 29.970 30.000 50.000 59.940 60.000) 1671 FPS=($(grep ID_VIDEO_FPS "$output".log | cut -f2 -d=) [1]=23.976 24.000 25.000 29.970 30.000 50.000 59.940 60.000)
1539 for ((i=1;i<9;i++)); do 1672 for ((i=1;i<9;i++)); do
1540 a=$(awk -v a=${FPS[0]} -v b=${FPS[i]} 'BEGIN{if (sqrt((a-b)*(a-b))<.02) print b}') 1673 a=$(awk -v a=${FPS[0]} -v b=${FPS[i]} 'BEGIN{if (sqrt((a-b)*(a-b))<.02) print b}')
1541 if [[ $a ]]; then 1674 if [[ $a ]]; then
1542 if [[ ${FPS[0]} != ${FPS[i]} ]]; then 1675 if [[ ${FPS[0]} != ${FPS[i]} ]]; then
1543 echo "++ WARN: [$PROGNAME] input video frame rate is not exactly ${FPS[i]}fps" | tee -a "$output".log 1676 do_log "++ WARN: [$PROGNAME] input video frame rate is not exactly ${FPS[i]}fps"
1544 FPS[0]=${FPS[i]} 1677 FPS[0]=${FPS[i]}
1545 fi 1678 fi
1546 FPS[10]=$i 1679 FPS[10]=$i
1547 break 1680 break
1548 fi 1681 fi
1549 done 1682 done
1550 [[ $usespeed && $i -eq 9 ]] && \ 1683 [[ $usespeed && $i -eq 9 ]] && do_log "++ WARN: [$PROGNAME] input video frame rate is not a valid NTSC/PAL value; disabling -usespeed" && usespeed=
1551 echo "++ WARN: [$PROGNAME] input video frame rate is not a valid NTSC/PAL value; disabling -usespeed" | tee -a "$output".log && usespeed=
1552 1684
1553 if [[ ${FPS[0]} = ${FPS[4]} || ${FPS[0]} = ${FPS[5]} ]]; then 1685 if [[ ${FPS[0]} = ${FPS[4]} || ${FPS[0]} = ${FPS[5]} ]]; then
1554 FPS[9]=$(mplayer -nocache -quiet "${MPLAYERINFO[@]}" -vo null -nosound -benchmark -frames 60 2>/dev/null | awk '/^demux_mpg:/{print $2}') 1686 FPS[9]=$(mplayer -nocache -quiet "${MPLAYERINFO[@]}" -vo null -nosound -benchmark -frames 60 2>/dev/null | awk '/^demux_mpg:/{print $2}')
1555 [[ ${FPS[9]} = 24fps || ${FPS[9]} = 24000/1001fps ]] && FPS[10]=$((FPS[10]-3)) 1687 [[ ${FPS[9]} = 24fps || ${FPS[9]} = 24000/1001fps ]] && FPS[10]=$((FPS[10]-3))
1688 elif [[ ${FPS[0]} = ${FPS[3]} ]]; then
1689 FPS[9]=$(is_film2pal "${MPLAYERINFO[@]}")
1690 if [[ ${FPS[9]} ]]; then
1691 [[ ${FPS[9]} = 24fps ]] && FPS[10]=2 || FPS[10]=1
1692 fi
1556 fi 1693 fi
1557 if [[ $usespeed ]]; then 1694 if [[ $usespeed ]]; then
1558 if ((vfr!=${FPS[10]})); then 1695 if ((vfr!=${FPS[10]})); then
1559 NSPEEDCOEF=([1]=1001 1001 5 1001 1001 5 1001 25 1250 5 25 2500 5 1200 6 2 2400 12 1001 1001 2 1001 5 2000 2 1200 6 1001 ) 1696 NSPEEDCOEF=([1]=1001 1001 5 1001 1001 5 1001 25 1250 5 25 2500 5 1200 6 2 2400 12 1001 1001 2 1001 5 2000 2 1200 6 1001 )
1560 MSPEEDCOEF=([1]=1000 960 4 800 480 2 400 24 1001 4 12 1001 2 1001 5 1 1001 5 1000 200 1 500 3 1001 1 1001 5 1000 ) 1697 MSPEEDCOEF=([1]=1000 960 4 800 480 2 400 24 1001 4 12 1001 2 1001 5 1 1001 5 1000 200 1 500 3 1001 1 1001 5 1000 )
1567 n=$((vfr+${FPS[10]}+${DCOEF[vfr]})) 1704 n=$((vfr+${FPS[10]}+${DCOEF[vfr]}))
1568 a=${MSPEEDCOEF[n]}/${NSPEEDCOEF[n]} 1705 a=${MSPEEDCOEF[n]}/${NSPEEDCOEF[n]}
1569 fi 1706 fi
1570 MENCODERARG=( -speed $a -srate $asr -af-adv force=1 "${MENCODERARG[@]}" ) 1707 MENCODERARG=( -speed $a -srate $asr -af-adv force=1 "${MENCODERARG[@]}" )
1571 MPLAYERYUVOPT=("${MPLAYERYUVOPT[@]}" -speed $a ) 1708 MPLAYERYUVOPT=("${MPLAYERYUVOPT[@]}" -speed $a )
1572 echo " INFO: [usespeed] using speed factor $a" | tee -a "$output".log 1709 do_log " INFO: [usespeed] using speed factor $a"
1573 fi 1710 fi
1574 elif [[ ${FPS[0]} = ${FPS[4]} || ${FPS[0]} = ${FPS[5]} ]]; then 1711 elif [[ ${FPS[0]} = ${FPS[4]} || ${FPS[0]} = ${FPS[5]} || ${FPS[0]} = ${FPS[3]} ]]; then
1575 if [[ ${FPS[9]} = 24fps || ${FPS[9]} = 24000/1001fps || $telesrc ]]; then 1712 if [[ ${FPS[9]} = 24fps || ${FPS[9]} = 24000/1001fps || $telesrc ]]; then
1576 { echo -n " INFO: [$PROGNAME] " 1713 { echo -n " INFO: [$PROGNAME] "
1577 [[ ${FPS[9]} = 24fps || ${FPS[9]} = 24000/1001fps ]] && echo -n "detected" || echo -n "user selected" 1714 [[ ${FPS[9]} = 24fps || ${FPS[9]} = 24000/1001fps ]] && echo -n "detected" || echo -n "user selected"
1715 [[ ${FPS[0]} = ${FPS[3]} ]] && echo -n " PAL" || echo -n " NTSC"
1578 echo " telecined source" 1716 echo " telecined source"
1579 } | tee -a "$output".log 1717 } | tee -a "$output".log
1580 MENCODERARG=( "${MENCODERARG[@]}" -ofps 24000/1001 -mc 0 ) 1718 [[ ${FPS[10]} = 1 ]] && MENCODERARG=( "${MENCODERARG[@]}" -ofps 24000/1001 -mc 0 ) || MENCODERARG=( "${MENCODERARG[@]}" -ofps 24 -mc 0 )
1581 fi 1719 fi
1582 fi 1720 fi
1583 fi 1721 fi
1584 1722
1585 ############################################################################### 1723 ###############################################################################
1590 a=$(get_aspect "${MPLAYERINFO[@]}") 1728 a=$(get_aspect "${MPLAYERINFO[@]}")
1591 [[ ${a:0:9} = undefined ]] && a=$(awk -v a=$h_res -v b=$v_res 'BEGIN{printf("%f",a/b)}') 1729 [[ ${a:0:9} = undefined ]] && a=$(awk -v a=$h_res -v b=$v_res 'BEGIN{printf("%f",a/b)}')
1592 [[ $mpegaspect == 1 ]] && b=$(awk -v a=$H_RES -v b=$V_RES 'BEGIN{printf("%f",a/b)}') || b=${ASPECT[${mpegaspect:-2}]} 1730 [[ $mpegaspect == 1 ]] && b=$(awk -v a=$H_RES -v b=$V_RES 'BEGIN{printf("%f",a/b)}') || b=${ASPECT[${mpegaspect:-2}]}
1593 vfilter=$(awk -v a=$a -v A=$b -v W=$H_RES -v H=$V_RES -v crop=$mpegfixaspect -v i=${interlaced:-0} -v r=$rotate -v o=$overscan -v logfile="$(echo "$output" | sed 's/\\/\\\\/g')".log 'BEGIN{ 1731 vfilter=$(awk -v a=$a -v A=$b -v W=$H_RES -v H=$V_RES -v crop=$mpegfixaspect -v i=${interlaced:-0} -v r=$rotate -v o=$overscan -v logfile="$(echo "$output" | sed 's/\\/\\\\/g')".log 'BEGIN{
1594 ko=(1-o/100) 1732 ko=(1-o/100)
1595 if(a==1.78)a=16/9 1733 if(a==1.78||a==1.74)a=16/9
1596 if(a==1.33)a=4/3 1734 if(a==1.33||a==1.30)a=4/3
1597 if(A=="4/3")A=4/3 1735 if(A=="4/3")A=4/3
1598 if(A=="16/9")A=16/9 1736 if(A=="16/9")A=16/9
1599 if(r!=""){ 1737 if(r!=""){
1600 A=1/A 1738 A=1/A
1601 tmp=W 1739 tmp=W
1637 done 1775 done
1638 fi 1776 fi
1639 fi 1777 fi
1640 1778
1641 ############################################################################### 1779 ###############################################################################
1780 #### warn for aspect ratio
1781 ###############################################################################
1782 if [[ ( $mpeg && $encode != ?:0:? || ! $mpeg && $step -gt 1 ) && ! $mpegfixaspect && ${#TITLESET[*]} -eq 0 && ! $testmca ]]; then
1783 a=$(get_aspect "${MPLAYERINFO[@]}")
1784 [[ ${mpegaspect:-2} = 2 && $a != 1.33 && $a != 1.30 || ${mpegaspect:-2} = 3 && $a != 1.78 && $a != 1.74 || ${mpegaspect:-2} = 4 && $a != 2.21 ]] && \
1785 do_log "++ WARN: [$PROGNAME] selected aspect ratio [${ASPECT[${mpegaspect:-2}]}] and source aspect ratio [$a] are different"
1786 fi
1787
1788 ###############################################################################
1642 #### dvd vobsub 1789 #### dvd vobsub
1643 ############################################################################### 1790 ###############################################################################
1644 #### function to select the vobsub to extract 1791 #### function to select the vobsub to extract
1645 next_vobsub_idx () { 1792 next_vobsub_idx () {
1646 if ((${#SID[*]})); then 1793 if ((${#SID[*]})); then
1647 if ((idx < ${#encsid[*]})); then 1794 if ((idx < ${#encsid[*]})); then
1648 SID=(-sid ${encsid[idx]} -vobsuboutindex ${encsdx[idx]} ${encsla:+-vobsuboutid ${encsla[idx]}} -vobsubout "$output") 1795 SID=(-sid ${encsid[idx]} -vobsuboutindex ${encsdx[idx]} ${encsla:+-vobsuboutid ${encsla[idx]}} -vobsubout "$output")
1649 echo " INFO: [$PROGNAME] dumping subtitle ${encsid[idx]} to vobsub ${encsdx[idx]}${encsla:+ (${encsla[idx]})}" | tee -a "$output".log 1796 do_log " INFO: [$PROGNAME] dumping subtitle ${encsid[idx]} to vobsub ${encsdx[idx]}${encsla:+ (${encsla[idx]})}"
1650 idx=$((idx+1)) 1797 idx=$((idx+1))
1651 else 1798 else
1652 unset SID 1799 unset SID
1653 fi 1800 fi
1654 fi 1801 fi
1666 1813
1667 ############################################################################### 1814 ###############################################################################
1668 #### test condition "extra" 1815 #### test condition "extra"
1669 ############################################################################### 1816 ###############################################################################
1670 IDACOD=$(grep "ID_AUDIO_CODEC" "$output".log | tail -1 | cut -f2 -d=) 1817 IDACOD=$(grep "ID_AUDIO_CODEC" "$output".log | tail -1 | cut -f2 -d=)
1671 [[ $mpeg && ! $pictsrc && ( $encode == 1:?:? || $multiaudio || $encode == 0:?:? && $IDACOD != mp3 && $IDACOD != a52 ) ]] && extra=1 || extra= 1818 [[ $IDACOD = hwdts ]] && echo "**ERROR: [$PROGNAME] dts audio support missing in MPlayer" && \
1672 [[ $extra ]] && echo "**ERROR: [$PROGNAME] output stream: unsupported audio codec $IDACOD" | tee -a "$output".log && exit 1 1819 echo "**ERROR: add dts support (libdts-0.0.2.tar.gz) or select a non dts stream" && \
1820 echo "**ERROR: example: -aid 128 (ac3), -aid 160 (lpcm), -aid 0 (mpeg)" && exit 1
1821 [[ $mpeg && ! $pictsrc && ( $encode == 1:?:? || $multiaudio || $encode == 0:?:? && $IDACOD != mp3 && $IDACOD != a52 && $IDACOD != faad ) ]] && extra=1 || \
1822 extra=
1823 [[ $extra ]] && do_log "**ERROR: [$PROGNAME] output stream: unsupported audio codec $IDACOD" && exit 1
1673 1824
1674 CLEAN[${#CLEAN[*]}]="$output".tmp 1825 CLEAN[${#CLEAN[*]}]="$output".tmp
1675 1826
1676 ############################################################################### 1827 ###############################################################################
1677 #### avi/mpeg section 1828 #### AVI/MPEG section
1678 ############################################################################### 1829 ###############################################################################
1679 if [[ $encode ]]; then 1830 if [[ $encode ]]; then
1680 if status_bit avi ; then 1831 if status_bit avi ; then
1681 find_sbr () { 1832 find_sbr () {
1682 local kv k ka 1833 local kv k ka
1683 if [[ $mpeg ]]; then 1834 sleep 2
1684 kv=9888 ; k=33 ; ka=996 1835 [[ $mpeg ]] && kv=9888 k=33 ka=1015 || kv=10000 k=0 ka=1011
1685 fi
1686 if ((usesbr<=6)); then 1836 if ((usesbr<=6)); then
1687 sbr=$(awk '/for '"${SBR[usesbr-1]}"'MB CD/{print $NF}' <"$output".log) 1837 sbr=$(awk '/for '"${SBR[usesbr-1]}"'MB CD/{print $NF}' <"$output".log)
1688 [[ $sbr ]] && ((sbr<vbitrate)) && VIDEOPASS=${VIDEOPASS/vbitrate=$vbitrate:/vbitrate=$sbr:} && \ 1838 [[ $sbr ]] && ((sbr<vbitrate)) && VIDEOPASS=${VIDEOPASS/vbitrate=$vbitrate:/vbitrate=$sbr:} && \
1689 echo " INFO: [mencoder] using vbitrate=$sbr" | tee -a "$output".log 1839 do_log " INFO: [mencoder] using vbitrate=$sbr"
1690 else 1840 else
1691 #### usesbr is in MB 1841 #### usesbr is in MB
1692 #### remind: 650-800,650-1400,800-1400 1842 #### remind: 650-800,650-1400,800-1400
1693 sbr[0]=650 1843 sbr[0]=650
1694 sbr[1]=1400 1844 sbr[1]=1400
1695 sbr[2]=$(awk '/for '"${SBR[0]}"'MB CD/{print $NF}' <"$output".log) 1845 sbr[2]=$(awk '/for '"${SBR[0]}"'MB CD/{print $NF}' <"$output".log)
1696 sbr[3]=$(awk '/for '"${SBR[4]}"'MB CD/{print $NF}' <"$output".log) 1846 sbr[3]=$(awk '/for '"${SBR[4]}"'MB CD/{print $NF}' <"$output".log)
1697 [[ ${sbr[2]} && ${sbr[3]} ]] && \ 1847 [[ ${sbr[2]} && ${sbr[3]} ]] && \
1698 sbr[4]=$(((((usesbr*kv/10000-k)-(audiosize*ka/1000))*(sbr[3]-sbr[2])+sbr[1]*sbr[2]-sbr[0]*sbr[3])/(sbr[1]-sbr[0]))) 1848 sbr[4]=$(((((usesbr*kv/10000-k)-(audiosize*ka/1000))*(sbr[3]-sbr[2])+sbr[1]*sbr[2]-sbr[0]*sbr[3])/(sbr[1]-sbr[0])))
1699 [[ ${sbr[4]} ]] && ((sbr[4]<vbitrate && sbr[4]>0)) && VIDEOPASS=${VIDEOPASS/vbitrate=$vbitrate:/vbitrate=${sbr[4]}:} && \ 1849 [[ ${sbr[4]} ]] && ((sbr[4]<vbitrate && sbr[4]>0)) && VIDEOPASS=${VIDEOPASS/vbitrate=$vbitrate:/vbitrate=${sbr[4]}:} && \
1700 echo " INFO: [mencoder] using vbitrate=${sbr[4]}" | tee -a "$output".log 1850 do_log " INFO: [mencoder] using vbitrate=${sbr[4]}"
1701 fi 1851 fi
1702 } 1852 }
1703 AID= 1853 AID=
1854 if [[ ! $extra ]]; then
1855 RAWVIDEO=( -o "$output".$SUF )
1856 fi
1704 #### start mencoder 1857 #### start mencoder
1705 PLOG=( -passlogfile "$output".avi2pass.log ) 1858 PLOG=( -passlogfile "$output".avi2pass.log )
1859 MSG=( -msglevel open=6:demuxer=6:demux=6 )
1706 rm -f frameno.avi 1860 rm -f frameno.avi
1707 if ((PASS==1)); then 1861 [[ $encode == 0:?:? && ! $extra ]] && F= || F=$af
1708 if [[ $usesbr && ! $extra ]]; then 1862 if [[ $usesbr && ! $extra ]]; then
1709 mencoder $OPTIONS -ovc frameno -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS 2>&1 | \ 1863 ((DEBUG)) && debug_line $((LINENO+2)) "usesbr "
1710 mp_single_log mencoder '^Recommended video bitrate' 1864 me_bit_log
1865 mencoder $OPTIONS -ovc frameno -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $F &>"$output".fifo
1711 find_sbr 1866 find_sbr
1712 next_vobsub_idx 1867 next_vobsub_idx
1713 fi 1868 fi
1714 ((DEBUG)) && debug_line $((LINENO+1)) "PASS 1/$PASS" 1869 if ((PASS==1)); then
1715 mencoder $OPTIONS $VIDEOPASS -o "$output".$SUF "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $volume -v | mplayer_log mencoder 1870 ((DEBUG)) && debug_line $((LINENO+2)) "PASS 1/$PASS"
1871 me_log
1872 mencoder $OPTIONS $VIDEOPASS "${RAWVIDEO[@]}" "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $F "${MSG[@]}" >"$output".fifo
1716 next_vobsub_idx 1873 next_vobsub_idx
1717 else 1874 else
1718 #### N pass 1875 #### N pass
1719 if [[ $usesbr && ! $extra ]]; then
1720 mencoder $OPTIONS -ovc frameno -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS 2>&1 | \
1721 mp_single_log mencoder '^Recommended video bitrate'
1722 find_sbr
1723 next_vobsub_idx
1724 fi
1725 CLEAN[${#CLEAN[*]}]="$output".avi2pass.log 1876 CLEAN[${#CLEAN[*]}]="$output".avi2pass.log
1726 ((DEBUG)) && debug_line $((LINENO+1)) "PASS 1/$PASS" 1877 ((DEBUG)) && debug_line $((LINENO+1)) "PASS 1/$PASS"
1727 mencoder $OPTIONS ${VIDEOPASS}:vpass=1$turbo -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $volume "${PLOG[@]}" 1878 mencoder $OPTIONS ${VIDEOPASS}:vpass=1$turbo -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $F "${PLOG[@]}"
1728 next_vobsub_idx 1879 next_vobsub_idx
1729 if ((PASS==2)); then 1880 if ((PASS==2)); then
1730 ((DEBUG)) && debug_line $((LINENO+1)) "PASS 2/$PASS" 1881 ((DEBUG)) && debug_line $((LINENO+2)) "PASS 2/$PASS"
1731 mencoder $OPTIONS ${VIDEOPASS}:vpass=2 -o "$output".$SUF "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $volume "${PLOG[@]}" -v | \ 1882 me_log
1732 mplayer_log mencoder 1883 mencoder $OPTIONS ${VIDEOPASS}:vpass=2 "${RAWVIDEO[@]}" "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $F "${PLOG[@]}" "${MSG[@]}" \
1884 >"$output".fifo
1733 next_vobsub_idx 1885 next_vobsub_idx
1734 else 1886 else
1735 for ((a=2;a<PASS;a++)); do 1887 for ((a=2;a<PASS;a++)); do
1736 ((DEBUG)) && debug_line $((LINENO+1)) "PASS $a/$PASS" 1888 ((DEBUG)) && debug_line $((LINENO+1)) "PASS $a/$PASS"
1737 mencoder $OPTIONS ${VIDEOPASS}:vpass=3 -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $volume "${PLOG[@]}" 1889 mencoder $OPTIONS ${VIDEOPASS}:vpass=3 -o /dev/null "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $F "${PLOG[@]}"
1738 next_vobsub_idx 1890 next_vobsub_idx
1739 done 1891 done
1740 ((DEBUG)) && debug_line $((LINENO+1)) "PASS $PASS/$PASS" 1892 ((DEBUG)) && debug_line $((LINENO+2)) "PASS $PASS/$PASS"
1741 mencoder $OPTIONS ${VIDEOPASS}:vpass=3 -o "$output".$SUF "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $volume "${PLOG[@]}" -v | \ 1893 me_log
1742 mplayer_log mencoder 1894 mencoder $OPTIONS ${VIDEOPASS}:vpass=3 "${RAWVIDEO[@]}" "${SID[@]}" "${MENCODERARG[@]}" $AID $AUDIOPASS $F "${PLOG[@]}" "${MSG[@]}" \
1895 >"$output".fifo
1743 next_vobsub_idx 1896 next_vobsub_idx
1744 fi 1897 fi
1745 fi 1898 fi
1746 status_bit avi set 1899 status_bit avi set
1747 fi 1900 fi
1797 status_bit mpa set 1950 status_bit mpa set
1798 status_bit mpg set 1951 status_bit mpg set
1799 mv "$output".$SUF "$output".mpg 1952 mv "$output".$SUF "$output".mpg
1800 fi 1953 fi
1801 fi 1954 fi
1802 #FIXME remove once the mpeg muxer is fixed 1955 fi
1803 #### NTSC dvd warn 1956
1804 [[ $videonorm = n && $frameformat = DVD ]] && \ 1957 ###############################################################################
1805 echo "++ WARN: [$PROGNAME] mencoder does not multiplex correctly NTSC mpeg, you may want to use encode2mpeg instead" | tee -a "$output".log 1958 #### split the MPEG stream (for MPEG Mode)
1806 fi
1807
1808 ###############################################################################
1809 #### split the mpeg stream (for Mpeg Mode)
1810 ############################################################################### 1959 ###############################################################################
1811 if status_bit spl ; then 1960 if status_bit spl ; then
1812 #### split for Mpeg Mode (mpeg4 codec not supported) 1961 #### split for MPEG Mode (MPEG-4 codec not supported)
1813 #### mencoder does not support split as it does mpeg2enc/mplex 1962 #### MEncoder does not support split as does mpeg2enc/mplex
1814 #### this solution is slow, but it seems quite accurate 1963 #### this solution is slow, but it seems quite accurate
1815 if [[ $mpeg && $split && $vcodec != mpeg4 ]]; then 1964 if [[ $mpeg && $split && $vcodec != mpeg4 ]]; then
1816 [[ ! $fast ]] && mv "$output"01.mpg "$output".mpg 1965 [[ ! $fast ]] && mv "$output"01.mpg "$output".mpg
1817 file_size "$output".mpg 1966 file_size "$output".mpg
1818 if ((split*1024*1024<fsize)); then 1967 if ((split*1024*1024<fsize)); then
1826 sort -n | tr '\012' ',' | sed 's/,$/\n/') 1975 sort -n | tr '\012' ',' | sed 's/,$/\n/')
1827 for ((i=0;i<chunks;i++)); do 1976 for ((i=0;i<chunks;i++)); do
1828 if ((i<chunks-1)); then 1977 if ((i<chunks-1)); then
1829 n=$(mplayer "$output".mpg -vf framestep=I -vo null -nosound -benchmark 2>/dev/null -sb $(((i+1)*split*1024*1024)) -frames 30 | \ 1978 n=$(mplayer "$output".mpg -vf framestep=I -vo null -nosound -benchmark 2>/dev/null -sb $(((i+1)*split*1024*1024)) -frames 30 | \
1830 tr '\015' '\012' | awk '{if($1=="I!"){print t;exit};t=$2}') 1979 tr '\015' '\012' | awk '{if($1=="I!"){print t;exit};t=$2}')
1831 n=$(awk '/^'"$n"'/{print $2-1;exit}' "$output".framelist) #should be -2 1980 n=$(awk '/^'"$n"'/{print $2-1;exit}' <"$output".framelist) #should be -2
1832 else 1981 else
1833 n= 1982 n=
1834 fi 1983 fi
1835 ((DEBUG)) && debug_line $((LINENO+1)) "mpeg_split $((i+1))/$chunks" 1984 ((DEBUG)) && debug_line $((LINENO+1)) "mpeg_split $((i+1))/$chunks"
1836 "$PROGFILE" -norc "$output".mpg -o "$output"$(printf "%02d" $((i+1))) -mpegonly -mpeg -encode 0:0:1 -$(echo $frameformat| tr '[:upper:]' '[:lower:]') -nosplit -noshowlog -sb $((i*split*1024*1024)) ${n:+-frames $((n-m))} -a ${mpegaspect:-2} ${multiaudio:+-multiaudio $a} -mc 0 1985 "$PROGFILE" -norc "$output".mpg -o "$output"$(printf "%02d" $((i+1))) -mpegonly -mpeg -encode 0:0:1 -$(echo $frameformat| tr '[:upper:]' '[:lower:]') -nosplit -noshowlog -sb $((i*split*1024*1024)) ${n:+-frames $((n-m))} -a ${mpegaspect:-2} ${multiaudio:+-multiaudio $a} -mc 0