# Video encoding

Media Blocks SDK .Net

Video encoding is the process of converting raw video data into a compressed format. This process is essential for reducing the size of video files, making them easier to store and stream over the internet. VisioForge Media Blocks SDK provides a wide range of video encoders that support various formats and codecs.

For some video encoders, SDK can use GPU acceleration to speed up the encoding process. This feature is especially useful when working with high-resolution video files or when encoding multiple videos simultaneously.

NVidia, Intel, and AMD GPUs are supported for hardware acceleration.

# AV1 encoder

AV1 (AOMedia Video 1): Developed by the Alliance for Open Media, AV1 is an open, royalty-free video coding format designed for video transmissions over the Internet. It is known for its high compression efficiency and better quality at lower bit rates compared to its predecessors, making it well-suited for high-resolution video streaming applications.

Use classes that implement the IAV1EncoderSettings interface to set the parameters.

# Settings

# AOMAV1EncoderSettings

AOM AV1 encoder settings. CPU encoder.

Platforms: Windows, Linux, macOS.

# QSVAV1EncoderSettings

Intel GPU AV1 video encoder.

Platforms: Windows, Linux, macOS.

# RAV1EEncoderSettings

RAV1E AV1 encoder settings.

Platforms: Windows, Linux, macOS.

# Block info

Name: AV1EncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output AV1 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->AV1EncoderBlock;
    AV1EncoderBlock-->MP4SinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var videoEncoderBlock = new AV1EncoderBlock(new QSVAV1EncoderSettings());
pipeline.Connect(fileSource.VideoOutput, videoEncoderBlock.Input);

