diff mbox series

[FFmpeg-devel,11/31] fftools/ffmpeg_dec: override video SAR with AVCodecParameters value

Message ID 20240124081702.4759-11-anton@khirnov.net
State Accepted
Commit 924a6f3cc7788e2d258348b1547a49805091ea2d
Headers show
Series [FFmpeg-devel,01/31] fftools/ffmpeg_dec: split Decoder into a private and public part | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 24, 2024, 8:16 a.m. UTC
Rather than access the AVStream one.

This is a step towards decoupling Decoder and InputStream.
---
 fftools/ffmpeg_dec.c   | 9 +++++++--
 fftools/ffmpeg_demux.c | 3 +++
 2 files changed, 10 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer March 24, 2024, 10:09 p.m. UTC | #1
On Wed, Jan 24, 2024 at 09:16:41AM +0100, Anton Khirnov wrote:
> Rather than access the AVStream one.
> 
> This is a step towards decoupling Decoder and InputStream.
> ---
>  fftools/ffmpeg_dec.c   | 9 +++++++--
>  fftools/ffmpeg_demux.c | 3 +++
>  2 files changed, 10 insertions(+), 2 deletions(-)

This breaks

./ffmpeg -i ~/tickets/4161/VR_MOVIE_GuyMartinsSpitfireBcast169\ qsf\ lappyAspectNoChnge_extract.mpg  -vcodec libx264 -an -vsync cfr /tmp/file-16:9.ts

the aspect ratio of the resulting file is completely wrong

https://trac.ffmpeg.org/ticket/4161

thx


[...]
diff mbox series

Patch

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index d16049ab4c..b5a0ce9080 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -42,6 +42,9 @@  typedef struct DecoderPriv {
     AVFrame         *frame;
     AVPacket        *pkt;
 
+    // override output video sample aspect ratio with this value
+    AVRational       sar_override;
+
     enum AVPixelFormat hwaccel_pix_fmt;
 
     // pts/estimated duration of the last decoded frame
@@ -311,8 +314,8 @@  static int video_frame_process(InputStream *ist, AVFrame *frame)
                frame->time_base.num, frame->time_base.den);
     }
 
-    if (ist->st->sample_aspect_ratio.num)
-        frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
+    if (dp->sar_override.num)
+        frame->sample_aspect_ratio = dp->sar_override;
 
     return 0;
 }
@@ -922,6 +925,8 @@  int dec_open(InputStream *ist, Scheduler *sch, unsigned sch_idx,
             return AVERROR(ENOMEM);
     }
 
+    dp->sar_override = ist->par->sample_aspect_ratio;
+
     dp->dec_ctx = avcodec_alloc_context3(codec);
     if (!dp->dec_ctx)
         return AVERROR(ENOMEM);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 11db118b72..a58217223b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1336,6 +1336,9 @@  static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
         return ret;
     }
 
+    if (ist->st->sample_aspect_ratio.num)
+        ist->par->sample_aspect_ratio = ist->st->sample_aspect_ratio;
+
     MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, ic, st);
     if (bsfs) {
         ret = av_bsf_list_parse_str(bsfs, &ds->bsf);