Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
@ 2025-02-05  8:37 Jack Lau via ffmpeg-devel
  0 siblings, 0 replies; 10+ messages in thread
From: Jack Lau via ffmpeg-devel @ 2025-02-05  8:37 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Jack Lau, Jack Lau

From: Jack Lau <jacklau1222gm@gmail.com>

The `dec_ctx->time_base` was incorrectly default set by avcodec_open2(), while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output.

This patch corrects the issue by adjusting the `enc_ctx->time_base` calculation to account for `ticks_per_frame`, ensuring that the time base is consistent between the decoder and encoder contexts.
---
 doc/examples/transcoding.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 013f89fc7d..09c2ad4b62 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
                 else
                     enc_ctx->pix_fmt = dec_ctx->pix_fmt;
                 /* video time_base can be set to whatever is handy and supported by encoder */
-                enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+                enc_ctx->time_base = av_inv_q(av_mul_q(dec_ctx->framerate, (AVRational){dec_ctx->ticks_per_frame, 1}));
             } else {
                 enc_ctx->sample_rate = dec_ctx->sample_rate;
                 ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
@@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
                     return ret;
                 /* take first format from list of supported formats */
                 enc_ctx->sample_fmt = encoder->sample_fmts[0];
-                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+                enc_ctx->time_base = (AVRational){1, dec_ctx->sample_rate};
             }
 
             if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
-- 
2.48.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-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
  2025-02-05  3:25     ` Jack Lau
@ 2025-02-05  9:00       ` Jack Lau
  0 siblings, 0 replies; 10+ messages in thread
From: Jack Lau @ 2025-02-05  9:00 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Hello.

I found one better method to fix this issue. Firstly, i think the problem
caused by incorrectly setting enc_ctx->time_base, so i refer to the
implementation in avcodec_open2()

361 #if FF_API_AVCTX_TIMEBASE
362        if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
363             avctx->time_base = av_inv_q(av_mul_q(avctx->framerate,
(AVRational){avctx->ticks_per_frame, 1}));
364 #endif

this is new version code and i submit it in new mail, it can be reviewed in
https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_7ADFE69819D49D96FA8BC2C9E688CCEC2506@qq.com/
-                enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+                enc_ctx->time_base = av_inv_q(av_mul_q(dec_ctx->framerate,
(AVRational){dec_ctx->ticks_per_frame, 1}));

-                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+                enc_ctx->time_base = (AVRational){1, dec_ctx->sample_rate};

but there is new issue in andriy/configure_x86 check:

error: Failed to merge in the changes.

i think it's maybe the mistake of branch? this patch is for release/5.1
branch rather than master branch.

Could any one give me some advice please so that i can fix it?


On Wed, Feb 5, 2025 at 11:25 AM Jack Lau <jacklau1222gm@gmail.com> wrote:

