Giter Club home page Giter Club logo

ffmpegsharp's Introduction

FFMpegSharp

FFMpeg Sharp

FFMpegSharp is a great way to use FFMpeg encoding when writing video applications, client-side and server-side. It has wrapper methods that allow conversion to all web formats: MP4, OGV, TS and methods of capturing screens from the videos.

Getting started

Setup your app config (ffmpeg files can be found in the 'Resources' folder):

  <appSettings>
    <add key="ffmpegRoot" value="C:\ffmpeg\bin\" />
  </appSettings>

FFProbe

FFProbe is used to gather video information

static void Main(string[] args)
        {
            string inputFile = "G:\\input.mp4";
            
            // loaded from configuration
            var video = new VideoInfo(inputFile);

            string output = video.ToString();

            Console.WriteLine(output);
        }

Sample output:

        Video Path : G:\input.mp4
        Video Root : G:\\
        Video Name: input.mp4
        Video Extension : .mp4
        Video Duration : 00:00:09
        Audio Format : none
        Video Format : h264
        Aspect Ratio : 16:9
        Framerate : 30fps
        Resolution : 1280x720
        Size : 2.88 Mb

FFMpeg

Convert your video files to web ready formats:

	static void Main(string[] args)
	{
		string inputFile = "input_path_goes_here";
		FileInfo outputFile = new FileInfo("output_path_goes_here");

		var video = VideoInfo.FromPath(inputFile);
				
		// easily track conversion progress
		video.OnConversionProgress += video_OnConversionProgress;

		// input and output strings are required
		// all other parameters are optional
		video.ConvertTo(VideoType.Mp4, outputFile, Speed.UltraFast,
			VideoSize.Original,
			AudioQuality.Hd, 
			true, 
			false);
		video.ConvertTo(VideoType.Ogv, outputFile, Speed.UltraFast,
			VideoSize.Original,
			AudioQuality.Hd,
			true,
			false);
		video.ConvertTo(VideoType.Ts, outputFile, Speed.UltraFast,
			VideoSize.Original,
			AudioQuality.Hd,
			true,
			false);
	}

	static void video_OnConversionProgress(double percentage)
	{
		Console.WriteLine("Progress {0}%", percentage);
	}

Easily capture screens from your videos:

static void Main(string[] args)
        {
            string inputFile = "input_path_goes_here";
            FileInfo output = new FileInfo("output_path_goes_here");

            var video = VideoInfo.FromPath(inputFile);

            video.Snapshot(output, new Size(200, 400), TimeSpan.FromMinutes(1));
        }

Join video parts:

static void Main(string[] args)
        {
            FFMpeg encoder = new FFMpeg();

            encoder.Join(new FileInfo(@"..\joined_video.mp4"), 
                VideoInfo.FromPath(@"..\part1.mp4"),
                VideoInfo.FromPath(@"..\part2.mp4"),
                VideoInfo.FromPath(@"..\part3.mp4"));
        }

Strip audio track from videos:

static void Main(string[] args)
        {
            string inputFile = "input_path_goes_here",
                   outputFile = "output_path_goes_here";
            
            VideoInfo.FromPath(inputFile).Mute(new FileInfo(outputFile));
        }

Save audio track from video:

static void Main(string[] args)
        {
            string inputVideoFile = "input_path_goes_here",
                   outputAudioFile = "output_path_goes_here";
                        
            VideoInfo.FromPath(inputVideoFile).ExtractAudio(new FileInfo(outputAudioFile));
        }

Add audio track to video:

static void Main(string[] args)
        {
            string inputVideoFile = "input_path_goes_here",
                   inputAudioFile = "input_path_goes_here",
                   outputVideoFile = "output_path_goes_here";

            FFMpeg encoder = new FFMpeg();

            VideoInfo.FromPath(inputVideoFile).ReplaceAudio(new FileInfo(inputAudioFile), new FileInfo(outputVideoFile));
        }

Add poster image to audio file (good for youtube videos):

static void Main(string[] args)
        {
            string inputImageFile = "input_path_goes_here",
                   inputAudioFile = "input_path_goes_here",
                   outputVideoFile = "output_path_goes_here";

            FFMpeg encoder = new FFMpeg();

            var image = (Bitmap)Image.FromFile(inputImageFile);
            image.AddAudio(new FileInfo(inputAudioFile), new FileInfo(outputVideoFile);
        }

Control over the 'FFmpeg' process doing the job:

static void Main(string[] args)
        {
            string inputVideoFile = "input_path_goes_here",
                   outputVideoFile = "input_path_goes_here";

            FFMpeg encoder = new FFMpeg();

            // start the conversion process
            Task.Run(() => {
                encoder.ToMp4(new VideoInfo(inputVideoFile), new FileInfo(outputVideoFile));
            });

            // stop encoding after 2 seconds (only for example purposes)
            Thread.Sleep(2000);
            encoder.Stop();
        }

Video Size enumeration:

public enum VideoSize
    {
        HD,
        FullHD,
        ED,
        LD,
        Original
    }

Speed enumeration:

public enum Speed
    {
        VerySlow,
        Slower,
        Slow,
        Medium,
        Fast,
        Faster,
        VeryFast,
        SuperFast,
        UltraFast
    }

ffmpegsharp's People

Contributors

vladjerca avatar

Watchers

James Cloos avatar DVD avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.