Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 23/12/2011, à 09:56

thurston

mencoder = decalage son

Bonjour,

J'utilise depuis des années mencoder sans souci. la commande suivante me donne une video avec un décalage son qui grandit. En fait j'ai l'impression que la video ne fait pas la bonne taille.
A noter que j'ai un pc qui fonctionne en 11.04 et qui lui encode parfaitement avec la même ligne de commande. Ainsi donc ci joint la ligne de commande utilisée sur les 2 PC avec des résultats différents: (-ofps 25 ou pas, rien n'y change, la video est bien une 25 im/s)

mencoder cobra-1.mpg -o cobra-1.mkv -vf crop=720:576:0:0 -ovc x264 -x264encopts crf=20:preset=fast:threads=0 -ofps 25 -oac copy -nosub

PC 11.04 MEncoder 1.0rc4-4.5.2
très nombreux:

1 duplicate frame(s)! Pos:  87.1s   3632f ( 6%) 13.62fps Trem:  65min 338mb  A-V:-0.084 [1875:191]

Video = durée video correcte + aucun décalage son wink

PC 11.10 MEncoder SVN-r34452-4.6.1
très nombreux:

1 duplicate frame(s)! Pos:  87.1s   3632f ( 6%) 13.62fps Trem:  65min 338mb  A-V:-0.084 [1875:191]

Video = durée video trop longue + gros décalage son sad

Help!! cela fait plusieurs heures que je chercher la solution sur google!!! mais rien d'évident
Je comprends pas pourquoi j'ai tous ces 1 duplicate frame(s)!...le video de base est un DVD rippé.

A noter que cette commande fonctionne sur les 2 pc!!! c'est donc le parametre -oac copy qui pose souci!!!! mais pourquoi?

mencoder cobra-1.mpg -o cobra-1.mkv -vf crop=720:576:0:0 -ovc x264 -x264encopts crf=20:preset=fast:threads=0 -ofps 25 -oac mp3lame -lameopts cbr:br=128 -nosub

et fini avec les:

1 duplicate frame(s)! Pos:  87.1s   3632f ( 6%) 13.62fps Trem:  65min 338mb  A-V:-0.084 [1875:191]

A+
thurston

Dernière modification par thurston (Le 23/12/2011, à 10:08)

Hors ligne

#2 Le 26/12/2011, à 11:05

thurston

Re : mencoder = decalage son

Bon je me réponds. Il semble que l'option -mc 0 "-oac copy -mc 0" soit nécessaire lorsque la video est encodée mais pas l'audio (-oac copy). Il semble que l'aspect variable de l'encodage de la video pose problème si l'on ne réencode pas l'audio.

Hors ligne

#3 Le 27/12/2011, à 11:19

ubuntuforce

Re : mencoder = decalage son

Salut les Linuxiens de mencoder,
Excuser l'intrusion mais:

thurston a écrit :

J'utilise depuis des années mencoder sans souci.

Est ce que tu pourrai si tu le veut bien m'orienter vers de la doc concernant l'encodage de vidéo: les commandes:

$mencoder /home/mon_nom/Bureau/Rave.avi -ovc lavc -oac pcm -o /home/mon_nom/Bureau/Rave.ogc
$mencoder /home/mon_nom/Bureau/Rave.ogv -ovc copy -oac pcm -o /home/mon_nom/Bureau/Rave.avi

Fonctionnent parfaitement.
Et je voudrai savoir si -ovc et -oac suffisent pour convertir sans perte des vidéo et pourrait tu me briefer sur la signification de ces options:

$mencoder -ovc help
MEncoder SVN-r1.0~rc3+svn20090426-4.4.3 (C) 2000-2009 MPlayer Team

Available codecs:
   copy     - frame copy, without re-encoding. Doesn't work with filters.
   frameno  - special audio-only file for 3-pass encoding, see DOCS.
   raw      - uncompressed video. Use fourcc option to set format explicitly.
   nuv      - nuppel video
   lavc     - libavcodec codecs - best quality!
   xvid     - XviD encoding
   x264     - H.264 encoding

et

$ mencoder -oac help
MEncoder SVN-r1.0~rc3+svn20090426-4.4.3 (C) 2000-2009 MPlayer Team

Available codecs:
   copy     - frame copy, without re-encoding (useful for AC3)
   pcm      - uncompressed PCM audio
   mp3lame  - cbr/abr/vbr MP3 using libmp3lame
   lavc     - FFmpeg audio encoder (MP2, AC3, ...)

Merci si vous désirez m'aider un peu et veuillez excuser mon intrusion dans votre post.


Rendez-vous sur mon site présentant mes créations open-source: http://www.open-source-projects.net/
Rendez-vous sur mon site dédier a mes créations d'imagerie 3D: http://www.3dreaming-imaging.net/
Testez pendant une semaine l'éditeur avec terminaux intégrées http://www.open-source-projects.net/it-edit/it-edit Vous l'adopterai sûrement !

Hors ligne

#4 Le 27/12/2011, à 15:06

twocats

Re : mencoder = decalage son

Pour précision :

crop=720:576:0:0

