[FFmpeg-devel] [PATCH] libavformat/concatdev.c use the unified time base

2022-02-28 Thread Ye Chuan
in some case, the input files have different time base
even though they  share the same codec and codec parameters,

so when we replace the packet, we need use the unified time base
instead of it of each stream own, which may lead to wrong pts/dts
of the output packet.

Signed-off-by: Chuan Ye 
mailto:yechuan0...@hotmail.com>>
---
libavformat/concatdec.c | 9 ++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..f7067d5059 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -740,6 +740,7 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
 ConcatStream *cs;
 AVStream *st;
 FFStream *sti;
+AVRational output_tb;

 if (cat->eof)
 return AVERROR_EOF;
@@ -782,13 +783,15 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

+/* replace the pkt base on the time base of target output stream */
+output_tb = avf->streams[cs->out_stream_index]->time_base;
 delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
  AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
+ output_tb);
 if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + delta;
 if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + delta;
 av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
--
2.30.1 (Apple Git-130)



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: use the unified time base

2022-02-28 Thread Ye Chuan
In some case, the input files have different time base
even though they  share the same codec and codec parameters,

So when we replace the packet, we need use the unified time base
instead of it of each stream own, which may lead to wrong pts/dts
of the output packet.

Signed-off-by: Chuan Ye 
---
libavformat/concatdec.c | 9 ++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..f7067d5059 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -740,6 +740,7 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
ConcatStream *cs;
AVStream *st;
FFStream *sti;
+AVRational output_tb;

if (cat->eof)
return AVERROR_EOF;
@@ -782,13 +783,15 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

+/* replace the pkt base on the time base of target output stream */
+output_tb = avf->streams[cs->out_stream_index]->time_base;
delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
 AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
+ output_tb);
if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + delta;
if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + delta;
av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
-- 
2.30.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,

while processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
---
libavformat/concatdec.c | 31 ---
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
ConcatMatchMode stream_match_mode;
unsigned auto_convert;
int segment_time_metadata;
+int unified_time_base;
} ConcatContext;

static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
  OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
{ "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
  OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ NULL }
};

-- 
2.30.1 (Apple Git-130)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
---
libavformat/concatdec.c | 31 ---
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
ConcatMatchMode stream_match_mode;
unsigned auto_convert;
int segment_time_metadata;
+int unified_time_base;
} ConcatContext;

static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
  OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
{ "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
  OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ NULL }
};

-- 
2.30.1 (Apple Git-130)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
   ConcatMatchMode stream_match_mode;
   unsigned auto_convert;
   int segment_time_metadata;
+int unified_time_base;
} ConcatContext;

static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
   av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
 OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
   { "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
 OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
   { NULL }
};

-- 
2.30.1 (Apple Git-130)


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavformat/concatdev.c: use the unified time base

2022-03-01 Thread Ye Chuan
Hi Gyan

Thanks for suggestion

Base on the different  time_base, the connection between the streams, the pts 
and dts may be not continuate, the the codec
May reporte warning. Is that ‘bug’ acceptable?

Regards,

Chuan Ye

From: ffmpeg-devel  on behalf of Gyan Doshi 

Date: Tuesday, March 1, 2022 at 12:49 PM
To: ffmpeg-devel@ffmpeg.org 
Subject: Re: [FFmpeg-devel] [PATCH] libavformat/concatdev.c: use the unified 
time base


On 2022-03-01 09:46 am, Ye Chuan wrote:
> In some case, the input files have different time base
> even though they  share the same codec and codec parameters,
>
> So when we replace the packet, we need use the unified time base
> instead of it of each stream own, which may lead to wrong pts/dts
> of the output packet.
Make this optional. This 'bug' has been used to effect speed change in
some inputs.

Regards,
Gyan

>
> Signed-off-by: Chuan Ye 
> ---
> libavformat/concatdec.c | 9 ++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> index 0603c6e254..f7067d5059 100644
> --- a/libavformat/concatdec.c
> +++ b/libavformat/concatdec.c
> @@ -740,6 +740,7 @@ static int concat_read_packet(AVFormatContext *avf, 
> AVPacket *pkt)
>  ConcatStream *cs;
>  AVStream *st;
>  FFStream *sti;
> +AVRational output_tb;
>
>  if (cat->eof)
>  return AVERROR_EOF;
> @@ -782,13 +783,15 @@ static int concat_read_packet(AVFormatContext *avf, 
> AVPacket *pkt)
> av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
> av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
>
> +/* replace the pkt base on the time base of target output stream */
> +output_tb = avf->streams[cs->out_stream_index]->time_base;
>  delta = av_rescale_q(cat->cur_file->start_time - 
> cat->cur_file->file_inpoint,
>   AV_TIME_BASE_Q,
> - cat->avf->streams[pkt->stream_index]->time_base);
> + output_tb);
>  if (pkt->pts != AV_NOPTS_VALUE)
> -pkt->pts += delta;
> +pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + delta;
>  if (pkt->dts != AV_NOPTS_VALUE)
> -pkt->dts += delta;
> +pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + delta;
>  av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
> av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
> av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fffmpeg.org%2Fmailman%2Flistinfo%2Fffmpeg-devel&data=04%7C01%7C%7Cab226031969d4870b10308d9fb3ed191%7C84df9e7fe9f640afb435%7C1%7C0%7C637817069495324409%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=oynDOjzOBfgxWDRTtsaPuS0PvD%2BIlRjnOsq%2FzFANz3o%3D&reserved=0

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
---
libavformat/concatdec.c | 31 ---
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
ConcatMatchMode stream_match_mode;
unsigned auto_convert;
int segment_time_metadata;
+int unified_time_base;
} ConcatContext;

