Skip to content

Commit 5c9e834

Browse files
committed
Avoid deprecated pixel format warnings
1 parent f5a0b8f commit 5c9e834

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/NitroSharp/Media/FormatContext.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ internal sealed unsafe class FormatContext : IDisposable
1818
// The delegates must be kept alive for the entire lifetime of the object.
1919
private readonly avio_alloc_context_read_packet _readFunc;
2020
private readonly avio_alloc_context_seek _seekFunc;
21+
private readonly AVCodecContext_get_format _getFormatFunc;
2122
// ReSharper restore PrivateFieldCanBeConvertedToLocalVariable
2223

2324
public FormatContext(Stream stream)
2425
{
2526
_stream = stream;
2627
_readFunc = IoReadPacket;
2728
_seekFunc = IoSeek;
29+
_getFormatFunc = GetFormat;
2830
// Both the buffer and the IO context are freed by avformat_close_input.
2931
byte* ioBuffer = (byte*)ffmpeg.av_malloc(IoBufferSize);
3032
AVIOContext* ioContext = ffmpeg.avio_alloc_context(
@@ -42,6 +44,21 @@ public FormatContext(Stream stream)
4244
CheckResult(ffmpeg.avformat_find_stream_info(ctx, null));
4345
}
4446

47+
private static AVPixelFormat GetFormat(AVCodecContext* s, AVPixelFormat* fmt)
48+
{
49+
int i = 0;
50+
while ((int)fmt[i] != -1)
51+
{
52+
if (fmt[i] == AVPixelFormat.AV_PIX_FMT_YUVJ444P)
53+
{
54+
fmt[i] = AVPixelFormat.AV_PIX_FMT_YUV444P;
55+
}
56+
i++;
57+
}
58+
59+
return ffmpeg.avcodec_default_get_format(s, fmt);
60+
}
61+
4562
public AVFormatContext* Inner => _ctx;
4663
public AVPacket* RecvPacket => _recvPacket;
4764

@@ -52,6 +69,7 @@ public FormatContext(Stream stream)
5269
AVCodec* codec = DecoderCollection.Shared.Get(stream->codecpar->codec_id);
5370
AVCodecContext* codecCtx = ffmpeg.avcodec_alloc_context3(codec);
5471
Debug.Assert(codecCtx is not null);
72+
codecCtx->get_format = _getFormatFunc;
5573
CheckResult(ffmpeg.avcodec_parameters_to_context(codecCtx, stream->codecpar));
5674
CheckResult(ffmpeg.avcodec_open2(codecCtx, codec, null));
5775
return codecCtx;

0 commit comments

Comments
 (0)