Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 13/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding
Date: Wed, 31 May 2023 16:54:43 +0200
Message-ID: <20230531145453.20994-13-anton@khirnov.net> (raw)
In-Reply-To: <20230531145453.20994-1-anton@khirnov.net>

The values currently written into it are not used after
enc_open(), so it is better to confine them to that function.
---
 fftools/ffmpeg_enc.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 5be6e9332a..1b0410ae74 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -214,11 +214,13 @@ int enc_open(OutputStream *ost, AVFrame *frame)
                              av_make_q(1, enc_ctx->sample_rate);
         break;
 
-    case AVMEDIA_TYPE_VIDEO:
-        if (!ost->frame_rate.num)
-            ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter);
-        if (!ost->frame_rate.num && !ost->max_frame_rate.num) {
-            ost->frame_rate = (AVRational){25, 1};
+    case AVMEDIA_TYPE_VIDEO: {
+        AVRational fr = ost->frame_rate;
+
+        if (!fr.num)
+            fr = av_buffersink_get_frame_rate(ost->filter->filter);
+        if (!fr.num && !ost->max_frame_rate.num) {
+            fr = (AVRational){25, 1};
             av_log(ost, AV_LOG_WARNING,
                    "No information "
                    "about the input framerate is available. Falling "
@@ -227,22 +229,22 @@ int enc_open(OutputStream *ost, AVFrame *frame)
         }
 
         if (ost->max_frame_rate.num &&
-            (av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) ||
-            !ost->frame_rate.den))
-            ost->frame_rate = ost->max_frame_rate;
+            (av_q2d(fr) > av_q2d(ost->max_frame_rate) ||
+            !fr.den))
+            fr = ost->max_frame_rate;
 
         if (enc->supported_framerates && !ost->force_fps) {
-            int idx = av_find_nearest_q_idx(ost->frame_rate, enc->supported_framerates);
-            ost->frame_rate = enc->supported_framerates[idx];
+            int idx = av_find_nearest_q_idx(fr, enc->supported_framerates);
+            fr = enc->supported_framerates[idx];
         }
         // reduce frame rate for mpeg4 to be within the spec limits
         if (enc_ctx->codec_id == AV_CODEC_ID_MPEG4) {
-            av_reduce(&ost->frame_rate.num, &ost->frame_rate.den,
-                      ost->frame_rate.num, ost->frame_rate.den, 65535);
+            av_reduce(&fr.num, &fr.den,
+                      fr.num, fr.den, 65535);
         }
 
         enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
-                             av_inv_q(ost->frame_rate);
+                             av_inv_q(fr);
 
         if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
             enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
@@ -277,9 +279,9 @@ int enc_open(OutputStream *ost, AVFrame *frame)
             enc_ctx->chroma_sample_location = frame->chroma_location;
         }
 
-        enc_ctx->framerate = ost->frame_rate;
+        enc_ctx->framerate = fr;
 
-        ost->st->avg_frame_rate = ost->frame_rate;
+        ost->st->avg_frame_rate = fr;
 
         // Field order: autodetection
         if (frame) {
@@ -307,6 +309,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
         }
 
         break;
+        }
     case AVMEDIA_TYPE_SUBTITLE:
         enc_ctx->time_base = AV_TIME_BASE_Q;
         if (!enc_ctx->width) {
-- 
2.40.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".

  parent reply	other threads:[~2023-05-31 14:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 03/23] fftools/ffmpeg_filter: drop a write-only variable Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 04/23] fftools/ffmpeg_filter: drop a block disabled since 2012 Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 05/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 08/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 09/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 11/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate Anton Khirnov
2023-05-31 15:16   ` Paul B Mahol
2023-05-31 14:54 ` Anton Khirnov [this message]
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 14/23] fftools/ffmpeg: convert timestamps inside the muxer Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 15/23] fftools/ffmpeg: factor out attaching FrameData to a frame Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 16/23] fftools/ffmpeg: attach filter framerate to frames Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 18/23] fftools/ffmpeg: simplify handling input -t for streamcopy Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF Anton Khirnov
2023-05-31 21:15   ` Michael Niedermayer
2023-06-03 20:09     ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 21/23] fftools/ffmpeg_mux: simplify calling of_output_packet() Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230531145453.20994-13-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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