/// <summary> /// Creates an empty FFmpeg format container for encoding. /// </summary> /// <param name="path">A output file path. It is used only to guess the container format.</param> /// <returns>A new instance of the <see cref="OutputContainer"/>.</returns> /// <remarks>Before you write frames to the container, you must call the <see cref="CreateFile(string)"/> method to create an ouput file.</remarks> public static OutputContainer Create(string path) { MediaToolkit.LoadFFmpeg(); if (!Path.HasExtension(path)) { throw new ArgumentException("The file path has no extension."); } var format = ffmpeg.av_guess_format(null, path, null); if (format == null) { throw new NotSupportedException($"Cannot find a container format for the \"{Path.GetExtension(path)}\" file extension."); } var formatContext = ffmpeg.avformat_alloc_context(); formatContext->oformat = format; return(new OutputContainer(formatContext)); }
/// <summary> /// Opens a media container and stream codecs from given path. /// </summary> /// <param name="path">A path to the multimedia file.</param> /// <param name="options">The media settings.</param> /// <returns>A new instance of the <see cref="InputContainer"/> class.</returns> public static InputContainer LoadFile(string path, MediaOptions options) { MediaToolkit.LoadFFmpeg(); var context = ffmpeg.avformat_alloc_context(); options.DemuxerOptions.ApplyFlags(context); var dict = new FFDictionary(options.DemuxerOptions.PrivateOptions); var ptr = dict.Pointer; ffmpeg.avformat_open_input(&context, path, null, &ptr) .ThrowIfError("An error ocurred while opening the file"); ffmpeg.avformat_find_stream_info(context, null) .ThrowIfError("Cannot find stream info"); dict.Update(ptr); var container = new InputContainer(context); container.OpenStreams(options); return(container); }