From 65930aedcc26f4df39fa938ef5a522d70d603dff Mon Sep 17 00:00:00 2001 From: "gabor.zavarko" Date: Sun, 18 Jan 2026 21:59:00 +0100 Subject: [PATCH] upgrade to ffmpeg 8 --- .../Unosquare.FFME.Windows.Sample.csproj | 2 +- Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj | 2 +- Unosquare.FFME/Container/MediaContainer.cs | 6 ++++-- Unosquare.FFME/Container/MediaFrame.cs | 5 +---- Unosquare.FFME/Container/VideoComponent.cs | 10 ++++------ 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Unosquare.FFME.Windows.Sample/Unosquare.FFME.Windows.Sample.csproj b/Unosquare.FFME.Windows.Sample/Unosquare.FFME.Windows.Sample.csproj index cc487ef7..98a72ae3 100644 --- a/Unosquare.FFME.Windows.Sample/Unosquare.FFME.Windows.Sample.csproj +++ b/Unosquare.FFME.Windows.Sample/Unosquare.FFME.Windows.Sample.csproj @@ -72,7 +72,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj b/Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj index 657a2a99..85e92758 100644 --- a/Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj +++ b/Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj @@ -78,7 +78,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Unosquare.FFME/Container/MediaContainer.cs b/Unosquare.FFME/Container/MediaContainer.cs index c490fe3a..e1984c70 100644 --- a/Unosquare.FFME/Container/MediaContainer.cs +++ b/Unosquare.FFME/Container/MediaContainer.cs @@ -719,7 +719,7 @@ private void StreamInitialize() } } - ffmpeg.av_format_inject_global_side_data(InputContext); + // ffmpeg.av_format_inject_global_side_data(InputContext); // This is useful for file formats with no headers such as MPEG. This function also computes // the real frame-rate in case of MPEG-2 repeat frame mode. @@ -822,7 +822,7 @@ private void StreamInitializeInputContext() // InputContext->flags |= opts.FlagKeepSideData ? ffmpeg.AVFMT_FLAG_KEEP_SIDE_DATA : InputContext->flags; InputContext->flags |= opts.FlagNoBuffer ? ffmpeg.AVFMT_FLAG_NOBUFFER : InputContext->flags; InputContext->flags |= opts.FlagSortDts ? ffmpeg.AVFMT_FLAG_SORT_DTS : InputContext->flags; - InputContext->flags |= opts.FlagStopAtShortest ? ffmpeg.AVFMT_FLAG_SHORTEST : InputContext->flags; + ////InputContext->flags |= opts.FlagStopAtShortest ? ffmpeg.AVFMT_FLAG_SHORTEST : InputContext->flags; InputContext->seek2any = opts.SeekToAny ? 1 : 0; @@ -998,6 +998,8 @@ private MediaType StreamRead() if (Data.TryHandleDataPacket(this, readPacket)) return MediaType.None; + readPacket.Pointer->opaque = (void*)readPacket.Pointer->size; + var componentType = Components.SendPacket(readPacket); // Discard the packet -- it was not accepted by any component diff --git a/Unosquare.FFME/Container/MediaFrame.cs b/Unosquare.FFME/Container/MediaFrame.cs index b8184143..0d55c49f 100644 --- a/Unosquare.FFME/Container/MediaFrame.cs +++ b/Unosquare.FFME/Container/MediaFrame.cs @@ -25,10 +25,7 @@ internal abstract unsafe class MediaFrame : IComparable, IDisposable protected MediaFrame(AVFrame* pointer, MediaComponent component, MediaType mediaType) : this((void*)pointer, component, mediaType) { -#pragma warning disable CS0618 // Type or member is obsolete - var packetSize = pointer->pkt_size; -#pragma warning restore CS0618 // Type or member is obsolete - CompressedSize = packetSize > 0 ? packetSize : 0; + CompressedSize = (int)pointer->opaque; PresentationTime = pointer->pts; DecodingTime = pointer->pkt_dts; } diff --git a/Unosquare.FFME/Container/VideoComponent.cs b/Unosquare.FFME/Container/VideoComponent.cs index 42a14ac7..6e1b0ff4 100644 --- a/Unosquare.FFME/Container/VideoComponent.cs +++ b/Unosquare.FFME/Container/VideoComponent.cs @@ -66,10 +66,8 @@ internal VideoComponent(MediaContainer container, int streamIndex) FrameHeight = CodecContext->height; // Retrieve Matrix Rotation -#pragma warning disable CS0618 // Type or member is obsolete - var displayMatrixRef = ffmpeg.av_stream_get_side_data(Stream, AVPacketSideDataType.AV_PKT_DATA_DISPLAYMATRIX, null); -#pragma warning restore CS0618 // Type or member is obsolete - DisplayRotation = ComputeRotation(displayMatrixRef); + var displayMatrixRef = ffmpeg.av_packet_side_data_get(Stream->codecpar->coded_side_data, Stream->codecpar->nb_coded_side_data, AVPacketSideDataType.AV_PKT_DATA_DISPLAYMATRIX); + DisplayRotation = displayMatrixRef == null ? 0 : ComputeRotation(displayMatrixRef->data); var aspectRatio = ffmpeg.av_d2q((double)FrameWidth / FrameHeight, int.MaxValue); DisplayAspectWidth = aspectRatio.num; @@ -89,7 +87,7 @@ internal VideoComponent(MediaContainer container, int streamIndex) /// Point / nearest-neighbor is the default and it is the cheapest. This is by design as /// we don't change the dimensions of the image. We only do color conversion. /// - public static int ScalerFlags { get; internal set; } = ffmpeg.SWS_POINT; + public static SwsFlags ScalerFlags { get; internal set; } = SwsFlags.SWS_POINT; /// /// Gets the base frame rate as reported by the stream component. @@ -223,7 +221,7 @@ public override bool MaterializeFrame(MediaFrame input, ref MediaBlock output, M source.Pointer->width, source.Pointer->height, Constants.VideoPixelFormat, - ScalerFlags, + (int)ScalerFlags, null, null, null);