[XviD-devel] XviD Encoding Steps

reno reballos rreballos at yahoo.com
Thu Apr 3 12:00:09 CEST 2008


Hi Xvid Guys,

i am sorry for the disturbance...
i just wanna ask something worth while, i am developing a system for live video stream compression and i am using the xvid source code libraries to interface with my application. along the way i can see that i have encoded the live video stream successfully somehow because i can play it back using my media player but the main problem is the play back is so fast, my question is there any way to make the play back normal? i think it is somewhere in my encoding parameter values that i have to change by the way my data is 320x240 RGB. here is the program excerpt: (i just predefined the values here for convenience) pleased tell me why i have fast play back.... or should i change the values i assigned..i am just into simple compresison so long it will play back good.. thank in advance... (please see the code)

-------------- xvid global initialization---------------
static int global_initialize()
{
    int retVal_GBL_init = NULL;
  
    xvid_gbl_init_t xvid_gbl_init;
    memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
    xvid_gbl_init.debug = XVID_DEBUG_ERROR;
    xvid_gbl_init.version = XVID_VERSION;
    xvid_gbl_init.cpu_flags = 0;
 
    //initialize xvid core, should be done once per process
    retVal_GBL_init = xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
    if(retVal_GBL_init==-1){
            Msg(TEXT("XVID_GBL_INIT, Xvid General Fault"));
    }
    else if(retVal_GBL_init==-2){
            Msg(TEXT("XVID_GBL_INIT, Memory Allocation Error"));
    }
    else if(retVal_GBL_init==-3){
            Msg(TEXT("XVID_GBL_INIT, File Format Error"));
    }
    else if(retVal_GBL_init==-4){
            Msg(TEXT("XVID_GBL_INIT, structure version not supported"));
    }

    return retVal_GBL_init;
}

--------------- encoder initialization-------------------
static int enc_init()
{
    
    //encoder handle
    int retVal_ENC_create = NULL;

    //global initialization function call
    global_initialize();

    //XviD encoder initialization
    xvid_enc_create_t create;
    memset(&create, 0, sizeof(create));
    create.version = XVID_VERSION;

    //xvid plugins cbr for single pass only (using single pass since using, live streaming encoding)
    xvid_plugin_single_t single;
    memset(&single, 0, sizeof(single));
    single.version = XVID_VERSION;
    xvid_enc_plugin_t plugins[7];

    //init plugins
#define MAX_ZONES 64
    static xvid_enc_zone_t ZONES[MAX_ZONES];
    create.zones = ZONES;
    create.num_zones = 0;
    create.plugins = plugins;
    create.num_plugins = 0;    
    plugins[create.num_plugins].func = xvid_plugin_single;//single-pass rate control 
    plugins[create.num_plugins].param = &single;
    create.num_plugins++;

    //Width and Height of input frames 
    create.width = sgGetDataWidth();  
    create.height = sgGetDataHeight();
    create.profile = XVID_PROFILE_AS_L0;

    //No fancy thread tests 
    create.num_threads = 0;

    //frame rate
    create.fincr = 1 ;
    create.fbase = 30; 

     create.max_key_interval = 30*10;
    
//Bframes settings 
    create.max_bframes = 31;       
    create.bquant_ratio = (float)1.5;  
    create.bquant_offset = 1;    

    //Dropping ratio frame -- we don't need that 
    create.frame_drop_ratio = 0;

    //Global encoder options 
    create.global = 0;//14.

    //if(ARG_CLOSED_GOP)
    create.global = XVID_GLOBAL_CLOSED_GOP;//15.

    single.reaction_delay_factor = 100;//16
    single.averaging_period = 100;
    single.bitrate = 320*240*3;
   
    //quantizers, this is necessary
    create.min_quant[0] = 1;
    create.max_quant[0] = 31;
      
    //xvid encore create operation
    retVal_ENC_create = xvid_encore(NULL, XVID_ENC_CREATE, &create, &single);
    if(retVal_ENC_create==-1){
            Msg(TEXT("XVID_ENC_CREATE, Xvid General Fault"));
    }
    else if(retVal_ENC_create==-2){
            Msg(TEXT("XVID_ENC_CREATE, Memory Allocation Error"));
    }
    else if(retVal_ENC_create==-3){
            Msg(TEXT("XVID_ENC_CREATE, File Format Error"));
    }
    else if(retVal_ENC_create==-4){
            Msg(TEXT("XVID_ENC_CREATE, structure version not supported"));
    }

    //Retrieve the encoder instance from the structure 
    enc_handle = create.handle;

   return retVal_ENC_create;
}

