90 lines
1.8 KiB
C#
90 lines
1.8 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace MoonWorks.Video
|
|
{
|
|
public unsafe class VideoAV1 : IDisposable
|
|
{
|
|
public IntPtr Handle => handle;
|
|
IntPtr handle;
|
|
|
|
public int Width => width;
|
|
public int Height => height;
|
|
public double FramesPerSecond { get; set; }
|
|
public Dav1dfile.PixelLayout PixelLayout => pixelLayout;
|
|
public int UVWidth { get; }
|
|
public int UVHeight { get; }
|
|
|
|
private int width;
|
|
private int height;
|
|
private Dav1dfile.PixelLayout pixelLayout;
|
|
|
|
bool IsDisposed;
|
|
|
|
public VideoAV1(string filename, double framesPerSecond)
|
|
{
|
|
if (!File.Exists(filename))
|
|
{
|
|
throw new ArgumentException("Video file not found!");
|
|
}
|
|
|
|
if (Dav1dfile.df_fopen(filename, out handle) == 0)
|
|
{
|
|
throw new Exception("Failed to open video file!");
|
|
}
|
|
|
|
Dav1dfile.df_videoinfo(Handle, out width, out height, out pixelLayout);
|
|
|
|
if (pixelLayout == Dav1dfile.PixelLayout.I420)
|
|
{
|
|
UVWidth = Width / 2;
|
|
UVHeight = Height / 2;
|
|
}
|
|
else if (pixelLayout == Dav1dfile.PixelLayout.I422)
|
|
{
|
|
UVWidth = Width / 2;
|
|
UVHeight = Height;
|
|
}
|
|
else if (pixelLayout == Dav1dfile.PixelLayout.I444)
|
|
{
|
|
UVWidth = width;
|
|
UVHeight = height;
|
|
}
|
|
else
|
|
{
|
|
throw new NotSupportedException("Unrecognized YUV format!");
|
|
}
|
|
|
|
FramesPerSecond = framesPerSecond;
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!IsDisposed)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// dispose managed state (managed objects)
|
|
}
|
|
|
|
// free unmanaged resources (unmanaged objects)
|
|
Dav1dfile.df_close(Handle);
|
|
|
|
IsDisposed = true;
|
|
}
|
|
}
|
|
|
|
~VideoAV1()
|
|
{
|
|
Dispose(disposing: false);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
}
|