ne sert à rien. En gros tu découpe une image avec une résolution de 720*576 en une image en 720*576. De plus tu as un ratio incorrect une fois convertie : 5/4 alors que ta vidéo est soit en 4/3 soit en 16/9 (Les DVD ont une image anamorphique). Si ton DVD est en NTSC c'est encore plus inutile car tu déforme une image en 720*480 en une image en 720*576 (cf. première remarque).

-ofps 25

ne sert à rien. Si ton DVD est en PAL ton image est déjà en 25 FPS. Si il est en NTSC l'image est de 23.976 FPS (en fait 24000/1001 FPS pour être précis). D'où décalage audio. Pour encoder correctement du NTSC il faut faire :

-vf pp=de/lb,pullup,softskip -ofps 24000/1001

Et comme d'hab. :

man mencoder

La réponse est 42

Hors ligne

#5 Le 16/01/2012, à 23:44

thurston

Re : mencoder = decalage son

Bonjour,

bien sur le crop, c'était un exemple...bon, pour dire, j'ai rencontré un nouveau pb alors que tout semblait résolu.
Les options pour lutter contre la désynchro semblent etre: -noskip, -skiplimit 1, -ofps 25, -mc 0
Voilà, je continue à encoder des dvds ACHETES au fait, mais que je prefere regarder sur mon home cinema !!!, et je poste si nouveau souci.
J'utilise ces 3 scripts, lancé l'un lance l'autre (batch process)
(un script vient de James Dastrup que j'ai customizé pour mes besoins)
donc, en 1er lieu un script de rip personnalisé, puis:mpeg2mp4launcher qui appelle mpeg2mp4
dvdripcli (choisir en général cdrom comme dvd par défaut)

#!/bin/bash
#########################################
# Script de Thurston / Ubuntu
# 
#########################################
# Nautilus script
# 
# Mplayer, zenity
#########################################
# Script Version: 02 (beta)
# Revision date:  2011-12-20
#
# Log
# *********************************************
# 02: Manage A-R-C-C-O-S in 2 possible ways: VLC + mplayer, or VLC + handbrake (to be installed both)
# 01: Better management of different same language tracks, with a 2nd step to choose correct one
# 00: Initial Version

# Variables initialisation
#******************************************************************************************

#help determining cd
#eject /dev/dvd
#sleep 15; eject /dev/cdrom; sleep 3; eject /dev/cdrom1; sleep 3; eject /dev/cdrom2; sleep 3; eject /dev/cdrom3; sleep 3; eject /dev/cdrom4; sleep 3; eject /dev/cdrom5

# ARCCOS protection: ./mplayer dvdnav://15
# Control of argument presence
#******************************************************************************************

# Handle options
#******************************************************************************************
while getopts "h" opt
do
   case $opt in
      h) # Help
         clear
         echo "usage: $0                              => sudo  if shutdown required"
         echo "usage: $0 [-h]                         => help"    
         echo "   *)Using Acidrip"
         echo "     -copy mode for Audio & Video"
         echo "     -Output= .mpg"
         echo "   *)Using DVD::Rip"
         echo "     -DVD Extraction"
         echo "     -Merge operation: cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using Command Line in a terminal"
         echo "     -DVD Info: lsdvd /dev/dvd"
         echo "     -Check correct file number x: mplayer dvd://x"
         echo "     -DVD Rip: mplayer dvd://x -dumpstream -dumpfile DVD.mpg or if n DVD players"
         echo "     -DVD Rip: mplayer dvd://x -dvd-device /dev/cdrom1 -dumpstream -dumpfile DVD.mpg"
         echo "   *)Using vobcopy"
         echo "     -vobcopy -m"
         echo "     -Note that sometimes, playing with -F (Fast) mode can help"
         echo "     -vobcopy -m -F x, with x in range [1..64]"
         echo ""
         echo "Notes:"
         echo "   *)mplayer, mencoder, libdvdcss, zenity proposed for auto-installation"
         echo "   *)a log file is created at the end of process"
         echo "   *)if launched using a ssh connexion:"
         echo "     - use ssh -X name@address, install xauth on remote computer"
         echo "     - use -ssh option when launching this script. It will removes the graphic"
         echo "       which makes the application to be auto-killed when closing ssh + screen"
         exit 1
         ;;
    esac

    # Remove option

    shift $((OPTIND - 1))
    OPTIND=1
done


#******************************************************************************************
# Control of minimum software requirements correctly installed
test -x /usr/bin/mplayer || sudo apt-get install mplayer -y
test -x /usr/bin/zenity || sudo apt-get install zenity -y
test -x /usr/bin/lsdvd || sudo apt-get install lsdvd -y

# Control of additionnal software correctly installed
#******************************************************************************************

if [ `test -x /usr/share/doc/libdvdcss2` ];
then
   echo "Do you want to proceed with libdvdcss2 installation? (y/n)"
   read answer
   if [ $answer = y ];
   then
      echo "##Dépôt Medibuntu" | sudo tee -a /etc/apt/sources.list
      echo "deb [url]http://fr.packages.medibuntu.org[/url]/ hardy free non-free" | sudo tee -a /etc/apt/sources.list
      wget -q [url]http://fr.packages.medibuntu.org/medibuntu-key.gpg[/url]
      sudo apt-key add medibuntu-key.gpg
      sudo apt-get update
      sudo apt-get install libdvdcss2
      sudo rm -rf medibuntu-key.gpg
   fi
