-1

I've searched without any luck about how this can be done in C#. What i'm trying to archieve is a program that accepts video files and converts them to H.264. Here is an example of a page where you can do this interactively:

http://www.ofoct.com/video-converter/convert-to-h-264-video.html

Question: How can I in .NET create a program that can do something similar to whats being done from that homepage I shared? Any help or input is highly appreciated, thanks!

EDIT: The reason i want to do this is because it seems like videos play in both iOS and Android devices when this is done, perhapps there is another way to make sure videos can play in both iOS and Android?

EDIT again: Lets say i film a Video on a phone Android/iOS, now I'm using a ASP.NET web api that I'd like to convert theese movies to H.264 before storing in Azure, Is this possible? If so, any pointers on how?

Mattias
  • 2,929
  • 5
  • 29
  • 46

4 Answers4

2

There is a wrapper available http://www.ffmpeg-csharp.com/

The main point is that no one is going to write an encoder due to how slow it would be in .NET

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Jamie Rees
  • 7,973
  • 2
  • 45
  • 83
1

The only plausable way would be to call out to an encoding application such as ffmpeg.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Ashigore
  • 4,618
  • 1
  • 19
  • 39
  • That's wrong. Media services are provided by the OS, through Direct X and other services. H.264 is already available – Panagiotis Kanavos Oct 16 '15 at 09:18
  • @PanagiotisKanavos What's wrong? I said the only PLAUSABLE way, not the only way. Media Foundation is extremely complex to use in a managed language and highly platform dependant. The question was about ENCODING not PLAYBACK. – Ashigore Oct 16 '15 at 09:24
  • And that's wrong. Video encoding applications, editors and games were availablei in Windows before ffmpeg. Newer applications don't bundle ffmpeg either. – Panagiotis Kanavos Oct 16 '15 at 09:27
  • @PanagiotisKanavos I clearly said SUCH AS ffmpeg, as an example. There are no encoding applications written in C#, because it would be too SLOW. – Ashigore Oct 16 '15 at 10:41
1

Encoding/decoding are provided by the OS, through Direct Show (in the past) or Microsoft Media Foundation. For example, the Microsoft Media Foundation already contains a [H.264 Video Encoder](H.264 Video Encoder).

The SDK is appropriate for C++ and Microsoft hasn't released a wrapper. There are wrapper projects available though, eg. MF.Net, DirectShow.NET, WindowsMedia.NET although it doesn't have any activity since 2012.

There are also similar questions in StackOverflow, that propose other options, like using Microsoft's Encoder, although H.264 support is available only in the Pro version

Community
  • 1
  • 1
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Just how many files do you have to encode? If you have a lot of files, perhaps using an encoding service like those offered by Amazon and Azure will be cheaper overall than running it locally. On the other hand, if the videos come from a camera, you could probably use other APIs to encode the video directly. – Panagiotis Kanavos Oct 16 '15 at 10:11
  • I'm a beginner of all this, What i've done is that i've created an asp.net web api that lets me upload images from devices to azure blob storage. Now I'd also like to upload video files to azure blob storage. What I've noticed is that the prefered format for theese videos is H.264, which means i need to convert them to it somehow, so my goal is to let the web-api accept a video file and then somehow convert it before uloading and this will happen regularely but only one file at the time. How would you tackle this? – Mattias Oct 16 '15 at 10:27
  • I must ask, when you say, if videos come from camera(which they do) i can encode directly? you mean that the encoding can somehow occour within the device or? and that does mean, when capturing the video or after getting the video – Mattias Oct 16 '15 at 12:21
  • @AkmalSalikhov no because that's *not* .NET's job. For playback, it's the job of the OS's or the browser. For video processing, it's the job of third party libraries. – Panagiotis Kanavos Jun 20 '19 at 15:39
  • Good Explanation. – QMaster Sep 20 '20 at 23:57
0

I'm not sure that this what you need but you can download a nuget called

NR.VideoConverter :> then you can write this code to convert the type of video like from mp4 to mvo or anything I'm not sure what is h264 but I did find it when I wanted to change my videos so it could help y

   var converter = new NReco.VideoConverter.FFMpegConverter();
            converter.ConvertMedia(FilePath, FilePath, NReco.VideoConverter.Format.h264);
Mohamed Fathallah
  • 1,274
  • 1
  • 15
  • 17