Video encoding

From YobiWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Converted with HTML::WikiConverter::MediaWiki from my old phpwiki site


Pour créer ses DIVX et VCD

DIVX (en 2 passes) :

VERSION 0.6.1

 
 # Script pour faire les divx de bonne qualite generalement en 2 CD
 # note: pour le debut et la fin d'encodage , il faut editer le script
 # ce sera corrige dans la prochaine version ;-) J-Ch
 # note : ayant eu des problemes avec les version successives de mplayer
 #        j'ai "arrete" la version a "0.90rc3-2.95.4"
 
 
 # version 0.6.1 - 26/04/2033 - Oli (Olivier at skycode.org)
 # Some bug fixing :
 #       1) looping around every time something is interactively
 #          asked to the user to prevent the script from exiting
 #          and having to do the rest manually
 #          note : there is still some work to do on values checking
 
 # version 0.6 - 25/04/2033 - Oli (Olivier at skycode.org)
 #
 # version 0.5 - J-Ch (dorian at be.linux.org)
 #
 # versions anterieures bulshit ;-)
 
 # Script usage :
 #
 # mdivx.sh -endpos 0:00:00 -ss 0:00:00 -audiochannel 128 -xscale 640 -yscale 480
 #          -audiobitrate 128 -videobitrate 1200 file.vob out.avi
 
 usage="mdivx.sh -e 0:00:00 -s 0:00:00 -a audichannel -x 640 -y 480\n-u audiobitrate -v videobitrate file.vob out.avi"
 
 # Some defaults
 
 audiochanneldef="128"
 xscaledef="640"
 yscaledef="480"
 audiobitratedef="128"
 videobitratedef="1200"
 
 # Option parsing
 
 while getopts ":e:s:a:x:y:u:v:" option
     do
         echo $option
         echo $OPTARG
         case "$option" in
         "e")
             endpos=$OPTARG
             ;;
         "s")
             ss=$OPTARG
             ;;
         "a")
             audiochannel=$OPTARG
             ;;
         "x")
             xscale=$OPTARG
             ;;
         "y")
             yscale=$OPTARG
             ;;
         "u")
             audiobitrate=$OPTARG
             ;;
         "v")
             videobitrate=$OPTARG
             ;;
         *)
             echo "Wrong option somewhere usage :\n"
             echo $usage
             exit 1
         esac
     done
 
 echo $OPTIND
 
 let a=$OPTIND-1
 
 shift $a
 
 echo $1
 
 # Let's sort out all those variable and set up some defaults if not specified by user
 
 if [ "$endpos" ]
     then
         endpos="-endpos $endpos"
     else
         endpos=""
 fi
 
 echo $endpos
 
 if [ "$ss" ]
     then
         ss="-ss $ss"
     else
         ss=""
 fi
 
 echo $ss
 
 if [ "$audiochannel" ]
     then
         audiochannel="-aid $audiochannel"
     else
         audiochannel="-aid $audiochanneldef"
 fi
 
 echo $audiochannel
 
 if [ "$xscale" ]&&[ "$yscale" ]
     then
         scaling="-vop scale=$xscale:$yscale"
     else
         scaling="-vop scale=$xscaledef:$yscaledef"
 fi
 
 echo $scaling
 
 if [ "$audiobitrate" ]
     then
         :
     else
         audiobitrate=$audiobitratedef
 fi
 
 echo $audiobitrate
 echo $videobitrate
 
 if [ -z "$1" ]||[ -z "$2" ]
     then
         echo "Missing file,  usage "
         echo $usage
         exit 2
     elif [ "$1" = "$2" ]
         then
             echo "Same name for source and destination !!!"
             printf "\a" # beep ! ;-)
             exit 3
 fi
 
 
 echo ""
 echo "================================================================================"
 echo "+                                   DO SOUND                                   +"
 echo "================================================================================"
 echo ""
 echo "si la langue n'est pas bonne : -aid 128-160 et -v => donnera la
 lists language"
 echo "ou -alang fr ????"
 
 if [ -e frameno.avi ]
 then
 while [ true ]
 do
     echo "frameno.avi exist ! what do I do now ?"
     echo ""
     echo "c = Continue without make sound"
     echo "d = Delete frameno.avi"
     echo "e = exit "
     echo ""
 
      read TMPVAR
      case $TMPVAR in
         e)
             exit 1
             ;;
         d)
             rm frameno.avi
             mencoder $ss $endpos -ovc frameno $audiochannel -oac mp3lame -lameopts cbr:br=$audiobitrate -o frameno.avi $1
             break
             ;;
         c)
             break
             ;;
         *)
             echo "Answer must be something of c, d, or e, try again :-)"
             echo ""
             continue
             ;;
      esac
 done
 
 else
 mencoder $ss $endpos -ovc frameno $audiochannel -oac mp3lame -lameopts cbr:br=$audiobitrate -o frameno.avi $1
 fi
 
 
 if [ "$videobitrate" ]
     then
         :
     else
         while [ true ]
             do
                 echo ""
                 echo ""
                 echo "Sound encoded, mplayer has suggested to you some bitrate for video"
                 echo "choose to enter it manually or to use script default ($videobitratedef)"
                 echo ""
                 echo "Note : if you specify a video bitrate (with -v option) to this script"
                 echo "it won't ask you this question"
                 echo ""
                 echo "***********************************************************************"
                 echo "* 1) Use script default ($videobitratedef)                             *"
                 echo "* 2) Enter manually video bitrate now                                 *"
                 echo "***********************************************************************"
 
                 # It would be nice to extract mencoder suggestion and give it user :-)
 
                 echo ""
                 echo "Your choice :"
                 read TMPVAR
                 echo ""
 
                 case $TMPVAR in
                     1)
                         videobitrate=$videobitratedef
                         echo "continuing with script default"
                         break
                         ;;
 
                     2)
                         echo "enter video bitrate :"
                         echo ""
                         read BITRATE
                         echo ""
                         videobitrate=$BITRATE
                         echo "continuing with $videobitrate as video bitrate"
                         echo ""
                         break
                         ;;
                     *)
                         echo "choose one of the menu option !! try again :-)"
                         echo ""
                         continue
                 esac
         done
 fi
 
 # mkfifo teste.wav
 # rm frameno.avi
 # mencoder -audiofile teste.wav -ovc frameno -o frameno.avi -oac mp3lame
 # -lameopts abr:br=128 -aid 128 $1 &
 # mplayer -vo null -ao pcm -aofile teste.wav $1
 # rm teste.wav
 
 
 
 echo ""
 echo "================================================================================"
 echo "+                               DO Video Pass 1                                +"
 echo "================================================================================"
 echo ""
 
 mencoder $ss $endpos -oac copy -o /dev/null -ovc lavc -lavcopts vcodec=mpeg4:vbitrate="$videobitrate":vhq:vpass=1 $scaling  $1
 echo ""
 echo "================================================================================"
 echo "+                               DO Video Pass 2                                +"
 echo "================================================================================"
 echo ""
 
 mencoder $ss $endpos -oac copy -o $2 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate="$videobitrate":vhq:vpass=2 $scaling $1
 

