Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: shell/awk script to get info from vdr files



Nice work !
But why is all this needed ? As far as i can see you use it to determine the 
av-delay and then use mencoder (from mplayer package) to encode to divx with 
the av-delay-value as a correction parameter - right ?

But, mencoder does correct the delay automatically ! And not only at the 
beginning but for the complete file !

I ask because i have a running convert script, which is triggered by the 
ending of vdr's cutting process and automatically calculates bitrates on 
marks.vdr (just like you did) for divx and starts conversion.
The output name is derived from the name of the vdr recording and if 16:9 is 
detected the resulting avi is apropriate scaled ...
This works very fine for me and everything is in sync ! 

If you like i can send you my scripts, although they are far from being 
perfect :-) (some error handling, cleanup and stuff is still missing) - but 
the do their duty (every day with Star Trek Voyager ;-)

Martin

Am Samstag, 16. Februar 2002 02:17 schrieben Sie:
> Hi,
>
> because I want to encode a vdr recording to divx in batch mode (linux
> only), i just wrote a some scripts which gives me some information about
> vdr recordings. The Movie Length will be calculated from info in
> marks.vdr after cutting vdr file.
> It's still not finished, but perhaps usefull for somebody
>
> please report if you have problems.
>
> try vdrinfo.sh -? to get info
>
> software requirements:
> mencoder -> this is part of mplayer, it's needed to determine the first
> Video and Audio PTS. You need to configure mplayer with option
> --enable-debug=1 or higher
> awk         -> i did some functions in awk
>
>
> sample output:
> Values which are not rounded
>
> Frames                          : 180000
> Audio in MB                     : 109
> Total MB                        : 1400
> Video in MB                     : 1291
> Video Bytes/Frame               : 7520
> DivX4 Bitrate                   : 1464
>
> Values which are more exactly
>
> Frames                          : 179328
> Audio in MB                     : 109.453
> Total MB                        : 1400
> Video in MB                     : 1290.55
> Video Bytes/Frame               : 7546.14
> DivX4 Bitrate                   : 1473.86
> DivX4 Bitrate rounded           : 1474
>
> PTS Information
>
> First Video PTS                 : 35093.039
> First Audio PTS                 : 35092.184
> A/V Difference                  : 0.855
> A/V Diff milli seconds          : 855
> A/V Delay in Frames             : 21.375
> A/V Delay in Frames rounded     : 21
> A/V Delay in Frames not-rounded : 21
>
>
> Gerald
>
> ------------ cut (vdrinfo_2.awk) -----------------
> BEGIN   { V_PTS = "V=1]"     # in this line we found a the first Video
> PTS
>         A_PTS = "A=1"        # same for Audio
>         U_PTS = "pts=0.000"  # sometimes the first Audio PTS isnt the
> really first one if so then pts is 0.000
>         V_First = 0          # switch which tell us only fill once
> Output Variable
>         A_First = 0          # switch which tell us only fill once
> Output Variable
>         }
>
>         {
>             split ($0, VDR_INFO) # split mencoder generated line
>             if ( VDR_INFO[11] == V_PTS && V_First != 1 ) {
>                 V_First = 1
>                 Video_PTS = VDR_INFO[7]
>                 First_Video_PTS = substr( Video_PTS, 5 )
>             }
>             if ( VDR_INFO[10] == A_PTS && A_First == 0 && VDR_INFO[7] !=
> U_PTS ) {
>                 A_First = 1
>                 Audio_PTS = VDR_INFO[7]
>                 First_Audio_PTS = substr( Audio_PTS, 5 )
>             }
>         }
>
> END     { print First_Audio_PTS " " First_Video_PTS " " (
> First_Video_PTS - First_Audio_PTS ) " " (( First_Video_PTS -
> First_Audio_PTS ) * 1000 ) " " (( First_Video_PTS - First_Audio_PTS ) /
> 0.040 ) " " int((( First_Video_PTS - First_Audio_PTS ) / 0.040 ) + 0.5 )
> " " int(( First_Video_PTS - First_Audio_PTS ) / 0.040 )
> #         print "First_Audio " First_Audio_PTS  " First_Video "
> First_Video_PTS " Difference " ( First_Video_PTS - First_Audio_PTS ) "
> Delay " (( First_Video_PTS - First_Audio_PTS ) / 0.040 ) " Delay rounded
> " int((( First_Video_PTS - First_Audio_PTS ) / 0.040 ) + 0.5 )
>         }
> ---------------- cut (vdrinfo.awk)
> BEGIN   { # frames_per_second = 25    # for PAL we have 25 Frames per
> second
> #         # frames_per_second = 29    # for NTSC we have 29 Frames per
> second
>           first_time = 0            # program switch
> #         Audio_Bytes = ARGV[1]         # first argument is number of
> bytes in audiopacket
> #         CD_Size = ARGV[2]             # second argument is CD Size in
> MB
> #         CD_Count = ARGV[3]              # third argument is the number
> of CDs you want to burn
>         }
>
>         {
>             split ( $0, VDR_TIME_INFO, ":" )
>             if ( first_time != 0 ) {
>                 VDR_Seconds = (( VDR_TIME_INFO[1] * 60 * 60 ) + (
> VDR_TIME_INFO[2] * 60 ) + VDR_TIME_INFO[3] )
>                 Frame_Count = ( VDR_Seconds * 25 )
>                 Audio_MB = ((( Frame_Count * Audio_Bytes ) / 1024 ) /
> 1024 )
>                 Total_MB = ( CD_Size * CD_Count )
>                 Video_MB = ( Total_MB - Audio_MB )
>                 V_Bytes_p_Frame = ( (Video_MB * 1024 * 1024 ) /
> Frame_Count )
>                 DivX_Bitrate = (((( V_Bytes_p_Frame * Frame_Count ) /
> VDR_Seconds ) / 1024 ) * 8 )
>                 DivX_Bitrate_rounded = int((((( V_Bytes_p_Frame *
> Frame_Count ) / VDR_Seconds ) / 1024 ) * 8 ) + 0.5 )
>             }
>             first_time = 1
>         }
>
> END     { print Frame_Count  " " Audio_MB " " Total_MB " " Video_MB " "
> V_Bytes_p_Frame " " DivX_Bitrate " " DivX_Bitrate_rounded
>           #print "Frame Count " Frame_Count  " Audio in MB " Audio_MB "
> Aval. MB on CD(s) " Total_MB " Video in MB " Video_MB " Video
> Bytes/Frame " V_Bytes_p_Frame " DivX Bitrate " DivX_Bitrate " DivX
> Bitrate rounded " DivX_Bitrate_rounded
>         }
> ------------------ cut (vdrinfo.sh)
> #!/bin/bash
> #
> # How DivX Calculating works, so far i understand all
> #
> # Things you should know
> # movie length in seconds
> # bytes per frame for audio (with 128Kbps you will have 640 bytes per
> frame)
> # number of CDs and there size in MB
> #
> # with these informations we can calculate bitrate with the following
> formula:
> # movie_length_in_seconds * frames_per_second = movie_frame_count
> # ((audio_bytes_per_frame * movie_frame_count) / 1024) / 1024 =
> audio_size_in_mb
> # number_o_fcds * cd_size = total_size_in_mb
> # total_size_in_mb - audio_size_in_mb = total_video_size_in_mb
> # (total_video_size_in_mb * 1024 * 1024) / movie_frame_count =
> video_frame_size_in_byte
> # ((((video_frame_size_in_byte * movie_frame_count) /
> movie_length_in_seconds) / 1024) * 8) = DivX_Bitrate
> # Example Movie with 1 hour and 20 minutes Pal on two 700MB CDs
> # 4800*25=120000
> # ((640*120000)/1024/1024=73
> # 2*700=1400MB
> # 1400-73=1327
> # (1327*1024*1024)/120000=11629
> # ((((11629*120000)/4800)/1024)*8)=2271
>
> # without parameter, we set some defaults
> Num_CDs=2    # default 2
> CD_Size=700  # default 700 MB
> vdr_dir="."  # default .
> TEMP=`getopt -q -o s:d:c: --long cd-size:num-cds:directory  -- "$@"`
> if [ $? != 0 ]; then
>         echo -e "\nUsage :" $0 "parameters or nothing\n\n"
>         echo "  -d DIR,  --directory=DIR  directory where VDR files are
> stored (default = current dir)"
>         echo "  -s SIZE, --cd-size=SIZE   size of a single CD in MB
> (default = 700)"
>         echo "  -c NUM,  --num-cds=NUM    on how many CD's you want to
> burn the movie (default = 2)"
>         echo -e "\n  -?, -h,  --help           shows this information\n"
>
>         exit 1
> fi
> eval set -- "$TEMP"
> while true ; do
>         case "$1" in
>                 -d|--directory) vdr_dir=$2; shift 2;;
>                 -s|--cd-size) CD_Size=$2; shift 2;;
>                 -c|--num-cds) Num_CDs=$2; shift 2;;
>                 --) shift;break;;
>         esac
> done
> vdr_file="$vdr_dir""/001.vdr"     # default $vdr_dir"/001.vdr"
> vdr_marks="$vdr_dir""/marks.vdr"  # default $vdr_dir"/marks.vdr"
> vdr_tmp_file="$vdr_dir""/tmp.vdr" # default $vdr_dir"/tmp.vdr"
> a_b_p_f=640                 # 128 Kb/sec Audio Bitrate -> 640
> bytes/frame
> frames_per_second=25        # Frames per Second
>
> # Read last Line in marks.vdr this contains the Video Length in hh:mm:ss
>
> while read movie_l
> do
>      vH=`echo "$movie_l"|cut -d ":" -f1`
>      vM=`echo "$movie_l"|cut -d ":" -f2`
> #     vS=`echo "$movie_l"|cut -d ":" -f3`
>      movie_length=$[($vH*3600) + ($vM*60) + 60]
> done < "$vdr_marks"
> Total_Seconds=$[$movie_length]
>
> # Calculate overall Framecount out of marks.vdr
> Framecount=$[$movie_length*$frames_per_second]
>
> # Always 128 Kb/sec Audio const. Bitrate -> 640 bytes/frame
>
> Audio_MB=$[(($a_b_p_f*$Framecount)/1024)/1024]
>
> # Calculate Total Size (Audio and Video) and Video
> Total_MB=$[$Num_CDs*$CD_Size]
> Total_MB_Video=$[$Total_MB-$Audio_MB]
>
> # Calc Bytes per Frame for Video
> Video_Frames_Byte=$[($Total_MB_Video*1024*1024)/$Framecount]
>
> # Calc DivX Bitrate
> Bitrate_DivX=$[(((($Video_Frames_Byte*$Framecount)/$Total_Seconds)/1024)*8)
>]
>
> # Calc Delay with mencoder debug version
> pts_info=`mencoder -v -v -frames 1 $vdr_file | awk -f
> /usr/local/bin/vdrinfo_2.awk`
> A_PTS=`echo "$pts_info"|cut -d " " -f1`
> V_PTS=`echo "$pts_info"|cut -d " " -f2`
> AV_Diff=`echo "$pts_info"|cut -d " " -f3`
> AV_Diff_ms=`echo "$pts_info"|cut -d " " -f4`
> AV_Delay=`echo "$pts_info"|cut -d " " -f5`
> AV_Delay_rounded=`echo "$pts_info"|cut -d " " -f6`
> AV_Delay_nrounded=`echo "$pts_info"|cut -d " " -f7`
>
> vdr_info=`cat $vdr_marks | awk -v Audio_Bytes=$a_b_p_f -v
> CD_Size=$CD_Size -v CD_Count=$Num_CDs -v
> frames_per_second=$frames_per_second -f /usr/local/bin/vdrinfo.awk`
> Framecount_awk=`echo "$vdr_info"|cut -d " " -f1`
> Audio_MB_awk=`echo "$vdr_info"|cut -d " " -f2`
> Total_MB_awk=`echo "$vdr_info"|cut -d " " -f3`
> Total_MB_Video_awk=`echo "$vdr_info"|cut -d " " -f4`
> Video_Frames_Byte_awk=`echo "$vdr_info"|cut -d " " -f5`
> Bitrate_DivX_awk=`echo "$vdr_info"|cut -d " " -f6`
> Bitrate_DivX_rounded_awk=`echo "$vdr_info"|cut -d " " -f7`
>
> #
> # You can implement transcoding here
> #
>
> # copy all 0*.vdr to test.vdr
> #echo cat $vdr_dir"/00*.vdr >$vdr_tmp_file"
>
> # transcode VDR File to two pass DivX
> # uncomment the next four lines if you want to encode using transcode
> #transcode -i $vdr_tmp_file -V -J pp=lb -y xvid,null -D
> $AV_Delay_rounded -O -R 1 -w $Bitrate_DivX -o $avi_tmp_file
> #transcode -i $vdr_tmp_file -V -J pp=lb -y xvid -D $AV_Delay_rounded -O
> -R 2 -w $Bitrate_DivX -o $avi_tmp_file
> #Split_Size=$[((($(filesize $avi_tmp_file) / $Num_CDs)/1024)/1024)+3]
> #avisplit -i $avi_tmp_file -o $movie_file -s $Split_Size
>
> echo "Values which are not rounded"
> echo " "
> echo "Frames                          :" $Framecount
> echo "Audio in MB                     :" $Audio_MB
> echo "Total MB                        :" $Total_MB
> echo "Video in MB                     :" $Total_MB_Video
> echo "Video Bytes/Frame               :" $Video_Frames_Byte
> echo "DivX4 Bitrate                   :" $Bitrate_DivX
> echo " "
> echo "Values which are more exactly"
> echo " "
> echo "Frames                          :" $Framecount_awk
> echo "Audio in MB                     :" $Audio_MB_awk
> echo "Total MB                        :" $Total_MB_awk
> echo "Video in MB                     :" $Total_MB_Video_awk
> echo "Video Bytes/Frame               :" $Video_Frames_Byte_awk
> echo "DivX4 Bitrate                   :" $Bitrate_DivX_awk
> echo "DivX4 Bitrate rounded           :" $Bitrate_DivX_rounded_awk
> echo " "
> echo "PTS Information"
> echo " "
> echo "First Video PTS                 :" $V_PTS
> echo "First Audio PTS                 :" $A_PTS
> echo "A/V Difference                  :" $AV_Diff
> echo "A/V Diff milli seconds          :" $AV_Diff_ms
> echo "A/V Delay in Frames             :" $AV_Delay
> echo "A/V Delay in Frames rounded     :" $AV_Delay_rounded
> echo "A/V Delay in Frames not-rounded :" $AV_Delay_nrounded
> #echo "PTS_Info                    :" $pts_info



Home | Main Index | Thread Index