Code Monkey home page Code Monkey logo

hudlffmpeg's Introduction

Hudl.FFmpeg

Extendable C# transcoding framework, built on top of FFmpeg. Hudl.FFmpeg helps you

  • Easily interface with FFmpeg in your .NET applications
  • Automate audio and video stream transcoding
  • Create reusable smart filterchain templates

Hudl.FFmpeg is built to work as a compliment to FFmpeg for all .NET applications. Its simplified syntax aids in building complex FFmpeg commands.

Check out the Wiki, or this awesome Blog for more information.

Coming soon

Hudl.FFmpeg for .NET Core, With plans to release by beginning of April 2016.

hudlffmpeg's People

Contributors

ajcf avatar andypryor avatar camtendo avatar casey-bateman avatar insomniacmonkey avatar joelhensley avatar killswtch avatar patrickkalkman avatar rversaw avatar seijikun avatar simonbuehler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hudlffmpeg's Issues

How to use ATrim with Concat?

I have to cut the music and made equal to the length of the video.
I need to join video files and also attach sound to them.

Incorrect filter works concat!

Thank you in advance.

 var commandFactory = CommandFactory.Create();
            var command = commandFactory.CreateOutputCommand();
            var concat = Filterchain.FilterTo<VideoStream>(new Concat(1,1));
            var sar = Filterchain.FilterTo<VideoStream>(new SetSar(new Ratio(1, 1)));

            var sm = Resource.From(inputPath + "2.mp4").LoadMetadata().Streams.OfType<VideoStream>().First().Info;
            var pad = new Pad(new System.Drawing.Size(1920, 1080), new Point(656, 1));
            pad.Color = "black,unsharp";
            var ff = Filterchain.FilterTo<VideoStream>(new Scale(1920, 1080));
            var sf = Filterchain.FilterTo<VideoStream>(new Scale(609, 1080), pad);

var first = command
        .WithInput<VideoStream>(inputPath + "1.mp4")
        .Filter(ff)
        .Filter(sar);       

    var a0 = command
        .WithInput<AudioStream>(inputPath + "1.mp3")
        .Filter(Filterchain.FilterTo<AudioStream>(
            new ATrim(null, 10, AudioUnitType.Seconds)
        )
        );

var second = command
    .WithInput<VideoStream>(inputPath + "2.mp4")
    .Filter(sf)
    .Filter(sar) ;

var a1 = command
        .WithInput<AudioStream>(inputPath + "2.mp3")
        .Filter(Filterchain.FilterTo<AudioStream>(
            new ATrim(null, 20, AudioUnitType.Seconds)
        )
        );
command
    .Select(first.StreamIdentifiers)
    .Select(a0.StreamIdentifiers)
    .Select(second.StreamIdentifiers)
    .Select(a1.StreamIdentifiers)
    .Filter(concat)            
    .MapTo<Mp4>(inputPath +
    inte +
    "1080.mp4", outputSettings);

command.Render();

Incorrect filter works.

 -i "path/1.mp4" -i "path/1.mp3" -i "path/2.mp4" -i "path/2.mp3" -filter_complex " [0:v]scale=w=1920:h=1080 [mpd1c8f485]; [mpd1c8f485] setsar=sar=1/1 [mp2bdbd193]; [1:a] atrim=end=10 [mpf8d320cb]; [2:v] scale=w=609:h=1080,pad=w=1920:h=1080:x=656:y=1:color=black,unsharp [mpb59b3366]; [mpb59b3366] setsar=sar=1/1 [mp69075c65]; [3:a] atrim=end=20 [mpd2b74d0a]; [mp2bdbd193] [mpf8d320cb] [mp69075c65] [mpd2b74d0a] concat=n=4:a=1 [mpeb0035ff]" -s 1920x1080 -map [mpeb0035ff] "path/6982857521080.mp4"

