aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAurelien Jacobs <aurel@gnuage.org>2008-08-23 23:43:20 +0000
committerAurelien Jacobs <aurel@gnuage.org>2008-08-23 23:43:20 +0000
commit5972945197d44e8bde6a986b9cba2e8196cfbc9c (patch)
tree94ba719e6f5efb53fc18d7eb38ccb96d25e7b194 /libavformat
parentc30a4489b444020ef951c1f0583afd8679c07c78 (diff)
downloadffmpeg-5972945197d44e8bde6a986b9cba2e8196cfbc9c.tar.gz
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
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/asf.c12
-rw-r--r--libavformat/avidec.c2
-rw-r--r--libavformat/avienc.c6
-rw-r--r--libavformat/c93.c2
-rw-r--r--libavformat/dv.c2
-rw-r--r--libavformat/libnut.c4
-rw-r--r--libavformat/matroskadec.c4
-rw-r--r--libavformat/matroskaenc.c9
-rw-r--r--libavformat/mov.c2
-rw-r--r--libavformat/movenc.c10
-rw-r--r--libavformat/mxfenc.c4
-rw-r--r--libavformat/nutdec.c8
-rw-r--r--libavformat/nutenc.c13
-rw-r--r--libavformat/nuv.c2
-rw-r--r--libavformat/oggparsetheora.c4
-rw-r--r--libavformat/yuv4mpeg.c6
16 files changed, 44 insertions, 46 deletions
diff --git a/libavformat/asf.c b/libavformat/asf.c
index fc0a86eff3..6d35b8f56d 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -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);
}
}
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index dcbf766d9e..ae19e53033 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -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;
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 63ada5d35a..3dabd3a371 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -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);
diff --git a/libavformat/c93.c b/libavformat/c93.c
index be1577b8c8..c377f4daba 100644
--- a/libavformat/c93.c
+++ b/libavformat/c93.c
@@ -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;
diff --git a/libavformat/dv.c b/libavformat/dv.c
index 2f9171789b..0670e5149c 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -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);
diff --git a/libavformat/libnut.c b/libavformat/libnut.c
index 2cadaefcbd..9a7a1b4505 100644
--- a/libavformat/libnut.c
+++ b/libavformat/libnut.c
@@ -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");
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 8839654fa2..8405e25c40 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -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);
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index e656bc3c3d..9346e9c84e 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -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;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c068160ac4..1edae19703 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -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);
}
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index b7601a13da..5e3b34a03e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -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]);
}
}
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index d7ed84704f..a3c9c537f6 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -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);
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 5dac94c4b9..cf41f62b56 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -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 */
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 447cea31a0..7bb826a891 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -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);
}
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index b76fe0cd6b..c3439c12bc 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -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
diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c
index 36848b1588..1a16ca501a 100644
--- a/libavformat/oggparsetheora.c
+++ b/libavformat/oggparsetheora.c
@@ -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);
diff --git a/libavformat/yuv4mpeg.c b/libavformat/yuv4mpeg.c
index 6af7d78a6e..bc6c781bcf 100644
--- a/libavformat/yuv4mpeg.c
+++ b/libavformat/yuv4mpeg.c
@@ -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;
}