Mercurial > libavformat.hg
changeset 3759:27537074f2a9 libavformat
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
the corresponding AVStream instead of AVCodecContext
author | aurel |
---|---|
date | Sat, 23 Aug 2008 23:43:20 +0000 |
parents | e966560661e5 |
children | fde28855a81e |
files | asf.c avidec.c avienc.c c93.c dv.c libnut.c matroskadec.c matroskaenc.c mov.c movenc.c mxfenc.c nutdec.c nutenc.c nuv.c oggparsetheora.c yuv4mpeg.c |
diffstat | 16 files changed, 44 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/asf.c Sat Aug 23 23:13:58 2008 +0000 +++ b/asf.c Sat Aug 23 23:43:20 2008 +0000 @@ -531,14 +531,14 @@ for(i=0; i<128; i++){ int stream_num= asf->asfid2avid[i]; if(stream_num>=0){ - AVCodecContext *codec= s->streams[stream_num]->codec; - if (!codec->bit_rate) - codec->bit_rate = bitrate[i]; + AVStream *st = s->streams[stream_num]; + if (!st->codec->bit_rate) + st->codec->bit_rate = bitrate[i]; if (dar[i].num > 0 && dar[i].den > 0) - av_reduce(&codec->sample_aspect_ratio.num, - &codec->sample_aspect_ratio.den, + av_reduce(&st->sample_aspect_ratio.num, + &st->sample_aspect_ratio.den, dar[i].num, dar[i].den, INT_MAX); -//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den); +//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); } }
--- a/avidec.c Sat Aug 23 23:13:58 2008 +0000 +++ b/avidec.c Sat Aug 23 23:43:20 2008 +0000 @@ -552,7 +552,7 @@ get_le32(pb); //nbFieldsPerFrame if(active_aspect.num && active_aspect.den && active.num && active.den){ - st->codec->sample_aspect_ratio= av_div_q(active_aspect, active); + st->sample_aspect_ratio= av_div_q(active_aspect, active); //av_log(s, AV_LOG_ERROR, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect.den, active.num, active.den); } size -= 9*4;
--- a/avienc.c Sat Aug 23 23:13:58 2008 +0000 +++ b/avienc.c Sat Aug 23 23:43:20 2008 +0000 @@ -284,10 +284,10 @@ } if( stream->codec_type == CODEC_TYPE_VIDEO - && stream->sample_aspect_ratio.num>0 - && stream->sample_aspect_ratio.den>0){ + && s->streams[i]->sample_aspect_ratio.num>0 + && s->streams[i]->sample_aspect_ratio.den>0){ int vprp= start_tag(pb, "vprp"); - AVRational dar = av_mul_q(stream->sample_aspect_ratio, + AVRational dar = av_mul_q(s->streams[i]->sample_aspect_ratio, (AVRational){stream->width, stream->height}); int num, den; av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
--- a/c93.c Sat Aug 23 23:13:58 2008 +0000 +++ b/c93.c Sat Aug 23 23:43:20 2008 +0000 @@ -84,7 +84,7 @@ video->codec->width = 320; video->codec->height = 192; /* 4:3 320x200 with 8 empty lines */ - video->codec->sample_aspect_ratio = (AVRational) { 5, 6 }; + video->sample_aspect_ratio = (AVRational) { 5, 6 }; video->time_base = (AVRational) { 2, 25 }; video->nb_frames = framecount; video->duration = framecount;
--- a/dv.c Sat Aug 23 23:13:58 2008 +0000 +++ b/dv.c Sat Aug 23 23:43:20 2008 +0000 @@ -247,7 +247,7 @@ apt = frame[4] & 0x07; is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); - avctx->sample_aspect_ratio = c->sys->sar[is16_9]; + c->vst->sample_aspect_ratio = c->sys->sar[is16_9]; avctx->bit_rate = av_rescale(c->sys->frame_size * 8, c->sys->frame_rate, c->sys->frame_rate_base);
--- a/libnut.c Sat Aug 23 23:13:58 2008 +0000 +++ b/libnut.c Sat Aug 23 23:43:20 2008 +0000 @@ -246,8 +246,8 @@ st->codec->width = s[i].width; st->codec->height = s[i].height; - st->codec->sample_aspect_ratio.num = s[i].sample_width; - st->codec->sample_aspect_ratio.den = s[i].sample_height; + st->sample_aspect_ratio.num = s[i].sample_width; + st->sample_aspect_ratio.den = s[i].sample_height; break; } if (st->codec->codec_id == CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n");
--- a/matroskadec.c Sat Aug 23 23:13:58 2008 +0000 +++ b/matroskadec.c Sat Aug 23 23:43:20 2008 +0000 @@ -1274,8 +1274,8 @@ st->codec->codec_tag = track->video.fourcc; st->codec->width = track->video.pixel_width; st->codec->height = track->video.pixel_height; - av_reduce(&st->codec->sample_aspect_ratio.num, - &st->codec->sample_aspect_ratio.den, + av_reduce(&st->sample_aspect_ratio.num, + &st->sample_aspect_ratio.den, st->codec->height * track->video.display_width, st->codec-> width * track->video.display_height, 255);
--- a/matroskaenc.c Sat Aug 23 23:13:58 2008 +0000 +++ b/matroskaenc.c Sat Aug 23 23:43:20 2008 +0000 @@ -593,11 +593,10 @@ // XXX: interlace flag? put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); - if (codec->sample_aspect_ratio.num) { - AVRational dar = av_mul_q(codec->sample_aspect_ratio, - (AVRational){codec->width, codec->height}); - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , dar.num); - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, dar.den); + if (st->sample_aspect_ratio.num) { + int d_width = codec->width*av_q2d(st->sample_aspect_ratio); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height); } end_ebml_master(pb, subinfo); break;
--- a/mov.c Sat Aug 23 23:13:58 2008 +0000 +++ b/mov.c Sat Aug 23 23:43:20 2008 +0000 @@ -1478,7 +1478,7 @@ ((int64_t) display_matrix[2][i] << 16); //sample aspect ratio is new width/height divided by old width/height - st->codec->sample_aspect_ratio = av_d2q( + st->sample_aspect_ratio = av_d2q( ((double) disp_transform[0] * height) / ((double) disp_transform[1] * width), INT_MAX); }
--- a/movenc.c Sat Aug 23 23:13:58 2008 +0000 +++ b/movenc.c Sat Aug 23 23:43:20 2008 +0000 @@ -887,7 +887,7 @@ return updateSize(pb, pos); } -static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track) +static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) { int64_t duration = av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP); int version = duration < INT32_MAX ? 0 : 1; @@ -930,7 +930,7 @@ /* Track width and height, for visual only */ if(track->enc->codec_type == CODEC_TYPE_VIDEO) { - double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio); + double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); if(!sample_aspect_ratio) sample_aspect_ratio = 1; put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000); put_be32(pb, track->enc->height*0x10000); @@ -978,12 +978,12 @@ return 0x34; } -static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track) +static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) { offset_t pos = url_ftell(pb); put_be32(pb, 0); /* size */ put_tag(pb, "trak"); - mov_write_tkhd_tag(pb, track); + mov_write_tkhd_tag(pb, track, st); if (track->mode == MODE_PSP || track->hasBframes) mov_write_edts_tag(pb, track); // PSP Movies require edts box mov_write_mdia_tag(pb, track); @@ -1350,7 +1350,7 @@ //mov_write_iods_tag(pb, mov); for (i=0; i<mov->nb_streams; i++) { if(mov->tracks[i].entry > 0) { - mov_write_trak_tag(pb, &(mov->tracks[i])); + mov_write_trak_tag(pb, &(mov->tracks[i]), s->streams[i]); } }
--- a/mxfenc.c Sat Aug 23 23:13:58 2008 +0000 +++ b/mxfenc.c Sat Aug 23 23:43:20 2008 +0000 @@ -447,8 +447,8 @@ put_be32(pb, st->codec->height); mxf_write_local_tag(pb, 8, 0x320E); - put_be32(pb, st->codec->height * st->codec->sample_aspect_ratio.den); - put_be32(pb, st->codec->width * st->codec->sample_aspect_ratio.num); + put_be32(pb, st->codec->height * st->sample_aspect_ratio.den); + put_be32(pb, st->codec->width * st->sample_aspect_ratio.num); // tmp write, will modified later mxf_write_local_tag(pb, 16, 0x3201);
--- a/nutdec.c Sat Aug 23 23:13:58 2008 +0000 +++ b/nutdec.c Sat Aug 23 23:43:20 2008 +0000 @@ -350,10 +350,10 @@ if (st->codec->codec_type == CODEC_TYPE_VIDEO){ GET_V(st->codec->width , tmp > 0) GET_V(st->codec->height, tmp > 0) - st->codec->sample_aspect_ratio.num= ff_get_v(bc); - st->codec->sample_aspect_ratio.den= ff_get_v(bc); - if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){ - av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->codec->sample_aspect_ratio.num, st->codec->sample_aspect_ratio.den); + st->sample_aspect_ratio.num= ff_get_v(bc); + st->sample_aspect_ratio.den= ff_get_v(bc); + if((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)){ + av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); return -1; } ff_get_v(bc); /* csp type */
--- a/nutenc.c Sat Aug 23 23:13:58 2008 +0000 +++ b/nutenc.c Sat Aug 23 23:43:20 2008 +0000 @@ -389,7 +389,8 @@ } } -static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext *codec, int i){ +static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, int i){ + AVCodecContext *codec = st->codec; put_v(bc, i); switch(codec->codec_type){ case CODEC_TYPE_VIDEO: put_v(bc, 0); break; @@ -422,12 +423,12 @@ put_v(bc, codec->width); put_v(bc, codec->height); - if(codec->sample_aspect_ratio.num<=0 || codec->sample_aspect_ratio.den<=0){ + if(st->sample_aspect_ratio.num<=0 || st->sample_aspect_ratio.den<=0){ put_v(bc, 0); put_v(bc, 0); }else{ - put_v(bc, codec->sample_aspect_ratio.num); - put_v(bc, codec->sample_aspect_ratio.den); + put_v(bc, st->sample_aspect_ratio.num); + put_v(bc, st->sample_aspect_ratio.den); } put_v(bc, 0); /* csp type -- unknown */ break; @@ -514,12 +515,10 @@ put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE); for (i=0; i < nut->avf->nb_streams; i++){ - AVCodecContext *codec = nut->avf->streams[i]->codec; - ret = url_open_dyn_buf(&dyn_bc); if(ret < 0) return ret; - write_streamheader(nut, dyn_bc, codec, i); + write_streamheader(nut, dyn_bc, nut->avf->streams[i], i); put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE); }
--- a/nuv.c Sat Aug 23 23:13:58 2008 +0000 +++ b/nuv.c Sat Aug 23 23:43:20 2008 +0000 @@ -158,7 +158,7 @@ vst->codec->width = width; vst->codec->height = height; vst->codec->bits_per_sample = 10; - vst->codec->sample_aspect_ratio = av_d2q(aspect * height / width, 10000); + vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000); vst->r_frame_rate = av_d2q(fps, 60000); av_set_pts_info(vst, 32, 1, 1000); } else
--- a/oggparsetheora.c Sat Aug 23 23:13:58 2008 +0000 +++ b/oggparsetheora.c Sat Aug 23 23:43:20 2008 +0000 @@ -87,8 +87,8 @@ st->codec->time_base.num = get_bits_long(&gb, 32); st->time_base = st->codec->time_base; - st->codec->sample_aspect_ratio.num = get_bits_long(&gb, 24); - st->codec->sample_aspect_ratio.den = get_bits_long(&gb, 24); + st->sample_aspect_ratio.num = get_bits_long(&gb, 24); + st->sample_aspect_ratio.den = get_bits_long(&gb, 24); if (version >= 0x030200) skip_bits(&gb, 38);
--- a/yuv4mpeg.c Sat Aug 23 23:13:58 2008 +0000 +++ b/yuv4mpeg.c Sat Aug 23 23:43:20 2008 +0000 @@ -44,8 +44,8 @@ av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1); - aspectn = st->codec->sample_aspect_ratio.num; - aspectd = st->codec->sample_aspect_ratio.den; + aspectn = st->sample_aspect_ratio.num; + aspectd = st->sample_aspect_ratio.den; if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown @@ -331,7 +331,7 @@ st->codec->pix_fmt = pix_fmt; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->sample_aspect_ratio= (AVRational){aspectn, aspectd}; + st->sample_aspect_ratio= (AVRational){aspectn, aspectd}; return 0; }