fi


#******************************************************************************************
function track_rip()
{
# $1: physical optical disk
media_info=`lsdvd -q /dev/$1 2>/dev/null`
title_dvd=`echo $media_info | awk -F ":" '{print $2}'| awk -F " " '{print $1}'`


#anti_copy_sign=`echo $media_info | grep "Title: 99,"`
#if [ $anti_copy_sign = 0 ];
echo $media_info | grep -q "Title: 99,"
if [ $? = 0 ];
then
   zenity --question --title="INFO" \
                     --text="DVD highly protected (ARCCOS), it seems. VLC + Mplayer (recommended) process. Continue?"
   if [ $? = 0 ];
   then
      vlc /dev/$1
      correct_track=`zenity --entry --title="INPUTS" \
                            --text="VLC played ID track\n" 2>&1`
      mplayer dvdnav://$correct_track -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd.mpg
      audio_track=`zenity --entry --title="INPUTS" \
                            --text="Audio ID?\n" 2>&1`
      mv $title_dvd.mpg $title_dvd-$audio_track.mpg
      exit
   else
      zenity --question --title="INFO" \
                        --text="DVD highly protected (ARCCOS), it seems. VLC + Handbrake (last chance) process . Continue?"
      if [ $? = 0 ];
      then
         vlc /dev/$1
         correct_track=`zenity --entry --title="INPUTS" \
                               --text="VLC played ID track\n" 2>&1`
         ghb /dev/$1
         exit
      fi  
   fi
fi

longest_track=`echo $media_info | grep "Longest track: "| awk -F ": " '{print $NF}'`

dvd_track_length=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1 2>/dev/null | grep "ID_LENGTH=" | awk -F "=" '{print $NF}' | awk -F "." '{print $1}'`
dvd_track_lenght_min=$(( dvd_track_length / 60 ))
dvd_track_audio=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio"`
atrack=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio" | grep "ac3" | awk -F " " '{print $NF}' | awk -F "." '{print $1}'`

atrack_nb=`echo "$atrack" | wc -w`
if [ ! $atrack_nb = 1 ];
then
   atrack0=`echo $atrack` # supress \n for nice zenity look
   zenity --question --title="QUESTION" \
          --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: Determined Next Step\n\nSettings except Audio (next step) correct?\n(If No, help: $0 -h)"
else
   zenity --question --title="QUESTION" \
          --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: $atrack\n($dvd_track_audio)\n\nSettings correct?\n(If No, help: $0 -h)"
fi

if [  $? = 0 ];
then
   if [ ! $atrack_nb = 1 ];
   then
      atrack=`zenity --entry --title="INPUTS" \
                             --text="More than 1 Audio Track found, please select one in this list:\n$dvd_track_audio\n\nSettings correct?\n(If No, help: $0 -h)" --entry-text="$atrack0" 2>&1`
   fi

   if [  $? = 0 ];
   then
      if [ -e $title_dvd-$language_ID.mpg ];
         then
         zenity --question --title="QUESTION" \
                           --text=" Overwrite already existing file? \n"
         if [  $? = 0 ];
         then
            mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
         else
            exit
         fi
      else
         mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
      fi 
   else
      exit
   fi
fi
}

#******************************************************************************************
function drive_selection()
#
{
# Choice Box (between different drives (up to 6)
drive=`zenity  --title="Drive Selection" \
                --text="Choose correct Drive to use" \
                --list \
                --radiolist \
                --height="300" \
                --width="400" \
                --column="Selection" \
                --column="Drive" \
                --column="Description" \
                TRUE "cdrom3" "Left-Top"\
                FALSE "cdrom" "Left-Middle"\
                FALSE "cdrom4" "Left-Bottom"\
                FALSE "cdrom2" "Right-Top"\
                FALSE "cdrom1" "Right-Middle"\
                FALSE "cdrom5" "Right-Bottom"\
                | sed 's/ max//g'`

# case of cancel action
if [ "$drive" = "" ];
then
   exit
fi
}

#******************************************************************************************
function postshutdown()
{
# Shutdown at the end of process Choice Box
end_action=`zenity  --title="End Of Process Action" \
                    --text="Select If PC enter shutdown at the end of encoding" \
                    --list \
                    --radiolist \
                    --height="250" \
                    --width="500" \
                    --column="Selection" \
                    --column="Action" \
                    --column="descriptif" \
                    FALSE "Shutdown" "Shutdown at End Of Encoding Process (sudo only)" \
                    TRUE "No-Shutdown" "PC Stays On at End Of Encoding Process" \
                    | sed 's/ max//g'`

if [ "$end_action" = "Shutdown" ];
then
   zenity --question --title="INFO" \
                     --text="You must be sudo for requesting a end process shutdown"
   if [ $? = 1 ];
   then
      exit
   fi
else
   if [ "$end_action" = "" ];
   then
      exit
   fi

fi    
}

