Esempio n. 1
0
        /// <summary>
        /// Used for encoding frames into a stream (Requires using a supported format like 'flv' for streaming)
        /// </summary>
        /// <param name="destinationStream">Output stream</param>
        /// <param name="width">Input width of the video in pixels</param>
        /// <param name="height">Input height of the video in pixels </param>
        /// <param name="framerate">Input framerate of the video in fps</param>
        /// <param name="encoderOptions">Extra FFmpeg encoding options that will be passed to FFmpeg</param>
        /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param>
        public VideoWriter(Stream destinationStream, int width, int height, double framerate,
                           FFmpegVideoEncoderOptions encoderOptions = null, string ffmpegExecutable = "ffmpeg")
        {
            if (width <= 0 || height <= 0)
            {
                throw new InvalidDataException("Video frame dimensions have to be bigger than 0 pixels!");
            }
            if (framerate <= 0)
            {
                throw new InvalidDataException("Video framerate has to be bigger than 0!");
            }
            if (destinationStream == null)
            {
                throw new NullReferenceException("Stream can't be null!");
            }

            UseFilename = false;

            ffmpeg = ffmpegExecutable;

            Width             = width;
            Height            = height;
            Framerate         = framerate;
            DestinationStream = destinationStream;
            EncoderOptions    = encoderOptions ?? new FFmpegVideoEncoderOptions();
        }
Esempio n. 2
0
        /// <summary>
        /// Used for encoding frames into a new video file
        /// </summary>
        /// <param name="filename">Output video file name/path</param>
        /// <param name="width">Input width of the video in pixels</param>
        /// <param name="height">Input height of the video in pixels </param>
        /// <param name="framerate">Input framerate of the video in fps</param>
        /// <param name="encoderOptions">Extra FFmpeg encoding options that will be passed to FFmpeg</param>
        /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param>
        public VideoWriter(string filename, int width, int height, double framerate,
                           FFmpegVideoEncoderOptions encoderOptions = null, string ffmpegExecutable = "ffmpeg")
        {
            if (width <= 0 || height <= 0)
            {
                throw new InvalidDataException("Video frame dimensions have to be bigger than 0 pixels!");
            }
            if (framerate <= 0)
            {
                throw new InvalidDataException("Video framerate has to be bigger than 0!");
            }
            if (string.IsNullOrEmpty(filename))
            {
                throw new NullReferenceException("Filename can't be null or empty!");
            }

            UseFilename = true;
            Filename    = filename;

            ffmpeg = ffmpegExecutable;

            Width             = width;
            Height            = height;
            Framerate         = framerate;
            DestinationStream = null;
            EncoderOptions    = encoderOptions ?? new FFmpegVideoEncoderOptions();
        }
Esempio n. 3
0
        /// <summary>
        /// Opens output stream for writing and returns both the input and output streams. Make sure to use a streaming format (like flv).
        /// </summary>
        /// <param name="options">Output options</param>
        /// <param name="process">FFmpeg process</param>
        /// <param name="inputArguments">Input arguments (such as -f, -v:c, -video_size,...)</param>
        /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param>
        public static (Stream Input, Stream Output) StreamToStream(FFmpegVideoEncoderOptions options, out Process process,
                                                                   string inputArguments = "", string ffmpegExecutable = "ffmpeg")
        {
            var(input, output) = FFmpegWrapper.Open(ffmpegExecutable, $"{inputArguments} -i - " +
                                                    $"-c:v {options.EncoderName} {options.EncoderArguments} -f {options.Format} -", out process);

            return(input, output);
        }
Esempio n. 4
0
        /// <summary>
        /// Uses input file and returns the output stream. Make sure to use a streaming format (like flv).
        /// </summary>
        /// <param name="inputFilename">Input video file name/path</param>
        /// <param name="options">Output options</param>
        /// <param name="process">FFmpeg process</param>
        /// <param name="inputArguments">Input arguments (such as -f, -v:c, -video_size,...)</param>
        /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param>
        public static Stream FileToStream(string inputFilename, FFmpegVideoEncoderOptions options, out Process process,
                                          string inputArguments = "", string ffmpegExecutable = "ffmpeg")
        {
            var output = FFmpegWrapper.OpenOutput(ffmpegExecutable, $"{inputArguments} -i \"{inputFilename}\" " +
                                                  $"-c:v {options.EncoderName} {options.EncoderArguments} -f {options.Format} -", out process);

            return(output);
        }
Esempio n. 5
0
        /// <summary>
        /// Opens output file for writing and returns the input stream.
        /// </summary>
        /// <param name="outputFilename">Output video file name/path</param>
        /// <param name="options">Output options</param>
        /// <param name="process">FFmpeg process</param>
        /// <param name="inputArguments">Input arguments (such as -f, -v:c, -video_size,...)</param>
        /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param>
        public static Stream StreamToFile(string outputFilename, FFmpegVideoEncoderOptions options, out Process process,
                                          string inputArguments = "", bool showOutput = false, string ffmpegExecutable = "ffmpeg")
        {
            var input = FFmpegWrapper.OpenInput(ffmpegExecutable, $"{inputArguments} -i - " +
                                                $"-c:v {options.EncoderName} {options.EncoderArguments} -f {options.Format} \"{outputFilename}\"", out process, showOutput);

            return(input);
        }
Esempio n. 6
0
        /// <summary>
        /// Converts given input file to output file.
        /// </summary>
        /// <param name="inputFilename">Input video file name/path</param>
        /// <param name="outputFilename">Input video file name/path</param>
        /// <param name="options">Output options</param>
        /// <param name="process">FFmpeg process</param>
        /// <param name="inputArguments">Input arguments (such as -f, -v:c, -video_size,...)</param>
        /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param>
        public static void FileToFile(string inputFilename, string outputFilename, FFmpegVideoEncoderOptions options, out Process process,
                                      string inputArguments = "", bool showOutput = false, string ffmpegExecutable = "ffmpeg")
        {
            var output = FFmpegWrapper.ExecuteCommand(ffmpegExecutable, $"{inputArguments} -i \"{inputFilename}\" " +
                                                      $"-c:v {options.EncoderName} {options.EncoderArguments} -f {options.Format} \"{outputFilename}\"", showOutput);

            process = output;
        }