> To be clear, i want to give an example, i use a 10s duration, 30fps video.
> The ifmt_ctx->streams[stream_index]->time_base is same as
> ofmt_ctx->streams[stream_index]->time_base after initializing.
> The stream->dec_ctx->time_base is default 0,60 but
> stream->enc_ctx->time_base is set to av_inv_q(dec_ctx->framerate) so it's
> 0,30
>
> 174                 /* video time_base can be set to whatever is handy and
> supported by encoder */
> 175                 enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
>
> so the twice rescale is this:
> input pkt in_tb: 15360   out_tb: 60
> output pkt in_tb: 30     out_tb: 15360
>
> so i get one 20s duration and 15fps video(audio duration is normal because
> the input's audio sample ratio is 44100)
>
> So i think the problem is that the enc_ctx->time_base shouldn't set to
> av_inv_q(dec_ctx->framerate)
>
> On Wed, Feb 5, 2025 at 10:29 AM Jack Lau <jacklau1222gm@gmail.com> wrote:
>
>>
>> AVCodecContext.time_base is not used for decoding.
>>
>>
>>
>> Thank you for your reply. I understand that time_base is not used during
>> decoding, but the transcoding code calls av_packet_rescale_ts twice,
>> once before decoding and once after encoding, as shown below:
>>
>> 540         if (filter_ctx[stream_index].filter_graph) {
>> 541             StreamContext *stream = &stream_ctx[stream_index];
>> 542
>> 543             av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the
>> frame\n");
>> 544
>> 545             av_packet_rescale_ts(packet,
>>
>>
>> 546
>>  ifmt_ctx->streams[stream_index]->time_base,
>> 547                                  stream->dec_ctx->time_base);
>> 548             ret = avcodec_send_packet(stream->dec_ctx, packet);
>>
>> 448         /* prepare packet for muxing */
>>
>>
>> 449         enc_pkt->stream_index = stream_index;
>> 450         av_packet_rescale_ts(enc_pkt,
>> 451                              stream->enc_ctx->time_base,
>> 452
>>  ofmt_ctx->streams[stream_index]->time_base);
>> 453
>> 454         av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
>> 455         /* mux encoded frame */
>> 456         ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
>>
>> If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can
>> lead to incorrect packet duration, which in turn causes issues with the
>> output file's duration.
>>
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
  2025-02-05  2:26   ` Jack Lau
@ 2025-02-05  3:25     ` Jack Lau
  2025-02-05  9:00       ` Jack Lau
  0 siblings, 1 reply; 10+ messages in thread
From: Jack Lau @ 2025-02-05  3:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

To be clear, i want to give an example, i use a 10s duration, 30fps video.
The ifmt_ctx->streams[stream_index]->time_base is same as
ofmt_ctx->streams[stream_index]->time_base after initializing.
The stream->dec_ctx->time_base is default 0,60 but
stream->enc_ctx->time_base is set to av_inv_q(dec_ctx->framerate) so it's
0,30

174                 /* video time_base can be set to whatever is handy and
supported by encoder */
175                 enc_ctx->time_base = av_inv_q(dec_ctx->framerate);

so the twice rescale is this:
input pkt in_tb: 15360   out_tb: 60
output pkt in_tb: 30     out_tb: 15360

so i get one 20s duration and 15fps video(audio duration is normal because
the input's audio sample ratio is 44100)

So i think the problem is that the enc_ctx->time_base shouldn't set to
av_inv_q(dec_ctx->framerate)

On Wed, Feb 5, 2025 at 10:29 AM Jack Lau <jacklau1222gm@gmail.com> wrote:

>
> AVCodecContext.time_base is not used for decoding.
>
>
>
> Thank you for your reply. I understand that time_base is not used during
> decoding, but the transcoding code calls av_packet_rescale_ts twice, once
> before decoding and once after encoding, as shown below:
>
> 540         if (filter_ctx[stream_index].filter_graph) {
> 541             StreamContext *stream = &stream_ctx[stream_index];
> 542
> 543             av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the
> frame\n");
> 544
> 545             av_packet_rescale_ts(packet,
>
>
> 546
>  ifmt_ctx->streams[stream_index]->time_base,
> 547                                  stream->dec_ctx->time_base);
> 548             ret = avcodec_send_packet(stream->dec_ctx, packet);
>
> 448         /* prepare packet for muxing */
>
>
> 449         enc_pkt->stream_index = stream_index;
> 450         av_packet_rescale_ts(enc_pkt,
> 451                              stream->enc_ctx->time_base,
> 452
>  ofmt_ctx->streams[stream_index]->time_base);
> 453
> 454         av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
> 455         /* mux encoded frame */
> 456         ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
>
> If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can
> lead to incorrect packet duration, which in turn causes issues with the
> output file's duration.
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
  2025-02-05  0:55 ` James Almer
  2025-02-05  2:26   ` Jack Lau
@ 2025-02-05  2:28   ` Jack Lau
  1 sibling, 0 replies; 10+ messages in thread
From: Jack Lau @ 2025-02-05  2:28 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> 
> AVCodecContext.time_base is not used for decoding.


Thank you for your reply. I understand that time_base is not used during decoding, but the transcoding code calls av_packet_rescale_ts twice, once before decoding and once after encoding, as shown below:

540         if (filter_ctx[stream_index].filter_graph) {
541             StreamContext *stream = &stream_ctx[stream_index];
542     
543             av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n");
544         
545             av_packet_rescale_ts(packet,                                                                                                                   
546                                  ifmt_ctx->streams[stream_index]->time_base,
547                                  stream->dec_ctx->time_base);
548             ret = avcodec_send_packet(stream->dec_ctx, packet);

448         /* prepare packet for muxing */                                                                                                                    
449         enc_pkt->stream_index = stream_index;
450         av_packet_rescale_ts(enc_pkt,
451                              stream->enc_ctx->time_base,
452                              ofmt_ctx->streams[stream_index]->time_base);
453 
454         av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
455         /* mux encoded frame */
456         ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);

If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can lead to incorrect packet duration, which in turn causes issues with the output file's duration.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
  2025-02-05  0:55 ` James Almer
@ 2025-02-05  2:26   ` Jack Lau
  2025-02-05  3:25     ` Jack Lau
  2025-02-05  2:28   ` Jack Lau
  1 sibling, 1 reply; 10+ messages in thread
From: Jack Lau @ 2025-02-05  2:26 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> 
> AVCodecContext.time_base is not used for decoding.


Thank you for your reply. I understand that time_base is not used during decoding, but the transcoding code calls av_packet_rescale_ts twice, once before decoding and once after encoding, as shown below:

540         if (filter_ctx[stream_index].filter_graph) {
541             StreamContext *stream = &stream_ctx[stream_index];
542     
543             av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n");
544         
545             av_packet_rescale_ts(packet,                                                                                                                   
546                                  ifmt_ctx->streams[stream_index]->time_base,
547                                  stream->dec_ctx->time_base);
548             ret = avcodec_send_packet(stream->dec_ctx, packet);

448         /* prepare packet for muxing */                                                                                                                    
449         enc_pkt->stream_index = stream_index;
450         av_packet_rescale_ts(enc_pkt,
451                              stream->enc_ctx->time_base,
452                              ofmt_ctx->streams[stream_index]->time_base);
453 
454         av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
455         /* mux encoded frame */
456         ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);

If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can lead to incorrect packet duration, which in turn causes issues with the output file's duration.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
@ 2025-02-05  2:17 Jack Lau
  0 siblings, 0 replies; 10+ messages in thread
From: Jack Lau @ 2025-02-05  2:17 UTC (permalink / raw)
  To: ffmpeg-devel

The `dec_ctx->time_base` was incorrectly default set to 0/60, while 
`enc_ctx->time_base` was derived from `dec_ctx->framerate`. This 
mismatch could cause incorrect video duration in the output.

This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to 
prevent rescaling issues and ensure correct video duration.

Signed-off-by: Jack Lau <jacklau1222gm@gmail.com>
---
  doc/examples/transcoding.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 013f89fc7d..847bdb7e1a 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
                  else
                      enc_ctx->pix_fmt = dec_ctx->pix_fmt;
                  /* video time_base can be set to whatever is handy and 
supported by encoder */
-                enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+                enc_ctx->time_base = dec_ctx->time_base;
              } else {
                  enc_ctx->sample_rate = dec_ctx->sample_rate;
                  ret = av_channel_layout_copy(&enc_ctx->ch_layout, 
&dec_ctx->ch_layout);
@@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
                      return ret;
                  /* take first format from list of supported formats */
                  enc_ctx->sample_fmt = encoder->sample_fmts[0];
-                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+                enc_ctx->time_base = dec_ctx->time_base;
              }
               if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
-- 
2.48.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-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
  2025-02-05  0:51 Jack Lau
@ 2025-02-05  0:55 ` James Almer
  2025-02-05  2:26   ` Jack Lau
  2025-02-05  2:28   ` Jack Lau
  0 siblings, 2 replies; 10+ messages in thread
From: James Almer @ 2025-02-05  0:55 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1976 bytes --]

> From bfd5500a5448ad468d32994816e8a55c0d4a2428 Mon Sep 17 00:00:00 2001
> From: Jack Lau <jacklau1222gm@gmail.com>
> Date: Tue, 4 Feb 2025 21:39:20 +0800
> Subject: [PATCH] examples/transcoding: Fix time_base handling
> 
> The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output.
> 
> This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration.
> ---
>  doc/examples/transcoding.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
> index 013f89fc7d..847bdb7e1a 100644
> --- a/doc/examples/transcoding.c
> +++ b/doc/examples/transcoding.c
> @@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
>                  else
>                      enc_ctx->pix_fmt = dec_ctx->pix_fmt;
>                  /* video time_base can be set to whatever is handy and supported by encoder */
> -                enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
> +                enc_ctx->time_base = dec_ctx->time_base;

AVCodecContext.time_base is not used for decoding.

>              } else {
>                  enc_ctx->sample_rate = dec_ctx->sample_rate;
>                  ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
> @@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
>                      return ret;
>                  /* take first format from list of supported formats */
>                  enc_ctx->sample_fmt = encoder->sample_fmts[0];
> -                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
> +                enc_ctx->time_base = dec_ctx->time_base;
>              }
>  
>              if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
> -- 
> 2.45.2
> 

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
@ 2025-02-05  0:51 Jack Lau
  2025-02-05  0:55 ` James Almer
  0 siblings, 1 reply; 10+ messages in thread
From: Jack Lau @ 2025-02-05  0:51 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: fix-time-base-handling.patch --]
[-- Type: application/octet-stream, Size: 1846 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
@ 2025-02-04 15:35 Jack Lau
  0 siblings, 0 replies; 10+ messages in thread
From: Jack Lau @ 2025-02-04 15:35 UTC (permalink / raw)
  To: ffmpeg-devel

The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output.

This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration.

Signed-off-by: JackLau1222 <2366536135@qq.com>
---
doc/examples/transcoding.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 013f89fc7d..847bdb7e1a 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
              else
                  enc_ctx->pix_fmt = dec_ctx->pix_fmt;
              /* video time_base can be set to whatever is handy and supported by encoder */
-                enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+                enc_ctx->time_base = dec_ctx->time_base;
          } else {
              enc_ctx->sample_rate = dec_ctx->sample_rate;
              ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
@@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
                  return ret;
              /* take first format from list of supported formats */
              enc_ctx->sample_fmt = encoder->sample_fmts[0];
-                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+                enc_ctx->time_base = dec_ctx->time_base;
          }

          if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