Quelques modifs au script de J-Ch pour les divx (j'ai pas touche a celui pour les VCDs) VERSION 0.6

Il y a encore plein de truc qu'on pourrait implementer et il faudrait ecrire une petite doc, sorry j'ai pas eu le temps :-(

VERSION 0.6 (J-ch + Oli)

 # Script pour faire les divx de bonne qualite generalement en 2 CD
 # note: pour le debut et la fin d'encodage , il faut editer le script
 # ce sera corrige dans la prochaine version ;-) J-Ch
 # note : ayant eu des problemes avec les version successives de mplayer
 #        j'ai "arrete" la version a "0.90rc3-2.95.4"
 
 # version 0.6 - Oli (Olivier at skycode.org)
 # version 0.5 - J-Ch (dorian at be.linux.org)
 # versions anterieures bulshit ;-)
 
 # Script usage :
 #
 # mdivx.sh -endpos 0:00:00 -ss 0:00:00 -audiochannel 128 -xscale 640 -yscale 480
 #          -audiobitrate 128 -videobitrate 1200 file.vob out.avi
 
 usage="mdivx.sh -e 0:00:00 -s 0:00:00 -a audichannel -x 640 -y 480\n-u audiobitrate -v videobitrate file.vob out.avi"
 
 # Some defaults
 
 audiochanneldef="128"
 xscaledef="640"
 yscaledef="480"
 audiobitratedef="128"
 videobitratedef="1200"
 
 # Option parsing
 
 while getopts ":e:s:a:x:y:u:v:" option
     do
         echo $option
         echo $OPTARG
         case "$option" in
         "e")
             endpos=$OPTARG
             ;;
         "s")
             ss=$OPTARG
             ;;
         "a")
             audiochannel=$OPTARG
             ;;
         "x")
             xscale=$OPTARG
             ;;
         "y")
             yscale=$OPTARG
             ;;
         "u")
             audiobitrate=$OPTARG
             ;;
         "v")
             videobitrate=$OPTARG
             ;;
         *)
             echo "Wrong option somewhere usage :\n"
             echo $usage
             exit 1
         esac
     done
 
 echo $OPTIND
 
 let a=$OPTIND-1
 
 shift $a
 
 echo $1
 
 # Let's sort out all those variable and set up some defaults if not specified by user
 
 if [ "$endpos" ]
     then
         endpos="-endpos $endpos"
     else
         endpos=""
 fi
 
 echo $endpos
 
 if [ "$ss" ]
     then
         ss="-ss $ss"
     else
         ss=""
 fi
 
 echo $ss
 
 if [ "$audiochannel" ]
     then
         audiochannel="-aid $audiochannel"
     else
         audiochannel="-aid $audiochanneldef"
 fi
 
 echo $audiochannel
 
 if [ "$xscale" ]&&[ "$yscale" ]
     then
         scaling="-vop scale=$xscale:$yscale"
     else
         scaling="-vop scale=$xscaledef:$yscaledef"
 fi
 
 echo $scaling
 
 if [ "$audiobitrate" ]
     then
         :
     else
         audiobitrate=$audiobitratedef
 fi
 
 echo $audiobitrate
 echo $videobitrate
 
 if [ -z "$1" ]||[ -z "$2" ]
     then
         echo "Missing file,  usage "
         echo $usage
         exit 2
     elif [ "$1" = "$2" ]
         then
             echo "Same name for source and destination !!!"
             printf "\a" # beep ! ;-)
             exit 3
 fi
 
 
 echo ""
 echo "================================================================================"
 echo "+                                   DO SOUND                                   +"
 echo "================================================================================"
 echo ""
 echo "si la langue n'est pas bonne : -aid 128-160 et -v => donnera la
 lists language"
 echo "ou -alang fr ????"
 
 if [ -e frameno.avi ]
 then echo "frameno.avi exist ! what to do ?";
      echo "c = Continue without make sound ; d = Delete frameno.avi ; e= exit ";
 
      read TMPVAR
      case $TMPVAR in
         "")
      ;;
  e)
      exit 1
      ;;
  d)
      rm frameno.avi
      mencoder $ss $endpos -ovc frameno $audiochannel -oac mp3lame -lameopts cbr:br=$audiobitrate -o frameno.avi $1
      ;;
  c)
      ;;
  *)
      exit 4
      ;;
      esac
 else
 mencoder $ss $endpos -ovc frameno $audiochannel -oac mp3lame -lameopts cbr:br=$audiobitrate -o frameno.avi $1
 fi
 
 if [ "$videobitrate" ]
     then
         :
     else
         echo ""
         echo ""
         echo "Sound encoded, mplayer has suggested to you some bitrate for video"
         echo "choose to enter it manually or to use script default ($videobitratedef)"
         echo ""
         echo "Note : if you specify a video bitrate (with -v option) to this script"
         echo "it won't ask you this question"
         echo "***********************************************************************"
         echo "* 1) Use script default ($videobitratedef)                             *"
         echo "* 2) Enter manually video bitrate now                                 *"
         echo "***********************************************************************"
 
         # It would be nice to extract mencoder suggestion and give it user :-)
 
         echo ""
         echo "Your choice :"
         read TMPVAR
         echo ""
 
         case $TMPVAR in
             1)
                 videobitrate=$videobitratedef
                 echo "continuing with script default"
                 ;;
 
             2)
                 echo "enter video bitrate :"
                 echo ""
                 read BITRATE
                 echo ""
                 videobitrate=$BITRATE
                 echo "continuing with $videobitrate as video bitrate"
                 echo ""
                 ;;
             *)
                 echo "error choose 1 or 2"
                 exit 4
                 #un peu brutal, faudrait laisser une seconde chance
         esac
 fi
 
 # mkfifo teste.wav
 # rm frameno.avi
 # mencoder -audiofile teste.wav -ovc frameno -o frameno.avi -oac mp3lame
 # -lameopts abr:br=128 -aid 128 $1 &
 # mplayer -vo null -ao pcm -aofile teste.wav $1
 # rm teste.wav
 
 
 
 echo ""
 echo "================================================================================"
 echo "+                               DO Video Pass 1                                +"
 echo "================================================================================"
 echo ""
 
 mencoder $ss $endpos -oac copy -o /dev/null -ovc lavc -lavcopts vcodec=mpeg4:vbitrate="$videobitrate":vhq:vpass=1 $scaling  $1
 echo ""
 echo "================================================================================"
 echo "+                               DO Video Pass 2                                +"
 echo "================================================================================"
 echo ""
 
 mencoder $ss $endpos -oac copy -o $2 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate="$videobitrate":vhq:vpass=2 $scaling $1
 

