Log in

View Full Version : OK Ill just go out and ask: auto conv. to Xvid?


niv
18th September 2004, 20:01
I am using iuVCR to capture tv shows from my bt 878/848 card using BTwincap drivers on a 1.8G/512/win2000 machine.
The best I could come up with is grabing 384X288X25(PAL) and 48Khz/16 bit PCM.

1. Is there any way to capture to Mjpeg at full size the right after the show ends have the pc compress it to Xvid using some script? that way I may go under the current 1600K/s and still get good quality.
2. Any audio codecs that take less cpu power then microsofts mp3 and still give quality audio?

Thanks,
Niv

pelle412
18th September 2004, 23:12
I don't know of any publicly available XviD encoding scripts but I can share the script I use, a .BAT file for Windows. It uses avs2avi.


E:\Movie>type encode.bat
@echo off
time /T
\bin\avs2avi Pre.avs huff.avi -c hfyu -p 0 -w
regedit /s defaults.reg
regedit /s pass1.reg
time /T
\bin\avs2avi Post.avs x1.avi -c xvid -p 0 -w
\comptest x1.avi >pass2.reg
regedit /s pass2.reg
\bin\avs2avi Post.avs x2.avi -c xvid -p 0 -w
"C:\Program Files\GordianKnot\BeSweet\BeSweet.exe" -core( -input %1.ac3 -output %1.wav -2ch ) -azid( -c normal -L -3db ) -ota ( -hybridgain )
\lame -v %1.wav %2 %3



I preprocess to huffyuv but that step is absolutely not necessary. It's just that I save some time overall in doing so. You'll also have to setup your XviD encoder settings in the .reg files. The command "comptest" is my own C-program that just takes the first pass XviD file and spits out pass 2 registry settings to compress the second pass with a file size that is 70% of the first pass file (works only if you encode a full first pass and don't discard the file). Kind of like a lazy person's compressibility test. If you are interested I can also post the .reg files.

niv
18th September 2004, 23:26
Please post your REG files.
Can you also share that program you wrote?

Niv

pelle412
19th September 2004, 01:10
To get the defaults.reg just navigate in regedit to HKEY_CURRENT_USER\Software\GNU\XviD and export the whole tree to a file (after loading defaults in encoder settings).

pass1.reg:



Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\GNU\XviD]
"mode"=dword:00000001
"vhq_mode"=dword:00000004
"turbo"=dword:00000001
"max_key_interval"=dword:000000f0
"min_iquant"=dword:00000002
"min_pquant"=dword:00000002
"min_bquant"=dword:00000002
"display_status"=dword:00000000
"zone0_type"=dword:00000001
"zone0_chroma_opt"=dword:00000001
"lum_masking"=dword:00000001
"trellis_quant"=dword:00000001
"discard1pass"=dword:00000000
"full1pass"=dword:00000001
"ar_mode"=dword:00000001
"ar_x"=dword:00000010
"ar_y"=dword:00000009
"num_zones"=dword:00000002
"zone1_type"=dword:00000001
"zone1_chroma_opt"=dword:00000001
"zone1_bvop_threshold"=dword:00000014
"zone1_frame"=dword:0001a8f6
"zone1_greyscale"=dword:00000001
"zone1_mode"=dword:00000001
"zone1_quant"=dword:000001f4
"zone1_weight"=dword:00000064
"packed"=dword:00000000



Note that this makes use of 2 zones, one for the main movie and one for the end credits. If you don't want that just remove those settings, including the "num_zones" one. Also remember that you'll need to tweak these settings for each encode, particularly the ar_x, ar_y, and zone1_frame settings.

Here's the code for the C-program (compile with favorite compiler):



#include <stdio.h>