static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
  OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
{ "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
  OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ NULL }
};

-- 
2.30.1 (Apple Git-130)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
---
libavformat/concatdec.c | 31 ---
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
ConcatMatchMode stream_match_mode;
unsigned auto_convert;
int segment_time_metadata;
+int unified_time_base;
} ConcatContext;

static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
  OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
{ "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
  OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ NULL }
};

-- 
2.30.1 (Apple Git-130)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
---
libavformat/concatdec.c | 31 ---
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
   ConcatMatchMode stream_match_mode;
   unsigned auto_convert;
   int segment_time_metadata;
+int unified_time_base;
} ConcatContext;
 
static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
   av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
 OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
   { "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
 OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
   { NULL }
};
 

-- 
2.30.1 (Apple Git-130)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add unified_time_base opt

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
mailto:yechuan0...@hotmail.com>>
---
 libavformat/concatdec.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
 ConcatMatchMode stream_match_mode;
 unsigned auto_convert;
 int segment_time_metadata;
+int unified_time_base;
 } ConcatContext;



 static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));



-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
 av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
   OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
 { "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
   OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
 { NULL }
 };



--
2.30.1 (Apple Git-130)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add unified_time_base opt

2022-03-01 Thread Ye Chuan
There is some bug on my mail application , when it open the .eml file , the 
space may be erase by the application, so the patch will not pass the test 
online

From: ffmpeg-devel  on behalf of Nicolas 
George 
Date: Tuesday, March 1, 2022 at 8:18 PM
To: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add 
unified_time_base opt
Ye Chuan (12022-03-01):
> In some case, the input files have different time base even though
> they share the same codec and codec parameters,
> While processing the packet, it will adjust the pts/dts by its own
> time base instead of the unified one of the output stream, which may
> lead to wrong pts/dts or unexpected speed change.
>
> So this patch add the "unified_time_base" opt, which could be setted by
> "-unified_time_base 1"
> With the option, it will concatenate the input streams whose time base
> are different , and won't course speed change issue.
>
> Signed-off-by: Chuan Ye 
> ---
> libavformat/concatdec.c | 31 ---
> 1 file changed, 24 insertions(+), 7 deletions(-)

Thanks for the patch. I need to examine exactly what it does.

In the meantime, I do not know why you keep posting new versions of this
patch every few minutes. Please take your time. And before next time:


> int segment_time_metadata;
> +int unified_time_base;

Mangled indentation.

Missing documentation.

Spelling mistake in the title of the commit message.

Regards,

--
  Nicolas George
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add unified_time_base option

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
mailto:yechuan0...@hotmail.com>>
---
 libavformat/concatdec.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,6 +69,7 @@ typedef struct {
 ConcatMatchMode stream_match_mode;
 unsigned auto_convert;
 int segment_time_metadata;
+int unified_time_base;
 } ConcatContext;


 static int concat_probe(const AVProbeData *probe)
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));



-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
 av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
   OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
 { "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
   OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
 { NULL }
 };



--
2.30.1 (Apple Git-130)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/concatdev.c: Add unified_time_base option

2022-03-01 Thread Ye Chuan
In some case, the input files have different time base even though
they share the same codec and codec parameters,
While processing the packet, it will adjust the pts/dts by its own
time base instead of the unified one of the output stream, which may
lead to wrong pts/dts or unexpected speed change.

So this patch add the "unified_time_base" opt, which could be setted by
"-unified_time_base 1"
With the option, it will concatenate the input streams whose time base
are different , and won't course speed change issue.

Signed-off-by: Chuan Ye 
mailto:yechuan0...@hotmail.com>>
---
 libavformat/concatdec.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..2cb656d87e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -69,4 +69,5 @@ typedef struct {
 ConcatMatchMode stream_match_mode;
 unsigned auto_convert;
 int segment_time_metadata;
+int unified_time_base;
 } ConcatContext;
@@ -782,13 +783,27 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));

-delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
- AV_TIME_BASE_Q,
- cat->avf->streams[pkt->stream_index]->time_base);
-if (pkt->pts != AV_NOPTS_VALUE)
-pkt->pts += delta;
-if (pkt->dts != AV_NOPTS_VALUE)
-pkt->dts += delta;
+if (cat->unified_time_base) {
+/* replace the pkt base on the time base of target output stream */
+AVRational output_tb;
+output_tb = avf->streams[cs->out_stream_index]->time_base;
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ output_tb);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts = av_rescale_q(pkt->pts, st->time_base, output_tb) + 
delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts = av_rescale_q(pkt->dts, st->time_base, output_tb) + 
delta;
+} else {
+delta = av_rescale_q(cat->cur_file->start_time - 
cat->cur_file->file_inpoint,
+ AV_TIME_BASE_Q,
+ cat->avf->streams[pkt->stream_index]->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += delta;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += delta;
+}
+
 av_log(avf, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
@@ -931,6 +946,8 @@ static const AVOption options[] = {
   OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
 { "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
   OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+{ "unified_time_base", "adjust to the same time base (from the first 
stream) while processing packets",
+  OFFSET(unified_time_base), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
 { NULL }
 };

--
2.30.1 (Apple Git-130)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".