[FFmpeg-devel] Maybe bit_rate is not correct?

Prince xianyu.ge
Tue Feb 9 10:11:02 CET 2010

Hi All,

I just want to decode a video which from my iPhone, get the many  
images and do some thing balabala...., then I will re-create a video  
from this images, the settings of video or audio is not change. This  
is my thinking.

According the output_simple.c sample code,  I write a test code, that  
just decode the video, then encode that to another video, but new  
there some issues with it.
The duration is decreased to half, and the quality is less that  
original, the file size is also less than original, what caused this,  
please give me a hand .
The following is the logs of ffmpeg, and some codes, any replies is  
welcome, thanks advance.

  The logs from dump_format:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/mobile/Applications/ 
     major_brand     : qt
     minor_version   : 0
     compatible_brands: qt
     year            : 2010-02-08T14:47:17+0800
     year-eng        : 2010-02-08T14:47:17+0800
   Duration: 00:00:06.31, start: 0.000000, bitrate: 3696 kb/s
     Stream #0.0(und): Video: h264, yuv420p, 640x480, 3670 kb/s, 26.28  
fps, 300 tbr, 600 tbn, 1200 tbc
     Stream #0.1(und): Audio: aac, 44100 Hz, mono, s16, 63 kb/s
Output #0, mov, to '/var/mobile/Applications/E106BA0F-03B0-41EC-BCC4- 
     Stream #0.0: Video: mpeg4, yuv420p, 640x480, q=2-31, 3670 kb/s,  
300 tbr, 600 tbn, 1200 tbc
     Stream #0.1: Audio: aac, 44100 Hz, 1 channels, 63 kb/s

Some codes that set the out put video stream:

static AVStream *add_video_stream(AVFormatContext *oc, int codec_id)
	AVCodecContext *c;
	AVStream *st;
	st = av_new_stream(oc, 0);
	if (!st) {
		fprintf(stderr, "Could not alloc stream\n");
	c = st->codec;
	c->codec_id = codec_id;
	c->codec_type = CODEC_TYPE_VIDEO;
	st->r_frame_rate.den = pFormatCtx->streams[videoStream]- 
	st->r_frame_rate.num = pFormatCtx->streams[videoStream]- 
	st->avg_frame_rate.den = pFormatCtx->streams[videoStream]- 
	st->avg_frame_rate.num = pFormatCtx->streams[videoStream]- 
	st->sample_aspect_ratio.den = pFormatCtx->streams[videoStream]- 
	st->sample_aspect_ratio.num = pFormatCtx->streams[videoStream]- 
	st->pts_wrap_bits = pFormatCtx->streams[videoStream]->pts_wrap_bits;
	st->quality = pFormatCtx->streams[videoStream]->quality;
	st->time_base.den = pFormatCtx->streams[videoStream]->time_base.den;
	st->time_base.num = pFormatCtx->streams[videoStream]->time_base.num;
	st->nb_frames = pFormatCtx->streams[videoStream]->nb_frames;
	/* put sample parameters */
	c->bit_rate = pCodecCtx->bit_rate;
	/* resolution must be a multiple of two */
	c->width = pCodecCtx->width;
	c->height = pCodecCtx->height;
	/* time base: this is the fundamental unit of time (in seconds) in  
	 of which frame timestamps are represented. for fixed-fps content,
	 timebase should be 1/framerate and timestamp increments should be
	 identically 1. */
	c->coded_frame = pCodecCtx->coded_frame;
	c->time_base.den = pCodecCtx->time_base.den;
	c->time_base.num = pCodecCtx->time_base.num;
	c->gop_size = pCodecCtx->gop_size; /* emit one intra frame every  
twelve frames at most */
	c->pix_fmt = pCodecCtx->pix_fmt;
	c->max_b_frames = pCodecCtx->max_b_frames;
	c->me_method = pCodecCtx->me_method;
	c->rate_emu = 0;

	if (c->codec_id == CODEC_ID_MPEG2VIDEO) {
		/* just for testing, we also add B frames */
		c->max_b_frames = 2;
	if (c->codec_id == CODEC_ID_MPEG1VIDEO){
		/* needed to avoid using macroblocks in which some coeffs overflow
		 this doesnt happen with normal video, it just happens here as the
		 motion of the chroma plane doesnt match the luma plane */
	// some formats want stream headers to be separate
	if(!strcmp(oc->oformat->name, "mp4") || !strcmp(oc->oformat->name,  
"mov") || !strcmp(oc->oformat->name, "3gp"))
	return st;

More information about the ffmpeg-devel mailing list