#******************************************************************************************
function duration()
{
# $1= Stop date
# $2= Start date
# $3 = log file
# date +%s gives duration between 1-01-1970 in seconds. Then easy for duration calculation
difference=$(( $1-$2 ))
hour=$(( difference/3600 ))
min=$(( (( difference/60 ))-$(( hour*60 )) ))                     
sec=$(( (( difference ))-$(( hour*3600 + min*60 )) ))          
echo "Process Duration = $hour hour $min minutes $sec seconds" >> "$3"
}

#******************************************************************************************

#******************************************************************************************
#************************* Main Program ***************************************************
#******************************************************************************************

#******************************************************************************************
# 1th step: what to be done end of global processing: shutdown or not
postshutdown

#******************************************************************************************
# 2nd step: collect drive info
drive_selection

#******************************************************************************************
# 3rd step: process
date_in=$(date +%s)
track_rip $drive
date_out=$(date +%s)

#******************************************************************************************
# 4rd step: report
log_encode_file="$title_dvd-$atrack-Rip.log"
echo $(date) > "$log_encode_file"
duration $date_out $date_in $log_encode_file


#******************************************************************************************
# 5th step: set final encoding action
# need to modify /etc/sudoers to get rights to shutdown PC though a script   

if [ "$end_action" = "Shutdown" ];
then
   sudo /sbin/shutdown -h now
fi
exit

mpeg2mp4launcher:

#!/bin/bash
#########################################
# Script de jcvittet & Thurston / Ubuntu
# mpeg2mp4launcher
#########################################
# Nautilus script
# Encodage de mpeg2 en avi (AC3/mp3,xvid)
# Mplayer, mencoder, zenity
#########################################
# Script Version: 01.1
# Revision date:  2011-12-xx
#
# Log
# *********************************************
# 01.1: 1st draft


# Variables initialisation
#******************************************************************************************
mode=standard

# Control of argument presence
#******************************************************************************************
if [ $# -eq 0 ]
then
   echo "Usage: $0 [-f] [-a] <film1.mpg> <film2.mpg>"  
   echo "usage: $0 [-h] => Help Notes"
   exit 1
fi

# Handle options
#******************************************************************************************
while getopts "hfas" opt
do
   case $opt in
      h) # Help
         clear
         echo "usage: $0 <film1.mpg> <film2.mpg>      => sudo  if shutdown required"
         echo "usage: $0 [-h]                         => help"    
         echo "usage: $0 [-f] <film1.mpg> <film2.mpg> => forced mode"
         echo "         referring to Mplayer bug on some video (-ss bug)"
         echo "usage: $0 [-a] <film1.mpg> <film2.mpg> => alternate mode"
         echo "         useful for *.ogg for movie length being extracted in alt. way"
         echo "usage: $s [-a] <film1.mpg> <film2.mpg> => alternate mode"
         echo "         useful for ssh mode, reducing audio check (not possible through ssh)"
         echo ""
         echo "This script prepare batch files encoding using external script mpeg2mp4"
         echo ""
         echo "Sources: any video file, DV, DVD being ripped:"
         echo "   *)Using Acidrip"
         echo "     -copy mode for Audio & Video"
         echo "     -Output= .mpg"
         echo "   *)Using DVD::Rip"
         echo "     -DVD Extraction"
         echo "     -Merge operation: cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using Command Line in a terminal"
         echo "     -DVD Info: lsdvd /dev/dvd"
         echo "     -Check correct file number x: mplayer dvd://x"
         echo "     -DVD Rip: mplayer dvd://x -dumpstream -dumpfile DVD.mpg or if n DVD players"
         echo "     -DVD Rip: mplayer dvd://x -dvd-device /dev/cdrom1 -dumpstream -dumpfile DVD.mpg"
         echo "   *)Using vobcopy"
         echo "     -vobcopy -m"
         echo "     -Note that sometimes, playing with -F (Fast) mode can help"
         echo "     -vobcopy -m -F x, with x in range [1..64]"
         echo "     -Merge operation: cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using OGMRip"
         echo "     -Preferences: Copie DVD + Ne pas supprimer fichiers temporaires"
         echo "     -Merge operation: /tmp/DVD/cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using vlc"
         echo "     -vlc > convertir > choose correct chapter"
         echo "     -create profil: MPEG-PS / Video > MPEG-2 > 8000 kb/s (max) > 25i/s / Audio: keep original"
         echo "     -Choose output file: film.mpg / display output flux and re-choose correct audio track"
         echo "     -Result can be passed through this script with -f option"
         echo "   *)Using Handbrake"
         echo "     -Play 1st with vlc to detect correct chapter to take"
         echo "     -Use mkv ouptut format if AC3 choosen"
         echo ""
         echo "Notes:"
         echo "   *)mplayer, mencoder, libdvdcss, zenity proposed for auto-installation"
         echo "   *)a log file is created at the end of process"
         echo "   *)if launched using a ssh connexion:"
         echo "     - use ssh -X name@address, install xauth on remote computer"
         echo "     - use -ssh option when launching this script. It will removes the graphic"
         echo "       which makes the application to be auto-killed when closing ssh + screen"
         exit 1
         ;;

      f) # Force mode solving problem of mplayer -ss incompatible with some video files
         mode=forced
         ;;

      a) # alternate mode solving problem of mplayer -ss incompatible with some video files
         mode=alternate
         ;;

      s) # alternate mode solving problem of mplayer -ss incompatible with some video files
         executive_mode=silent
         ;;
    esac

    # Remove option

    shift $((OPTIND - 1))
    OPTIND=1
