Skip to content

Commit

Permalink
Arreglo error de calcular la resolución antes de fijar el tamaño de l…
Browse files Browse the repository at this point in the history
…a fuente
  • Loading branch information
josago97 committed Nov 15, 2022
1 parent 4b6f9d1 commit 9315594
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ConsoleMediaPlayer.Common/MediaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ConsoleMediaPlayer.VideoApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("\"", "");

Expand Down
55 changes: 25 additions & 30 deletions ConsoleMediaPlayer.VideoApp/VideoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -82,9 +82,6 @@ public override async void Play()
{
Thread.Sleep(TimeSpan.FromTicks(waitTicks));
}
else
{
}
}

SpinWait.SpinUntil(() => _soundOut.PlaybackState != PlaybackState.Playing);
Expand All @@ -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));
}
}

Expand Down

0 comments on commit 9315594

Please sign in to comment.