我正在编写一个 bash 脚本,我想将一组视频(mp4)的元数据(长度、分辨率等)回显到文件中。
有没有一种简单的方法可以从 MP4 文件中获取此信息?
答案1
在基于 Debian 的系统上(但想必其他发行版的存储库中也会有mediainfo
):
$ sudo apt-get install mediainfo
$ mediainfo foo.mp4
这会喷出很多信息。例如,要获取长度、分辨率、编解码器和尺寸,请使用:
$ mediainfo "The Blues Brothers.mp4" | grep -E 'Duration|Format |Width|Height' | sort | uniq
Duration : 2h 27mn
Format : AAC
Format : AVC
Format : MPEG-4
Height : 688 pixels
Width : 1 280 pixels
答案2
您可以使用 exiftool。要安装它,请运行:
sudo apt-get install libimage-exiftool-perl
然后要从 mp4 文件中获取元数据,请运行:
exiftool video_file.mp4 > medatata.txt
保存在文件中的输出应该是这样的:
ExifTool Version Number : 9.60
File Name : video_file.mp4
Directory : .
File Size : 11 MB
File Modification Date/Time : 2014:05:12 21:25:11+03:00
File Access Date/Time : 2014:05:20 23:05:35+03:00
File Inode Change Date/Time : 2014:05:12 21:25:11+03:00
File Permissions : rw-r--r--
File Type : MP4
MIME Type : video/mp4
Major Brand : MP4 v2 [ISO 14496-14]
Minor Version : 0.0.0
Compatible Brands : isom, mp42
Movie Header Version : 0
Create Date : 2014:04:24 05:33:58
Modify Date : 2014:04:24 05:33:58
Time Scale : 600
Duration : 0:03:10
Preferred Rate : 1
Preferred Volume : 100.00%
Preview Time : 0 s
Preview Duration : 0 s
Poster Time : 0 s
Selection Time : 0 s
Selection Duration : 0 s
Current Time : 0 s
Next Track ID : 3
Track Header Version : 0
Track Create Date : 0000:00:00 00:00:00
Track Modify Date : 2014:04:24 05:33:59
Track ID : 1
Track Duration : 0:03:10
Track Layer : 0
Track Volume : 0.00%
Image Width : 450
Image Height : 360
Graphics Mode : srcCopy
Op Color : 0 0 0
Compressor ID : avc1
Source Image Width : 450
Source Image Height : 360
X Resolution : 72
Y Resolution : 72
Bit Depth : 24
Buffer Size : 19318
Max Bitrate : 1059760
Average Bitrate : 396688
Video Frame Rate : 25
Matrix Structure : 1 0 0 0 1 0 0 0 1
Media Header Version : 0
Media Create Date : 2014:04:24 05:33:58
Media Modify Date : 2014:04:24 05:33:59
Media Time Scale : 44100
Media Duration : 0:03:10
Media Language Code : und
Handler Description : IsoMedia File Produced by Google, 5-11-2011
Balance : 0
Audio Format : mp4a
Audio Channels : 2
Audio Bits Per Sample : 16
Audio Sample Rate : 44100
Handler Type : Metadata
Handler Vendor ID : Apple
Google Start Time : 0
Google Track Duration : 191006
Google Source Data : B567F7685HH1399919109001385
Google Ping URL :
Google Ping Message :
Google Host Header : r2---sn-gqn-vhge.googlevideo.com
Movie Data Size : 11755744
Movie Data Offset : 60204
Avg Bitrate : 493 kbps
Image Size : 450x360
Rotation : 0
答案3
您可以使用FFmpeg 项目:
ffprobe 'Yagya (IS) - Topic-Choose-Hlw4YohQzr4.webm'
结果:
Input #0, matroska,webm, from 'Yagya (IS) - Topic-Choose-Hlw4YohQzr4.webm':
Metadata:
encoder : google/video-file
Duration: 00:08:45.52, start: 0.000000, bitrate: 294 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 720x720,
SAR 1:1 DAR 1:1, 25 fps, 25 tbr, 1k tbn (default)