[Libav-user] Bit rate not changing

francesco at bltitalia.com francesco at bltitalia.com
Tue Apr 3 10:19:44 CEST 2012


I set the pts and the pkt_pts but nothing changes.  Keep account that I 
have only I-Frames.
best regards

At 09.33 03/04/2012 +0200, you wrote:
>
>How can I set It ?  In the examples included I didn't find this.
>best regards
>
>At 09.09 03/04/2012 +0200, you wrote:
>>2012/4/3 <francesco at bltitalia.com>
>>
>>> Hi to all
>>> I am attempting to transcode compressed SD video in JP2K format to MPEG-2
>>> compressed video at 30, 40 and 50Mbit
>>> using libavcodec only for compressing.  Here is the code:
>>>
>>>  pQTcodec = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); // find the mpeg2
>>> video encoder
>>>  if (!pQTcodec) {str1="Unable to find codec MPEG2";ferr=-1; goto
>>> _CoreMakeMPEG2Video_err;}
>>>
>>>  pQTCodecCtx = avcodec_alloc_context3(pQTcodec);
>>>  if(pQTCodecCtx==NULL) {str1="Unable to alloc codec context";ferr=-2; goto
>>> _CoreMakeMPEG2Video_err;}
>>>  pQTFrame = avcodec_alloc_frame();
>>>  if(pQTFrame==NULL) {str1="Unable to alloc frame";ferr=-3; goto
>>> _CoreMakeMPEG2Video_err;}
>>>
>>>  switch(comp_drate)
>>>  {
>>>  case  0 :cvbr=30000000;  break;   // 30Mbs
>>>  case  1 :cvbr=40000000;  break;   // 40Mbs
>>>  case  2 :cvbr=50000000;  break;   // 50Mbs
>>>  default :cvbr=25000000;  break;   // 25Mbs
>>>  }
>>>
>>>  pQTCodecCtx->bit_rate = cvbr;
>>>
>>>  pQTCodecCtx->rc_max_rate = pQTCodecCtx->rc_min_rate =pQTCodecCtx->bit_rate
>>> = cvbr;
>>>
>>>  pQTCodecCtx->flags =  CODEC_FLAG_INTERLACED_DCT |
>>> CODEC_CAP_AUTO_THREADS;//
>>> | CODEC_FLAG_SVCD_SCAN_OFFSET ;
>>>
>>>  pQTCodecCtx->flags2 =  CODEC_FLAG2_INTRA_VLC |
>>> CODEC_FLAG2_NON_LINEAR_QUANT;
>>>
>>>  pQTCodecCtx->qmin = 1;
>>>  pQTCodecCtx->vbv_delay = 3600;
>>>  pQTCodecCtx->rtp_payload_size = 1;
>>>  pQTCodecCtx->rc_buffer_size = 2000000;
>>>  pQTCodecCtx->rc_initial_buffer_occupancy = 2000000;
>>>
>>>  pQTCodecCtx->lmin = 1*FF_QP2LAMBDA;
>>>  pQTCodecCtx->rc_max_available_vbv_use = 1;
>>>  pQTCodecCtx->rc_min_vbv_overflow_use = 1;
>>>  vform.num = 4;
>>>  vform.den = 3;
>>>  pQTCodecCtx->sample_aspect_ratio = vform;
>>>  pQTCodecCtx->rc_buffer_aggressivity = 0.25F;
>>>  pQTCodecCtx->intra_dc_precision = 2;
>>>  pQTCodecCtx->qmax = 3;
>>>
>>> after this I call a routine that expands original frame (jpeg 2000
>>> compressed) and recompress in MPEG2 format.  To this routine I pass the
>>> pointer to Codec Context (pQTCodecCtx) , the pointer to a frame (pQTFrame)
>>> and the pointer to the codec; that is
>>>
>>>
>>> int Expand_Inter_MPEG2Comp_Image(unsigned char * frame, void *pCodecCtx,
>>> void *pFrame,void *p_codec)
>>> {
>>>  AVFrame         *locpFrame;
>>>  AVCodecContext  *locpCodecCtx;
>>>  AVCodec         *codec;
>>>
>>>  locpCodecCtx = (AVCodecContext*) pCodecCtx;
>>>  locpFrame = (AVFrame*)pFrame;
>>>  codec = (AVCodec*) p_codec;
>>>
>>>  locpCodecCtx->width = Hsize;
>>>  locpCodecCtx->height =  (Vsize<<1) + 32;  // Add 32 blank rows on top for
>>> compatibility
>>>    /* frames per second */
>>>
>>>  locpCodecCtx->time_base.num =  1;
>>>  locpCodecCtx->time_base.den =  25;
>>>  locpCodecCtx->gop_size = 0;     /* emit only intra frame  */
>>>  locpCodecCtx->max_b_frames=0;
>>>  locpCodecCtx->pix_fmt = PIX_FMT_YUV422P;  ///< planar YUV 4:2:2, 16bpp, (1
>>> Cr & Cb sample per 2x1 Y samples)
>>>
>>>  rtv = av_image_alloc(locpFrame->data, locpFrame->linesize,
>>>                   locpCodecCtx->width, locpCodecCtx->height,
>>> locpCodecCtx->pix_fmt, 1);
>>>
>>>
>>> <code for expanding original JP2K frame and setting raw data in
>>> locpFrame->data array>
>>>
>>>  locpFrame->qscale_type = 1;
>>>  locpFrame->top_field_first = 1;
>>>  locpFrame->interlaced_frame = 1;
>>>
>>>  if (avcodec_open2(locpCodecCtx, codec,NULL) < 0) {rtv=-6;str1="on av codec
>>> open";goto __end_rdec;}
>>>
>>>  encBufSize = 0x500000;
>>>  out_size = avcodec_encode_video(locpCodecCtx,
>>> &tempBuffer[kagsz],encBufSize
>>> , locpFrame);
>>>
>>>
>>>  return out_size;
>>> }
>>>
>>> in this case if I set different frame rates, the result is a file of
>>> different size for each frame.
>>> The size is congruent with frame rate, the headers are set accordingly, but
>>> the remainig content is the same! !
>>> As if the only thing is to adjust headers.  The only difference is that
>>> files with highter frame rate are filled with zeroes at the end.
>>> I upload the compressed images of the first frame compressed at 50M and at
>>> 40M. Here you can see that the only diference is the header and the zero
>>> fill at the end in order to obtain the size. The same frame recompressed
>>> with final cut pro gives compressed stream very different.
>>>
>>> _______________________________________________
>>> Libav-user mailing list
>>> Libav-user at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/libav-user
>>>
>>
>>did you set the right PTS Timestamps for the Frames to be encoded?
>>The PTS Timestamps are needed by the Encoder to calculate the right bitrate.
>>
>>
>>-- 
>>*Media Encoding Cluster <http://codergrid.de>, *
>>*the first Open Source Cluster Encoding Solution *
>>*for distributed Media Encoding.*
>>
>>
>>
>>__________ Informazioni da ESET NOD32 Antivirus, versione del database
>delle firme digitali 7014 (20120330) __________
>>
>>Il messaggio è stato controllato da ESET NOD32 Antivirus.
>>
>>www.nod32.it
>>
>><br><br><div class="gmail_quote">2012/4/3  <span dir="ltr"><<a
>href="mailto:francesco at bltitalia.com">francesco at bltitalia.com</a>></span>
><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px
>#ccc solid;padding-left:1ex">
>>Hi to all<br>
>>I am attempting to transcode compressed SD video in JP2K format to MPEG-2<br>
>>compressed video at 30, 40 and 50Mbit<br>
>>using libavcodec only for compressing.  Here is the code:<br>
>><br>
>> pQTcodec = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); // find the mpeg2<br>
>>video encoder<br>
>> if (!pQTcodec) {str1="Unable to find codec MPEG2";ferr=-1; goto<br>
>>_CoreMakeMPEG2Video_err;}<br>
>><br>
>> pQTCodecCtx = avcodec_alloc_context3(pQTcodec);<br>
>> if(pQTCodecCtx==NULL) {str1="Unable to alloc codec
>context";ferr=-2; goto<br>
>>_CoreMakeMPEG2Video_err;}<br>
>> pQTFrame = avcodec_alloc_frame();<br>
>> if(pQTFrame==NULL) {str1="Unable to alloc frame";ferr=-3; goto<br>
>>_CoreMakeMPEG2Video_err;}<br>
>><br>
>> switch(comp_drate)<br>
>> {<br>
>>  case  0 :cvbr=30000000;  break;   // 30Mbs<br>
>>  case  1 :cvbr=40000000;  break;   // 40Mbs<br>
>>  case  2 :cvbr=50000000;  break;   // 50Mbs<br>
>>  default :cvbr=25000000;  break;   // 25Mbs<br>
>> }<br>
>><br>
>> pQTCodecCtx->bit_rate = cvbr;<br>
>><br>
>> pQTCodecCtx->rc_max_rate = pQTCodecCtx->rc_min_rate
>=pQTCodecCtx->bit_rate<br>
>>= cvbr;<br>
>><br>
>> pQTCodecCtx->flags =  CODEC_FLAG_INTERLACED_DCT |
>CODEC_CAP_AUTO_THREADS;//<br>
>>| CODEC_FLAG_SVCD_SCAN_OFFSET ;<br>
>><br>
>> pQTCodecCtx->flags2 =  CODEC_FLAG2_INTRA_VLC |
>CODEC_FLAG2_NON_LINEAR_QUANT;<br>
>><br>
>> pQTCodecCtx->qmin = 1;<br>
>> pQTCodecCtx->vbv_delay = 3600;<br>
>> pQTCodecCtx->rtp_payload_size = 1;<br>
>> pQTCodecCtx->rc_buffer_size = 2000000;<br>
>> pQTCodecCtx->rc_initial_buffer_occupancy = 2000000;<br>
>><br>
>>  pQTCodecCtx->lmin = 1*FF_QP2LAMBDA;<br>
>>  pQTCodecCtx->rc_max_available_vbv_use = 1;<br>
>>  pQTCodecCtx->rc_min_vbv_overflow_use = 1;<br>
>>  vform.num = 4;<br>
>>  vform.den = 3;<br>
>>  pQTCodecCtx->sample_aspect_ratio = vform;<br>
>>  pQTCodecCtx->rc_buffer_aggressivity = 0.25F;<br>
>>  pQTCodecCtx->intra_dc_precision = 2;<br>
>>  pQTCodecCtx->qmax = 3;<br>
>><br>
>>after this I call a routine that expands original frame (jpeg 2000<br>
>>compressed) and recompress in MPEG2 format.  To this routine I pass the<br>
>>pointer to Codec Context (pQTCodecCtx) , the pointer to a frame (pQTFrame)<br>
>>and the pointer to the codec; that is<br>
>><br>
>><br>
>>int Expand_Inter_MPEG2Comp_Image(unsigned char * frame, void *pCodecCtx,<br>
>>void *pFrame,void *p_codec)<br>
>>{<br>
>> AVFrame         *locpFrame;<br>
>> AVCodecContext  *locpCodecCtx;<br>
>> AVCodec         *codec;<br>
>><br>
>> locpCodecCtx = (AVCodecContext*) pCodecCtx;<br>
>> locpFrame = (AVFrame*)pFrame;<br>
>> codec = (AVCodec*) p_codec;<br>
>><br>
>> locpCodecCtx->width = Hsize;<br>
>> locpCodecCtx->height =  (Vsize<<1) + 32;  // Add 32 blank rows on
>top for<br>
>>compatibility<br>
>>    /* frames per second */<br>
>><br>
>> locpCodecCtx->time_base.num =  1;<br>
>> locpCodecCtx->time_base.den =  25;<br>
>> locpCodecCtx->gop_size = 0;     /* emit only intra frame  */<br>
>> locpCodecCtx->max_b_frames=0;<br>
>> locpCodecCtx->pix_fmt = PIX_FMT_YUV422P;  ///< planar YUV 4:2:2,
>16bpp, (1<br>
>>Cr & Cb sample per 2x1 Y samples)<br>
>><br>
>> rtv = av_image_alloc(locpFrame->data, locpFrame->linesize,<br>
>>                   locpCodecCtx->width, locpCodecCtx->height,<br>
>>locpCodecCtx->pix_fmt, 1);<br>
>><br>
>><br>
>><code for expanding original JP2K frame and setting raw data in<br>
>>locpFrame->data array><br>
>><br>
>> locpFrame->qscale_type = 1;<br>
>> locpFrame->top_field_first = 1;<br>
>> locpFrame->interlaced_frame = 1;<br>
>><br>
>> if (avcodec_open2(locpCodecCtx, codec,NULL) < 0) {rtv=-6;str1="on
>av codec<br>
>>open";goto __end_rdec;}<br>
>><br>
>> encBufSize = 0x500000;<br>
>> out_size = avcodec_encode_video(locpCodecCtx,
>&tempBuffer[kagsz],encBufSize<br>
>>, locpFrame);<br>
>><br>
>><br>
>> return out_size;<br>
>>}<br>
>><br>
>>in this case if I set different frame rates, the result is a file of<br>
>>different size for each frame.<br>
>>The size is congruent with frame rate, the headers are set accordingly,
but<br>
>>the remainig content is the same! !<br>
>>As if the only thing is to adjust headers.  The only difference is that<br>
>>files with highter frame rate are filled with zeroes at the end.<br>
>>I upload the compressed images of the first frame compressed at 50M and at<br>
>>40M. Here you can see that the only diference is the header and the zero<br>
>>fill at the end in order to obtain the size. The same frame recompressed<br>
>>with final cut pro gives compressed stream very different.<br>
>><br>
>>_______________________________________________<br>
>>Libav-user mailing list<br>
>><a href="mailto:Libav-user at ffmpeg.org">Libav-user at ffmpeg.org</a><br>
>><a href="http://ffmpeg.org/mailman/listinfo/libav-user"
>target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>></blockquote></div><br>did you set the right PTS Timestamps for the Frames
>to be encoded?<div>The PTS Timestamps are needed by the Encoder to calculate
>the right bitrate.</div><div><br clear="all"><div><br></div>-- <br><span
>style="color:rgb(51,51,51);font-family:'Lucida
>Grande',Helvetica,Verdana,sans-serif;font-size:12px;line-height:20px"><b
>><u><a href="http://codergrid.de" target="_blank">Media Encoding
>Cluster</a></u>, </b></span><div>
>><span style="color:rgb(51,51,51);font-family:'Lucida
>Grande',Helvetica,Verdana,sans-serif;font-size:12px;line-height:20px"><b
>>the first Open Source Cluster Encoding Solution </b></span></div><div><span
>style="color:rgb(51,51,51);font-family:'Lucida
>Grande',Helvetica,Verdana,sans-serif;font-size:12px;line-height:20px"><b
>>for distributed Media Encoding.</b></span></div>
>><br>
>></div>
>>_______________________________________________
>>Libav-user mailing list
>>Libav-user at ffmpeg.org
>>http://ffmpeg.org/mailman/listinfo/libav-user
>>
>>
>>
>>__________ Informazioni da ESET NOD32 Antivirus, versione del database
>delle firme digitali 7014 (20120330) __________
>>
>>Il messaggio è stato controllato da ESET NOD32 Antivirus.
>>
>>www.nod32.it
>>
>>
>
>_______________________________________________
>Libav-user mailing list
>Libav-user at ffmpeg.org
>http://ffmpeg.org/mailman/listinfo/libav-user
>
>__________ Informazioni da ESET NOD32 Antivirus, versione del database
delle firme digitali 7014 (20120330) __________
>
>Il messaggio è stato controllato da ESET NOD32 Antivirus.
>
>www.nod32.it
>
>
>
>



More information about the Libav-user mailing list