From 931559407347fa2d8dc5bc13e2e1e9651eb311d7 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 15 Nov 2022 21:35:56 +0100 Subject: [PATCH] =?UTF-8?q?Arreglo=20error=20de=20calcular=20la=20resoluci?= =?UTF-8?q?=C3=B3n=20antes=20de=20fijar=20el=20tama=C3=B1o=20de=20la=20fue?= =?UTF-8?q?nte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleMediaPlayer.Common/MediaPlayer.cs | 2 +- ConsoleMediaPlayer.VideoApp/Program.cs | 3 ++ ConsoleMediaPlayer.VideoApp/VideoPlayer.cs | 55 ++++++++++------------ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/ConsoleMediaPlayer.Common/MediaPlayer.cs b/ConsoleMediaPlayer.Common/MediaPlayer.cs index c185f30..b7c37a1 100644 --- a/ConsoleMediaPlayer.Common/MediaPlayer.cs +++ b/ConsoleMediaPlayer.Common/MediaPlayer.cs @@ -14,13 +14,13 @@ public MediaPlayer(string filePath) if (!File.Exists(filePath)) throw new Exception($"El archivo {filePath} no existe"); FilePath = filePath; + ConsoleHelper.SetCurrentFont(FontSize); } public abstract void Play(); public void ResizeConsoleScreen() { - ConsoleHelper.SetCurrentFont(FontSize); int width = Resolution.Width + MARGIN.Width; int height = Resolution.Height + MARGIN.Height; Console.SetWindowSize(width, height); diff --git a/ConsoleMediaPlayer.VideoApp/Program.cs b/ConsoleMediaPlayer.VideoApp/Program.cs index 9fe2938..3efffc4 100644 --- a/ConsoleMediaPlayer.VideoApp/Program.cs +++ b/ConsoleMediaPlayer.VideoApp/Program.cs @@ -4,6 +4,9 @@ public class Program { public static void Main(string[] args) { + Console.WriteLine(Console.LargestWindowHeight); + Console.WriteLine(Console.LargestWindowWidth); + Console.WriteLine("Introduce ruta de un vídeo:"); string filePath = Console.ReadLine().Replace("\"", ""); diff --git a/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs b/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs index 1eae3f5..55ea3b6 100644 --- a/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs +++ b/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs @@ -16,7 +16,7 @@ public class VideoPlayer : MediaPlayer { private const int DEFAULT_HEIGHT = 250; private const int FPS_LIMIT = 24; - private static string ASCII_PIXEL_TABLE = @"█▓@8#x+o=:-. "; + private const string ASCII_PIXEL_TABLE = @"█▓@8#x+o=:-. "; private ISoundOut _soundOut; @@ -48,7 +48,7 @@ private void ExtractMetadata(int height) private int CalculateBytesPerFrame(int width, int height) { int lineSizeWithoutPadding = width * 3; - int lineSizeWithPadding = (int)Math.Ceiling(lineSizeWithoutPadding / 4f) * 4; + int lineSizeWithPadding = (int)Math.Ceiling(lineSizeWithoutPadding / 4.0) * 4; return 54 + lineSizeWithPadding * height; } @@ -82,9 +82,6 @@ public override async void Play() { Thread.Sleep(TimeSpan.FromTicks(waitTicks)); } - else - { - } } SpinWait.SpinUntil(() => _soundOut.PlaybackState != PlaybackState.Playing); @@ -108,33 +105,31 @@ await FFMpegArguments public async void ExtractFramesAsync() { - using (var stream = new MemoryTributary()) + using Stream stream = new MemoryTributary(); + + await FFMpegArguments + .FromFileInput(FilePath) + .OutputToPipe(new StreamPipeSink(stream), options => options + .ForceFormat("rawvideo") + .WithFramerate(FPS) + .WithVideoCodec("bmp") + .WithCustomArgument("-ss 00:00") + .Resize(Resolution.Width, Resolution.Height) + ).ProcessAsynchronously(); + + stream.Position = 0; + byte[] buffer = new byte[BytesPerFrame]; + Frames.Clear(); + + while (stream.Position < stream.Length) { - await FFMpegArguments - .FromFileInput(FilePath) - .OutputToPipe(new StreamPipeSink(stream), options => options - .ForceFormat("rawvideo") - .WithFramerate(FPS) - .WithVideoCodec("bmp") - .WithCustomArgument("-ss 00:00") - .Resize(Resolution.Width, Resolution.Height) - ).ProcessAsynchronously(); - - stream.Position = 0; - byte[] buffer = new byte[BytesPerFrame]; - Frames.Clear(); - - while (stream.Position < stream.Length) - { - int bytesReaded = stream.Read(buffer, 0, BytesPerFrame); + int bytesReaded = stream.Read(buffer, 0, BytesPerFrame); - using (MemoryStream auxStream = new MemoryStream(buffer, 0, bytesReaded)) - { - auxStream.Position = 0; - Bitmap frame = (Bitmap)Image.FromStream(auxStream); - Frames.Add(RenderFrame(frame)); - } - } + using MemoryStream auxStream = new MemoryStream(buffer, 0, bytesReaded); + + auxStream.Position = 0; + Bitmap frame = (Bitmap)Image.FromStream(auxStream); + Frames.Add(RenderFrame(frame)); } }