[FFmpeg-devel] [PATCH 2/5] ffmpeg: Fix direct use of AVStream fields

Michael Niedermayer michael at niedermayer.cc
Wed Jun 29 21:36:40 CEST 2016


Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 ffmpeg.c     |   37 +++++++++++++++++++------------------
 ffmpeg_opt.c |    4 ++--
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 9ffd833..c68461d 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -948,7 +948,7 @@ static void do_video_out(AVFormatContext *s,
         filter->inputs[0]->frame_rate.den > 0)
         duration = 1/(av_q2d(filter->inputs[0]->frame_rate) * av_q2d(enc->time_base));
 
-    if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
+    if(ist && ist->st->start_time != AV_NOPTS_VALUE && av_stream_get_first_dts(ist->st) != AV_NOPTS_VALUE && ost->frame_rate.num)
         duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
 
     if (!ost->filters_script &&
@@ -2917,14 +2917,14 @@ static int transcode_init(void)
              * overhead
              */
             if(!strcmp(oc->oformat->name, "avi")) {
-                if ( copy_tb<0 && ist->st->r_frame_rate.num
-                               && av_q2d(ist->st->r_frame_rate) >= av_q2d(ist->st->avg_frame_rate)
-                               && 0.5/av_q2d(ist->st->r_frame_rate) > av_q2d(ist->st->time_base)
-                               && 0.5/av_q2d(ist->st->r_frame_rate) > av_q2d(dec_ctx->time_base)
+                if ( copy_tb<0 && av_stream_get_r_frame_rate(ist->st).num
+                               && av_q2d(av_stream_get_r_frame_rate(ist->st)) >= av_q2d(ist->st->avg_frame_rate)
+                               && 0.5/av_q2d(av_stream_get_r_frame_rate(ist->st)) > av_q2d(ist->st->time_base)
+                               && 0.5/av_q2d(av_stream_get_r_frame_rate(ist->st)) > av_q2d(dec_ctx->time_base)
                                && av_q2d(ist->st->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
                      || copy_tb==2){
-                    enc_ctx->time_base.num = ist->st->r_frame_rate.den;
-                    enc_ctx->time_base.den = 2*ist->st->r_frame_rate.num;
+                    enc_ctx->time_base.num = av_stream_get_r_frame_rate(ist->st).den;
+                    enc_ctx->time_base.den = 2*av_stream_get_r_frame_rate(ist->st).num;
                     enc_ctx->ticks_per_frame = 2;
                 } else if (   copy_tb<0 && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > 2*av_q2d(ist->st->time_base)
                                  && av_q2d(ist->st->time_base) < 1.0/500
@@ -3032,7 +3032,7 @@ static int transcode_init(void)
                     sar = dec_ctx->sample_aspect_ratio;
                 ost->st->sample_aspect_ratio = enc_ctx->sample_aspect_ratio = sar;
                 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
-                ost->st->r_frame_rate = ist->st->r_frame_rate;
+                av_stream_set_r_frame_rate(ost->st, av_stream_get_r_frame_rate(ist->st));
                 break;
             case AVMEDIA_TYPE_SUBTITLE:
                 enc_ctx->width  = dec_ctx->width;
@@ -3085,7 +3085,7 @@ static int transcode_init(void)
                 if (ist && !ost->frame_rate.num)
                     ost->frame_rate = ist->framerate;
                 if (ist && !ost->frame_rate.num)
-                    ost->frame_rate = ist->st->r_frame_rate;
+                    ost->frame_rate = av_stream_get_r_frame_rate(ist->st);
                 if (ist && !ost->frame_rate.num) {
                     ost->frame_rate = (AVRational){25, 1};
                     av_log(NULL, AV_LOG_WARNING,
@@ -3422,10 +3422,11 @@ static OutputStream *choose_output(void)
 
     for (i = 0; i < nb_output_streams; i++) {
         OutputStream *ost = output_streams[i];
-        int64_t opts = ost->st->cur_dts == AV_NOPTS_VALUE ? INT64_MIN :
-                       av_rescale_q(ost->st->cur_dts, ost->st->time_base,
+        int64_t cur_dts = av_stream_get_cur_dts(ost->st);
+        int64_t opts = cur_dts == AV_NOPTS_VALUE ? INT64_MIN :
+                       av_rescale_q(cur_dts, ost->st->time_base,
                                     AV_TIME_BASE_Q);
-        if (ost->st->cur_dts == AV_NOPTS_VALUE)
+        if (cur_dts == AV_NOPTS_VALUE)
             av_log(NULL, AV_LOG_DEBUG, "cur_dts is invalid (this is harmless if it occurs once at the start per stream)\n");
 
         if (!ost->finished && opts < opts_min) {
@@ -3873,7 +3874,7 @@ static int process_input(int file_index)
                av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q));
     }
 
-    if(!ist->wrap_correction_done && is->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){
+    if(!ist->wrap_correction_done && is->start_time != AV_NOPTS_VALUE && av_stream_get_pts_wrap_bits(ist->st) < 64){
         int64_t stime, stime2;
         // Correcting starttime based on the enabled streams
         // FIXME this ideally should be done before the first use of starttime but we do not know which are the enabled streams at that point.
@@ -3895,15 +3896,15 @@ static int process_input(int file_index)
         }
 
         stime = av_rescale_q(is->start_time, AV_TIME_BASE_Q, ist->st->time_base);
-        stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
+        stime2= stime + (1ULL<<av_stream_get_pts_wrap_bits(ist->st));
         ist->wrap_correction_done = 1;
 
-        if(stime2 > stime && pkt.dts != AV_NOPTS_VALUE && pkt.dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
-            pkt.dts -= 1ULL<<ist->st->pts_wrap_bits;
+        if(stime2 > stime && pkt.dts != AV_NOPTS_VALUE && pkt.dts > stime + (1LL<<(av_stream_get_pts_wrap_bits(ist->st)-1))) {
+            pkt.dts -= 1ULL<<av_stream_get_pts_wrap_bits(ist->st);
             ist->wrap_correction_done = 0;
         }
-        if(stime2 > stime && pkt.pts != AV_NOPTS_VALUE && pkt.pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
-            pkt.pts -= 1ULL<<ist->st->pts_wrap_bits;
+        if(stime2 > stime && pkt.pts != AV_NOPTS_VALUE && pkt.pts > stime + (1LL<<(av_stream_get_pts_wrap_bits(ist->st)-1))) {
+            pkt.pts -= 1ULL<<av_stream_get_pts_wrap_bits(ist->st);
             ist->wrap_correction_done = 0;
         }
     }
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 7785a30..791fede 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -2053,7 +2053,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
             for (i = 0; i < nb_input_streams; i++) {
                 int new_area;
                 ist = input_streams[i];
-                new_area = ist->st->codec->width * ist->st->codec->height + 100000000*!!ist->st->codec_info_nb_frames;
+                new_area = ist->st->codec->width * ist->st->codec->height + 100000000*!!av_stream_get_codec_info_nb_frames(ist->st);
                 if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
                     new_area = 1;
                 if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
@@ -2074,7 +2074,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
             for (i = 0; i < nb_input_streams; i++) {
                 int score;
                 ist = input_streams[i];
-                score = ist->st->codec->channels + 100000000*!!ist->st->codec_info_nb_frames;
+                score = ist->st->codec->channels + 100000000*!!av_stream_get_codec_info_nb_frames(ist->st);
                 if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
                     score > best_score) {
                     best_score = score;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list