[FFmpeg-devel] libavdevice/lavfi.c: adjust subcc_packet->pts to correct timebase with av_rescale_q

Submitted by Chris Landry on Oct. 1, 2016, 6:04 p.m.

Details

Message ID 1475345069-71261-1-git-send-email-topher.p.landry@gmail.comm
State New
Headers show

Commit Message

Chris Landry Oct. 1, 2016, 6:04 p.m.
From: Chris Landry <topher.p.landry@gmail.com>

Should have used av_rescale_q to do the timebase adjustment. Fixed compiler warning for variable declaration.

Signed-off-by: Chris Landry <topher.p.landry@gmail.com>
---
 libavdevice/lavfi.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Chris Landry Oct. 1, 2016, 6:06 p.m.
Sorry, this was supposed to be submitted in response to my thread on this
one. New to sending email with git.

On Sat, Oct 1, 2016 at 2:04 PM, Chris Landry <topher.p.landry@gmail.com>
wrote:

> From: Chris Landry <topher.p.landry@gmail.com>
>
> Should have used av_rescale_q to do the timebase adjustment. Fixed
> compiler warning for variable declaration.
>
> Signed-off-by: Chris Landry <topher.p.landry@gmail.com>
> ---
>  libavdevice/lavfi.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
> index ffe5e0e..89979db 100644
> --- a/libavdevice/lavfi.c
> +++ b/libavdevice/lavfi.c
> @@ -364,6 +364,7 @@ static int create_subcc_packet(AVFormatContext
> *avctx, AVFrame *frame,
>      LavfiContext *lavfi = avctx->priv_data;
>      AVFrameSideData *sd;
>      int stream_idx, i, ret;
> +    int64_t pts;
>
>      if ((stream_idx = lavfi->sink_stream_subcc_map[sink_idx]) < 0)
>          return 0;
> @@ -377,10 +378,7 @@ static int create_subcc_packet(AVFormatContext
> *avctx, AVFrame *frame,
>          return ret;
>      memcpy(lavfi->subcc_packet.data, sd->data, sd->size);
>
> -    AVRational time_base = lavfi->video_time_base;
> -
> -    double adjust_factor = time_base.den / (90000.0 * time_base.num);
> -    double pts = frame->pts / adjust_factor;
> +    pts = av_rescale_q(frame->pts, lavfi->video_time_base,
> (AVRational){1, 90000});
>
>      lavfi->subcc_packet.stream_index = stream_idx;
>      lavfi->subcc_packet.pts = (int64_t)pts;
> --
> 2.8.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Patch hide | download patch | download mbox

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index ffe5e0e..89979db 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -364,6 +364,7 @@  static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame,
     LavfiContext *lavfi = avctx->priv_data;
     AVFrameSideData *sd;
     int stream_idx, i, ret;
+    int64_t pts;
 
     if ((stream_idx = lavfi->sink_stream_subcc_map[sink_idx]) < 0)
         return 0;
@@ -377,10 +378,7 @@  static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame,
         return ret;
     memcpy(lavfi->subcc_packet.data, sd->data, sd->size);
 
-    AVRational time_base = lavfi->video_time_base;
-
-    double adjust_factor = time_base.den / (90000.0 * time_base.num);
-    double pts = frame->pts / adjust_factor;
+    pts = av_rescale_q(frame->pts, lavfi->video_time_base, (AVRational){1, 90000});
 
     lavfi->subcc_packet.stream_index = stream_idx;
     lavfi->subcc_packet.pts = (int64_t)pts;