Commit 59729451 authored by Aurelien Jacobs's avatar Aurelien Jacobs
Browse files

convert every muxer/demuxer to write/read sample_aspect_ratio from/to

the corresponding AVStream instead of AVCodecContext

Originally committed as revision 14933 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent c30a4489
......@@ -531,14 +531,14 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
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);
}
}
......
......@@ -552,7 +552,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
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;
......
......@@ -284,10 +284,10 @@ static int avi_write_header(AVFormatContext *s)
}
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);
......
......@@ -84,7 +84,7 @@ static int read_header(AVFormatContext *s,
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;
......
......@@ -247,7 +247,7 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
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);
......
......@@ -246,8 +246,8 @@ static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) {
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");
......
......@@ -1274,8 +1274,8 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
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);
......
......@@ -593,11 +593,10 @@ static int mkv_write_tracks(AVFormatContext *s)
// 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;
......
......@@ -1478,7 +1478,7 @@ static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
((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);
}
......
......@@ -887,7 +887,7 @@ static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack *track)
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 @@ static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track)
/* 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 @@ static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov)
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 @@ static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov,
//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]);
}
}
......
......@@ -447,8 +447,8 @@ static void mxf_write_mpeg_video_desc(AVFormatContext *s, const MXFDescriptorWri
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);
......
......@@ -350,10 +350,10 @@ static int decode_stream_header(NUTContext *nut){
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 */
......
......@@ -389,7 +389,8 @@ static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
}
}
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 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext
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 @@ static int write_headers(NUTContext *nut, ByteIOContext *bc){
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);
}
......
......@@ -158,7 +158,7 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
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
......
......@@ -87,8 +87,8 @@ theora_header (AVFormatContext * s, int idx)
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);
......
......@@ -44,8 +44,8 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
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 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment