Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
C#
HI, i need code c# to convert video (mp4) to MP3 or WAV >>pleas any answer >>advice >:)
Posted

1 solution

Wrong question. First, video is not converted to audio (what it would even possibly mean?) It's just video files contain several streams, and some of them are video, and some are audio, and you can have some different kinds of streams (subtitles, for example). So, you can first extract some streams for further processing.

This is not the only wrong idea. The term MPEG itself covers both audio and video: https://en.wikipedia.org/wiki/MPEG-4[^].

Next wrong item is: you assume that there is such a definitive thing as "MP4". No. (Surprised?) There is not such thing. The are too many different variations related to the concept of MPEG-4. First of all, there are no just MPEG files. Files are just the media containers which can support some subset of different kinds of streams, supported by different kinds of codecs (perhaps, Matroska media container standard is the only one which is supposed to support nearly everything, it's sometimes referred as to the "king of containers"). Please see:
https://en.wikipedia.org/wiki/Digital_container_format[^],
https://en.wikipedia.org/wiki/Codec[^],
(https://en.wikipedia.org/wiki/Matroska[^]).

I would also like to note that MP3 audio format is pretty much obsolete, and the most used ones are also based on MPEG-4 (such as AAC). However, if you want to prepare audio for your car audio unit, you may need MP3 or WMA. (By my estimate, typical car audio features on new cars are typically obsolete by some 10+ years; it's hard to explain, but probably the reasons are purely cultural factors, such as massive ignorance :-).)

So, you first need to decide what you really need to achieve. Let's not discuss it, because you can do this investigation by yourself; examine your existing files and find out what are they, test the machinery you want to use and find out what is it compatible with. I'll just recommend you the most reliable and universal tool which will cover nearly all problems, just one of the possible solutions, but one of the best one. This is open-source FFMpeg or libav it uses.

http://en.wikipedia.org/wiki/Ffmpeg[^],
http://ffmpeg.org/[^],
http://en.wikipedia.org/wiki/Libavcodec[^],
http://libav.org/[^].

This is the best library and utility set I ever knew. I could be used just by running the available utility (FFmpeg.exe), programmatically or not, using command-line interface.

Optionally, you can embed is as a library. It's apparently possible with C++, as the library is written on C. Same thing if you need .NET functionality: you can still use the unmanaged library, using it in your C++/CLI mixed-mode (managed + unmanaged) project. You can expose just the functionality you need, in managed "ref" classes; then you can use these classes referencing the resulting module as a usual .NET assembly.

With .NET and without C++/CLI, it can be more complex as it would require using P/Invoke. At the same time, you can find appropriate wrapper. Please see:
http://www.ffmpeg-csharp.com/[^],
http://sourceforge.net/projects/sharpffmpeg/[^],
http://vbffmpegwrapper.codeplex.com/[^].

After all, try to find some more: http://bit.ly/VpboUJ[^].

If you wish to work at such wrapper by yourself but don't know how, ask a question, I'll give you the basic ideas (using P/Invoke or C++/CLI "mixed-mode" project).

Good luck,
—SA
 
Share this answer
 
Comments
Matt T Heffron 28-Aug-15 16:57pm    
+5
Sergey Alexandrovich Kryukov 28-Aug-15 16:59pm    
Thank you, Matt.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900