-- 
2.45.2

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
@ 2025-02-04 15:13 Jack Lau
  0 siblings, 0 replies; 10+ messages in thread
From: Jack Lau @ 2025-02-04 15:13 UTC (permalink / raw)
  To: ffmpeg-devel

The `dec_ctx->time_base` was incorrectly default set to 0/60, while
`enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch
could cause incorrect video duration in the output.

This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent
rescaling issues and ensure correct video duration.

Signed-off-by: Jack Lau <jacklau1222gm@gmail.com>
---
doc/examples/transcoding.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 013f89fc7d..847bdb7e1a 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
            else
                enc_ctx->pix_fmt = dec_ctx->pix_fmt;
            /* video time_base can be set to whatever is handy and
supported by encoder */
-                enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+                enc_ctx->time_base = dec_ctx->time_base;
        } else {
            enc_ctx->sample_rate = dec_ctx->sample_rate;
            ret = av_channel_layout_copy(&enc_ctx->ch_layout,
&dec_ctx->ch_layout);
@@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
                return ret;
            /* take first format from list of supported formats */
            enc_ctx->sample_fmt = encoder->sample_fmts[0];
-                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+                enc_ctx->time_base = dec_ctx->time_base;
        }

        if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
-- 
2.45.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-02-05  9:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-05  8:37 [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling Jack Lau via ffmpeg-devel
  -- strict thread matches above, loose matches on Subject: below --
2025-02-05  2:17 Jack Lau
2025-02-05  0:51 Jack Lau
2025-02-05  0:55 ` James Almer
2025-02-05  2:26   ` Jack Lau
2025-02-05  3:25     ` Jack Lau
2025-02-05  9:00       ` Jack Lau
2025-02-05  2:28   ` Jack Lau
2025-02-04 15:35 Jack Lau
2025-02-04 15:13 Jack Lau

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git