[FFmpeg-cvslog] r14933 - in trunk/libavformat: 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

aurel subversion
Sun Aug 24 01:43:20 CEST 2008


Author: aurel
Date: Sun Aug 24 01:43:20 2008
New Revision: 14933

Log:
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
the corresponding AVStream instead of AVCodecContext


Modified:
   trunk/libavformat/asf.c
   trunk/libavformat/avidec.c
   trunk/libavformat/avienc.c
   trunk/libavformat/c93.c
   trunk/libavformat/dv.c
   trunk/libavformat/libnut.c
   trunk/libavformat/matroskadec.c
   trunk/libavformat/matroskaenc.c
   trunk/libavformat/mov.c
   trunk/libavformat/movenc.c
   trunk/libavformat/mxfenc.c
   trunk/libavformat/nutdec.c
   trunk/libavformat/nutenc.c
   trunk/libavformat/nuv.c
   trunk/libavformat/oggparsetheora.c
   trunk/libavformat/yuv4mpeg.c

Modified: trunk/libavformat/asf.c
==============================================================================
--- trunk/libavformat/asf.c	(original)
+++ trunk/libavformat/asf.c	Sun Aug 24 01:43:20 2008
@@ -531,14 +531,14 @@ static int asf_read_header(AVFormatConte
     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);
         }
     }
 

Modified: trunk/libavformat/avidec.c
==============================================================================
--- trunk/libavformat/avidec.c	(original)
+++ trunk/libavformat/avidec.c	Sun Aug 24 01:43:20 2008
@@ -552,7 +552,7 @@ static int avi_read_header(AVFormatConte
                 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;

Modified: trunk/libavformat/avienc.c
==============================================================================
--- trunk/libavformat/avienc.c	(original)
+++ trunk/libavformat/avienc.c	Sun Aug 24 01:43:20 2008
@@ -284,10 +284,10 @@ static int avi_write_header(AVFormatCont
         }
 
         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);

Modified: trunk/libavformat/c93.c
==============================================================================
--- trunk/libavformat/c93.c	(original)
+++ trunk/libavformat/c93.c	Sun Aug 24 01:43:20 2008
@@ -84,7 +84,7 @@ static int read_header(AVFormatContext *
     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;

Modified: trunk/libavformat/dv.c
==============================================================================
--- trunk/libavformat/dv.c	(original)
+++ trunk/libavformat/dv.c	Sun Aug 24 01:43:20 2008
@@ -247,7 +247,7 @@ static int dv_extract_video_info(DVDemux
         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);

Modified: trunk/libavformat/libnut.c
==============================================================================
--- trunk/libavformat/libnut.c	(original)
+++ trunk/libavformat/libnut.c	Sun Aug 24 01:43:20 2008
@@ -246,8 +246,8 @@ static int nut_read_header(AVFormatConte
 
             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");

Modified: trunk/libavformat/matroskadec.c
==============================================================================
--- trunk/libavformat/matroskadec.c	(original)
+++ trunk/libavformat/matroskadec.c	Sun Aug 24 01:43:20 2008
@@ -1274,8 +1274,8 @@ static int matroska_read_header(AVFormat
             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);

Modified: trunk/libavformat/matroskaenc.c
==============================================================================
--- trunk/libavformat/matroskaenc.c	(original)
+++ trunk/libavformat/matroskaenc.c	Sun Aug 24 01:43:20 2008
@@ -593,11 +593,10 @@ static int mkv_write_tracks(AVFormatCont
                 // 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;

Modified: trunk/libavformat/mov.c
==============================================================================
--- trunk/libavformat/mov.c	(original)
+++ trunk/libavformat/mov.c	Sun Aug 24 01:43:20 2008
@@ -1478,7 +1478,7 @@ static int mov_read_tkhd(MOVContext *c, 
                 ((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);
     }

Modified: trunk/libavformat/movenc.c
==============================================================================
--- trunk/libavformat/movenc.c	(original)
+++ trunk/libavformat/movenc.c	Sun Aug 24 01:43:20 2008
@@ -887,7 +887,7 @@ static int mov_write_mdia_tag(ByteIOCont
     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(ByteIOCont
 
     /* 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(ByteIO
     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(ByteIOCont
     //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]);
         }
     }
 

Modified: trunk/libavformat/mxfenc.c
==============================================================================
--- trunk/libavformat/mxfenc.c	(original)
+++ trunk/libavformat/mxfenc.c	Sun Aug 24 01:43:20 2008
@@ -447,8 +447,8 @@ static void mxf_write_mpeg_video_desc(AV
     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);

Modified: trunk/libavformat/nutdec.c
==============================================================================
--- trunk/libavformat/nutdec.c	(original)
+++ trunk/libavformat/nutdec.c	Sun Aug 24 01:43:20 2008
@@ -350,10 +350,10 @@ static int decode_stream_header(NUTConte
     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 */

Modified: trunk/libavformat/nutenc.c
==============================================================================
--- trunk/libavformat/nutenc.c	(original)
+++ trunk/libavformat/nutenc.c	Sun Aug 24 01:43:20 2008
@@ -389,7 +389,8 @@ static void write_mainheader(NUTContext 
     }
 }
 
-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
         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
     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);
     }
 

Modified: trunk/libavformat/nuv.c
==============================================================================
--- trunk/libavformat/nuv.c	(original)
+++ trunk/libavformat/nuv.c	Sun Aug 24 01:43:20 2008
@@ -158,7 +158,7 @@ static int nuv_header(AVFormatContext *s
         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

Modified: trunk/libavformat/oggparsetheora.c
==============================================================================
--- trunk/libavformat/oggparsetheora.c	(original)
+++ trunk/libavformat/oggparsetheora.c	Sun Aug 24 01:43:20 2008
@@ -87,8 +87,8 @@ theora_header (AVFormatContext * s, int 
         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);

Modified: trunk/libavformat/yuv4mpeg.c
==============================================================================
--- trunk/libavformat/yuv4mpeg.c	(original)
+++ trunk/libavformat/yuv4mpeg.c	Sun Aug 24 01:43:20 2008
@@ -44,8 +44,8 @@ static int yuv4_generate_header(AVFormat
 
     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(AVFormatCont
     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;
 }




More information about the ffmpeg-cvslog mailing list