done


#******************************************************************************************
# Control of minimum software requirements correctly installed
test -x /usr/bin/mplayer || sudo apt-get install mplayer -y
test -x /usr/bin/mencoder || sudo apt-get install mencoder -y
test -x /usr/bin/zenity || sudo apt-get install zenity -y

# Control of additionnal software correctly installed
#******************************************************************************************

if [ `test -x /usr/share/doc/libdvdcss2` ];
then
   echo "Do you want to proceed with libdvdcss2 installation? (y/n)"
   read answer
   if [ $answer = y ];
   then
      echo "##Dépôt Medibuntu" | sudo tee -a /etc/apt/sources.list
      echo "deb [url]http://fr.packages.medibuntu.org[/url]/ hardy free non-free" | sudo tee -a /etc/apt/sources.list
      wget -q [url]http://fr.packages.medibuntu.org/medibuntu-key.gpg[/url]
      sudo apt-key add medibuntu-key.gpg
      sudo apt-get update
      sudo apt-get install libdvdcss2
      sudo rm -rf medibuntu-key.gpg
   fi
fi

#******************************************************************************************
cropDetect ()
{
#$1 value of the timeline considered
  echo "Please wait while doing cropdetect..."
  echo "sector of reference=" $2
  sleep 1
  mplayer -vf cropdetect -v -v -v -v -v -nosound -ss $2 -frames 20 "$1" -quiet -vo null | grep 'crop=' > $0.tmp
  exec < $0.tmp
  while read line
   do
    crop=${line#*\-vf\ }
    crop=${crop%\)\.}
   done
  unlink $0.tmp
  echo
  echo "Crop is ${crop/crop=/}" # only the digital value (remove crop=)
  sleep 1
 }

#******************************************************************************************
function encoding_type()
# => $encode
# $1: file to be analysed
# $2: encoding setting file
{
encode="h264 (2p) + ac3"
echo $encode > "$2"
}

#******************************************************************************************
function videoinfo()
# $1: file to be analysed
# $2: encoding setting file
# $3= $encode (xvid-ac3 or xvid-mp3...)
# => $vbitrate
# => $ampli
# => $atrack 
# => $crop
{

video_analyse_sector=320

#bitrate
vbitrate=1500

#ampli
ampli=5

# Audio validation (auto-scan of possible id audio track, with display of initial size
movie_info=`mplayer -vo null -ao null -frames 0 -identify "$1" 2>/dev/null | grep "ID_"`
audio_id=`echo "$movie_info" | grep "ID_AUDIO_ID=" 2>/dev/null |awk -F "=" '{print $NF}' | sort`
audio_id=`echo $audio_id` # supress \n for nice zenity look

atrack=`zenity --entry --title="$1 Audio Selection" \
                       --text="Enter audio track ID (ex: 128): auto-detected => $audio_id "\
                       --entry-text="$audio_id" 2>&1`
if [ $? -eq 1 ];
then
  exit
fi

if [ ! $executive_mode = "silent" ];
then
   mplayer "$1" -ss $video_analyse_sector -aid $atrack
   zenity --question --title="$1 Audio Validation" \
                     --text=" Audio track/language correct ? \n Selected audio id $atrack"
   if [ ! $? = 0 ];
   then
      return
   fi
fi

#crop validation
zenity --question --title="$1 Auto-Crop Process" \
                  --text="Crop: Automatic process ?"
if [ $? = 0 ];
then
   while [ $crop_process -eq 1 ]
   do
      cropDetect "$1" $(( video_analyse_sector + n_crop_ss )); value1=$crop
      if [ "$value1" = "$value2" ]; then
         n_crop_ss=$(( n_crop_ss + 10 ))
         crop=${crop/crop=/}
         echo $crop
         crop_process=0
      else
         n_crop_ss=$(( n_crop_ss + 10 ))
         value2=$value1
   fi
   done

else
   zenity --info --title="$1 Crop Process" \
                 --text=" Next: Crop processing \n Wait and Play up to clear scene... \n ... then Echap"
   crop=`mplayer "$1" -aid $atrack -ss $video_analyse_sector -vf cropdetect | tail -n 4 | head -n 1 | cat | cut -d= -f2 | cut -d")" -f1`
   echo $crop
fi

mplayer "$1" -aid $atrack -ss $video_analyse_sector -vf rectangle=$crop
 
zenity --question --title="$1 Crop Validation" \
                  --text="Crop: $crop seems correct ?"
if [ ! $? = 0 ];
then
   crop_process=1
   return
fi

echo $atrack           >> "$2"
echo $ampli            >> "$2"
echo $vbitrate         >> "$2"
echo $crop             >> "$2"

videoinfo_ok=1
}


