Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2
@ 2023-09-02 15:19 Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Apply various fixes to transcode.c, with some bonus patches fixing a
typo and adding some debug logs in the aresample filter.

In particular fixes:
http://trac.ffmpeg.org/ticket/5849

_______________________________________________
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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-03  7:37   ` Paul B Mahol
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 02/11] lavfi/aresample: show time_base information during setup Stefano Sabatini
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

---
 libavcodec/avcodec.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 649411ac79..070e36795d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1794,9 +1794,9 @@ typedef struct AVCodecContext {
     enum AVPixelFormat sw_pix_fmt;
 
     /**
-     * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
-     * - encoding unused.
-     * - decoding set by user.
+     * Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
+     * - encoding: unused.
+     * - decoding: set by user.
      */
     AVRational pkt_timebase;
 
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 02/11] lavfi/aresample: show time_base information during setup
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 03/11] doc/examples/transcode: apply style fixes Stefano Sabatini
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

---
 libavfilter/af_aresample.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index f4bcc45616..b71ed5b91c 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -28,6 +28,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
 #include "libavutil/samplefmt.h"
+#include "libavutil/timestamp.h"
 #include "libavutil/avassert.h"
 #include "libswresample/swresample.h"
 #include "avfilter.h"
@@ -164,9 +165,9 @@ static int config_output(AVFilterLink *outlink)
     av_channel_layout_describe(&inlink ->ch_layout, inchl_buf,  sizeof(inchl_buf));
     av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf));
 
-    av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n",
-           inlink ->ch_layout.nb_channels, inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
-           outlink->ch_layout.nb_channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
+    av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz tb:%d/%d -> ch:%d chl:%s fmt:%s r:%dHz tb:%d/%d\n",
+           inlink ->ch_layout.nb_channels, inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate, inlink->time_base.num, inlink->time_base.den,
+           outlink->ch_layout.nb_channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate, outlink->time_base.num, outlink->time_base.den);
     return 0;
 }
 
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 03/11] doc/examples/transcode: apply style fixes
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 02/11] lavfi/aresample: show time_base information during setup Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 04/11] doc/examples/transcode: factorize codec_type definition Stefano Sabatini
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

---
 doc/examples/transcode.c | 97 +++++++++++++++++++++-------------------
 1 file changed, 50 insertions(+), 47 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index ed6ac9fa03..81a88dd577 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -82,19 +82,23 @@ static int open_input_file(const char *filename)
         AVStream *stream = ifmt_ctx->streams[i];
         const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
         AVCodecContext *codec_ctx;
+
         if (!dec) {
             av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i);
             return AVERROR_DECODER_NOT_FOUND;
         }
+
         codec_ctx = avcodec_alloc_context3(dec);
         if (!codec_ctx) {
-            av_log(NULL, AV_LOG_ERROR, "Failed to allocate the decoder context for stream #%u\n", i);
+            av_log(NULL, AV_LOG_ERROR,
+                   "Failed to allocate the decoder context for stream #%u\n", i);
             return AVERROR(ENOMEM);
         }
+
         ret = avcodec_parameters_to_context(codec_ctx, stream->codecpar);
         if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters to input decoder context "
-                   "for stream #%u\n", i);
+            av_log(NULL, AV_LOG_ERROR,
+                   "Failed to copy decoder parameters to input decoder context for stream #%u\n", i);
             return ret;
         }
 
@@ -103,8 +107,7 @@ static int open_input_file(const char *filename)
         codec_ctx->pkt_timebase = stream->time_base;
 
         /* Reencode video & audio and remux subtitles etc. */
-        if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
-                || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+        if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
             if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
                 codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, NULL);
             /* Open decoder */
@@ -141,7 +144,6 @@ static int open_output_file(const char *filename)
         return AVERROR_UNKNOWN;
     }
 
-
     for (i = 0; i < ifmt_ctx->nb_streams; i++) {
         out_stream = avformat_new_stream(ofmt_ctx, NULL);
         if (!out_stream) {
@@ -152,8 +154,7 @@ static int open_output_file(const char *filename)
         in_stream = ifmt_ctx->streams[i];
         dec_ctx = stream_ctx[i].dec_ctx;
 
-        if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
-                || dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+        if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
             /* in this example, we choose transcoding to same codec */
             encoder = avcodec_find_encoder(dec_ctx->codec_id);
             if (!encoder) {
@@ -241,8 +242,8 @@ static int open_output_file(const char *filename)
     return 0;
 }
 
-static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
-        AVCodecContext *enc_ctx, const char *filter_spec)
+static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
+                       AVCodecContext *enc_ctx, const char *filter_spec)
 {
     char args[512];
     int ret = 0;
@@ -269,29 +270,29 @@ static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
         }
 
         snprintf(args, sizeof(args),
-                "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
-                dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
-                dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
-                dec_ctx->sample_aspect_ratio.num,
-                dec_ctx->sample_aspect_ratio.den);
+                 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
+                 dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
+                 dec_ctx->time_base.num, dec_ctx->time_base.den,
+                 dec_ctx->sample_aspect_ratio.num,
+                 dec_ctx->sample_aspect_ratio.den);
 
         ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
-                args, NULL, filter_graph);
+                                           args, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
             goto end;
         }
 
         ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
-                NULL, NULL, filter_graph);
+                                           NULL, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
             goto end;
         }
 
         ret = av_opt_set_bin(buffersink_ctx, "pix_fmts",
-                (uint8_t*)&enc_ctx->pix_fmt, sizeof(enc_ctx->pix_fmt),
-                AV_OPT_SEARCH_CHILDREN);
+                             (uint8_t*)&enc_ctx->pix_fmt, sizeof(enc_ctx->pix_fmt),
+                             AV_OPT_SEARCH_CHILDREN);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
             goto end;
@@ -308,45 +309,46 @@ static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
 
         if (dec_ctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
             av_channel_layout_default(&dec_ctx->ch_layout, dec_ctx->ch_layout.nb_channels);
+
         av_channel_layout_describe(&dec_ctx->ch_layout, buf, sizeof(buf));
         snprintf(args, sizeof(args),
-                "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
-                dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, dec_ctx->sample_rate,
-                av_get_sample_fmt_name(dec_ctx->sample_fmt),
-                buf);
+                 "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
+                 dec_ctx->time_base.num, dec_ctx->time_base.den, dec_ctx->sample_rate,
+                 av_get_sample_fmt_name(dec_ctx->sample_fmt),
+                 buf);
+
         ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
-                args, NULL, filter_graph);
+                                           args, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer source\n");
             goto end;
         }
 
         ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
-                NULL, NULL, filter_graph);
+                                           NULL, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n");
             goto end;
         }
 
         ret = av_opt_set_bin(buffersink_ctx, "sample_fmts",
-                (uint8_t*)&enc_ctx->sample_fmt, sizeof(enc_ctx->sample_fmt),
-                AV_OPT_SEARCH_CHILDREN);
+                             (uint8_t*)&enc_ctx->sample_fmt, sizeof(enc_ctx->sample_fmt),
+                             AV_OPT_SEARCH_CHILDREN);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot set output sample format\n");
             goto end;
         }
 
         av_channel_layout_describe(&enc_ctx->ch_layout, buf, sizeof(buf));
-        ret = av_opt_set(buffersink_ctx, "ch_layouts",
-                         buf, AV_OPT_SEARCH_CHILDREN);
+        ret = av_opt_set(buffersink_ctx, "ch_layouts", buf, AV_OPT_SEARCH_CHILDREN);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot set output channel layout\n");
             goto end;
         }
 
         ret = av_opt_set_bin(buffersink_ctx, "sample_rates",
-                (uint8_t*)&enc_ctx->sample_rate, sizeof(enc_ctx->sample_rate),
-                AV_OPT_SEARCH_CHILDREN);
+                             (uint8_t*)&enc_ctx->sample_rate, sizeof(enc_ctx->sample_rate),
+                             AV_OPT_SEARCH_CHILDREN);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot set output sample rate\n");
             goto end;
@@ -373,7 +375,7 @@ static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
     }
 
     if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_spec,
-                    &inputs, &outputs, NULL)) < 0)
+                                        &inputs, &outputs, NULL)) < 0)
         goto end;
 
     if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
@@ -401,20 +403,21 @@ static int init_filters(void)
         return AVERROR(ENOMEM);
 
     for (i = 0; i < ifmt_ctx->nb_streams; i++) {
+        AVStream *st = ifmt_ctx->streams[i];
         filter_ctx[i].buffersrc_ctx  = NULL;
         filter_ctx[i].buffersink_ctx = NULL;
         filter_ctx[i].filter_graph   = NULL;
-        if (!(ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO
-                || ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO))
-            continue;
 
+        if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ||
+              st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO))
+            continue;
 
-        if (ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
             filter_spec = "null"; /* passthrough (dummy) filter for video */
         else
             filter_spec = "anull"; /* passthrough (dummy) filter for audio */
         ret = init_filter(&filter_ctx[i], stream_ctx[i].dec_ctx,
-                stream_ctx[i].enc_ctx, filter_spec);
+                          stream_ctx[i].enc_ctx, filter_spec);
         if (ret)
             return ret;
 
@@ -477,8 +480,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
 
     av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n");
     /* push the decoded frame into the filtergraph */
-    ret = av_buffersrc_add_frame_flags(filter->buffersrc_ctx,
-            frame, 0);
+    ret = av_buffersrc_add_frame_flags(filter->buffersrc_ctx, frame, 0);
     if (ret < 0) {
         av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
         return ret;
@@ -487,8 +489,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
     /* pull filtered frames from the filtergraph */
     while (1) {
         av_log(NULL, AV_LOG_INFO, "Pulling filtered frame from filters\n");
-        ret = av_buffersink_get_frame(filter->buffersink_ctx,
-                                      filter->filtered_frame);
+        ret = av_buffersink_get_frame(filter->buffersink_ctx, filter->filtered_frame);
         if (ret < 0) {
             /* if no more frames for output - returns AVERROR(EAGAIN)
              * if flushed and no more frames for output - returns AVERROR_EOF
@@ -499,7 +500,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
             break;
         }
 
-        filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx);;
+        filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx);
         filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE;
         ret = encode_write_frame(stream_index, 0);
         av_frame_unref(filter->filtered_frame);
@@ -512,8 +513,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
 
 static int flush_encoder(unsigned int stream_index)
 {
-    if (!(stream_ctx[stream_index].enc_ctx->codec->capabilities &
-                AV_CODEC_CAP_DELAY))
+    if (!(stream_ctx[stream_index].enc_ctx->codec->capabilities & AV_CODEC_CAP_DELAY))
         return 0;
 
     av_log(NULL, AV_LOG_INFO, "Flushing stream #%u encoder\n", stream_index);
@@ -546,8 +546,7 @@ int main(int argc, char **argv)
         if ((ret = av_read_frame(ifmt_ctx, packet)) < 0)
             break;
         stream_index = packet->stream_index;
-        av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n",
-                stream_index);
+        av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", stream_index);
 
         if (filter_ctx[stream_index].filter_graph) {
             StreamContext *stream = &stream_ctx[stream_index];
@@ -636,8 +635,12 @@ end:
     av_packet_free(&packet);
     for (i = 0; i < ifmt_ctx->nb_streams; i++) {
         avcodec_free_context(&stream_ctx[i].dec_ctx);
-        if (ofmt_ctx && ofmt_ctx->nb_streams > i && ofmt_ctx->streams[i] && stream_ctx[i].enc_ctx)
+
+        if (ofmt_ctx && ofmt_ctx->nb_streams > i &&
+            ofmt_ctx->streams[i] &&
+            stream_ctx[i].enc_ctx)
             avcodec_free_context(&stream_ctx[i].enc_ctx);
+
         if (filter_ctx && filter_ctx[i].filter_graph) {
             avfilter_graph_free(&filter_ctx[i].filter_graph);
             av_packet_free(&filter_ctx[i].enc_pkt);
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 04/11] doc/examples/transcode: factorize codec_type definition
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (2 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 03/11] doc/examples/transcode: apply style fixes Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 05/11] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

---
 doc/examples/transcode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 81a88dd577..3c57fb36c9 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -82,6 +82,7 @@ static int open_input_file(const char *filename)
         AVStream *stream = ifmt_ctx->streams[i];
         const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
         AVCodecContext *codec_ctx;
+        enum AVMediaType codec_type;
 
         if (!dec) {
             av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i);
@@ -105,11 +106,13 @@ static int open_input_file(const char *filename)
         /* Inform the decoder about the timebase for the packet timestamps.
          * This is highly recommended, but not mandatory. */
         codec_ctx->pkt_timebase = stream->time_base;
+        codec_type = codec_ctx->codec_type;
 
         /* Reencode video & audio and remux subtitles etc. */
-        if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-            if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (codec_type == AVMEDIA_TYPE_VIDEO || codec_type == AVMEDIA_TYPE_AUDIO) {
+            if (codec_type == AVMEDIA_TYPE_VIDEO)
                 codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, NULL);
+
             /* Open decoder */
             ret = avcodec_open2(codec_ctx, dec, NULL);
             if (ret < 0) {
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 05/11] doc/examples/transcode: improve reporting when the encoder is not found
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (3 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 04/11] doc/examples/transcode: factorize codec_type definition Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Also return EINVAL in place of INVALIDDATA.
---
 doc/examples/transcode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 3c57fb36c9..dd64c38f15 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -161,8 +161,8 @@ static int open_output_file(const char *filename)
             /* in this example, we choose transcoding to same codec */
             encoder = avcodec_find_encoder(dec_ctx->codec_id);
             if (!encoder) {
-                av_log(NULL, AV_LOG_FATAL, "Necessary encoder not found\n");
-                return AVERROR_INVALIDDATA;
+                av_log(NULL, AV_LOG_FATAL, "Necessary encoder with ID %d not found\n", dec_ctx->codec_id);
+                return AVERROR(EINVAL);
             }
             enc_ctx = avcodec_alloc_context3(encoder);
             if (!enc_ctx) {
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame()
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (4 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 05/11] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-03  7:39   ` Paul B Mahol
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 07/11] doc/examples/transcode: introduce timestamp logging Stefano Sabatini
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Favor it over av_buffersrc_add_frame_flags, simplify.
---
 doc/examples/transcode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index dd64c38f15..21ea14b614 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -483,7 +483,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
 
     av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n");
     /* push the decoded frame into the filtergraph */
