Resize is independent of bit-rate please set your bit-rate to a smaller value when you use 320x240
On Wed, Apr 14, 2010 at 5:24 AM, German Vallejos C. <[email protected]> wrote: > Hello, i resize mpeg4 files to 640x480 and 320x240 with this code, but > the size (Kb) of this files is the same (both files has a length 60 > seconds). what is wrong in this code.? > thanks > > CResize::CResize( enum PixelFormat format_src, int width_src, int > height_src, enum PixelFormat format_dst, int width_dst, int height_dst > ) > { > m_format_src = format_src; > m_width_src = width_src; > m_height_src = height_src; > > m_format_dst = format_dst; > m_width_dst = width_dst; > m_height_dst = height_dst; > > m_sws_context = NULL; > > m_avframe_src = NULL; > m_avframe_dst = NULL; > > //alloc m_avframe_src, needed to recieve libavcodec source avframe > m_avframe_src = allocAVFrame( format_src, width_src, height_src ); > > //alloc m_avframe_dst, needed to 'sws_scale' function > m_avframe_dst = allocAVFrame( format_dst, width_dst, height_dst ); > } > > CResize::~CResize() > { > if( m_avframe_src != NULL ){ > av_free( m_avframe_src ); > m_avframe_src = NULL; > } > > if( m_avframe_dst != NULL ){ > av_free( m_avframe_dst ); > m_avframe_dst = NULL; > } > > if( m_sws_context != NULL ){ > sws_freeContext( m_sws_context ); > m_sws_context = NULL; > } > } > > AVFrame* CResize::resize( AVFrame* av_frame ) > { > //copy orignal libavcodec avframe to allocated m_avframe_src > av_picture_copy( (AVPicture*)m_avframe_src, //dest. frame > > (AVPicture*)av_frame, //src. frame > > m_format_src, //src. format > > m_width_src, > //src. width (input codec) > > m_height_src ); //src. > height (input codec) > > //check avframe > if( m_avframe_src == NULL || m_avframe_src->data == NULL){ > return NULL; > } > > //free the convert context > if( m_sws_context != NULL ) sws_freeContext(m_sws_context); > > > //create convert context > m_sws_context = sws_getContext( m_width_src, //src. width (input > codec, AVCodecContext->width) > > m_height_src,//src. > height (input codec, > AVCodecContext->height) > > m_format_src,//could > be, PIX_FMT_YUV420P > > m_width_dst, //dest. > width > > m_height_dst,//dest. > height > > m_format_dst,//could > be, PIX_FMT_YUV420P or PIX_FMT_YUVJ420P > > SWS_BICUBIC, > > NULL, > > NULL, > > NULL ); > if( m_sws_context == NULL ){ > perror("m_sws_context"); > return NULL; > } > > //resize frame > sws_scale( m_sws_context, > m_avframe_src->data, > > m_avframe_src->linesize, > 0, > m_height_src, > m_avframe_dst->data, > > m_avframe_dst->linesize ); > > return m_avframe_dst; > } > > AVFrame* CResize::allocAVFrame( enum PixelFormat pix_fmt, int width, > int height ) > { > AVFrame *av_frame; > uint8_t *avframe_buf; > int size; > > av_frame = avcodec_alloc_frame(); > if( !av_frame ) > return NULL; > > size = avpicture_get_size( pix_fmt, width, height ); > //determine required buffer size and allocate buffer > avframe_buf = (uint8_t *)av_malloc(size); > if (!avframe_buf) { > av_free(av_frame); > return NULL; > } > //assign appropriate parts of buffer to image planes in av_frame > avpicture_fill( (AVPicture *)av_frame, avframe_buf, pix_fmt, width, > height ); > > return av_frame; > } > _______________________________________________ > libav-user mailing list > [email protected] > https://lists.mplayerhq.hu/mailman/listinfo/libav-user > -- ----------------------------------------------------------------------------------------- My key fingerprint: d1:03:f5:32:26:ff:d7:3c:e4:42:e3:51:ec:92:78:b2 _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