Correct filter works.

 -i "path/1.mp4" -i "path/1.mp3" -i "path/2.mp4" -i "path/2.mp3" -filter_complex " [0:v]scale=w=1920:h=1080 [mpd1c8f485]; [mpd1c8f485] setsar=sar=1/1 [mp2bdbd193]; [1:a] atrim=end=10 [mpf8d320cb]; [2:v] scale=w=609:h=1080,pad=w=1920:h=1080:x=656:y=1:color=black,unsharp [mpb59b3366]; [mpb59b3366] setsar=sar=1/1 [mp69075c65]; [3:a] atrim=end=20 [mpd2b74d0a]; [mp2bdbd193] [mpf8d320cb] [mp69075c65] [mpd2b74d0a] concat=n=2:a=1 [mpeb0035ff] [audio]" -s 1920x1080 -map [mpeb0035ff] -map [audio] "path/6982857521080.mp4"

error messages returned by Ffmpeg/Fprobe are always swallowed

Reproducing:

  • corrupt sample video file HudlFfmpeg\Samples\Assets\sample-video.mp4 by inserting couple of spaces at the beggining of it in text editor
  • start (in Visual Studio) Samples app and select [2] - ConcatVideo

Observed:
Exception is thrown with message in innermost exception "FFmpeg failed processing with an exit code of 1"

Expected:
Exception with message "Invalid data found when processing input"

Reason:
<...>.ProcessIt methods running ffmpeg/fprobe redirect only stdout, they don't redirect stderr at all but Ffmpeg prints errors (and even not errors, but statistics, header etc. - everything) into stderr

Advice how clean error message without any junk can be retrieved:
Run ffmpeg.exe with args -loglevel error -hide_banner -nostats

Only Validate Filterparameter if no default value is given

Hi,

it seems to be not possible to define a Filterparameter like this:

        [FilterParameter(Name = "lx", Default = 5)]
        [Validate(LogicalOperators.GreaterThanOrEqual, 3)]
        [Validate(LogicalOperators.LesserThanOrEqual, 63)]

if lx is not set, it throws an error (0 not allowed) but should use the Default (5) instead and Validate tue.

How can i fix this?

Blend opacity

I'm trying to blend 2 videos together, but do not see any type of support for all_opacity. Am I overlooking something here? Basically I want to overlay 1 video ontop of another and i want the top video to be semi-transparent. Any tips?

Space missing between settings

Space is not being added between settings, leading to the end of one setting being 'stuck' to the start of the next. I've made a potential fix by chaning line 184 of FFmpegCommandBuilder.cs to output.Settings.SettingsList.ForEach(setting => BuilderBase.AppendFormat(" {0}", SettingSerializer.Serialize(setting))); but I'm not certain that this is the correct place to introduce the space character. I'm also having difficulties with Git at the moment, so haven't committed.

Progress reporting and cancellation

I can't see a way to get progress information out of an ffmpeg run. Some of these operations are long running. It would be very useful to get progress and have the ability to cancel a currently running process.

Any way to use the Concat demuxer?

Hi,

is there a simple way to add support for the Concat demuxer?
This would need to generate a temp file somewhere and looks like its not yet doable ? It would safe a lot of time on reencoding though...

Any ideas?

Raw data as InputStream

Is it possible to use raw data without a container (like pcm for raw audio) as input at the moment?
What I got:

var commandFactory = CommandFactory.Create();
var cmd = commandFactory.CreateOutputCommand();
var inSettings = SettingsCollection.ForInput(new FormatInput("u16le"), new SampleRate(44100));
var mp3Settings = SettingsCollection.ForOutput(new BitRateAudio(Hudl.FFmpeg.Enums.AudioBitRateType.Mp3Cd));

cmd.AddInput("input.raw", inSettings);
cmd.To<Mp3>(mp3Settings);
commandFactory.Render();

But, obviously, since the file extension is not registered, I get a:

System.InvalidOperationException: Cannot derive resource type from path provided.
  at Hudl.FFmpeg.Resources.Resource.From (System.String filePath, System.String fileName) [0x0007d] in HudlFfmpeg/Hudl.Ffmpeg/Resources/Resource.cs:95 
  at Hudl.FFmpeg.Resources.Resource.From (System.String fullPath) [0x00011] in HudlFfmpeg/Hudl.Ffmpeg/Resources/Resource.cs:75 
  at Hudl.FFmpeg.Sugar.FFmpegCommandExtensions.AddInput (Hudl.FFmpeg.Command.FFmpegCommand command, System.String fileName, Hudl.FFmpeg.Settings.BaseTypes.SettingsCollection settings) [0x00009] in HudlFfmpeg/Hudl.Ffmpeg/Sugar/FfmpegCommandExtensions.cs:42