#******************************************************************************************
function postshutdown()
{
# Shutdown at the end of process Choice Box
end_action=`zenity  --title="End Of Process Action" \
                    --text="Select If PC enter shutdown at the end of encoding" \
                    --list \
                    --radiolist \
                    --height="250" \
                    --width="500" \
                    --column="Selection" \
                    --column="Action" \
                    --column="descriptif" \
                    FALSE "Shutdown" "Shutdown at End Of Encoding Process (sudo only)" \
                    TRUE "No-Shutdown" "PC Stays On at End Of Encoding Process" \
                    | sed 's/ max//g'`

if [ "$end_action" = "Shutdown" ];
then
   zenity --question --title="INFO" \
                     --text="You must be sudo for requesting a end process shutdown"
   if [ $? = 1 ];
   then
      exit
   fi
else
   if [ "$end_action" = "" ];
   then
      exit
   fi

fi    
}

#******************************************************************************************
function duration()
{
# $1= Stop date
# $2= Start date
# $3 = log file
# date +%s gives duration between 1-01-1970 in seconds. Then easy for duration calculation
difference=$(( $1-$2 ))
hour=$(( difference/3600 ))
min=$(( (( difference/60 ))-$(( hour*60 )) ))                     
sec=$(( (( difference ))-$(( hour*3600 + min*60 )) ))          
echo "Process Duration = $hour hour $min minutes $sec seconds" >> "$3"
}

#******************************************************************************************
function log_info()
# $1= video file log
# Calculate & fill the log file with time needed for encoding
{
log_final="${1/%.*/.log}"

echo -e "Original File Name: `basename "$1"`"                                    >> $log_final
echo -e "Initial Video Size: `du -h "$1" | awk -F " " '{print $1}'` \n"        >> $log_final
echo -e "Encoding Settings
 -encoding type: $encode
 -audio track:   $atrack
 -amplification: $ampli (not used if AC3-type)
 -video Bitrate: $vbitrate
 -crop applied:  $crop
 -script mode:   $mode
 -target size:   $final_movie_size Mo\n"                                      >> $log_final

encoding_start=`sed -n '6p' $log_encode_file`
encoding_stop=`sed -n '7p' $log_encode_file`
duration $encoding_stop $encoding_start "$log_final"

echo -e "\nProcessor type & memory size"                                      >> $log_final
cat /proc/cpuinfo | grep "model name"                                         >> $log_final
cat /proc/meminfo | grep MemTotal                                             >> $log_final
}

#******************************************************************************************

#******************************************************************************************
#************************* Main Program ***************************************************
#******************************************************************************************

#******************************************************************************************
# 0th step: Validity test: name and source available
process_valid="true"

for source in "$@"
do
   if [ ! -e "$source" ];
   then
      zenity --info --title="INFO" \
                    --text=" File "$source" not available"
      process_valid="false"
   fi
done

if [ "$process_valid" = "false" ];
then
      exit
fi


#******************************************************************************************
# 1th step: what to be done end of global processing: shutdown or not
postshutdown

#******************************************************************************************
# 2nd step: collect all info on video to be later encoded
for source in "$@"
do

   # creation of log file
   log_encode_file="${source/%.*/_encode_settings.txt}"
   touch "$log_encode_file"

   # identification of video type
   typevid=`file -bi "$source"`

   # if argument = video/mp2p
   if [ ! `echo $typevid |grep video >> /dev/null` ];
   then
      zenity --question --title="INFO" \
                        --text="Settings Process on - `basename "$source"` -  will start."
      if [ $? -eq 1 ];
      then
         exit
      fi

      encoding_type "$source" "$log_encode_file" # simpl returns type

      crop_process=1
      value2=""
      n_crop_ss=0
      videoinfo_ok=0
      while [ $videoinfo_ok -eq 0 ]
      do
         videoinfo     "$source" "$log_encode_file" $encode
      done
   else
      zenity --info --title="INFO" \
                    --text="Not a valid video file. Consult help $0 -h \n Encoding canceled" && exit  
   fi
done

#******************************************************************************************
# 3rd step: process encoding using individual log file
for source in "$@"
do   
   # point at log file previously created
   log_encode_file="${source/%.*/_encode_settings.txt}" 

   # set initial encoding time
   echo $(date +%s)     >> "$log_encode_file"  #7th line

   encode=`sed -n '1p' "$log_encode_file"`
   atrack=`sed -n '2p' "$log_encode_file"`
   ampli=`sed -n '3p' "$log_encode_file"`
   vbitrate=`sed -n '4p' "$log_encode_file"`
   crop=`sed -n '5p' "$log_encode_file"`
   
   ./mpeg2mp4  -i "$source" -o "${source/%.*/-x264.mp4}" -a $atrack -b $vbitrate -c $crop 

   # set initial encoding time
   echo $(date +%s)     >> "$log_encode_file"   #8th line

   # collect all info in dedicated log file
   log_info "$source"
   
   # clean files
   rm -f "$log_encode_file"
done

#******************************************************************************************
# 4th step: set final encoding action
# need to modify /etc/sudoers to get rights to shutdown PC though a script   

if [ "$end_action" = "Shutdown" ];
then
   sudo /sbin/shutdown -h now
fi
exit

mpeg2mp4

#!/bin/bash
#Author: James Dastrup
#Date: April 17, 2008
#customized: thurston (2011)

