如何使用FFmpeg确定文件的视频编解码器 [英] How to determine video codec of a file with FFmpeg
问题描述
如果我的电视DVD播放器不是DivX或Xvid(例如,DX50不可读),我通常会在用其DVD播放器读取AVI文件时遇到问题.
我想制作一个快速脚本来确定这些文件的视频编解码器,然后再将它们刻录到CD-ROM或DVD.
命令
ffmpeg -i file.avi
打印视频流(mpeg4,mpeg2等)的容器",而不是编解码器.
有任何提示吗?
谢谢
mediainfo
mediainfo --Inform="Video;%Codec%" video.mkv
在我的情况下,
将返回:
V_MPEG4/ISO/AVC
如何使用以秒为单位或其他格式的mediainfo查找视频文件的持续时间? >
ffprobe(ffmpeg)简单方法
假设您的视频只有一个视频流:
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name \
-of default=noprint_wrappers=1:nokey=1 video.mkv
在我的情况下会退货:
h264
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-管道并对其进行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
I often have problems reading AVI files with my TV's DVD player if they are not DivX or Xvid (e.g., DX50 is not readable).
I'd like to make a fast script to determine the video codec of these files before burning them to CD-ROM or DVD.
The command
ffmpeg -i file.avi
prints the "container" of the video stream (mpeg4, mpeg2, etc), not the codec.
Any hint?
Thanks
mediainfo
mediainfo --Inform="Video;%Codec%" video.mkv
will in my case return:
V_MPEG4/ISO/AVC
Answer made possible thanks to How to find duration of a video file using mediainfo in seconds or other formats?
ffprobe (ffmpeg) easy way
Assuming your video has one video stream only:
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name \
-of default=noprint_wrappers=1:nokey=1 video.mkv
Will in my case return:
h264
Answer made possible thanks to How to get video duration in seconds?
ffprobe (ffmpeg) dirty way
This method is easier to understand but messy.
To get the codec information without playing back the file, use 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
To extract the video codec information - since ffmpeg sends information to stderr - pipe and grep it:
$ 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)
To reduce the output even further, introduce sed:
$ ffprobe video.mkv 2>&1 >/dev/null |grep Stream.*Video | sed -e 's/.*Video: //' -e 's/[, ].*//'
h264
这篇关于如何使用FFmpeg确定文件的视频编解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!