-------- encoding process-------------------
int enc_encode(unsigned char *image, unsigned char *bitstream)
{

   int retVal_ENC_encode=NULL;

    //initialize encoder, note: initializing the encoder initializes also the global initialization
    enc_init();

    //get width and height values 
    int bmpWidth = sgGetDataWidth();                //geting the data width
    int bmpHeight = sgGetDataHeight();              //getting the data height

      //frame struct and stats struct
    xvid_enc_frame_t frame;

    //version for the xvid_enc_frame
    memset(&frame, 0, sizeof(frame));
    frame.version = XVID_VERSION;

       //aspect ratio
    frame.par = XVID_PAR_43_PAL;//4:3 PAL, 12:11, 625-line

    //version for the stats
    xvid_enc_stats_t xvid_enc_stats;
    memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats));
    xvid_enc_stats.version = XVID_VERSION;
   
  
    //initialize input image fields
    frame.input.plane[0] = image; // compression input
    frame.input.csp = XVID_CSP_BGR;
    frame.input.stride[0] = bmpWidth * 3;
       
    //setup core's general features
    frame.vop_flags = vop_presets[6];
    frame.vol_flags = XVID_VOL_MPEGQUANT ;

    //frame type, let xvid core decide for us
    frame.type = XVID_TYPE_AUTO;

    //for the right quantizer --force the right quantizer it is internally managed by RC plugins
    frame.quant = 0;   //cbr mode, automatic rate control

    //setup motion estimation flags
    frame.motion = motion_presets[6];

    //we dont use special matrices, use default
    frame.quant_inter_matrix = 0;
    frame.quant_intra_matrix = 0;

    //bind output buffer
    frame.length = -1;//230400*3;
    frame.bitstream = bitstream;   //, compression output

    //encode the frame
    retVal_ENC_encode = xvid_encore(enc_handle, XVID_ENC_ENCODE, &frame, &xvid_enc_stats);
    if(retVal_ENC_encode==-1){
            Msg(TEXT("XVID_ENC_ENCODE, Xvid General Fault"));
    }
    else if(retVal_ENC_encode==-2){
            Msg(TEXT("XVID_ENC_ENCODE, Memory Allocation Error"));
    }
    else if(retVal_ENC_encode==-3){
            Msg(TEXT("XVID_ENC_ENCODE, File Format Error"));
    }
    else if(retVal_ENC_encode==-4){
        Msg(TEXT("XVID_ENC_ENCODE, structure version not supported"));
    }

    return retVal_ENC_encode;
}

regards,
reno

----- Original Message ----
From: Anand Patel <Anand.Patel at arm.com>
To: xvid-devel at xvid.org
Sent: Wednesday, April 2, 2008 4:49:41 PM
Subject: Re: [XviD-devel] XviD Encoding Steps

Have you looked at the MPEG-4 Part 2 specification? 

This should detail the steps involved. 

-----Original Message-----
From: xvid-devel-bounces at xvid.org [mailto:xvid-devel-bounces at xvid.org]
On Behalf Of Sujit
Sent: 02 April 2008 09:45
To: xvid-devel at xvid.org
Subject: [XviD-devel] XviD Encoding Steps

Hi
Normally for video encoding, the steps followed are:

1) Color Space of original data changed to YUV.
2) Color Space SubSampling.
3) Discrete Cosine Transformation.
4) Quantization.
5) Run Length Encoding.
6) I-frame or P-frame and B-frame encoding.
7) Image division to Macroblock.
8) Motion Prediction and Compensation.
9) Error Prediction.

i want to ask you that, does XviD follow all these steps,or there are
any extra steps which it follow or any steps which it skips.If it
follows the above steps, then where actually in the source code,this DCT
and Quantization takes place.
Also tell me whether  the above steps are sufficient for MPEG-4 ASP
video encoding.If not then tell me what else i have to follow.
_______________________________________________
XviD-devel mailing list
XviD-devel at xvid.org
http://list.xvid.org/mailman/listinfo/xvid-devel

-- 
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.


_______________________________________________
XviD-devel mailing list
XviD-devel at xvid.org
http://list.xvid.org/mailman/listinfo/xvid-devel






      ____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com


More information about the XviD-devel mailing list