VERSION 0.5 (J-ch)

 # Script pour faire les divx de bonne qualite generalement en 2 CD
 # note: pour le debut et la fin d'encodage , il faut editer le script
 # ce sera corrige dans la prochaine version ;-) J-Ch
 # note : ayant eu des problemes avec les version successives de mplayer
 #        j'ai "arrete" la version a "0.90rc3-2.95.4"
 
 # version 0.5 - J-Ch (dorian at be.linux.org)
 # versions anterieures bulshit ;-)
 
 # Parametre : end position
 # decommenter la 1ere ou la 2eme ligne suivant que l'on veut ou
 # non terminer l'encodage a telle position
 #endpos="-endpos 0:41:20";
 endpos=""
 
 # Parametre : debut position
 # decommenter la 1ere ou la 2eme ligne suivant que l'on veut ou
 # non debuter l'encodage a telle position
 # note importante : ne correspond en rien avec la -endpos .. faut y aller au pif !
 
 #ss="-ss 0:41:20"
 ss=""
 
 # parametre obsolete ..
 crop="";
 #crop="-vop crop=714:428:0:74"
 
 # Parametre : selection audio channel
 AID="129"
 let BITRATE=1350
 if [ -z "$1" ]||[ -z "$2" ]
 then
 echo "usage : mdivx.sh files.vob out.avi (bitrate)"
 else
     if [ "$1" = "$2" ]
     then echo "Same name for source and destination !!!"
          printf "\a" # beep ! ;-)
     exit 1
     fi
 
     if [ -z "$3" ]
     then echo "default bitrate use: $BITRATE"
     else let BITRATE=$3
          echo "Configured bitrate :$BITRATE"
     fi
 
 echo ""
 echo "================================================================================"
 echo "+                                   DO SOUND                                   +"
 echo "================================================================================"
 echo ""
 echo "si la langue n'est pas bonne : -aid 128-160 et -v => donnera la lists language"
 echo "ou -alang fr ????"
 
 if [ -e frameno.avi ]
 then echo "frameno.avi exist ! what to do ?";
      echo "c = Continue without make sound ; d = Delete frameno.avi ; e = exit ";
 
      read TMPVAR
      case $TMPVAR in
         "")
             ;;
         e)
             exit 1
             ;;
         d)
             rm frameno.avi
             mencoder.divx $ss -ovc frameno -aid $AID -oac mp3lame -lameopts abr:br=128 -o frameno.avi $endpos $1
             ;;
         c)
             ;;
         *)
             exit 1
             ;;
      esac
 else
 mencoder.divx $ss -ovc frameno -aid $AID -oac mp3lame -lameopts abr:br=128 -o frameno.avi $endpos $1
 fi
 
 #mkfifo teste.wav
 #rm frameno.avi
 #mencoder -audiofile teste.wav -ovc frameno -o frameno.avi -oac mp3lame -lameopts abr:br=128 -aid 128 $1 &
 #mplayer -vo null -ao pcm -aofile teste.wav $1
 #rm teste.wav
 echo ""
 echo "================================================================================"
 echo "+                               DO Video Pass 1                                +"
 echo "================================================================================"
 echo ""
 
 mencoder.divx $ss -oac copy -o /dev/null -ovc lavc -lavcopts vcodec=mpeg4:vbitrate="$BITRATE":vhq:vpass=1 $crop $endpos $1 echo ""
 echo "================================================================================"
 echo "+                               DO Video Pass 2                                +"
 echo "================================================================================"
 echo ""
 mencoder.divx $ss -oac copy -o $2 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate="$BITRATE":vhq:vpass=2 $crop $endpos $1
 fi

