<br><br><div class="gmail_quote">2012/4/3 <span dir="ltr"><<a href="mailto:francesco@bltitalia.com">francesco@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@ffmpeg.org">Libav-user@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>