-    ret = av_buffersrc_add_frame_flags(filter->buffersrc_ctx, frame, 0);
+    ret = av_buffersrc_add_frame(filter->buffersrc_ctx, frame);
     if (ret < 0) {
         av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
         return ret;
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 07/11] doc/examples/transcode: introduce timestamp logging
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (5 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources Stefano Sabatini
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Aid timestamp debugging.
---
 doc/examples/transcode.c | 43 +++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 21ea14b614..5671c6664b 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -37,6 +37,7 @@
 #include <libavutil/channel_layout.h>
 #include <libavutil/opt.h>
 #include <libavutil/pixdesc.h>
+#include <libavutil/timestamp.h>
 
 static AVFormatContext *ifmt_ctx;
 static AVFormatContext *ofmt_ctx;
@@ -435,6 +436,26 @@ static int init_filters(void)
     return 0;
 }
 
+static void log_packet(AVPacket *pkt, const AVFormatContext *fmt_ctx, const char *tag)
+{
+    AVRational *time_base = &fmt_ctx->streams[pkt->stream_index]->time_base;
+
+    av_log(NULL, AV_LOG_INFO,
+           "%s [pkt] stream:%d tb:%d/%d pts_time:%s\n",
+           tag, pkt->stream_index, time_base->num, time_base->den,
+           av_ts2timestr(pkt->pts, time_base));
+}
+
+static void log_frame(AVFrame *frame, int stream_index, const char *tag)
+{
+    AVRational *time_base = &frame->time_base;
+
+    av_log(NULL, AV_LOG_INFO,
+           "%s [frame] stream:%d tb:%d/%d pts_time:%s\n",
+           tag, stream_index, time_base->num, time_base->den,
+           av_ts2timestr(frame->pts, time_base));
+}
+
 static int encode_write_frame(unsigned int stream_index, int flush)
 {
     StreamContext *stream = &stream_ctx[stream_index];
@@ -443,16 +464,16 @@ static int encode_write_frame(unsigned int stream_index, int flush)
     AVPacket *enc_pkt = filter->enc_pkt;
     int ret;
 
-    av_log(NULL, AV_LOG_INFO, "Encoding frame\n");
     /* encode filtered frame */
     av_packet_unref(enc_pkt);
 
-    if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE)
+    if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) {
         filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
                                        stream->enc_ctx->time_base);
