Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] Re: script to convert multiple *vdr to cd-sized *avi
-----Original Message-----
[...]
> I use a similar script for converting vdr to divx. I use mencoder (from
> mplayer) instead of pvastrumento and wine. The script watches a directory
> if there are links of vdr directories. If so, the vdr files in these
> directories are transformed into divx. After that the original directory
is
> renamed with a preceeding ! to reflect the conversion and then the link is
> removed.
>
> I use a patched version of the 3-pass enabled mencoder which returns the
> bitrates for different CD sizes after the first pass in a file. So I can
> set the bitrate for the movie to fit on 1, 1/2, 1/3 or 1/4 CD. It is
> guaranteed that a minumum bitrate is used. So movies can be archived in an
> economc way :-).
>
> If somebody is interested, I can post this script and the patch for
> mencoder.
Sounds good, please do so.
-------------------------------------------------------------------
So here is the script. It was my 1st bash script I wrote, so there may be
some parts which could be improved. Suggestions and improvements are very
welcome.
The features are the following:
- converts vdr files in one single divx file without further
user interaction using mencoder from the MPlayer package
- bitrate is calculated, so the divx file fits onto 1 CD,
1/2 CD, 1/3 CD or 1/4 CD. So you can produce CD's without
empty space overhead.
- a minimum bitrate is guaranteed (configurable)
- renames divx files to the name of the vdr film directory
- zip log files for later insection
- moves converted files to a configurable destination directory
- after conversion the original directory is preceeded with
a special character to reflect the converted film in the
vdr recordings menu
- writes a semaphore file in the film directory, so it doesn't
convert a film twice :-)
- runs as separate programm in an endless loop
Prereq:
- a current mencoder version from the MPlayer package which
can use 3 passes for converting in divx
- a patch to mencoder to write bitrate information in a file
after the 1st encoding pass (included below)
I use this script for some month without bigger problems. The vdr version I
use is still 0.96, so it is not tested with the new subdirectory structure
used in newer versions.
For making the links to the working directory of this script I use the
modifications described some days ago (Thread: "Command which transfer the
marked Filename for VDR?"). So I can convert selected films in divx with one
single click from my remote control. Really nice :-)
Now for the code.
1st the script:
--------------------- schnipp ------------------------------------
#!/bin/sh
#
============================================================================
# RJR 2001-08-07 2002-01-14
# --------------------------------------------------------------------------
--
#
# Convert all directories from VDR into DIVX format
#
# 1.00 2001-08-07 initial version
# 1.01 2001-12-30 add renaming of original directory after converting
# 1.02 2002-01-05 add renaming of avi and summary file
# 1.03 2002-01-14 add visual reponse to vdr (via write2vdr)
# 1.04 2002-01-15 add packing of conversion log files (filmname.zip)
# 1.05 2002-01-29 add mplayer switches br, pp
# 1.06 2002-01-31 add mplayer switches -x, -y, 3-pass for
mplayer-2002-01-31
# 1.07 2002-02-05 check output from 1st pass to calculate bitrate
# separate logfile added
# 1.08 2002-02-09 add moving converted files to $(avi_dest_dir)
#
# PREREQ: You need a patched version of mencoder which in the first pass
# gives back bitrate information in a file.
#
#
============================================================================
prg_name=vdr2divx
# where you have to link your film to convert
vdr2divx_working_dir=/usr/tmp/convert/vdr_to_divx
# where the log is written to
vdr2divx_log=/var/log/vdr2divx
# where the converted files are copied to
avi_dest_dir=/dvb/video/video1/avi
# some semaphore files
signal_converting=divx.converting
signal_converted=divx.converted
# the converted directory name is preceeded with this sign to reflect
# the conversion in the vdr recordings menu
directory_marker=!
sleep_seconds=15
# set the maximum CD size - here 80 min CD's
dest_size=700
# set your minimum bitrate
min_bitrate=770
mkdir /tmp/vdr_to_divx 2>/dev/null
mkdir /usr/tmp/convert 2>/dev/null
mkdir $vdr2divx_working_dir 2>/dev/null
while (true) do
(
echo $prg_name: $(date)
cd $vdr2divx_working_dir;
# process all directories in working root (film directories)
if ls * >/dev/null 2>/dev/null;
then for film_dir in *;
do
cd $vdr2divx_working_dir/${film_dir};
# process all subdirectories in film directory (recording
directories)
if ls * >/dev/null 2>/dev/null;
then for recording_dir in *;
do
cd $vdr2divx_working_dir/${film_dir}/${recording_dir};
echo $prg_name: processing ${film_dir}/${recording_dir}
logger -i -t $prg_name processing
${film_dir}/${recording_dir}
echo $(date) $HOSTNAME $prg_name [$$]: processing
${film_dir}/${recording_dir} >> $vdr2divx_log
# process files in directory if not already converted
if !(ls $signal_converted >/dev/null 2>/dev/null);
then
# process files in directory if not actually converting
if !(ls $signal_converting >/dev/null 2>/dev/null);
then
echo $prg_name:' 'converting VDR files into DIVX;
echo $(date) $HOSTNAME $prg_name [$$]: ' 'converting
VDR files into DIVX >> $vdr2divx_log
echo $(date) > $signal_converting
echo $(date) > $signal_converting.pass1
# check if file size > chunk size --- TODO
big_size=0;
if [ $big_size -eq 1 ];
then ls -l
else
echo $prg_name:' 'concatenating vdr files;
echo $(date) $HOSTNAME $prg_name [$$]: '
'concatenating vdr files >> $vdr2divx_log
rm ./frameno.avi 2>/dev/null >/dev/null
rm ./all.vdr 2>/dev/null >/dev/null
rm ./mencoder.bitrate 2>/dev/null >/dev/null
nice --adjustment=18 cat ./0*.vdr >> ./all.vdr
echo $prg_name:' 'converting - pass 1;
echo $(date) $HOSTNAME $prg_name [$$]: '
'converting - pass 1 >> $vdr2divx_log
nice --adjustment=10 mencoder all.vdr -ovc
frameno -o frameno.avi >>mencoder.log 2>>mencoder.log
bitrate=1000
test -e ./mencoder.bitrate && {
read _bitrate700 _bitrate350 _bitrate230
_bitrate175 _bitrate140 _bitrate116 _bitrate800 _bitrate650
<mencoder.bitrate
let bitrate700=_bitrate700
let bitrate350=_bitrate350
let bitrate230=_bitrate230
let bitrate175=_bitrate175
let bitrate140=_bitrate140
let bitrate116=_bitrate116
let bitrate800=_bitrate800
let bitrate650=_bitrate650
echo $prg_name:' 'bitrates: 800/$bitrate800
700/$bitrate700 650/$bitrate650 350/$bitrate350 230/$bitrate230
175/$bitrate175 140/$bitrate140 116/$bitrate116
echo $(date) $HOSTNAME $prg_name [$$]: '
'bitrates: 800/$bitrate800 700/$bitrate700 650/$bitrate650 350/$bitrate350
230/$bitrate230 175/$bitrate175 140/$bitrate140 116/$bitrate116 >>
$vdr2divx_log
bitrate=$bitrate700
if [ $bitrate350 -gt $min_bitrate ]
then bitrate=$bitrate350
fi
if [ $bitrate230 -gt $min_bitrate ]
then bitrate=$bitrate230
fi
if [ $bitrate175 -gt $min_bitrate ]
then bitrate=$bitrate175
fi
if [ $bitrate140 -gt $min_bitrate ]
then bitrate=$bitrate140
fi
if [ $bitrate116 -gt $min_bitrate ]
then bitrate=$bitrate116
fi
let bitrate=$bitrate-20
}
echo $prg_name:' 'using bitrate $bitrate
echo $(date) $HOSTNAME $prg_name [$$]: ' 'using
bitrate $bitrate >> $vdr2divx_log
echo ----------------------------------------------------------------
>>mencoder.log
echo $(date) >> $signal_converting
echo $(date) > $signal_converting.pass2
echo $prg_name:' 'converting - pass 2;
echo $(date) $HOSTNAME $prg_name [$$]: '
'converting - pass 2 >> $vdr2divx_log
nice --adjustment=10 mencoder -oac copy -x 720 -y
576 -sws 2 -pp 0x20000 -divx4opts br=$bitrate -pass 1 -o ${film_dir}.avi
all.vdr >>mencoder.log 2>>mencoder.log
echo ----------------------------------------------------------------
>>mencoder.log
echo $(date) >> $signal_converting
echo $(date) > $signal_converting.pass3
echo $prg_name:' 'converting - pass 3;
echo $(date) $HOSTNAME $prg_name [$$]: '
'converting - pass 3 >> $vdr2divx_log
nice --adjustment=10 mencoder -oac copy -x 720 -y
576 -sws 2 -pp 0x20000 -divx4opts br=$bitrate -pass 2 -o ${film_dir}.avi
all.vdr >>mencoder.log 2>>mencoder.log
rm ./all.vdr
echo $(date) >> $signal_converting
echo $prg_name:' 'cleaning up;
echo $(date) $HOSTNAME $prg_name [$$]: '
'cleaning up >> $vdr2divx_log
# remove temporary files
rm ./$signal_converting.pass1 2>/dev/null >/dev/null
rm ./$signal_converting.pass2 2>/dev/null >/dev/null
rm ./$signal_converting.pass3 2>/dev/null >/dev/null
rm ./frameno.avi 2>/dev/null >/dev/null
rm ./mencoder.bitrate 2>/dev/null >/dev/null
# rename semaphore file to reflect end of conversion
rename ./divx.converting ./divx.converted
./divx.converting
# copy summary file to filmname.Summary
test -e ./summary.vdr && cp ./summary.vdr
${film_dir}.Summary
# zip log files to filmname.zip for later inspection
zip -m ${film_dir} ./*.log 2>/dev/null >/dev/null
# move converted files to target directory
mv ./${film_dir}.* --target-dir=${avi_dest_dir}
fi;
else
echo $prg_name:' 'Files are already in process for
converting in DIVX format;
echo $(date) $HOSTNAME $prg_name [$$]: ' 'Files are
already in process for converting in DIVX format >> $vdr2divx_log
fi;
else
echo $prg_name:' 'Files are already in DIVX format;
echo $(date) $HOSTNAME $prg_name [$$]: ' 'Files are
already in DIVX format >> $vdr2divx_log
fi;
logger -i -t $prg_name processing
${film_dir}/${recording_dir} done
# rename original film directory to reflect conversion in
vdr recordings menu
cd $vdr2divx_working_dir;
cd -P ${film_dir}
cd ..
rename ${film_dir} $directory_marker${film_dir} ${film_dir}
cd $vdr2divx_working_dir;
done;
fi;
# remove directory link from working directory
if [ -L $vdr2divx_working_dir/${film_dir} ];
then
echo $prg_name:' 'removing symbolic directory link;
echo $(date) $HOSTNAME $prg_name [$$]: ' 'removing symbolic
directory link >> $vdr2divx_log
rm $vdr2divx_working_dir/${film_dir};
fi;
echo $prg_name: $(date)
done;
fi;
sleep $sleep_seconds;
)
done;
--------------------- schnapp ------------------------------------
And 2nd the modifications to mencoder.c. In my snapshot the modifications
are aoriund line 1570. This may vary in other cvs snapshots.
--------------- schnapp ---------------------------------------------
printf("\nWriting AVI index...\n");
aviwrite_write_index(muxer,muxer_f);
muxer_f_size=ftell(muxer_f);
printf("Fixup AVI header...\n");
fseek(muxer_f,0,SEEK_SET);
aviwrite_write_header(muxer,muxer_f); // update header
fclose(muxer_f);
if(out_video_codec==VCODEC_FRAMENO && mux_v->timer>100){
// modification start
FILE* bitrate_f=NULL;
printf("Recommended video bitrate for 650MB CD:
%d\n",(int)((650*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 800MB CD:
%d\n",(int)((800*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 1/1 700MB CD:
%d\n",(int)((700*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 1/2 700MB CD:
%d\n",(int)((350*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 1/3 700MB CD:
%d\n",(int)((230*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 1/4 700MB CD:
%d\n",(int)((175*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 1/5 700MB CD:
%d\n",(int)((140*1024*1024-muxer_f_size)/mux_v->timer/125));
printf("Recommended video bitrate for 1/6 700MB CD:
%d\n",(int)((116*1024*1024-muxer_f_size)/mux_v->timer/125));
// write bitrate file
bitrate_f=fopen("mencoder.bitrate","w");
if(bitrate_f) {
fprintf(bitrate_f,
"%d %d %d %d %d %d %d %d\n",
(int)((700*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((350*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((230*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((175*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((140*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((116*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((800*1024*1024-muxer_f_size)/mux_v->timer/125),
(int)((650*1024*1024-muxer_f_size)/mux_v->timer/125));
fclose(bitrate_f);
} else
printf("Cannot open output file 'mencoder.bitrate'\n");
// modification end
}
--------------- schnapp ---------------------------------------------
That's all.
ciao
Richard
Home |
Main Index |
Thread Index