# ubuntu
#pass 1: mencoder video.vob -o video.avi -vf pp=ci,crop=720:576:0:0 -ovc x264 -x264encopts bitrate=1500:frameref=8:mixed_refs:bframes=3:b_adapt:b_pyramid=strict:weight_b:partitions=all:8x8dct:me=umh:subq=7:trellis=2:threads=auto:pass=1 -nosound -nosub
#pass 2: mencoder video.vob -o video.avi -vf pp=ci,crop=720:576:0:0 -ovc x264 -x264encopts bitrate=1500:frameref=8:mixed_refs:bframes=3:b_adapt:b_pyramid=strict:weight_b:partitions=all:8x8dct:me=umh:subq=7:trellis=2:threads=auto:pass=2 -nosound -nosub

# -mc 0 -noskip > L'Oeil du mal: out of sync this give trouble on L'oeil du Mal, audio start shifting around 55min
# -mc 0 -noskip > RED: ok

# -mc 0 -ofps 25 > RED : out of sync out of sync solved using -mc 0 -ofps 25, but a lot of 1 duplicate frame in return...
# -mc 0 -ofps 25 > L'Oeil du mal OK

# -noskip and -ofps > cannot be used together (exclusive)

# -noskip -skiplimit 1 > L'Oeil du mal OK
# -noskip -skiplimit 1 > RED out of sync

# best compatible and no audio out of sync seems using -noskip only (no -ofps, no -mc 0, no -skiplimit)

# to be tested (HQ) mencoder filename.mpg -nosound -vf pp=ci -ovc x264 -x264encopts qp=30:trellis=1:nr=500:pass=1:turbo:threads=3:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b -o /dev/null && mencoder filename.mpg -oac copy -vf pp=ci -ovc x264 -x264encopts qp=30:trellis=1:nr=500:pass=2:threads=3:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b -o filename.av


usage ()
 {
  echo "This script encodes a movie with x264."
  echo
  echo "-i [file]      Input file. Required."
  echo "-o [file]      Output file. Optional. If not supplied, a file will"
  echo "                be created in the same location as the original"
  echo "                with an extension of .avi"
  echo "-d             Deinterlace. Optional. Default is auto-detect."
  echo "-c [crop]      Crop. by default. [crop] should use this format:"
  echo "                720:480:0:0 "
  echo "                or use 'nocrop' to not autodetect. "
  echo "                Be careful with auto! Not perfect even if dual check, always verify the results."
  echo "-a [track]     Audio Track. Optional Default is 128."
  echo "-b [bitrate]   Bitrate. Optional. Default is 1500."
  echo "-p [1,2]       Encoding passes. Optional. Default is 2."
  echo "-f [x]         Framerate. Optional. Default is auto-detect, but will"
  echo "                fall back to 25 fps if it is unable to detect."1
  echo "-t [#]         Threads. Optional. Default is auto, which creates"
  echo "                about 1 thread per core. Keep it <= # of cores."
  exit 1
 }

cropDetect ()
 {
#$1 value of the timeline considered
  echo "Please wait while doing cropdetect..."
  sleep 1
  mplayer -vf cropdetect -v -v -v -v -v -nosound -sb $1 -frames 20 $infile -quiet -vo null | grep 'crop=' > $0.tmp
  exec < $0.tmp
  while read line
   do
    cropdo=${line#*\-vf\ }
    cropdo=${cropdo%\)\.}
   done
  unlink $0.tmp
  echo
  echo "Crop is ${cropdo/crop=/}" # only the digital value (remove crop=)
  sleep 1
 }


fpsDetect ()
 {
  movie_info=`mplayer -vo null -ao null -frames 0 -identify "$infile" 2>/dev/null | grep "ID_"`
  framerate=`echo "$movie_info" | grep "ID_VIDEO_FPS=" | awk -F "=" '{print $NF}' | sort -r | awk 'NR==1{print $0}'`
  if [ "$framerate" = 25.000 ]; then
   frame=$framerate
  else
   echo "strange framerate: $framerate, 25.000 being used per default"
   frame=25.000
  fi
 }

while getopts ":i:o:c:a:b:dp:f:t:" Option
 do
  case $Option in
   i ) infile=$OPTARG;;
   o ) outfile=$OPTARG;;
   d ) deint="pp=lb";;
   c ) crop=$OPTARG;;
   a ) audio=$OPTARG;;
   b ) bitrate=$OPTARG;;
   p ) pass=$OPTARG;;
   f ) frame=$OPTARG;;
   t ) threads=$OPTARG;;
   \? ) usage
    exit 1;;
   * ) usage
    exit 1;;
  esac
 done