int main(int argc, char** argv)
{
FILE* fp;
double size;

if (argc != 2)
{
printf("Syntax: comptext xvid1passoutput\n");
return 0;
}

fp = fopen(argv[1], "rb");

if (!fp)
{
printf("Error opening first pass file.\n");
return 0;
}

fseek(fp, 0, SEEK_END);
size = (double)ftell(fp);
fclose(fp);
printf("Windows Registry Editor Version 5.00\n\n");
printf("[HKEY_CURRENT_USER\\Software\\GNU\\XviD]\n");
printf("\"mode\"=dword:00000002\n");
printf("\"desired_size\"=dword:%08lx\n", (unsigned long)(((size * 7 / 10) / 1024) + 1));
return 0;



Have fun with your encodes. You could probably write a script to automatically mux audio and video using VirtualDubMod command line but I haven't gotten to it yet.

niv
29th December 2004, 16:55
I did what you suggested. works well.
some questions remain:

I. "I preprocess to huffyuv but that step is absolutely not necessary. It's just that I save some time overall in doing so. " does it matter if I capture to MJPEG in time saving?

II. What does Pre.avs and Post.avs include?
I now use a simple DirectShow("file.avi"). I hope to add some filters in the pre-processing to de-interlace, levels , 2-d smoth and 3d clean. any suggestion?

III. I am not familier with Besweet :-(
what does this do?
"
"C:\Program Files\GordianKnot\BeSweet\BeSweet.exe" -core( -input %1.ac3 -output %1.wav -2ch ) -azid( -c normal -L -3db ) -ota ( -hybridgain )
\lame -v %1.wav %2 %3
"
don't you combine it back to your avi file?

NIv

pelle412
30th December 2004, 06:10
does it matter if I capture to MJPEG in time saving?
What I meant by time savings was that since I use some really slow AviSynth filters I don't want to use them more than once. By doing a single pass with the slow (but wonderfully great) filters I can avoid having them run in every encode pass.

II. What does Pre.avs and Post.avs include?
I now use a simple DirectShow("file.avi"). I hope to add some filters in the pre-processing to de-interlace, levels , 2-d smoth and 3d clean. any suggestion?

In Pre.avs I use whatever IVTC, deinterlacing, and noise filtering that I want. In Post.avs I do cropping and resizing, followed by some light noise filtering (e.g. Undot()).

I am not familier with Besweet :-(
what does this do?


It takes an AC3 input file and decompresses it to a 2 channel PCM WAV file, then the lame encoder compresses it into VBR MP3.

don't you combine it back to your avi file?
Yes but I use VirtualDubMod to do that.

niv
25th January 2005, 18:02
Hay all,
The chor in hand is to take a tv show that is captured weekly at Mjpeg/MP3. clean it and 2 pass it to xvid. I am doing it because I later send it via a 128Kbit. so the file can't be to big.

I came up with this batch file:

Any thoughts of how to make things better?

~~~~~~~~~~~~~~~~~~~ e6.bat ~~~~~~~~~~~~~~~~~~~~
rem ******************************************************************
rem * This script will encode a mjpeg avi show recorded from the tv *
rem * it recevies %1 as the file name. so the syntax is e6 <file> *
rem * if %2 is 3 it will preforme a vhs bad quality filtering *
rem ******************************************************************
rem * This script needs these files in the same directory it is running from
rem * - avi2avs (program)
rem * - defaults.reg (default xvid settings)
rem * - comptest (a program to compute the required bit rate for encodin)
rem * these files are created during the run:
rem * - mux_snd_out.syl (Virtualdub script to mux out the audio)
rem * - pass1.reg (1st pass xvid settings)
rem * - mux_snd_in.syl (script to mux out the audio)
rem *
rem * took 3:48 hours to proccess a 35 min show on the 200v/1.8Ghz
rem ******************************************************************

if %1=="" goto error
if not exist %1 goto error

rem -- here I need to check if the encode finished correctly when
rem it was last run.
rem The check shuold be if the output final file (%1.2.avi) is from
rem the same date as the original (%1.avi) or a day older AND it is
rem larger then 500Mb

rem ***********************************************************************
echo muxing original audio out
rem ***********************************************************************

move "%~1" f:\film.avi

rem ~~~ generate mux_snd_out.syl
echo VirtualDub.Open("F:\\film.avi","",0); >mux_snd_out.syl
echo VirtualDub.RemoveInputStreams(); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetSource(0x73647561,0,0); >>mux_snd_out.syl
echo VirtualDub.stream[0].DeleteComments(1); >>mux_snd_out.syl
echo VirtualDub.stream[0].AdjustChapters(1); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetMode(0); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetInterleave(1,500,1,0,0); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetClipMode(1,1); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetConversion(0,0,0,0,0); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetVolume(); >>mux_snd_out.syl
echo VirtualDub.stream[0].SetCompression(); >>mux_snd_out.syl
echo VirtualDub.stream[0].EnableFilterGraph(0); >>mux_snd_out.syl
echo VirtualDub.stream[0].filters.Clear(); >>mux_snd_out.syl
echo VirtualDub.video.AdjustChapters(1); >>mux_snd_out.syl
echo VirtualDub.video.SetDepth(24,24); >>mux_snd_out.syl
echo VirtualDub.video.SetMode(0); >>mux_snd_out.syl
echo VirtualDub.video.SetFrameRate(0,1); >>mux_snd_out.syl
echo VirtualDub.video.SetRange(0,0); >>mux_snd_out.syl
echo VirtualDub.video.filters.Clear(); >>mux_snd_out.syl
echo VirtualDub.stream[0].SaveWAV("F:\\audio.mp3"); >>mux_snd_out.syl
echo VirtualDub.Close(); >>mux_snd_out.syl

"E:\Program Files\VirtualDubMod\VirtualDubMod.exe" /s"mux_snd_out.syl" /x
move f:\film.avi "%~1"
move f:\audio.mp3 "%~1.mp3"
if not exist "%~1.mp3" goto mux_out_err
if not exist "%~1" goto mux_out_err
del mux_snd_out.syl

rem ******************************************************************
echo pre-prosesing
rem * Now to generate an avs file which: *
rem * 1. open file *
rem * 2. 2-D clean *
rem * 3. deinterlace - Telecide() *
rem * 4. fix levels - add 20% gamma *
rem * 5. 3-D Clean *
rem ******************************************************************

date /T
time /T

rem chk to see that a previos run was not interupted after this stage
if exist "%~1.MJPG.avi" goto 1st_pass

rem chk that there is enogh free space on target drive
echo SetMemoryMax(40) > "%~1.pre.avs"
echo AVISource("%~1") >> "%~1.pre.avs"

rem use this if previos line fails
rem echo DirectShowSource("%~1") > "%~1.pre.avs"
rem %~1 removes the doble quote from %1

echo GuavaComb("PAL") >> "%~1.pre.avs"
echo PeachSmoother() >> "%~1.pre.avs"
echo Telecide(order=1,guide=2,post=2,vthresh=25) >> "%~1.pre.avs"
echo Levels(0,1.15,255,0,255) >> "%~1.pre.avs"

echo Convolution3D(preset = "movieLQ") >> "%~1.pre.avs"
rem e.l.s.e echo Convolution3D(0, 32, 128, 16, 64, 10, 0) >> "%~1.pre.avs"

avs2avi "%~1.pre.avs" "%~1.MJPG.avi" -c MJPG -p 0 -w
rem get audio out of "%~1"
rem if "%~1.MJPG.avi" is as big as %1 -> delete %1

if not exist "%~1.MJPG.avi" goto pre-err
del "%~1"
del "%~1.pre.avs"

:1st_pass
rem ******************************************************************
echo starting first encode
rem ******************************************************************

if exist "%~1.1.avi" goto 2nd_pass

rem chk to see the file is big enotgh lots of tilda z where removed
rem if "%1.MJPG.avi" <= %1 * 0.9 goto pre-err
rem set %size%=(%1*9/10)
rem set %mjpg%=(%1.MJPG.avi)
rem if %size% <= %mjpg go2 pre-err


date /T
time /T

echo SetMemoryMax(40) > "%~1.post.avs"
echo AVISource("%1.MJPG.avi") >> "%~1.post.avs"
rem echo DirectShowSource("%1.MJPG.avi") >> "%~1.post.avs"

rem ~~~ generete pass1.reg
echo Windows Registry Editor Version 5.00 >pass1.reg
echo [HKEY_CURRENT_USER\Software\GNU\XviD] >>pass1.reg
echo "Supported_4CC"=dword:00000007 >>pass1.reg
echo "Videoinfo_Compat"=dword:00000000 >>pass1.reg
echo "mode"=dword:00000001 >>pass1.reg
echo "bitrate"=dword:0000051d >>pass1.reg
echo "desired_size"=dword:00146334 >>pass1.reg
echo "use_2pass_bitrate"=dword:00000001 >>pass1.reg
echo "desired_quant"=dword:00000190 >>pass1.reg
echo "quant_type"=dword:00000000 >>pass1.reg
echo "lum_masking"=dword:00000001 >>pass1.reg
echo "interlacing"=dword:00000000 >>pass1.reg
echo "qpel"=dword:00000001 >>pass1.reg
echo "gmc"=dword:00000000 >>pass1.reg
echo "reduced_resolution"=dword:00000000 >>pass1.reg
echo "use_bvop"=dword:00000001 >>pass1.reg
echo "max_bframes"=dword:00000002 >>pass1.reg
echo "bquant_ratio"=dword:00000096 >>pass1.reg
echo "bquant_offset"=dword:000000c8 >>pass1.reg
echo "packed"=dword:00000000 >>pass1.reg
echo "closed_gov"=dword:00000001 >>pass1.reg
echo "ar_mode"=dword:00000000 >>pass1.reg
echo "aspect_ratio"=dword:00000001 >>pass1.reg
echo "par_x"=dword:00000001 >>pass1.reg
echo "par_y"=dword:00000001 >>pass1.reg
echo "ar_x"=dword:00000010 >>pass1.reg
echo "ar_y"=dword:00000009 >>pass1.reg
echo "num_zones"=dword:00000001 >>pass1.reg
echo "rc_reaction_delay_factor"=dword:00000010 >>pass1.reg
echo "rc_averaging_period"=dword:00000064 >>pass1.reg
echo "rc_buffer"=dword:00000064 >>pass1.reg
echo "discard1pass"=dword:00000000 >>pass1.reg
echo "full1pass"=dword:00000001 >>pass1.reg
echo "keyframe_boost"=dword:0000000a >>pass1.reg
echo "kfreduction"=dword:00000014 >>pass1.reg
echo "kfthreshold"=dword:00000001 >>pass1.reg
echo "curve_compression_high"=dword:00000000 >>pass1.reg
echo "curve_compression_low"=dword:00000000 >>pass1.reg
echo "overflow_control_strength"=dword:00000005 >>pass1.reg
echo "twopass_max_overflow_improvement"=dword:00000005 >>pass1.reg
echo "twopass_max_overflow_degradation"=dword:00000005 >>pass1.reg
echo "container_type"=dword:00000001 >>pass1.reg
echo "target_size"=dword:000a2800 >>pass1.reg
echo "subtitle_size"=dword:00000000 >>pass1.reg
echo "hours"=dword:00000001 >>pass1.reg
echo "minutes"=dword:0000001e >>pass1.reg
echo "seconds"=dword:00000000 >>pass1.reg
echo "fps"=dword:00000002 >>pass1.reg
echo "audio_mode"=dword:00000000 >>pass1.reg
echo "audio_type"=dword:00000000 >>pass1.reg
echo "audio_rate"=dword:00000080 >>pass1.reg
echo "audio_size"=dword:00000000 >>pass1.reg
echo "motion_search"=dword:00000005 >>pass1.reg
echo "vhq_mode"=dword:00000004 >>pass1.reg
echo "chromame"=dword:00000001 >>pass1.reg
echo "cartoon_mode"=dword:00000000 >>pass1.reg
echo "turbo"=dword:00000001 >>pass1.reg
echo "max_key_interval"=dword:000000fa >>pass1.reg
echo "frame_drop_ratio"=dword:00000000 >>pass1.reg
echo "min_iquant"=dword:00000002 >>pass1.reg
echo "max_iquant"=dword:0000001f >>pass1.reg
echo "min_pquant"=dword:00000002 >>pass1.reg
echo "max_pquant"=dword:0000001f >>pass1.reg
echo "min_bquant"=dword:00000002 >>pass1.reg
echo "max_bquant"=dword:0000001f >>pass1.reg
echo "trellis_quant"=dword:00000001 >>pass1.reg
echo "fourcc_used"=dword:00000000 >>pass1.reg
echo "debug"=dword:00000000 >>pass1.reg
echo "vop_debug"=dword:00000000 >>pass1.reg
echo "display_status"=dword:00000000 >>pass1.reg
echo "Deblock_Y"=dword:00000000 >>pass1.reg
echo "Deblock_UV"=dword:00000000 >>pass1.reg
echo "Dering"=dword:00000000 >>pass1.reg
echo "FilmEffect"=dword:00000000 >>pass1.reg
echo "profile"="AS @ L5" >>pass1.reg
echo "stats"="\\video.pass" >>pass1.reg
echo "qmatrix_intra"=hex:08,11,12,13,15,17,19,1b,11,12,13,15,17,19,1b,1c,14,15,16,\ >>pass1.reg
echo 17,18,1a,1c,1e,15,16,17,18,1a,1c,1e,20,16,17,18,1a,1c,1e,20,23,17,18,1a,1c,\ >>pass1.reg
echo 1e,20,23,26,19,1a,1c,1e,20,23,26,29,1b,1c,1e,20,23,26,29,2d >>pass1.reg
echo "qmatrix_inter"=hex:10,11,12,13,14,15,16,17,11,12,13,14,15,16,17,18,12,13,14,\ >>pass1.reg
echo 15,16,17,18,19,13,14,15,16,17,18,1a,1b,14,15,16,17,19,1a,1b,1c,15,16,17,18,\ >>pass1.reg
echo 1a,1b,1c,1e,16,17,18,1a,1b,1c,1e,1f,17,18,19,1b,1c,1e,1f,21 >>pass1.reg

regedit /s defaults.reg
regedit /s pass1.reg

avs2avi "%~1.post.avs" "%~1.1.avi" -c xvid -p 0 -w

if not exist "%~1.1.avi" goto first_err

:2nd_pass
rem ******************************************************************
echo second encode at
rem ******************************************************************

date /T
time /T

rem could use this for better quality comptest "%~1.1.avi" >"%~1.pass2.reg"
rem ~~~ generete pass2.reg
echo Windows Registry Editor Version 5.00 >"%~1.pass2.reg"
echo [HKEY_CURRENT_USER\Software\GNU\XviD] >>"%~1.pass2.reg"
echo "mode"=dword:00000002 >>"%~1.pass2.reg"
echo "bitrate"=dword:0000051d >>"%~1.pass2.reg"

if not exist "%~1.pass2.reg" goto first_err
del "%~1.1.avi"
regedit /s "%~1.pass2.reg"
avs2avi "%~1.post.avs" "%~1.2.avi" -c xvid -p 0 -w

rem -- If the file was encoded - delete the original
rem -- to know this check the date of the %1.2.avi file and that it is
rem .. above 600 Mb

if not exist "%~1.2.avi" goto second_err
del "%~1.post.avs"
del "%1.MJPG.avi"
rem del \video.pass

rem ***********************************************************************
echo muxing audio back in
rem ***********************************************************************

move "%~1.2.avi" f:\film_wo_snd.avi
move "%~1.mp3" f:\audio.mp3

echo VirtualDub.Open("F:\\film_wo_snd.avi","",0); >mux_snd_in.syl
echo VirtualDub.RemoveInputStreams(); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetSource("F:\\audio.mp3",0x00000202,0); >>mux_snd_in.syl
echo VirtualDub.stream[0].DeleteComments(1); >>mux_snd_in.syl
echo VirtualDub.stream[0].AdjustChapters(1); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetMode(0); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetInterleave(1,500,1,0,0); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetClipMode(1,1); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetConversion(0,0,0,0,0); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetVolume(); >>mux_snd_in.syl
echo VirtualDub.stream[0].SetCompression(); >>mux_snd_in.syl
echo VirtualDub.stream[0].EnableFilterGraph(0); >>mux_snd_in.syl
echo VirtualDub.stream[0].filters.Clear(); >>mux_snd_in.syl
echo VirtualDub.video.DeleteComments(1); >>mux_snd_in.syl
echo VirtualDub.video.AdjustChapters(1); >>mux_snd_in.syl
echo VirtualDub.video.SetDepth(24,24); >>mux_snd_in.syl
echo VirtualDub.video.SetMode(0); >>mux_snd_in.syl
echo VirtualDub.video.SetFrameRate(0,1); >>mux_snd_in.syl
echo VirtualDub.video.SetIVTC(0,0,-1,0); >>mux_snd_in.syl
echo VirtualDub.video.SetRange(0,0); >>mux_snd_in.syl
echo VirtualDub.video.filters.Clear(); >>mux_snd_in.syl
echo VirtualDub.SaveAVI("F:\\fin.film.avi"); >>mux_snd_in.syl
echo VirtualDub.Close(); >>mux_snd_in.syl

rem usually I capture with audio at mp3 "E:\Program Files\lame\lame.exe" -b 96 --priority 0 -h -m m f:\audio.wav audio.mp3
"E:\Program Files\VirtualDubMod\VirtualDubMod.exe" /s"mux_snd_in.syl" /x

move f:\fin.film.avi "%~1.fin.avi"

if not exist "%~1.fin.avi" goto mux_in_err
del f:\film_wo_snd.avi
del f:\audio.mp3
del mux_snd_in.syl
goto end

:error
echo You need to enter the file name after this program
goto end

:mux_out_err
echo mux out error
goto end

:pre-err
echo error preprocessing
goto end

:first_err
error in 1st pass
goto end

:second_err
echo error in 2nd pass
goto end

:mux_in_err
echo mux in error

:end
regedit /s defaults.reg
echo All done :-)
date /T
time /T

~~~~~~~~~~~~~ end of e6.bat ~~~~~~~~~~~~~~~~~~