Loop doesnt break in Helpers.BreakStreamIdentifiers(maximumInputs, streamIds);

hi,

following setup leads to an endless loop and memory exception in Helpers.BreakStreamIdentifiers(maximumInputs, streamIds);

   ResourceManagement.CommandConfiguration = CommandConfiguration.Create(outputPath, FFmpegPath, FFprobePath);

            var outputSettings = SettingsCollection.ForOutput(
                new OverwriteOutput(),
                new CodecVideo(VideoCodecType.Libx264),
                new BitRateVideo(3000),
                new BitRateTolerance(3000),
                new FrameRate(30),
                new AspectRatio(new Ratio(1, 1))
                );
            var commandFactory = CommandFactory.Create();

            var filterchain = Filterchain.FilterTo<VideoStream>(new SetSar(new Ratio(1, 1)));


            commandFactory.CreateOutputCommand()
                .WithInput<VideoStream>(@"C:\tmp\%04d.png")
                .Filter(filterchain)
                .WithInput<VideoStream>(@"C:\tmp\%04d.png")
                .Filter(filterchain)
                .Filter(new Dissolve(1))
                .MapTo<Mp4>(@"c:\tmp\bar.mp4", outputSettings);

            commandFactory.Render();

how can i fix this ?

Missing audio output when using filters

I'm conditionally constructing the command object with settings and filters indirectly defined by the user. Filters are optionally applied, but when they are the audio is stripped from the video because -filter_complex requires that audio be explicitly included in a separate -map command if it's not included in the filters. I can't find a way to add the -map command for audio. I've only got one input and one output, and the filters are relatively simple, so how can I get audio into the output from the input file?

Here's a slightly simplified version of what I'm doing at the moment. settingsList is a List<ISetting> which may contain codecs, frame rate, output duration, format, quality etc.

var outputSettings = SettingsCollection.ForOutput(settingsList.ToArray());

var videoFilterList = new List<IFilter>();

if (resizeSettings.ContentScale != 1f)
{
    videoFilterList.Add(new Scale(resizeSettings.ContentRect.Width, resizeSettings.ContentRect.Height));

    if (resizeSettings.Crop)
        videoFilterList.Add(new Crop(resizeSettings.CropRect.Size.Width, resizeSettings.CropRect.Size.Height, resizeSettings.CropRect.Location.X, resizeSettings.CropRect.Location.Y));

    if (resizeSettings.Pad)
    {
        int expectedOutputHeight = sourceHeight * (resizeSettings.OutputSize.Width / sourceWidth);
        var padFilter = new Pad(new System.Drawing.Size(resizeSettings.OutputSize.Width, resizeSettings.OutputSize.Height), new System.Drawing.Point(Math.Max(0, (int)(resizeSettings.OutputSize.Width - (sourceWidth * resizeSettings.ContentScale)) / 2), Math.Max(0, (int)(resizeSettings.OutputSize.Height - (sourceHeight * resizeSettings.ContentScale)) / 2)));
        if (backgroundColor != null)
            padFilter.Color = ToHexString(backgroundColor.Value);

        videoFilterList.Add(padFilter);
    }
}

var commandFactory = CommandFactory.Create();
CommandStage command = null;

if (inputSettingsList.Count > 0)
    command = commandFactory.CreateOutputCommand().WithInput<VideoStream>(tempFile.FullName, SettingsCollection.ForInput(inputSettingsList.ToArray()));
else
    command = commandFactory.CreateOutputCommand().WithInput<VideoStream>(tempFile.FullName);

if (videoFilterList.Count > 0)
{
    command = command.Filter(Filterchain.FilterTo<VideoStream>(videoFilterList.ToArray()));
}

Guid outputFileID = Guid.NewGuid();
string outputTempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), String.Format("{0}.mp4", outputFileID));

List<CommandOutput> output = command.MapTo<Mp4>(outputTempFilePath, outputSettings); 

var result = commandFactory.Render();

