开发者

How to determine whether or not a video format is supported

I've had to write an application that lists and plays tutorial videos along with accompanying text. It works well but since the videos are added by the user I need a way of checking to see whether or not a video can be played on the machine.

I'm not sure whether or not there is an easy way to try test the file (and catch开发者_运维知识库 errors) or if I need to start looking at codecs installed.

Does anybody have any experience with this?


Easy!

  1. Use FFmpeg, a wildly popular and capable tool, to read the file and output what CODECs are used and what the container format is
  2. Parse the output
  3. Decide if you want to deal with it or not

Example:

stu@manoa:~ $ ffmpeg -i new.avi 
FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
  built on Dec 19 2010 11:41:10 with gcc 4.2.1 (Apple Inc. build 5664)
                   {snip}
Input #0, avi, from 'new.avi':
  Metadata:
    ISFT            : MEncoder Sherpya-SVN-r32735-4.2.5
  Duration: 00:01:49.10, start: 0.000000, bitrate: 1374 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 24 tbr, 24 tbn, 24 tbc
    Stream #0.1: Audio: mp2, 48000 Hz, 2 channels, s16, 128 kb/s
At least one output file must be specified

While the command technically fails, the output is usable for your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