[FoLUG] DivX2DVD

Masotti Alessandro listaam@gmail.com
Mar 29 Mar 2005 11:14:00 CEST


io uso questi per la conversione e vado benissimo

Enrico Pasini wrote:
> Ciao a tutti.
>  ho appena aquistato un lettore dvd e perciò vorrei convertire i miei 
> filmati divX in dvd (4.7G).
> Ho trovato su internet lo script che allego.
> Il problema è che il file mpgeg che ottengo è ribaltato rispetto 
> all'originale!?!?!
> Qulalcuno che conosce questi strumenti mi sa dire il perché? E cosa devo 
> modificare nello script
> Usa transcode e mplex...
> 
> Grazie
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> FoLUG mailing list
> FoLUG@lists.linux.it
> http://lists.linux.it/listinfo/folug per cancellarsi dalla lista

-------------- parte successiva --------------
#!/bin/bash

# Este script pasa un Divx a CVCD. Para los archivos temporales se
# necesita al menos 4.5 Gigas (mpv y mpa, los .mpg y los .bin)

# This script conversts a Divx file to CVCD. For temp files, it
# needs at least 4.5 Gb free (mpv, mpa, .mpg and .bin files)

# If movie length can't be determined by tcprobe, it will use
# this value (1 hour and 53 minutes). If your file is not an avi
# you can set here its length in seconds to get the CVCD adjusted
# to fit on the CD with maximum bitrate
DEFAULT_MOVIE_SECONDS=6800

# Default is to transcode a file with 16:9 (most divx files)
# If you want to transcode a file in 4:3 (letterboxed), like a
# recording from TV, you need to change this to "-M BICUBIC"
#SCALING="-M BICUBIC"
SCALING="-M WIDE2STD"

# CDSIZE Values. VCDs are write in Mode 2, so the filesizes are the
# the following: 
# 	74 Min/650Mb ---> CDSIZE=735
#	80 Min/700Mb ---> CDSIZE=795
CDSIZE=795

# Quantum is the quality, values are 1-31,
# the nearest to 1, the better
QUANTUM=3
# Audio bitrate for the mp2 stream
AUDIORATE=128