Here is an example of the command currently being sent to ffmpeg:
-i "C:/Users/simon.smith/AppData/Local/Temp/b820e6bf-ded8-46cb-a734-89c60addc5a4.flv" -filter_complex " [0:v] scale=w=800:h=450 [mpf48d96de]" -s 800x450 -c:v libvpx -c:a libvorbis -crf 10 -map [mpf48d96de] "C:/Users/simon.smith/AppData/Local/Temp/2bb4f849-74c0-4317-9c71-41762eab7f4c.webm"

Which audio encoders/decoders are included in this library

Firstly I would like to save great library. I have been searching for a proper ffmpeg library for weeks. I'm a newb to this all so I was wondering which codecs are supported by default ffmpeg. I know the library sits on top of the pre existing ffmpeg instance however I'm still not clear on how to determine what's available and how to install additional codecs. I am planning to work with mp4 and possibly mp3 audio files. I am interested in trimming them, merging them and also increasing their respective volumes. Thanks for your help.

CHANGELOG

This project needs a maintained changelog. The current tag releases don't provide any context for outside devs to know how a new version will affect them.

Can i load video data from memory stream?

I apologize if this is answered or not appropriate for this section.

I can't find a way of using binary data as input. Know it's possible in ffmpeg.

I'm trying to get videos from the web and then take specific frames.

How to convert both audio and video streams

Hi:

I have a video in H.263 format. Audio stream including in the container is in AMR format.
I need to convert these in H.264 and AAC format.

If I use ffmpeg command line I can do this
ffmpeg -i c:\videos\input\inh263.mp4 -vcodec h264 -f mp4 c:\videos\output\outh264.mp4

The resulting video is H264 and audio is AAC.

Can you provide an example for how to do the same conversion using your API?

Thanks

.MTS files

I used the "getting started" documentation to write a simple method to encode a .MTS file to MP4, and it's failing with the exception: Cannot derive resource type from path provided. It appears as though the only files that it will process are those with a Resources class: Mov, MP4, TS, WMV etc. To process any other file format, do you have to create a class for each file type? If so, there are a bunch of types missing, and the list changes frequently. When I added a class for .MTS, I didn't get this error, but instead got this one: "FFmpeg encountered an exception while attempting to render the file." Any suggestions?

parsing of floating point numbers in ffprobe output

when using the library on a system with different number format (semicolon as decimal separator and full stop as group separator), parsing of duration attribute fails.

SerializeAsFFprobeDouble could use

double.TryParse(ffprobeObject.Value.ToString(), NumberStyles.Number, CultureInfo.InvariantCulture, out value)

instead of

double.TryParse(ffprobeObject.Value.ToString(), out value)

decode h264 stream

Is it possible to decode stream of bytes encoded in H264_ES with this wrapper?

How should I format paths?

I cannot get sample code to run, I just get a file not found exception.

In part of your documentation you use forward slashes, in other you use a single backslash (which causes an invalid escape character error for me). I have tried also with double backslashes but I am always getting a "The system cannot find the file specified" excaption.

Here is my complete code but I have tried the paths several different ways:

            var outputPath = @"E:\\Videos\\prospecting\\output";
            var FFmpegPath = @"E:\\Program Files\\ffmpeg\\binFFmpeg.exe";
            var FFprobePath = @"E:\\Program Files\\ffmpeg\\FFprobe.exe";

            ResourceManagement.CommandConfiguration = CommandConfiguration.Create(outputPath, FFmpegPath, FFprobePath);

            var filterchain = Filterchain.FilterTo<VideoStream>(new Concat());

            var outputSettings = SettingsCollection.ForOutput(new CodecVideo("libx264"));

            var commandFactory = CommandFactory.Create();

            commandFactory.CreateOutputCommand()
                          .WithInput<VideoStream>(@"c:\\Users\\mikey\\Videos\\part2-proper.mp4")
                          .WithInput<VideoStream>(@"E:\\Videos\\prospecting\\New Video Saved Folder\\2001 Travel.mp4")
                          .Filter(filterchain)
                          .MapTo<Mp4>(@"E:\\Videos\\prospecting\\output\\joined.mp4", outputSettings);

            commandFactory.Render();

Constructing a complex filtergraph

I am having a little trouble understanding how to construct a complex filtergraph.

If I wanted to represent the following filtergraph in Hudl, how would I do it?

