From 72507f2e2f627b00674b777517d08a4c490718c4 Mon Sep 17 00:00:00 2001 From: Speykious Date: Fri, 17 Dec 2021 12:30:18 +0100 Subject: [PATCH 1/3] Yeet `avformat_find_stream_info()` call --- SeeShark/FFmpeg/VideoStreamDecoder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SeeShark/FFmpeg/VideoStreamDecoder.cs b/SeeShark/FFmpeg/VideoStreamDecoder.cs index 5b0a0c6..01c460c 100644 --- a/SeeShark/FFmpeg/VideoStreamDecoder.cs +++ b/SeeShark/FFmpeg/VideoStreamDecoder.cs @@ -38,7 +38,6 @@ public VideoStreamDecoder(string url, AVInputFormat* inputFormat = null) var formatContext = FormatContext; ffmpeg.avformat_open_input(&formatContext, url, inputFormat, null).ThrowExceptionIfError(); - ffmpeg.avformat_find_stream_info(formatContext, null).ThrowExceptionIfError(); AVCodec* codec = null; StreamIndex = ffmpeg From 494f72b894274cc6b4f52a090e489ffa084efd22 Mon Sep 17 00:00:00 2001 From: Speykious Date: Fri, 17 Dec 2021 12:45:22 +0100 Subject: [PATCH 2/3] Do not create a converter until a new frame is available --- SeeShark.Example.Ascii/Program.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SeeShark.Example.Ascii/Program.cs b/SeeShark.Example.Ascii/Program.cs index 3b8c27f..2fad256 100644 --- a/SeeShark.Example.Ascii/Program.cs +++ b/SeeShark.Example.Ascii/Program.cs @@ -121,6 +121,10 @@ static void Main(string[] args) /// public static void OnFrameEventHandler(object? _sender, FrameEventArgs e) { + // Don't redraw the frame if it's not new, unless it's resized. + if (e.Status != FFmpeg.DecodeStatus.NewFrame) + return; + var frame = e.Frame; if (converter == null || Console.WindowWidth != converter.SrcWidth || Console.WindowHeight != converter.SrcHeight) @@ -130,11 +134,6 @@ public static void OnFrameEventHandler(object? _sender, FrameEventArgs e) converter?.Dispose(); converter = new FrameConverter(frame, Console.WindowWidth, Console.WindowHeight, PixelFormat.Gray8); } - else if (e.Status != FFmpeg.DecodeStatus.NewFrame) - { - // Don't redraw the frame if it's not new, unless it's resized. - return; - } // Resize the frame to the size of the terminal window, then draw it in ASCII. Frame cFrame = converter.Convert(frame); From d2e32e815d4db1fe720f71e9a28c93511f61f4a6 Mon Sep 17 00:00:00 2001 From: Speykious Date: Fri, 17 Dec 2021 12:49:56 +0100 Subject: [PATCH 3/3] Do not accept zero for src/dst Width/Height --- SeeShark/FrameConverter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SeeShark/FrameConverter.cs b/SeeShark/FrameConverter.cs index 9cc1a9e..ae2441c 100644 --- a/SeeShark/FrameConverter.cs +++ b/SeeShark/FrameConverter.cs @@ -57,6 +57,9 @@ public FrameConverter( int srcWidth, int srcHeight, PixelFormat srcPixelFormat, int dstWidth, int dstHeight, PixelFormat dstPixelFormat) { + if (srcWidth == 0 || srcHeight == 0 || dstWidth == 0 || dstHeight == 0) + throw new ArgumentException("Source/Destination's Width/Height cannot be zero"); + SrcWidth = srcWidth; SrcHeight = srcHeight; DstWidth = dstWidth;