if [ $# -eq 0 ]; then
	echo "Usage:"
	echo "        divx2cvcd <divxfile> [mplayer-params]"
	exit 1
fi

DIR=`pwd`
TEMPFOLDER=/tmp/divx2vcd-$RANDOM
TEMP_TEMPLATE=/tmp/tcmplex-template-$RANDOM
LOG="$DIR/log"
rm $LOG

FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
	FILE="$DIR/$1"
fi

shift 1
MPLAYER_PARAMS=$*

mkdir $TEMPFOLDER
cd $TEMPFOLDER

tcprobe -i "$FILE" > $TEMPFOLDER/info

WIDTH=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
  perl -e ' $line=<STDIN> ; $line =~ /width=(\d+)/  ;  print $1' `
HEIGHT=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
  perl -e ' $line=<STDIN> ; $line =~ /height=(\d+)/  ;  print $1' `
FPS=`grep 'frame rate' $TEMPFOLDER/info | \
  perl -e ' $line=<STDIN> ; $line =~ /frame rate: -f (.+?) \[/  ;  print $1' `
FPS_1=`echo "scale=1 ; $FPS/1"| bc -l`
FRAMES=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
  perl -e ' $line=<STDIN> ; $line =~ /frames=(\d+)/  ;  print $1' `
SEGUNDOS_TOTAL=`echo "scale=0 ; ($FRAMES / $FPS)"| bc -l`
#If couldn't get the length, use the default
[ "$SEGUNDOS_TOTAL" == "" ] && SEGUNDOS_TOTAL=$DEFAULT_MOVIE_SECONDS
HORAS=`echo "scale=0 ; ($SEGUNDOS_TOTAL / 3600)"| bc -l`
MINUTOS=`echo "scale=0 ; (($SEGUNDOS_TOTAL - \
  3600 * $HORAS)/60)"| bc -l`
SEGUNDOS=`echo "scale=0 ; ($SEGUNDOS_TOTAL % 60)"| bc -l`

VIDEO_RATE=`echo "scale=0 ;(($CDSIZE * 1024 - \
  ($AUDIORATE/8*$SEGUNDOS_TOTAL))*8 / $SEGUNDOS_TOTAL)"| bc -l`

MAXRATE=$VIDEO_RATE
[ "$MAXRATE" == "" ] && MAXRATE=1050
[ $MAXRATE -gt 2000 ] && MAXRATE=2000


echo "*************** FILE INFO ***************" >> $LOG
echo "Frame Size: ${WIDTH}x${HEIGHT}  -   FPS: $FPS" >> $LOG
echo "Length: $FRAMES   -  Seconds: $SEGUNDOS_TOTAL" >> $LOG
echo "$HORAS hours, $MINUTOS minutes, $SEGUNDOS seconds" >> $LOG
echo "Recommended averagge video bitrate: $VIDEO_RATE" >> $LOG
echo -e "Using max video bitrate: $MAXRATE \n" >> $LOG

FRAMERATE=""
NORM=""
if [ $FPS_1 == "29.9" -o $FPS_1 == "30" -o  $FPS_1 == "23.9" -o $FPS_1 == "24" ]; then
	WIDTH_OUT=352
	HEIGHT_OUT=240
	NORM="-n n"
	[ $FPS_1 == "29.9" ] && FRAMERATE="-F 4"
	[ $FPS_1 == "30" ] && FRAMERATE="-F 5"
	[ $FPS_1 == "23.9" ] && FRAMERATE="-F 1"
	[ $FPS_1 == "24" ] && FRAMERATE="-F 2"
else
	WIDTH_OUT=352
	HEIGHT_OUT=288
fi



echo "Video Output: ${WIDTH_OUT}x${HEIGHT_OUT}"

# Ahora calculamos los valores pa los bordes.

ANCHO_1_1_OUT=`echo "($HEIGHT_OUT * 4/3)"| bc -l`
ALTO_OUT=`echo "$HEIGHT / ($WIDTH / $ANCHO_1_1_OUT)" | bc -l`
# Redondeamos
ALTO_OUT=`echo "scale=0 ; $ALTO_OUT/1"| bc -l`
# Nos aseguramos de que sea par
ALTO_OUT=`echo "scale=0 ; $ALTO_OUT+$ALTO_OUT%2" | bc -l`

BORDE=`echo "scale=0 ; ($HEIGHT_OUT-$ALTO_OUT)/2"| bc -l`

echo "alto sin bordes: $ALTO_OUT, con borde: $BORDE"

# Borramos Pelicula.mpv y Pelicula.mpa
rm -f Pelicula.mpv Pelicula.mpa 


cd $TEMPFOLDER


mkfifo -m 660 stream.yuv
mkfifo -m 660 audiodump.wav

echo "mplayer -noframedrop -vo yuv4mpeg -ao pcm -waveheader \
    -v -osdlevel 0 $MPLAYER_PARAMS \"$FILE\" &
    " >> $LOG

mplayer -noframedrop -vo yuv4mpeg -ao pcm -waveheader \
    -v -osdlevel 0 $MPLAYER_PARAMS "$FILE" &

echo "(cat stream.yuv | yuvscaler -v 0 $SCALING -O VCD $NORM | \
    mpeg2enc -v 0 -s -f 2 -b $MAXRATE -q $QUANTUM $FRAMERATE $NORM -4 2 -2 1 \
       -o $DIR/Pelicula.mpv) &
       "  >> $LOG

(cat stream.yuv | yuvscaler -v 0 $SCALING -O VCD $NORM | \
    mpeg2enc -v 0 -s -f 2 -b $MAXRATE -q $QUANTUM $FRAMERATE $NORM -4 2 -2 1 \
       -o $DIR/Pelicula.mpv) &

mp2enc -b $AUDIORATE -r 44100 -o $DIR/Pelicula.mpa < audiodump.wav &

wait


RETVAL=$?
if [ $RETVAL -ne 0 ]; then
	echo -e "\n**** ERROR during transcoding. Error value $RETVAL"
	exit 1
fi


rm $TEMPFOLDER/*
rmdir $TEMPFOLDER

cd $DIR


# Si no hay Pelicula.mpv y Pelicula.mpa salir
[ -f Pelicula.mpv -a -f Pelicula.mpa ] || exit 1

rm -f Pelicula*.mpg

#Ahora multiplexamos el mpg
echo "maxFileSize = $CDSIZE" > $TEMP_TEMPLATE
tcmplex -i Pelicula.mpv -p Pelicula.mpa -o Pelicula.mpg \
  -m 1 -F $TEMP_TEMPLATE

rm $TEMP_TEMPLATE


[ -n "`ls Pelicula*mpg 2> /dev/null`" ] || exit 1

# Y creamos las imagenes...
for i in `ls Pelicula*.mpg` ; do
	vcdimager -t vcd2 -c $i.cue -b $i.bin $i
	RETVAL=$?
	if [ $RETVAL -ne 0 ]; then
		echo -e "\n**** ERROR creating VCD images. Error value $RETVAL"
		exit 1
	fi
done

echo -e "\n****** CVCD creation finished successfully"
-------------- parte successiva --------------
#!/bin/bash

# Convert any video/audio stream that mplayer can play
# into VCD, SVCD, or DVD-compatible Mpeg output file.
# Arguments: $1 - format: Video CD, Super Video CD, DVD, or VCD-on-DVD [vcd|svcd|dvd]
#            $2 - aspect: Widescreen or full-frame [wide|full]
#            $3 - name of input file
#            $4 - name of output prefix

USAGE="Usage: tovid [vcd|svcd|dvd|dvd-vcd] [wide|full] <input file> <output prefix>"

if [ $# -ne 4 ]; then
  echo $USAGE
  exit 1
elif [[ $1 == "vcd" || $1 == "dvd-vcd" ]]; then
  TGTWIDTH="352"
  TGTHEIGHT="240"
  PALHEIGHT="288"
  FORMAT="VCD"
  VIDFMT="-f 1"
  # For VCD, use VCD sound profile of mp2enc
  if [[ $1 == "vcd" ]]; then
    SNDOPTS="-V"
  # For VCD-on-DVD, use DVD-format audio
  else
    SNDOPTS="-r 48000 -s"
  fi
  MUXOPTS="-m v"
  SUF="m1v"
elif [[ $1 == "svcd" ]]; then
  TGTWIDTH="480"
  TGTHEIGHT="480"
  PALHEIGHT="576"
  FORMAT="SVCD"
  # -d for dummy SVCD scan offsets
  VIDFMT="-f 4 -d"
  SNDOPTS="-V"
  MUXOPTS="-m s"
  SUF="m2v"
elif [[ $1 == "dvd" ]]; then
  TGTWIDTH="720"
  TGTHEIGHT="480"
  PALHEIGHT="576"
  FORMAT="DVD"
  VIDFMT="-f 8"
  SNDOPTS="-r 48000 -s"
  MUXOPTS="-m d"
  SUF="m2v"
else
  echo $USAGE
  exit 1
fi

if [[ $2 == "wide" ]]; then
  ASPECT="WIDE"
elif [[ $2 == "full" ]]; then
  ASPECT="FULL"
else
  echo "$USAGE"
  exit 1
fi

INFILE=$3
OUTPREFIX=$4

# Probe for width, height, and frame rate
tcprobe -i "$INFILE" > fileinfo
CURWIDTH=`grep 'import frame size' fileinfo | \
  perl -e ' $line=<STDIN> ; $line =~ /import frame size: -g (\d+?)x\d+ /  ;  print $1' `
CURHEIGHT=`grep 'import frame size' fileinfo | \
  perl -e ' $line=<STDIN> ; $line =~ /import frame size: -g \d+?x(\d+) /  ;  print $1' `
CURFPS=`grep 'frame rate' fileinfo | \
  perl -e ' $line=<STDIN> ; $line =~ /frame rate: -f (.+?) \[/  ;  print $1' `

echo "Input file is $CURWIDTH x $CURHEIGHT at $CURFPS fps."

# If FPS is already 29.97 (NTSC) or 23.976 (NTSC film), leave it alone
if [[ $CURFPS == "29.970" ]];
then
  echo "Source is 29.970 fps (NTSC). Encoding as NTSC video."
  ADJUSTFPS=""
  VIDFPS="-F 4"
elif [[ $CURFPS == "23.976" ]];
then
  echo "Source is 23.976 fps (NTSC film). Encoding as NTSC film."
  ADJUSTFPS="yuvfps -s 24000:1001 -r 30000:1001 -v 0 |"
  VIDFPS="-F 4"
else
  echo "Source is not at an NTSC frame rate. Adjusting FPS."
  ADJUSTFPS="yuvfps -r 30000:1001 -v 0 |"
  VIDFPS="-F 4"
fi

# Set appropriate aspect ratio for output format
# Widescreen on DVD should be 16:9
[ $ASPECT == "WIDE" ] && [ $FORMAT == "DVD" ] && ASPECTFMT="-a 3"
# Widescreen on VCD/SVCD needs to be padded out to 4:3
[ $ASPECT == "WIDE" ] && [ $FORMAT != "DVD" ] && ASPECTFMT="-a 2"
# Standard (fullscreen) is always 4:3
[ $ASPECT == "FULL" ] && ASPECTFMT="-a 2"

# Estimate existing aspect ratio (integer math!)
ESTASPECT=$(($CURWIDTH * 100 / $CURHEIGHT))
# Tolerances for wide/full aspect ratio (+/- 10% of target)
if [[ $ASPECT == "WIDE" ]];
then
  MINASPECT=160
  MAXASPECT=195
else
  MINASPECT=120
  MAXASPECT=147
fi

# Determine whether any rescaling needs to be done
# If resolution is already the same as the target, do not rescale.
if [[ $CURWIDTH == $TGTWIDTH && $CURHEIGHT == $TGTHEIGHT ]];
then
  echo "Source is already at target resolution ($TGTWIDTH x $TGTHEIGHT)."
  echo "No rescaling will be applied."
  ADJSIZE=""
# See if source is target resolution in PAL
# If so, just rescale; aspect ratio should be fine
elif [[ $CURWIDTH == $TGTWIDTH && $CURHEIGHT == $PALHEIGHT ]];
then
  echo "Source appears to be PAL of target resolution ($TGTWIDTH x $PALHEIGHT)."
  echo "Assuming correct aspect ratio and rescaling."
  ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
elif [[ $ESTASPECT -ge $MINASPECT && $ESTASPECT -le $MAXASPECT ]];
then
  echo "Source is within 10% of target aspect ratio."
  echo "Assuming correct aspect ratio and rescaling."
  ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
# Otherwise, scale and/or pad with black bars
else
  echo "Scaling and/or padding with letterbox bars"
  # For non-DVD formats, widescreen needs to be padded to make
  # it fullscreen.
  [ $FORMAT != "DVD" ] && [ $ASPECT == "WIDE" ] && \
    ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n -M WIDE2STD |"
  # Non-DVD standard sizes can be scaled directly
  [ $FORMAT != "DVD" ] && [ $ASPECT == "FULL" ] && \
    ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
  # DVD can be scaled directly
  [ $FORMAT == "DVD" ] && \
    ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
fi

echo "Creating and encoding video stream..."
mkfifo stream.yuv
mplayer -nosound -noframedrop -vo yuv4mpeg -vf pp=hb/vb/dr,hqdn3d "$INFILE" &
eval `echo "cat stream.yuv | $ADJUSTFPS $ADJSIZE nice -n 16 mpeg2enc $ASPECTFMT $VIDFMT $VIDFPS -v 0 -n n -H -o $OUTPREFIX.$SUF"`

echo "Creating WAV of audio stream..."
mplayer -vc dummy -vo null -ao pcm -aofile stream.wav "$INFILE"
# echo "Normalizing WAV audio..."
# normalize --amplitude=-14dBFS stream.wav
echo "Encoding WAV..."
cat stream.wav | mp2enc $SNDOPTS -o "$OUTPREFIX.mpa"

echo "Multiplexing audio and video together..."
tcmplex -i "$OUTPREFIX.$SUF" -p "$OUTPREFIX.mpa" -o "$OUTPREFIX.mpg" $MUXOPTS

echo "Cleaning up..."
rm stream.yuv
rm stream.wav
# rm "$OUTPREFIX.$SUF"
# rm "$OUTPREFIX.mpa"
rm fileinfo

echo "Done" 


Maggiori informazioni sulla lista FoLUG