VCD (1 passe)

 #!/bin/bash
 # script pour la creadtion d'u fichier compatible VCD
 
 if [ -z "$1" ]||[ -z "$2" ]
 then echo "usage : mvcd.sh file.vob file.mpg (channel:128-160)"; exit 1
 fi
 
 if [ -e stream.wav ]
 then rm stream.wav; mkfifo stream.wav;
 else  mkfifo stream.wav
 fi
 
 if [ -e stream.yuv ]
 then rm stream.yuv; mkfifo stream.yuv;
 else mkfifo stream.yuv
 fi
 
 # selection audio channel
 let AID="129"
 if [ -z "$3" ]
 then echo ""; echo "using default channel: 129 !";
 else let AID=$3
 fi
 
 echo "=============================================================================================="
 echo "=                                Do audio & vido Files                                       ="
 echo "=============================================================================================="
 
 echo "";echo " Systeme de transformation ? (default 16:9)"
 echo " a - 16:9 | b - 16:9 -> letterbox | c - normal"
 echo " other -> exit "
 read TMPVAR
 case $TMPVAR in
     "")
         WIDE="-M WIDE2STD"
         ;;
     a)
         WIDE="-M WIDE2STD"
         ;;
     b)
         WIDE="-M WIDE2VCD"
         ;;
     c)
         WIDE=""
         ;;
     *)
         exit 1
         ;;
 esac
 cat stream.yuv| yuvscaler $WIDE -M BICUBIC -O VCD |mpeg2enc -f 2 -b 1150 -o vcd.video.mpg &
 cat stream.wav | sox -c 2 -s -r 48000 -w -t raw - -r 44100 -t wav - | toolame -m s -e -b 224 - vcd.audio.mp2 &
 mplayer $1 -vo yuv4mpeg -aid $AID -ao pcm -aofile stream.wav -waveheader
 
 rm stream.yuv
 rm stream.wav
 
 echo "=============================================================================================="
 echo "=                                     DO MIXING                                              ="
 echo "=============================================================================================="
 
 mplex -v 1 -f 1 -o $2 vcd.video.mpg vcd.audio.mp2
 
 exit 0

Pour sauver un flux

mplayer -dumpstream -dumpfile ....vmw mms://...
mencoder mms://... -o ....wmv -oac copy -ovc copy

Pour réencoder le son

Lorsque le son ne fonctionne pas correctement sur le mediaplayer, la plupart du temps il suffit de le réencoder:

mencoder -oac mp3lame -ovc copy -o new.avi old.avi