if [ $# -eq 0 ]; then
 usage
fi

if [ "$infile" = "" ]; then
 usage
fi

if [ "$crop" = "" ]; then
 cropDetect 100000000
 value1=$cropdo
 cropDetect 500000000
 value2=$cropdo
 if [ "$value1" = "$value2" ]; then
    echo "confident in cropdetect value since both detection equal"
 else
   echo "probleme with cropdetect"
   exit
 fi


elif [ "$crop" = "nocrop" ]; then
 crop=""
else
 cropcheck=0
 cropcheck=`expr index "$crop" \:`
 if [ $cropcheck = 0 ]; then
  usage
 else
  cropdo="crop=$crop"
 fi
fi

if [ "$outfile" = "" ]; then
# outfile=${infile/.vob/}.avi
outfile=${infile/%.*/-x264.mp4}
outfile=${outfile//\ /\\\ }
else
 outfile=${outfile//\ /\\\ }
fi

if [ "$audio" = "" ]; then
 audio=128
fi

if [ "$bitrate" = "" ]; then
 bitrate=1500
fi

if [ "$frame" = "" ]; then
 fpsDetect
fi

if [ "$threads" = "" ]; then
 threads="auto"
fi

if [ "$pass" = "1" ]; then
 pass=1
elif [ "$pass" = "2" ]; then
 pass=2
elif [ "$pass" = "" ]; then
 pass=2
else
 usage
fi

doThis="mencoder $infile "
if [ "$crop" != "" ]; then
 doThis="$doThis-vf $cropdo,pullup,softskip"
 if [ $deint ]; then
  doThis="$doThis,$deint"
 fi
else
 if [ $deint ]; then
  doThis="$doThis-vf $deint,pullup,softskip"
 else
  doThis="$doThis-vf pullup,softskip"
 fi
fi

doThis="$doThis -aid $audio -sid 0 -forcedsubsonly -ovc x264 -x264encopts threads=$threads:bframes=3:weight_b"
if [ "$pass" = "2" ]; then
doThis2="$doThis:pass=2:partitions=all:8x8dct:qcomp=0.7:subq=6:b_pyramid=normal:bitrate=${bitrate} -skiplimit 1 -oac copy -passlogfile "${outfile/%.*/.log}" -o $outfile"
doThis="$doThis:pass=1:partitions=none:subq=1:turbo=2:frameref=1:qcomp=0.7:bitrate=${bitrate} -skiplimit 1 -oac copy -passlogfile "${outfile/%.*/.log}" -o /dev/null"
 echo "The following commands will be executed:"
 echo
 echo $doThis
 echo
 echo $doThis2
 echo
 echo
 echo "Press CTRL-C to cancel in the next 3 seconds..."
 echo
 sleep 3
 nice -n 20 $doThis && nice -n 20 $doThis2
else
# doThis="$doThis:partitions=all:8x8dct:subq=6:bitrate=${bitrate} -oac copy -mc 0 -ofps $frame -o $outfile"
doThis="$doThis:partitions=all:8x8dct:subq=6:bitrate=${bitrate} -skiplimit 1 -oac copy -mc 0 -o $outfile"
 echo "The following command will be executed:"
 echo
 echo $doThis
 echo
 echo
 echo "Press CTRL-C to cancel in the next 3 seconds..."
 echo
 sleep 3
 nice -n 20 $doThis
fi

Dernière modification par thurston (Le 22/01/2012, à 20:58)

Hors ligne

#6 Le 21/01/2012, à 11:45

thurston

Re : mencoder = decalage son

Bon alors, les résultats effectués sur 3 DVDs typiques out of sync
L'oeil du mal, Red, et Zombieland.
Le résultat, sachant que j'ai joué sur les 3 options suivantes: -mc 0 -noskip -skiplimit 1 -ofps 25
Le seul soft d'encodage ayant fonctionné sur les 3 rips est celui utilisant uniquement -skiplimit 1
Sinon, souvent 2 ok et le 3ème desync...c'est très bizarre. l'option -mc 0 ne résoud pas à coup sur, ni le -noskip...roule donc avec le -skiplimit 1 jusqu'à nouveau pb...
A+
T

Dernière modification par thurston (Le 22/01/2012, à 20:59)

Hors ligne

#7 Le 18/02/2012, à 15:03

thurston

Re : mencoder = decalage son

Incroyable ca recommence sur nouveaux dvds achetés.
Impossible de synchroniser A et V.
Est ce quelqu'un a un script ou des lignes de commandes qui fonctionnent?
Mon but:
DVD -> mp4 (h264) + AC3, en conservant la synchro.
Merci
A+
T

Hors ligne

#8 Le 05/03/2012, à 22:26

cypherpunk

Re : mencoder = decalage son

Salut

Est ce que tu as essayé d'encoder que l'image (-nosound) - d'extraire le son a part (mplayer "dvd://X" -dvd-device TON_DEVICE -aid 128 -dumpaudio -dumpfile nomdufichier.xx) puis de merger les deux ensemble? (ffmpeg -i videofile.avi -i audiofile.mp3 -vcodec copy -acodec copy fichier_final.avi - ou mkvmerge si tu veux faire un mkv par exemple)?

Ca peut etre la solution.

Hors ligne

#9 Le 12/03/2012, à 14:56

thurston

Re : mencoder = decalage son

Bonjour cypherpunk

Oui je me dis que c'est une solution, mais un peu pénible j'ai l'impression...je me garde ca en dernier recours...
A noter que handbrake fonctionne lui toujours, je serais curieux de connaitre la méthode interne au soft, pour m'en inspirer.
Je testerais à l'occas ta proposition
A+
T

Hors ligne