Using ffmpeg convert a file from one format to another

Pannu picture Pannu · Nov 10, 2011 · Viewed 25.8k times · Source

I'm new to ffmpeg and I was trying to find out how to convert a audio or video file from one format to another. I don't want to use CLI, I just want to know if I can use ffmpeg as a library and call a function to convert a file from one format to another. I went through the documentation and found functions avcodec_encode_audio and avcodec_encode_video but its not clear how I can use this to convert. A tutorial or an example will be very helpful.

Answer

Jeegar Patel picture Jeegar Patel · Nov 10, 2011

usually i do this by command line

ffmpeg -i input.mp4 -vcodec copy -acodec copy out.mkv

here i/p file is input.mp4 which will be converted into out.mkv with having same codec of all elementary stream

NOTE: upper command will only work when the input.mp4 's all codec will be supported by .mkv container.

and if you are not concern with codec then use

 ffmpeg -i input.mp4 out.mkv

this will convert mp4 to mkv (if necessary it will also change codec of output format)