Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added simple universal UncompressedVideoEncoder. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions SharpAvi/Codecs/FlipUncompressedVideoEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Diagnostics.Contracts;

namespace SharpAvi.Codecs
{
/// <summary>
/// Flip bitmap vertically without compression (from top-down to bottom-up).
/// </summary>
public class UniversalUncompressedVideoEncoder : IVideoEncoder
{
private readonly int _width;
private readonly int _height;
private readonly BitsPerPixel _bitsPerPixel;
private readonly int _bytesPerPixel;


public UniversalUncompressedVideoEncoder(int width, int height, BitsPerPixel bitsPerPixel)
{
Contract.Requires(width > 0);
Contract.Requires(height > 0);

_width = width;
_height = height;
_bitsPerPixel = bitsPerPixel;
_bytesPerPixel = (int)bitsPerPixel / 8;
}

#region IVideoEncoder Members

/// <summary>Video codec.</summary>
public FourCC Codec
{
get { return KnownFourCCs.Codecs.Uncompressed; }
}

/// <summary>
/// Number of bits per pixel in encoded image.
/// </summary>
public BitsPerPixel BitsPerPixel
{
get { return _bitsPerPixel; }
}

/// <summary>
/// Maximum size of encoded frame.
/// </summary>
public int MaxEncodedSize
{
get { return _width * _height * _bytesPerPixel; }
}

/// <summary>
/// Encodes a frame.
/// </summary>
/// <seealso cref="IVideoEncoder.EncodeFrame"/>
public int EncodeFrame(byte[] source, int srcOffset, byte[] destination, int destOffset, out bool isKeyFrame)
{
BitmapUtils.FlipVertical(source, srcOffset, destination, destOffset, _height, _width * _bytesPerPixel);
isKeyFrame = true;
return MaxEncodedSize;
}

#endregion
}
}
1 change: 1 addition & 0 deletions SharpAvi/SharpAvi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<Compile Include="AudioFormats.cs" />
<Compile Include="Codecs\CodecInfo.cs" />
<Compile Include="Codecs\EncodingStreamFactory.cs" />
<Compile Include="Codecs\FlipUncompressedVideoEncoder.cs" />
<Compile Include="Codecs\IAudioEncoder.cs" />
<Compile Include="Codecs\Mp3AudioEncoderLame.cs" />
<Compile Include="Codecs\Mp3AudioEncoderLame.ILameFacade.cs" />
Expand Down