Ok, I get the basics of video format - there are some container formats and then you have core video/audio formats. I would like to write a web based application that determines what video/audio codec a file is using.
How best can I programmatically determine a video codec? Would it be best to use a standard library via system calls and parse its output? (eg ffmpeg, transcode, etc?)
Which file format is my video file? On Mac, right-click the video file and click “Get Info”, then under “More Info” you should see both the video and audio codec. On Windows, right-click the file and click “Properties”. Under the “Details” tab you will see the file format and codecs used.
To determine what codec was used with a specific file, play the file in the Player, if possible. While the file is playing, right-click the file in the library, and then select Properties. On the File tab, look at the Audio codec and Video codec sections. Use a non-Microsoft codec identification tool.
You may need to right-click the video title and select Play with VLC Media Player, if VLC is not your default video player. Once the video starts, select Tools > Codec Information. Here, you'll see the codec for the video.
MP4 is a popular container today, as it supports several of the most-used codecs and is broadly supported. The original MPEG-4 Part 1 file format was introduced in 1999; the version 2 format, defined in Part 14, was added in 2003.
mplayer -identify
will do the trick. Just calling ffmpeg
on a file will also work--it will automatically print a set of info at the start about the input file regardless of what you're telling ffmpeg to actually do.
Of course, if you want to do it from your program without an exec call to an external program, you can just include the avcodec libraries and run its own identify routine directly.
While you could implement your own detection, it will surely be inferior to existing routines given the absolutely enormous number of formats that libav* supports. And it would be a rather silly case of reinventing the wheel.
Linux's "file" command can also do the trick, but the amount of data it prints out depends on the video format. For example, on AVI it gives all sorts of data about resolution, FOURCC, fps, etc, while for an MKV file it just says "Matroska data," telling you nothing about the internals, or even the video and audio formats used.
I have used FFMPEG in a perl script to achieve this.
$info = `ffmpeg -i $path$file 2>&1 /dev/null`;
@fields = split(/\n/, $info);
And just find out what items in @fields you need to extract.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With