+        log_frame(filt_frame, stream_index, "encoder <-");
+    }
 
     ret = avcodec_send_frame(stream->enc_ctx, filt_frame);
-
     if (ret < 0)
         return ret;
 
@@ -468,8 +489,8 @@ static int encode_write_frame(unsigned int stream_index, int flush)
                              stream->enc_ctx->time_base,
                              ofmt_ctx->streams[stream_index]->time_base);
 
-        av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
         /* mux encoded frame */
+        log_packet(enc_pkt, ofmt_ctx, "muxer <-");
         ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
     }
 
@@ -481,8 +502,11 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
     FilteringContext *filter = &filter_ctx[stream_index];
     int ret;
 
-    av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n");
     /* push the decoded frame into the filtergraph */
+    if (frame) {
+        log_frame(frame, stream_index, "filters <-");
+    }
+
     ret = av_buffersrc_add_frame(filter->buffersrc_ctx, frame);
     if (ret < 0) {
         av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
@@ -491,7 +515,6 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
 
     /* pull filtered frames from the filtergraph */
     while (1) {
-        av_log(NULL, AV_LOG_INFO, "Pulling filtered frame from filters\n");
         ret = av_buffersink_get_frame(filter->buffersink_ctx, filter->filtered_frame);
         if (ret < 0) {
             /* if no more frames for output - returns AVERROR(EAGAIN)
@@ -505,6 +528,8 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
 
         filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx);
         filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE;
+
+        log_frame(filter->filtered_frame, stream_index, "filters ->");
         ret = encode_write_frame(stream_index, 0);
         av_frame_unref(filter->filtered_frame);
         if (ret < 0)
@@ -549,13 +574,11 @@ int main(int argc, char **argv)
         if ((ret = av_read_frame(ifmt_ctx, packet)) < 0)
             break;
         stream_index = packet->stream_index;
-        av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", stream_index);
+        log_packet(packet, ifmt_ctx, "demuxer ->");
 
         if (filter_ctx[stream_index].filter_graph) {
             StreamContext *stream = &stream_ctx[stream_index];
 
-            av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n");
-
             ret = avcodec_send_packet(stream->dec_ctx, packet);
             if (ret < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Decoding failed\n");
@@ -569,6 +592,7 @@ int main(int argc, char **argv)
                 else if (ret < 0)
                     goto end;
 
+                log_frame(stream->dec_frame, stream_index, "decoder ->");
                 stream->dec_frame->pts = stream->dec_frame->best_effort_timestamp;
                 ret = filter_encode_write_frame(stream->dec_frame, stream_index);
                 if (ret < 0)
@@ -580,6 +604,7 @@ int main(int argc, char **argv)
                                  ifmt_ctx->streams[stream_index]->time_base,
                                  ofmt_ctx->streams[stream_index]->time_base);
 
+            log_packet(packet, ofmt_ctx, "muxer <-");
             ret = av_interleaved_write_frame(ofmt_ctx, packet);
             if (ret < 0)
                 goto end;
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (6 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 07/11] doc/examples/transcode: introduce timestamp logging Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-03  7:38   ` Paul B Mahol
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 09/11] doc/examples/transcode: fix timestamps scaling Stefano Sabatini
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

---
 doc/examples/transcode.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 5671c6664b..b94fdbede2 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -280,14 +280,14 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
                  dec_ctx->sample_aspect_ratio.num,
                  dec_ctx->sample_aspect_ratio.den);
 
-        ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
+        ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "video-in",
                                            args, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
             goto end;
         }
 
-        ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
+        ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "video-out",
                                            NULL, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
@@ -321,14 +321,14 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
                  av_get_sample_fmt_name(dec_ctx->sample_fmt),
                  buf);
 
-        ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
+        ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "audio-in",
                                            args, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer source\n");
             goto end;
         }
 
-        ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
+        ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "audio-out",
                                            NULL, NULL, filter_graph);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n");
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 09/11] doc/examples/transcode: fix timestamps scaling
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (7 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 10/11] doc/examples/transcode: simplify selection of pix_fmt Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder Stefano Sabatini
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Set pkt_timebase in the decoder and in the decoded frame, use it for
the filterchain source, and rescale the filtered frame to the target
encoder time_base.

This fixes filtering in case the time base was not set in the decoder,
causing the error:
[in @ 0x5647fc26ec80] Invalid time base 0/1
---
 doc/examples/transcode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index b94fdbede2..524bb47f50 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -276,7 +276,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
         snprintf(args, sizeof(args),
                  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
                  dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
-                 dec_ctx->time_base.num, dec_ctx->time_base.den,
+                 dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
                  dec_ctx->sample_aspect_ratio.num,
                  dec_ctx->sample_aspect_ratio.den);
 
@@ -303,6 +303,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
         }
     } else if (dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
         char buf[64];
+
         buffersrc = avfilter_get_by_name("abuffer");
         buffersink = avfilter_get_by_name("abuffersink");
         if (!buffersrc || !buffersink) {
@@ -317,7 +318,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
         av_channel_layout_describe(&dec_ctx->ch_layout, buf, sizeof(buf));
         snprintf(args, sizeof(args),
                  "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
-                 dec_ctx->time_base.num, dec_ctx->time_base.den, dec_ctx->sample_rate,
+                 dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, dec_ctx->sample_rate,
                  av_get_sample_fmt_name(dec_ctx->sample_fmt),
                  buf);
 
@@ -470,6 +471,7 @@ static int encode_write_frame(unsigned int stream_index, int flush)
     if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) {
         filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
                                        stream->enc_ctx->time_base);
+        filt_frame->time_base = stream->enc_ctx->time_base;
         log_frame(filt_frame, stream_index, "encoder <-");
     }
 
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 10/11] doc/examples/transcode: simplify selection of pix_fmt
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (8 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 09/11] doc/examples/transcode: fix timestamps scaling Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder Stefano Sabatini
  10 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Use ternary operator.
---
 doc/examples/transcode.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 524bb47f50..1d22a4b09e 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -178,11 +178,10 @@ static int open_output_file(const char *filename)
                 enc_ctx->height = dec_ctx->height;
                 enc_ctx->width = dec_ctx->width;
                 enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
-                /* take first format from list of supported formats */
-                if (encoder->pix_fmts)
-                    enc_ctx->pix_fmt = encoder->pix_fmts[0];
-                else
-                    enc_ctx->pix_fmt = dec_ctx->pix_fmt;
+
+                /* take first format from list of supported formats or use decoder one */
+                enc_ctx->pix_fmt = encoder->pix_fmts ? encoder->pix_fmts[0] : 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);
             } else {
-- 
2.34.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] 20+ messages in thread

* [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder
  2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
                   ` (9 preceding siblings ...)
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 10/11] doc/examples/transcode: simplify selection of pix_fmt Stefano Sabatini
@ 2023-09-02 15:19 ` Stefano Sabatini
  2023-09-03  7:41   ` Paul B Mahol
  10 siblings, 1 reply; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Fix crash occurring when the list of sample formats is not defined in the encoder,
use the decoder one in that case.

Possibly fix issue:
http://trac.ffmpeg.org/ticket/5849
---
 doc/examples/transcode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 1d22a4b09e..3c72b9377e 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -189,8 +189,10 @@ static int open_output_file(const char *filename)
                 ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
                 if (ret < 0)
                     return ret;
-                /* take first format from list of supported formats */
-                enc_ctx->sample_fmt = encoder->sample_fmts[0];
+
+                /* take first format from list of supported formats or use decoder one */
+                enc_ctx->sample_fmt = encoder->sample_fmts ? encoder->sample_fmts[0] : dec_ctx->sample_fmt;
+
                 enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
             }
 
-- 
2.34.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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
@ 2023-09-03  7:37   ` Paul B Mahol
  0 siblings, 0 replies; 20+ messages in thread
From: Paul B Mahol @ 2023-09-03  7:37 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

OK
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources Stefano Sabatini
@ 2023-09-03  7:38   ` Paul B Mahol
  0 siblings, 0 replies; 20+ messages in thread
From: Paul B Mahol @ 2023-09-03  7:38 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

LGTM
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame()
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
@ 2023-09-03  7:39   ` Paul B Mahol
  2023-09-05 23:18     ` Stefano Sabatini
  0 siblings, 1 reply; 20+ messages in thread
From: Paul B Mahol @ 2023-09-03  7:39 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

This simplify nothing at all.
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder
  2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder Stefano Sabatini
@ 2023-09-03  7:41   ` Paul B Mahol
  2023-09-05 23:48     ` Stefano Sabatini
  2023-09-05 23:49     ` Stefano Sabatini
  0 siblings, 2 replies; 20+ messages in thread
From: Paul B Mahol @ 2023-09-03  7:41 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Decoder formats may not relate to encoder formats, thus this one looks too
hackish to me to accept.
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame()
  2023-09-03  7:39   ` Paul B Mahol
@ 2023-09-05 23:18     ` Stefano Sabatini
  0 siblings, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-05 23:18 UTC (permalink / raw)
  To: Paul B Mahol; +Cc: FFmpeg development discussions and patches

On date Sunday 2023-09-03 09:39:02 +0200, Paul B Mahol wrote:
> This simplify nothing at all.

I don't mind dropping this one.
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder
  2023-09-03  7:41   ` Paul B Mahol
@ 2023-09-05 23:48     ` Stefano Sabatini
  2023-09-05 23:49     ` Stefano Sabatini
  1 sibling, 0 replies; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-05 23:48 UTC (permalink / raw)
  To: Paul B Mahol; +Cc: FFmpeg development discussions and patches

On date Sunday 2023-09-03 09:41:49 +0200, Paul B Mahol wrote:
> Decoder formats may not relate to encoder formats, thus this one looks too
> hackish to me to accept.

Agreed, but this is yet another change unrelated to the fix.
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder
  2023-09-03  7:41   ` Paul B Mahol
  2023-09-05 23:48     ` Stefano Sabatini
@ 2023-09-05 23:49     ` Stefano Sabatini
  2023-09-06  0:37       ` Paul B Mahol
  1 sibling, 1 reply; 20+ messages in thread
From: Stefano Sabatini @ 2023-09-05 23:49 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Paul B Mahol

On date Sunday 2023-09-03 09:41:49 +0200, Paul B Mahol wrote:
> Decoder formats may not relate to encoder formats, thus this one looks too
> hackish to me to accept.

Agreed but this is unrelated to the crash fix.
_______________________________________________
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] 20+ messages in thread

* Re: [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder
  2023-09-05 23:49     ` Stefano Sabatini
@ 2023-09-06  0:37       ` Paul B Mahol
  0 siblings, 0 replies; 20+ messages in thread
From: Paul B Mahol @ 2023-09-06  0:37 UTC (permalink / raw)
  To: FFmpeg development discussions and patches, Paul B Mahol

On Wed, Sep 6, 2023 at 1:49 AM Stefano Sabatini <stefasab@gmail.com> wrote:

> On date Sunday 2023-09-03 09:41:49 +0200, Paul B Mahol wrote:
> > Decoder formats may not relate to encoder formats, thus this one looks
> too
> > hackish to me to accept.
>
> Agreed but this is unrelated to the crash fix.
>

And what if decoder ones are empty too?
_______________________________________________
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] 20+ messages in thread

end of thread, other threads:[~2023-09-06  0:29 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
2023-09-03  7:37   ` Paul B Mahol
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 02/11] lavfi/aresample: show time_base information during setup Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 03/11] doc/examples/transcode: apply style fixes Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 04/11] doc/examples/transcode: factorize codec_type definition Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 05/11] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
2023-09-03  7:39   ` Paul B Mahol
2023-09-05 23:18     ` Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 07/11] doc/examples/transcode: introduce timestamp logging Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources Stefano Sabatini
2023-09-03  7:38   ` Paul B Mahol
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 09/11] doc/examples/transcode: fix timestamps scaling Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 10/11] doc/examples/transcode: simplify selection of pix_fmt Stefano Sabatini
2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder Stefano Sabatini
2023-09-03  7:41   ` Paul B Mahol
2023-09-05 23:48     ` Stefano Sabatini
2023-09-05 23:49     ` Stefano Sabatini
2023-09-06  0:37       ` Paul B Mahol

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