var mp4SinkBlock = new MP4SinkBlock(new MP4SinkSettings(@"output.mp4"));
pipeline.Connect(videoEncoderBlock.Output, mp4SinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux, iOS, Android.

# DV encoder

DV (Digital Video): A format for storing digital video introduced in the 1990s, primarily used in consumer digital camcorders. DV employs intra-frame compression to deliver high-quality video on digital tapes, making it suitable for home videos as well as semi-professional productions.

# Block info

Name: DVEncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output video/x-dv 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->DVEncoderBlock;
    DVEncoderBlock-->AVISinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var videoEncoderBlock = new DVEncoderBlock(new DVVideoEncoderSettings());
pipeline.Connect(fileSource.VideoOutput, videoEncoderBlock.Input);

var sinkBlock = new AVISinkBlock(new AVISinkSettings(@"output.avi"));
pipeline.Connect(videoEncoderBlock.Output, sinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux, iOS, Android.

# H264 encoder

The H264 encoder block is used for encoding files in MP4, MKV, and some other formats, as well as for network streaming using RTSP and HLS.

Use classes that implement the IH264EncoderSettings interface to set the parameters.

# Settings

# NVENCH264EncoderSettings

Nvidia GPUs H264 video encoder.

Platforms: Windows, Linux, macOS.

# AMFHEVCEncoderSettings

AMD/ATI GPUs H264 video encoder.

Platforms: Windows, Linux, macOS.

# QSVH264EncoderSettings

Intel GPU H264 video encoder.

Platforms: Windows, Linux, macOS.

# OpenH264EncoderSettings

Software CPU H264 encoder.

Platforms: Windows, macOS, Linux, iOS, Android.

# Block info

Name: H264EncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output H264 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->H264EncoderBlock;
    H264EncoderBlock-->MP4SinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var h264EncoderBlock = new H264EncoderBlock(new NVENCH264EncoderSettings());
pipeline.Connect(fileSource.VideoOutput, h264EncoderBlock.Input);

var mp4SinkBlock = new MP4SinkBlock(new MP4SinkSettings(@"output.mp4"));
pipeline.Connect(h264EncoderBlock.Output, mp4SinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Sample applications

# Platforms

Windows, macOS, Linux, iOS, Android.

# HEVC/H265 encoder

HEVC encoder is used for encoding files in MP4, MKV, and some other formats, as well as for network streaming using RTSP and HLS.

Use classes that implement the IHEVCEncoderSettings interface to set the parameters.

# Settings

# MFHEVCEncoderSettings

Microsoft Media Foundation HEVC encoder. CPU encoder.

Platforms: Windows.

# NVENCHEVCEncoderSettings

Nvidia GPUs HEVC video encoder.

Platforms: Windows, Linux, macOS.

# AMFHEVCEncoderSettings

AMD/ATI GPUs HEVC video encoder.

Platforms: Windows, Linux, macOS.

# QSVHEVCEncoderSettings

Intel GPU HEVC video encoder.

Platforms: Windows, Linux, macOS.

# Block info

Name: HEVCEncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output HEVC 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->HEVCEncoderBlock;
    HEVCEncoderBlock-->MP4SinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var hevcEncoderBlock = new HEVCEncoderBlock(new NVENCHEVCEncoderSettings());
pipeline.Connect(fileSource.VideoOutput, hevcEncoderBlock.Input);

var mp4SinkBlock = new MP4SinkBlock(new MP4SinkSettings(@"output.mp4"));
pipeline.Connect(hevcEncoderBlock.Output, mp4SinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux, iOS, Android.

# MJPEG encoder

MJPEG (Motion JPEG): A video compression format where each frame of video is separately compressed into a JPEG image. This technique is straightforward and results in no interframe compression, making it ideal for situations where frame-specific editing or access is required, such as in surveillance and medical imaging. Use classes that implement the IH264EncoderSettings interface to set the parameters.

# Settings

# MJPEGEncoderSettings

Default MJPEG encoder. CPU encoder.

Platforms: Windows, Linux, macOS, iOS, Android.

# QSVMJPEGEncoderSettings

Intel GPUs MJPEG encoder.

Platforms: Windows, Linux, macOS.

# Block info

Name: MJPEGEncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output MJPEG 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->MJPEGEncoderBlock;
    MJPEGEncoderBlock-->AVISinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var videoEncoderBlock = new MJPEGEncoderBlock(new MJPEGEncoderSettings());
pipeline.Connect(fileSource.VideoOutput, videoEncoderBlock.Input);

var aviSinkBlock = new AVISinkBlock(new AVISinkSettings(@"output.avi"));
pipeline.Connect(videoEncoderBlock.Output, aviSinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux, iOS, Android.

# Theora encoder

The Theora encoder is used to encode video files in WebM format.

# Block info

Name: TheoraEncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output video/x-theora 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->TheoraEncoderBlock;
    TheoraEncoderBlock-->WebMSinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var theoraEncoderBlock = new TheoraEncoderBlock(new TheoraEncoderSettings());
pipeline.Connect(fileSource.VideoOutput, theoraEncoderBlock.Input);

var webmSinkBlock = new WebMSinkBlock(new WebMSinkSettings(@"output.webm"));
pipeline.Connect(theoraEncoderBlock.Output, webmSinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux, iOS, Android.

# VPX encoder

VPX encoder block is used to encode files in WebM, MKV, or OGG files. VPX encoder is a set of video codecs for encoding in VP8 and VP9 formats.

Use classes that implement the IVPXEncoderSettings interface to set the parameters.

# Settings

# VP8EncoderSettings

VP8 CPU encoder.

# VP9EncoderSettings

VP9 CPU encoder.

# Block info

Name: VPXEncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output VP8/VP9 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->VPXEncoderBlock;
    VPXEncoderBlock-->WebMSinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var vp8EncoderBlock = new VPXEncoderBlock(new VP8EncoderSettings());
pipeline.Connect(fileSource.VideoOutput, vp8EncoderBlock.Input);

var webmSinkBlock = new WebMSinkBlock(new WebMSinkSettings(@"output.webm"));
pipeline.Connect(vp8EncoderBlock.Output, webmSinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux, iOS, Android.

# WMV encoder

# Overview

WMV encoder block encodes video in WMV format.

# Block info

Name: WMVEncoderBlock.

Pin direction Media type Pins count
Input Uncompressed video 1
Output video/x-wmv 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->WMVEncoderBlock;
    WMVEncoderBlock-->ASFSinkBlock;

# Sample code

var pipeline = new MediaBlocksPipeline(false);

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var wmvEncoderBlock = new WMVEncoderBlock(new WMVEncoderSettings());
pipeline.Connect(fileSource.VideoOutput, wmvEncoderBlock.Input);

var asfSinkBlock = new ASFSinkBlock(new ASFSinkSettings(@"output.wmv"));
pipeline.Connect(wmvEncoderBlock.Output, asfSinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));

await pipeline.StartAsync();

# Platforms

Windows, macOS, Linux.