2010-05-19 64 views
10

如果我的電視DVD播放機不是Divx或xvid(DX50,即不可讀),那麼我經常會遇到讀取AVI文件的問題。如何使用ffmpeg識別文件的視頻編解碼器

我想製作一個快速腳本來識別這些文件的視頻編解碼器,然後刻錄到CDROM/DVD上。

的命令:

ffmpeg -i file.avi 

得到視頻流(MPEG4,MPEG2等)的 「容器」,而不是編解碼器。

任何提示?

謝謝

+0

無法重現。 ffmpeg-0.5-5.20091026svn.fc12.x86_64 – 2010-05-20 04:32:06

回答

2

FFmpeg也提供編解碼器。拉Stream #0.0: Video線,你可以看到編解碼器。 (請注意,它在技術上可能有不同的流號碼,如0.1。)下面的輸出使用MS Video-1。這是不同的,就像你的願望,從通過Input #0, avi

例如: - 所表示的容器

FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al. 
    configuration: --prefix=/opt/local --disable-vhook --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libfaac --enable-libfaad --enable-libxvid --enable-libx264 --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64 
    libavutil  49.15. 0/49.15. 0 
    libavcodec 52.20. 0/52.20. 0 
    libavformat 52.31. 0/52.31. 0 
    libavdevice 52. 1. 0/52. 1. 0 
    libavfilter 1. 4. 0/1. 4. 0 
    libswscale  1. 7. 1/1. 7. 1 
    libpostproc 51. 2. 0/51. 2. 0 
    built on Jan 8 2010 15:34:15, gcc: 4.2.1 (Apple Inc. build 5646) (dot 1) 
Input #0, avi, from 'Movies/fvss_demo.avi': 
    Duration: 00:02:00.30, start: 0.000000, bitrate: 719 kb/s 
    Stream #0.0: Video: msvideo1, rgb555, 160x120, 10 tbr, 10 tbn, 10 tbc 
    Stream #0.1: Audio: pcm_u8, 8000 Hz, mono, s16, 64 kb/s 
At least one output file must be specified 
manoa:~ stu$ 
2

嘗試MediaInfo代替。

它列出了每個流的編解碼器,並且其輸出足夠簡單,可以解析 - 如果您喜歡XPath查詢,還有一個XML輸出選項。

20

的MediaInfo

mediainfo --Inform="Video;%Codec%" video.mkv 

將我的情況下返回:

V_MPEG4/ISO/AVC 

答案應歸功於 How to find duration of a video file using mediainfo in seconds or other formats?

ffprobe(ffmpeg)來簡單的方法

假設你的視頻有一個僅限視頻流:

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name \ 
    -of default=noprint_wrappers=1:nokey=1 video.mkv 

將在我的情況下回報:

h264 

答案應歸功於How to get video duration in seconds?

ffprobe(ffmpeg)來骯髒的方式

這種方法比較容易理解,但凌亂。

要獲取編解碼器信息而不播放文件,請使用ffprobe

$ ffprobe video.mkv 
[...] 
Input #0, matroska,webm, from 'video.mkv': 
    Metadata: 
    ENCODER   : Lavf56.25.101 
    Duration: 00:28:05.15, start: 0.000000, bitrate: 4353 kb/s 
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 1280x960, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default) 
    Metadata: 
     ENCODER   : Lavc56.26.100 libx264 
    Stream #0:1: Audio: vorbis, 48000 Hz, stereo, fltp (default) 
    Metadata: 
     ENCODER   : Lavc56.26.100 libvorbis 

要提取的視頻編解碼器的信息 - 因爲ffmpeg的將信息發送到stderr - pipe和grep它:

$ ffprobe video.mkv 2>&1 >/dev/null | grep Stream.*Video 
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 1280x960, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)

爲了進一步減少這一點,推出SED:

$ ffprobe video.mkv 2>&1 >/dev/null |grep Stream.*Video | sed -e 's/.*Video: //' -e 's/[, ].*//' 
h264
+2

您也可以使用-show_streams(和其他相關選項),而不是使用有點模糊和不穩定的sed/grep選項。 「ffprobe $ file -show_streams | grep^codec_name =」將提供編解碼器輸出,但是採用更向前兼容的方法。 – 2015-04-14 00:24:14

0

的ffmpeg有它。在Mac上我就是這麼做的:

先下載ffmpeg的是這樣的:

brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools 

,然後在命令行中運行以下命令:

ffmpeg -filter:v idet \ 
    -frames:v 100 \ 
    -an \ 
    -f rawvideo -y /dev/null \ 
    -i ~/Downloads/yourfile.mp4 

然後檢查輸出是這樣的:

時間:00:00:05.48,啓動:0.000000,比特率:952 kb/s的 流#0:0(ENG):視頻:H264( Main)(avc1/0x31637661),yuv420p(tv,bt709),750x1334,619 kb/s,29.97 fps,29.97 tbr,30k tbn,59.94 tbc(默認)

相關問題