[0:v]trim=0:5,setpts=PTS-STARTPTS[firstpart];[0:v]trim=start=5,setpts=PTS-STARTPTS[secondpart];[firstpart]setpts=PTS*2[first];[secondpart]setpts=PTS*0.5[second];[first][second]concat=n=2:v=1

I tried

    private void Test()
    {
        var commandFactory = CommandFactory.Create();
        var outputSettings = SettingsCollection.ForOutput(new CodecVideo("libx264"));

        var concat = Filterchain.FilterTo<VideoStream>(new Concat());

        commandFactory.CreateOutputCommand()
            .WithInput<VideoStream>(InputVideo)
            .Filter(CreateSegmentFilterChain(0, 5, 2))
            .Filter(CreateSegmentFilterChain(5, null, 0.5f))
            .Filter(concat)
            .MapTo<Mp4>(OutputVideo, outputSettings);

        commandFactory.Render();

    }

    private Filterchain CreateSegmentFilterChain(double start, double? end, float ratio)
    {
        var filters = new IFilter[]
        {
            new Trim(start, end, VideoUnitType.Seconds),
            new SetPts(SetPtsExpressionType.ResetTimestamp),
            new SetPts("PTS*" + ratio.ToString("0.####"))
        };

        var chain = Filterchain.FilterTo<VideoStream>(filters);
        return chain;
    }

But the FilterChain blows up with a InvalidOperationException due to the fact that there are two SetPts commands in the same chain.

Can you show me a example of how to make a filtergraph like the one in my original example? There is no example of it on the wiki that I can find.

One Source to multiple outputs

This looks like a really interesting project. I am attempting to write a hudl command with a single input file and several separate output videos with different sizes and settings to render concurrently but am not able to figure out how to accomplish this in your sugar syntax.

Any help would be appreciated.

regards,
Bob

MetadataInfo class is not testable

While attempting to write some unit tests in another project, I came across the need to construct a MetadataInfo object. Unfortunately, its constructor is private and its Create methods are internal.

Ideally, I would like to be able to mock this class like any other "dumb" model. My larger goal here is to mock VideoStream and AudioStream objects that have particular metadata properties, that I can use in unit tests for methods that perform sanity checks against these streams.

I could certainly submit a PR to make the constructor and Create properties more accessible, but I'm not sure that's the best approach here, and was hoping to start some discussion around it.

Streaming support (streaming output)

I would like to use your library to stream content to rtmp server, but if I'm not mistaken, currently only file based outputs are supported. I'm thinking about implementing a custom IContainer implementation to prevent extension validation and use UriBuilder to build output url.

Can you share any hints or suggestions before I dive in?

Many thanks!

Is there a maintainer for this project?

I would like to know if this project is still being developed, otherwise I will work on a fork of this and continue its development with the limited knowledge of programming that I have. At least for some things that are still missing, such as subtitle support and showing the conversion progress.

Best regards

Video/Audio Concat

Hello i'm trying to concat two mp4 files, both contain video/audio stream. After some search i've found a working solution:

var commandFactory = CommandFactory.Create();
var command = commandFactory
.CreateOutputCommand()
.AddInput(@"c:\temp\vvv1.mp4")
.AddInput(@"c:\temp\\vvv2.mp4");

var videoConcat = command
.Select<VideoStream>(0)
.Select<VideoStream>(1)
.Filter(Filterchain.FilterTo<VideoStream>(new Concat()));

var audioConcat = command
.Select<AudioStream>(0)
.Select<AudioStream>(1)
.Filter(Filterchain.FilterTo<AudioStream>(new Concat(1, 0)));

command.Select(videoConcat, audioConcat)
.MapTo<Mp4>(@"c:\temp\output.mp4", SettingsCollection.ForOutput(new OverwriteOutput()));
commandFactory.Render();

Is there a way to do it in a single stage?

How to limit the cpu usage

hi,

how can I limit the CPU used by the ffmpeg process, or how can I run the process with lesser priority, currently it is running with max cpu, I am just curious how this will be dealt with

CrossfadeConcatenate referenced in RenderTests

The filter chain template CrossfadeConcatenate is referenced in Hudl.FFmpeg.Tests.Render.RenderTests, but that class no longer exists. It appears that it has been replaced with the Dissolve class, in which case the reference needs updating. Cannot build in DEBUG configuration until resolved.

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.