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 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description
@ 2023-09-01 23:14 Stefano Sabatini
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 2/6] doc/examples/transcode: apply style fixes Stefano Sabatini
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-01 23:14 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] 9+ messages in thread

* [FFmpeg-devel] [PATCH 2/6] doc/examples/transcode: apply style fixes
  2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
@ 2023-09-01 23:14 ` Stefano Sabatini
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 3/6] doc/examples/transcode: factorize codec_type definition Stefano Sabatini
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-01 23:14 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

---
 doc/examples/transcode.c | 95 +++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 46 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index ed6ac9fa03..9af5674953 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
@@ -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] 9+ messages in thread

* [FFmpeg-devel] [PATCH 3/6] doc/examples/transcode: factorize codec_type definition
  2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 2/6] doc/examples/transcode: apply style fixes Stefano Sabatini
@ 2023-09-01 23:14 ` Stefano Sabatini
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 4/6] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-01 23:14 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 9af5674953..1ec4a3c230 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] 9+ messages in thread

* [FFmpeg-devel] [PATCH 4/6] doc/examples/transcode: improve reporting when the encoder is not found
  2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 2/6] doc/examples/transcode: apply style fixes Stefano Sabatini
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 3/6] doc/examples/transcode: factorize codec_type definition Stefano Sabatini
@ 2023-09-01 23:14 ` Stefano Sabatini
  2023-09-03  7:40   ` Paul B Mahol
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 5/6] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-01 23:14 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 1ec4a3c230..aa6594f4ec 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] 9+ messages in thread

* [FFmpeg-devel] [PATCH 5/6] doc/examples/transcode: use av_buffersrc_add_frame()
  2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
                   ` (2 preceding siblings ...)
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 4/6] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
@ 2023-09-01 23:14 ` Stefano Sabatini
  2023-09-03  7:43   ` Paul B Mahol
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 6/6] doc/examples/transcode: introduce timestamp logging Stefano Sabatini
  2023-09-02 15:22 ` [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
  5 siblings, 1 reply; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-01 23:14 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 aa6594f4ec..b4b2d3c4c9 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] 9+ messages in thread

* [FFmpeg-devel] [PATCH 6/6] doc/examples/transcode: introduce timestamp logging
  2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
                   ` (3 preceding siblings ...)
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 5/6] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
@ 2023-09-01 23:14 ` Stefano Sabatini
  2023-09-02 15:22 ` [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
  5 siblings, 0 replies; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-01 23:14 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

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

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index b4b2d3c4c9..983a8f2845 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,28 @@ 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 dts_time:%s\n",
+           tag, pkt->stream_index, time_base->num, time_base->den,
+           av_ts2timestr(pkt->pts, time_base),
+           av_ts2timestr(pkt->dts, 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 dts_time:%s\n",
+           tag, stream_index, time_base->num, time_base->den,
+           av_ts2timestr(frame->pts, time_base),
+           av_ts2timestr(frame->pkt_dts, time_base));
+}
+
 static int encode_write_frame(unsigned int stream_index, int flush)
 {
     StreamContext *stream = &stream_ctx[stream_index];
@@ -443,16 +466,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 +491,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 +504,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 +517,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 +530,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 +576,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 +594,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 +606,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] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description
  2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
                   ` (4 preceding siblings ...)
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 6/6] doc/examples/transcode: introduce timestamp logging Stefano Sabatini
@ 2023-09-02 15:22 ` Stefano Sabatini
  5 siblings, 0 replies; 9+ messages in thread
From: Stefano Sabatini @ 2023-09-02 15:22 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On date Saturday 2023-09-02 01:14:42 +0200, Stefano Sabatini wrote:
> ---
>  libavcodec/avcodec.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Patchset dropped in favor of version 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] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH 4/6] doc/examples/transcode: improve reporting when the encoder is not found
  2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 4/6] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
@ 2023-09-03  7:40   ` Paul B Mahol
  0 siblings, 0 replies; 9+ messages in thread
From: Paul B Mahol @ 2023-09-03  7:40 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

On Sat, Sep 2, 2023 at 1:15 AM Stefano Sabatini <stefasab@gmail.com> wrote:

> Also return EINVAL in place of INVALIDDATA.
>

Better return also name, id number is meaningless to user.


> ---
>  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 1ec4a3c230..aa6594f4ec 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".
>
_______________________________________________
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] 9+ messages in thread

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

See no real gain in this.
_______________________________________________
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] 9+ messages in thread

end of thread, other threads:[~2023-09-03  7:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01 23:14 [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini
2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 2/6] doc/examples/transcode: apply style fixes Stefano Sabatini
2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 3/6] doc/examples/transcode: factorize codec_type definition Stefano Sabatini
2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 4/6] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini
2023-09-03  7:40   ` Paul B Mahol
2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 5/6] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini
2023-09-03  7:43   ` Paul B Mahol
2023-09-01 23:14 ` [FFmpeg-devel] [PATCH 6/6] doc/examples/transcode: introduce timestamp logging Stefano Sabatini
2023-09-02 15:22 ` [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini

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