[FFmpeg-devel] [PATCH 2/2] hevc: Correctly set time_base

Guillaume Martres smarter at ubuntu.com
Tue Dec 10 15:37:22 CET 2013


- Try reading the time_base information from the VPS too, not just the VUI
- Only set time_base when an SPS is activated, not when it's decoded.
- Reduce the fraction before setting it.
- Don't set anything if the fraction is invalid (because the VUI is not
  present or because the encoded value is invalid).

Conflicts:
	libavcodec/hevc_ps.c
---
 libavcodec/hevc.c    | 14 ++++++++++++++
 libavcodec/hevc_ps.c |  2 --
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index 553c60d..2993bd4 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -283,6 +283,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
 static int set_sps(HEVCContext *s, const HEVCSPS *sps)
 {
     int ret;
+    int num = 0, den = 0;
 
     pic_arrays_free(s);
     ret = pic_arrays_init(s, sps);
@@ -327,6 +328,19 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps)
 
     s->sps = sps;
     s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]->data;
+
+    if (s->vps->vps_timing_info_present_flag) {
+        num = s->vps->vps_num_units_in_tick;
+        den = s->vps->vps_time_scale;
+    } else if (sps->vui.vui_timing_info_present_flag) {
+        num = sps->vui.vui_num_units_in_tick;
+        den = sps->vui.vui_time_scale;
+    }
+
+    if (num != 0 && den != 0)
+        av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,
+                  num, den, 1 << 30);
+
     return 0;
 
 fail:
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 988a539..63b5ddd 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -511,8 +511,6 @@ static void decode_vui(HEVCContext *s, HEVCSPS *sps)
     if (vui->vui_timing_info_present_flag) {
         vui->vui_num_units_in_tick               = get_bits(gb, 32);
         vui->vui_time_scale                      = get_bits(gb, 32);
-        s->avctx->time_base.num                  = vui->vui_num_units_in_tick;
-        s->avctx->time_base.den                  = vui->vui_time_scale;
         vui->vui_poc_proportional_to_timing_flag = get_bits1(gb);
         if (vui->vui_poc_proportional_to_timing_flag)
             vui->vui_num_ticks_poc_diff_one_minus1 = get_ue_golomb_long(gb);
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list