ZZMpeg 1.0.4

FFMpeg transcoding wrapper for .NET

Install-Package ZZMpeg -Version 1.0.4
dotnet add package ZZMpeg --version 1.0.4
<PackageReference Include="ZZMpeg" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZZMpeg --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ZZMpeg - highlevel wrapper for FFMpeg libraries (not ffmpeg binary) for WPF.
Basic usage:

  1. Create an object FFMpeg
  2. Call FFMpeg.ExtractVideoFrame to get preview image from video
  3. Call FFMpeg.ConvertMediaFile to asynchronously convert video to other format
  4. Call FFMpeg.AssembleMediaFiles to asynchronously concat multiple input files into single output. They are concatinated in the same order they are specified in inputFiles array
  5. Call FFMpeg.SplitMediaFile to asynchronously split source media file into specified number of lesser files of equal duartion
  6. Call FFmpeg.SplitMediaFileWithTS to asynchronously split source media file into several lesser files based on specified timestamps array
  7. Call FFMpeg.ExtractMediaInfo to get media info from file
  8. Call CreateVideoFromImages to asynchronously create video from images files
  9. Call SetOutputLogFileFromPath to set output log file

Example converting video:

public class ConvertOperation: INotifyPropertyChanged
{

 public enum ConvertionState
{
    Idle,
    Converting,
    Cancelling,
    Cancelled,
    Error,
    Done
}

    #region INPC implementation

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void NotifyPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    #endregion

    private string path;
    private string format;
    private string destPath;
    private CancellationTokenSource cTokenSource;
    private ConvertionState state;

    public string Name => Path.GetFileName(path);
    public BindableProgress<double> Progress { get; private set; }

    public ConvertionState State
    {
        get => state;
        set
        {
            state = value;
            NotifyPropertyChanged("State");
        }
    }

    public ConvertOperation(string filePath,string destPath, string destFormat)
    {
        path = filePath;
        this.destPath = destPath;
        format = destFormat;
        Progress = new BindableProgress<double>();
        cTokenSource = new CancellationTokenSource();
        State = ConvertionState.Idle;
    }

    public async Task Start()
    {
        State = ConvertionState.Converting;
        string outPath = Path.Combine(destPath, $"converted_{Path.GetFileNameWithoutExtension(path)}.{format}");

        try
        {
            using (var ffmpeg = new FFMpeg())
            {
                ffmpeg.EncoderParametersInit(out EncoderParameters parameters);
                parameters.AudioEncoder = AudioCodec.AAC.StringValue();
                await ffmpeg.ConvertMediaFile(path, outPath, parameters, Progress, cTokenSource.Token);;
                State = ConvertionState.Done;
            }
        }
        catch(TaskCanceledException)
        {
            State = ConvertionState.Cancelled;
        }
        catch(Exception ex)
        {
            State = ConvertionState.Error;
            Console.WriteLine($"Error converting file: {ex.Message}");
            MessageBox.Show($"Error converting file: {ex.Message}");
        }
    }

    public void Cancel()
    {
        if (State != ConvertionState.Converting)
            return;
        State = ConvertionState.Cancelling;
        cTokenSource.Cancel();
    }
}

ZZMpeg - highlevel wrapper for FFMpeg libraries (not ffmpeg binary) for WPF.
Basic usage:

  1. Create an object FFMpeg
  2. Call FFMpeg.ExtractVideoFrame to get preview image from video
  3. Call FFMpeg.ConvertMediaFile to asynchronously convert video to other format
  4. Call FFMpeg.AssembleMediaFiles to asynchronously concat multiple input files into single output. They are concatinated in the same order they are specified in inputFiles array
  5. Call FFMpeg.SplitMediaFile to asynchronously split source media file into specified number of lesser files of equal duartion
  6. Call FFmpeg.SplitMediaFileWithTS to asynchronously split source media file into several lesser files based on specified timestamps array
  7. Call FFMpeg.ExtractMediaInfo to get media info from file
  8. Call CreateVideoFromImages to asynchronously create video from images files
  9. Call SetOutputLogFileFromPath to set output log file

Example converting video:

public class ConvertOperation: INotifyPropertyChanged
{

 public enum ConvertionState
{
    Idle,
    Converting,
    Cancelling,
    Cancelled,
    Error,
    Done
}

    #region INPC implementation

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void NotifyPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    #endregion

    private string path;
    private string format;
    private string destPath;
    private CancellationTokenSource cTokenSource;
    private ConvertionState state;

    public string Name => Path.GetFileName(path);
    public BindableProgress<double> Progress { get; private set; }

    public ConvertionState State
    {
        get => state;
        set
        {
            state = value;
            NotifyPropertyChanged("State");
        }
    }

    public ConvertOperation(string filePath,string destPath, string destFormat)
    {
        path = filePath;
        this.destPath = destPath;
        format = destFormat;
        Progress = new BindableProgress<double>();
        cTokenSource = new CancellationTokenSource();
        State = ConvertionState.Idle;
    }

    public async Task Start()
    {
        State = ConvertionState.Converting;
        string outPath = Path.Combine(destPath, $"converted_{Path.GetFileNameWithoutExtension(path)}.{format}");

        try
        {
            using (var ffmpeg = new FFMpeg())
            {
                ffmpeg.EncoderParametersInit(out EncoderParameters parameters);
                parameters.AudioEncoder = AudioCodec.AAC.StringValue();
                await ffmpeg.ConvertMediaFile(path, outPath, parameters, Progress, cTokenSource.Token);;
                State = ConvertionState.Done;
            }
        }
        catch(TaskCanceledException)
        {
            State = ConvertionState.Cancelled;
        }
        catch(Exception ex)
        {
            State = ConvertionState.Error;
            Console.WriteLine($"Error converting file: {ex.Message}");
            MessageBox.Show($"Error converting file: {ex.Message}");
        }
    }

    public void Cancel()
    {
        if (State != ConvertionState.Converting)
            return;
        State = ConvertionState.Cancelling;
        cTokenSource.Cancel();
    }
}

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.4 177 9/26/2018
1.0.3 379 2/1/2018
1.0.2 253 12/14/2017