Hi to all I am attempting to encode in MPEG2 XDCAM long gop 50Mbit using libavcodec, but I think that some settings are wrong and I can't setup values correctly. Here is the code that generates first 20 blocks of data in separate files:
/* find the video encoder */ pcodec_xd = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); if (pcodec_xd==NULL) { Memo1->Lines->Add("Unable to find codec "); goto _Encod1Frame_err;} pCodecCtx_xd = avcodec_alloc_context3(pcodec_xd); if(pCodecCtx_xd==NULL) { Memo1->Lines->Add("Unable to alloc codec context");goto _Encod1Frame_err;} pFrame_xd = avcodec_alloc_frame(); if(pFrame_xd==NULL) { Memo1->Lines->Add("Unable to alloc frame");goto _Encod1Frame_err;} vform.num = 16; vform.den = 9; pCodecCtx_xd->sample_aspect_ratio = vform; // Set 16:9 aspect ratio pCodecCtx_xd->rc_max_rate = pCodecCtx_xd->rc_min_rate =pCodecCtx_xd->bit_rate = 50000000; pCodecCtx_xd->flags = CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME ;//| CODEC_FLAG_CLOSED_GOP ; pCodecCtx_xd->qmin = 1; // pCodecCtx_xd->qmax = 3; pCodecCtx_xd->rc_buffer_size = 2000000; pCodecCtx_xd->rc_initial_buffer_occupancy = 2000000; pCodecCtx_xd->time_base.num = 1; pCodecCtx_xd->time_base.den = 25; pCodecCtx_xd->gop_size = 12; pCodecCtx_xd->max_b_frames= 1; pCodecCtx_xd->pix_fmt = PIX_FMT_YUV422P; pCodecCtx_xd->thread_count = Thread_Count; // Thread_Count = Number of available processors /* resolution must be a multiple of two */ pCodecCtx_xd->width = Hsize; // Hsize = 1920 pCodecCtx_xd->height = (Vsize<<1) ; // Vsize = 540 /* the image can be allocated by any means and av_image_alloc() is * just the most convenient way if av_malloc() is to be used */ rtv = av_image_alloc(pFrame_xd->data, pFrame_xd->linesize, pCodecCtx_xd->width, pCodecCtx_xd->height, pCodecCtx_xd->pix_fmt, 1); pFrame_xd->qscale_type = 1; pFrame_xd->top_field_first = 1; pFrame_xd->interlaced_frame = 1; if (avcodec_open2(pCodecCtx_xd, pcodec_xd,NULL) < 0) {rtv = -6; goto _Encod1Frame_err; } for(fldXDCamCnt=0;fldXDCamCnt<nuFlds;fldXDCamCnt+=2) { < Code for read two fields, decompress and interlace them inserting data in pFrame_xd->data[] > out_size = avcodec_encode_video(pCodecCtx_xd, tempBuffer,encBufSize , pFrame_xd); // encBufSize = 0x500000; if(out_size>0) { str1 = ExtractFilePath(Application->ExeName) + "\\RecompDir\\compressed_"; str1.cat_printf("f%d_b%d.m2v",xd_frmNum,blk_cnt); PutBufferIntoFile (str1.c_str(), tempBuffer, frameSz); str1.printf("Saved block %d",blk_cnt); Memo1->Lines->Add(str1); blk_cnt++; if(blk_cnt>20) break; } } Some questions: Data out is analyzed using MPEG2-Video ES utils, and has a sample aspect ratio of 1:2.21 not 16:9. Why ? If I set the CODEC_FLAG_CLOSED_GOP in the pCodecCtx_xd->flags then the avcodec_open2 routine fails (returns -1). Why he fails ? I have a block output for every frame in input. Shouldn't I have a block about every 12 frames ? Did someone have an idea ? _______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user