[PATCH] libavdevice/lavfi.c: adjust subcc_packet->pts to be in 90 timebase
From: Chris Landry <topher.p.landry@gmail.com> When a video stream timebase is not 90k, the cc packet pts is relevant to the timebase of the video stream, but later is assumed to be 90k. Adjust it here to be 90k so timing is accurate in resulting subs. Signed-off-by: Chris Landry <topher.p.landry@gmail.com> --- libavdevice/lavfi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index f9b2694..ffe5e0e 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -58,6 +58,7 @@ typedef struct { AVFrame *decoded_frame; int nb_sinks; AVPacket subcc_packet; + AVRational video_time_base; } LavfiContext; static int *create_all_formats(int n) @@ -317,6 +318,8 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) st->codecpar->codec_type = link->type; avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den); if (link->type == AVMEDIA_TYPE_VIDEO) { + lavfi->video_time_base = link->time_base; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; st->codecpar->format = link->format; st->codecpar->width = link->w; @@ -373,8 +376,14 @@ static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame, if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0) 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; + lavfi->subcc_packet.stream_index = stream_idx; - lavfi->subcc_packet.pts = frame->pts; + lavfi->subcc_packet.pts = (int64_t)pts; lavfi->subcc_packet.pos = av_frame_get_pkt_pos(frame); return 0; } -- 2.8.2
On Fri, Sep 30, 2016 at 11:02:32PM -0400, Chris Landry wrote:
From: Chris Landry <topher.p.landry@gmail.com>
When a video stream timebase is not 90k, the cc packet pts is relevant to the timebase of the video stream, but later is assumed to be 90k. Adjust it here to be 90k so timing is accurate in resulting subs.
Signed-off-by: Chris Landry <topher.p.landry@gmail.com> --- libavdevice/lavfi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index f9b2694..ffe5e0e 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -58,6 +58,7 @@ typedef struct { AVFrame *decoded_frame; int nb_sinks; AVPacket subcc_packet; + AVRational video_time_base; } LavfiContext;
static int *create_all_formats(int n) @@ -317,6 +318,8 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) st->codecpar->codec_type = link->type; avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den); if (link->type == AVMEDIA_TYPE_VIDEO) { + lavfi->video_time_base = link->time_base; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; st->codecpar->format = link->format; st->codecpar->width = link->w; @@ -373,8 +376,14 @@ static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame, if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0) return ret; memcpy(lavfi->subcc_packet.data, sd->data, sd->size); + + AVRational time_base = lavfi->video_time_base;
likely triggers compiler warning
+ + double adjust_factor = time_base.den / (90000.0 * time_base.num);
floating point is not needed and not ok due to binary non portability theres av_rescale* also this breaks make fate do you have a testcase that this fixes ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Freedom in capitalist society always remains about the same as it was in ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
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
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
Haven't been able to connect to upload.ffmpeg.org. Sample file is here: https://www.dropbox.com/s/38ll6y7wws7zssr/cc_different_video_timebase.mp4?dl... Also have not been able to get the fate stuff working. I am not a C developer and have a lot to learn here. On Sat, Oct 1, 2016 at 6:27 AM, Michael Niedermayer <michael@niedermayer.cc> wrote:
From: Chris Landry <topher.p.landry@gmail.com>
When a video stream timebase is not 90k, the cc packet pts is relevant to the timebase of the video stream, but later is assumed to be 90k. Adjust it here to be 90k so timing is accurate in resulting subs.
Signed-off-by: Chris Landry <topher.p.landry@gmail.com> --- libavdevice/lavfi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index f9b2694..ffe5e0e 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -58,6 +58,7 @@ typedef struct { AVFrame *decoded_frame; int nb_sinks; AVPacket subcc_packet; + AVRational video_time_base; } LavfiContext;
static int *create_all_formats(int n) @@ -317,6 +318,8 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) st->codecpar->codec_type = link->type; avpriv_set_pts_info(st, 64, link->time_base.num,
On Fri, Sep 30, 2016 at 11:02:32PM -0400, Chris Landry wrote: link->time_base.den);
if (link->type == AVMEDIA_TYPE_VIDEO) { + lavfi->video_time_base = link->time_base; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; st->codecpar->format = link->format; st->codecpar->width = link->w; @@ -373,8 +376,14 @@ static int create_subcc_packet(AVFormatContext
*avctx, AVFrame *frame,
if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0) return ret; memcpy(lavfi->subcc_packet.data, sd->data, sd->size); + + AVRational time_base = lavfi->video_time_base;
likely triggers compiler warning
+ + double adjust_factor = time_base.den / (90000.0 * time_base.num);
floating point is not needed and not ok due to binary non portability theres av_rescale*
also this breaks make fate
do you have a testcase that this fixes ?
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Freedom in capitalist society always remains about the same as it was in ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
participants (3)
-
Chris Landry -
Chris Landry -
Michael Niedermayer