aydinadn / mediatoolkit Goto Github PK
View Code? Open in Web Editor NEWA .NET library to convert and process all your video & audio files.
License: MIT License
A .NET library to convert and process all your video & audio files.
License: MIT License
When I change video resolution succeded saving output path. But i try to run file i get File Unresolved error. And this error get some files.
Code
int fps = Convert.ToInt32(input.Metadata.VideoData.Fps > 30 ? 30 : input.Metadata.VideoData.Fps);
int yHeight = 360;
int orjWidth = Convert.ToInt32(input.Metadata.VideoData.FrameSize.Split('x')[0]);
int orjHeight = Convert.ToInt32(input.Metadata.VideoData.FrameSize.Split('x')[1]);
double yuzde = orjHeight / yHeight;
int height = yHeight;
int width = (int)(orjWidth / yuzde);
MediaToolkit.Options.ConversionOptions o = new MediaToolkit.Options.ConversionOptions
{
VideoFps = fps,
CustomHeight = height,
CustomWidth = width,
VideoSize = MediaToolkit.Options.VideoSize.Custom
};
I used this libery file on my MVC Web application and uploaded on Dodaddy.
"Access to the path '\MediaToolkit' is denied." error occour and can't finish converting process.
The converting process is very work when I used at local.
So, somebody help how to fix this error. Thanks all.
hello
i have integrated the toolkit in my asp .net website. but when i run it on a shared hosting server, it gives me an error.
is it possible to convert files on shared hosting?
thanks
raxit
hi i use iis express and VS 2012 asp mvc
help me.
why at engine.GetMetadata(inputFile) exception error "The specified executable is not a valid application for this OS platform"?
my code
var inputFile = new MediaToolkit.Model.MediaFile { Filename = path };
using (var engine = new MediaToolkit.Engine())
{
engine.GetMetadata(inputFile);
}
return inputFile;
webm source files always produce a "System.FormatException" exception (they work fine fine with ffmpeg console).
This is more like an suggestion than an issue:
I would like to be able to handle public Engine.OnError event if an error occurs from FFMpeg.
Currently it is privatly handled in the Engine.FFmpegProcess.ErrorDataReceived but AFAIK it does not notify user about it. Instead, it should invoke the OnError event handler. The user then could log the error and decide if the process should be canceled or ignored.
Since Version=1.1.0.1, I'm receiving this warning while compilation
warning CS1685: The predefined type 'ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'MediaToolkit, Version=1.1.0.1, Culture=neutral, PublicKeyToken=null'
My project is Framework 4.5.2
Hi, I,m suggest thumbnail export function when custom resolution.
follow code :
public class ConversionOptions
{
....
/// <summary>
/// Thumbnailwidth when thumbnail width is set
/// </summary>
public int? thumbnailWidth { get; set; }
/// <summary>
/// Thumbnailheight when thumbnail height is set
/// </summary>
public int? thumbnailHeight { get; set; }
}
and
internal class CommandBuilder
{
....
private static string GetThumbnail(MediaFile inputFile, MediaFile outputFile, ConversionOptions conversionOptions)
{
var commandBuilder = new StringBuilder();
commandBuilder.AppendFormat(CultureInfo.InvariantCulture, " -ss {0} ", conversionOptions.Seek.GetValueOrDefault(TimeSpan.FromSeconds(1)).TotalSeconds);
commandBuilder.AppendFormat(" -i \"{0}\" ", inputFile.Filename);
commandBuilder.AppendFormat(" -vframes {0} ", 1);
// here my code :
if (conversionOptions.thumbnailWidth.HasValue && conversionOptions.thumbnailHeight.HasValue)
if(conversionOptions.thumbnailWidth.Value > 0 && conversionOptions.thumbnailHeight.Value > 0)
commandBuilder.AppendFormat(" -s {0}*{1} ", conversionOptions.thumbnailWidth.Value, conversionOptions.thumbnailHeight.Value);
return commandBuilder.AppendFormat(" \"{0}\" ", outputFile.Filename).ToString();
}
}
thank you.
Hey there. I recently encountered an error when obtaining video metadata using the mediatoolkit. On occasion I'm getting a 'System.FormatException' (Input string was not in a correct format).
The FPS string ffmpeg is spitting out looks like ',1k tbr, 1k tbn....' (looks invalid; tough to deal with). The regex string doesn't like the string format it's being given. The error is happening around line 127 of RegexEngine.cs.
Thanks for the great project
ConvertProgressEventArgs::ProcessedDuration
has a non-zero value but the TotalDuration
always seems to be zero. I am using Engine::CustomCommand
and Engine::ConvertProgressEvent
This is more like an enhancment than an issue.
I would like to be able to see the final and actual FFMpeg command with parameters to pinpoint invalid commands and problems
The actual command could be sent to the output and/or read from the progress/completed event parameter.
This is especially important feature if I am not able to see errors from FFMpeg as all tasks are "completed succesfully" (if ever).
I had problem with the Engine.CustomCommand() not knowing what the method adds extra to my command.
Actually files with ext .AVI after converting don't have video stream, there is only audio. Maybe it will help you to fix this issue - the parameter "-pix_fmt yuv420p" fixes the problem
could you update the library on NuGet?
Hello,
Thanks for such a great wrapper.
Is there any way to implement Stream-to-Stream operations? There are some cases where exporting/importing stuff to/from files is overkill.
For example, this could process data directly from request buffer and serves the thumbnail as it generated.
[HttpPut("video")]
public void video(CancellationToken ct) {
Request.EnableRewind();
Response.Headers["Content-Type"] = "image/png";
using(var engine = new Engine()) {
engine.GetThumbnail(Request.Body, Response.Body, ...);
}
}
There is a Special AudiBitRate "ftlp" in ffmpeg.
RegexEngine.cs Line 155: FormatException of EmptyString To Int32
hi all
i wanted to open webcam and get image/video as bitmap using directShow.
i know its possible with ffmpeg
ffmpeg.exe -f dshow -i video="Webcam C110" out.mp4
Above code opens webcam and saves video to mp4 file.
i didn't find example method using MediaToolkit.
does anybody know how to make this happen?
Thanks
A big improvement, you could add the option to insert a watermark in the videos, from an image. It would be a great help this functionality.
Splitting process become very slow if there is a HD video file having size around 2 GB.
Convert method takes approx 30 seconds or more for one split of Timespan 15 sec.
Hey! First of all let me tell you that I found this wrapper SUPER useful :)
As per the README MaediaToolkit "supports custom FFmpeg command line arguments"
I've been trying to speed up the video (to create a timelapse like one) using this
but I can't find any example of a command line invocation. Having this'd be very useful
can't cut some mp4 video especially video from this link http://www.sample-videos.com/
i try to merge a video merg audio
ffmpeg -i video.mp4 -i audio.mp3 -c copy merged_output.mp4
how can i do it with mediatoolkit c#
when converting MP4 to MP3 itunes song length doubled but windows properties are correct. is this a bitrate issue? thoughts?
`Dim inputFile = New MediaFile(tbOutputFolder.Text + VideoMP4)
Dim outputFile = New MediaFile(tbOutputFolder.Text + AudioMP3)
Using engine = New MediaToolkit.Engine()
engine.Convert(inputFile, outputFile)
End Using`
Thank you very much, the library is very intuitive and easy to use. Is there a way to kill the process once it has been invoked method (engine) .Convert? I tried with .Dispose but the process continues working in background. Thank You
I use this on asp.net mvc. Works correctly localhost. But when i upload the site video is stretch width and height.
Update Nuget package with last release for correct numbers parsing on different locales.
var inputFile = new MediaFile {Filename = @"C:\Path\To_Video.flv"};
var outputFile = new MediaFile {Filename = @"C:\Path\To_Save_ExtractedVideo.flv"};
using (var engine = new Engine())
{
engine.GetMetadata(inputFile);
var options = new ConversionOptions();
// This example will create a 25 second video, starting from the
// 30th second of the original video.
//// First parameter requests the starting frame to cut the media from.
//// Second parameter requests how long to cut the video.
options.CutMedia(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(25));
engine.Convert(inputFile, outputFile, options);
}
The Engine.Dispose() should end or kill the FFMpeg process.
Currently if I close the application by stopping the debugger in the VS the FFMpeg process keeps running. Opening the application and starting a new task will create another FFMPeg process.
Okay maybe it did not had a chance to dispose the Engine but running the program again should kill the previous priocess:
private void EnsureFFmpegIsNotUsed()
{
if (!Document.IsLocked(this.FFmpegFilePath))
return;
try
{
this.Mutex.WaitOne();
EngineBase.KillFFmpegProcesses();
}
finally
{
this.Mutex.ReleaseMutex();
}
}
What if the "Document" is not locked? Then it just create a new instance of the FFMpeg.
Hi,
I'm trying to cut media files, especially ts extension media files.
But there is a problem, when I use the example code sample with 30 and 25 parameters there isn' t any problem, when I change parameters; for example, first parameter 120 and second one is 100 parameters, in this case it create output file with wrong start and end time.
Especially this problem occruing when I write first parameter greater than 55-59
Thank you.
Suggestion:
I would like to be able to cancel currently running task.
Conversions and video file processing could take a long time and in that case it is crusial to be able to cancel current task by a click of a button.
Hi there, i found out that in case of GetThumbnail() the conversion completion event will never trigger.
Its not that hard, but its better if its officially supported.
Any way to stop or pause the encode proccess an resume later.
When I try to convert a video .mpg to an audio .wav, both ConvertProgressEvent and ConversionCompleteEvent events are not fired.
Hello,
when i make thumbnail from video (made by Android or IPhone) in portrait orientation, thumbnail is rotated by 90 degrees.
Is there any posybility to take thumbnail in orientation of video?
Great, Simple, Library. Much appreciated for all your work.
So, I'm not sure this is properly thread safe since, in the constructor for Engine object, it kills any running processes of ffmpeg. If you're currently running a transcoding process and you initiate another instance of Engine in a separate thread, it will kill any existing processes.
Am I missing something?
Hey , i am trying to reduce fps of a video with this code :
var conversionOpt = new ConversionOptions
{
VideoSize = VideoSize.Qvga,
VideoFps = 2,
};
engine.Convert(videoIn, videoOut, conversionOpt);
Changing VideoFps
does not not affect the video .
Can I convert mp3 to mp4? If possible, would you disclose it with a small sample?
Hello,
I notice swf is not in your supported formats - but it is supported by ffmpeg.
I wonder if there is a way to use this to get a thumbnail from swf?
Thanks for your help
This is available using MediaInfo, wondering it that can be extracted using metadata.
Simple suggestion, could it be possible to expose some methods to convert audio files with MemoryStreams or byte arrays ?
Great work on the library, thank you.
How can I convert without re-encoding? (similar to ffmpeg console " -vcodec copy -acodec copy")
Here: https://github.com/AydinAdn/MediaToolkit/blob/master/MediaToolkit%20src/MediaToolkit/Engine.cs#L126
Howebver, ffmpeg supports wildcards, so the input string may not represent 1 file. You could get clever and skip the file exists check if /%[^%]/
or something, but why bother? Just let ffmpeg tell you there was a problem..
But unfortunately, exit code 1, which would inform that, gets treated equal to success, here: https://github.com/AydinAdn/MediaToolkit/blob/master/MediaToolkit%20src/MediaToolkit/Engine.cs#L297
Why not let error code 1 throw an exception?
Hi,
I started to use your library in and it looks great
only one question,
on production the engine create the file "ffmpeg.exe" in "'C:\Windows\TEMP\MediaToolkit", and from security reasons that could be a problem
is there a way to define a specific directory for this file ?
I also tried to copy "ffmpeg.exe" to bin directory, but it didn't work
Suggestion for improvement:
As an user I want to be able to formalise a full FFMpeg command and expect the method to accept everything as it is without adding any additional parameter or conversion.
2nd suggestion:
As an user I would expect the Engine.CustomCommand() to be executed right away or to be added to the task queue for later execution.
It all started when I wanted to cut and merge my video without re-encoding. I have the following commands what I know work well:
ffmpeg -ss 30 -t 60 -i D:\VideoCutting\Sample.avi -c copy -avoid_negative_ts make_zero -fflags +genpts D:\VideoCutting\Segment1.ts
ffmpeg -ss 3600 -t 60 -i D:\VideoCutting\Sample.avi -c copy -avoid_negative_ts make_zero -fflags +genpts D:\VideoCutting\Segment2.ts
ffmpeg -i "concat:D:\VideoCutting\Segment1.ts|D:\VideoCutting\Segment2.ts" -c copy -flags +global_header -fflags +genpts D:\VideoCutting\Merged.mp4
Converted them into two separate CustomCommand. I learned the following:
Did I misunderstood or do something wrong? I apologise if I did.
Having a great time learning more about Media Toolkit! Nice work!
I did have a question regarding the licensing of this library and packaging. The FFMPEG licensing checklist (https://www.ffmpeg.org/legal.html) specifies that the GPL libraries shouldn't be compiled if building a version under the LGPL. But the ffmpeg source readme has the following: "This FFmpeg build was configured with:
--enable-gpl"
There were some other stipulations from the FFMPEG checklist, of course, but does the Media Toolkit library work around this somehow? Software licensing has been kinda an odd thing to me to wrap my head around. Any explanation would be most helpful.
Thank you.
PS
Not sure how many would find this useful but I've found the following helpful in simplifying software licensing: https://tldrlegal.com/
Hi, just one question. why the folder MediaToolkit was not leave on Application StartUp path.
This is my sample code:
Dim engine As MediaToolkit.Engine
engine = New MediaToolkit.Engine
Dim file As New MediaToolkit.Model.MediaFile
file.Filename = "D:\Utils\big_buck_bunny_1080p_surround.mov"
engine.GetMetadata(file)
When i'm use it a folder MediaToolkit was created on my D: drive within it, ffmpeg.
Thanks for your work.
Regards.
Romain.
Example:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=15:15" output-watermark.mp4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.