bash 从 MediaInfo 获取视频信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7376477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting video information from MediaInfo
提问by David542
To get the dimensions of a file, I can do:
要获取文件的尺寸,我可以执行以下操作:
$ mediainfo '--Inform=Video;%Width%x%Height%' ~/Desktop/lawandorder.mov
1920x1080
However, if I give a url instead of a file, it returns None:
但是,如果我提供一个 url 而不是一个文件,它会返回 None:
$ mediainfo '--Inform=Url;%Width%x%Height%' 'http://url/lawandorder.mov'
(none)
How would I correctly pass a url to MediaInfo?
我将如何正确地将 url 传递给MediaInfo?
采纳答案by Dan Cecile
You can also use curl | headto partially download the file before running mediainfo.
您还可以使用curl | head在运行之前部分下载文件mediainfo。
Here's an example of getting the dimensions of a 12 MB file from the web, where only a small portion (less than 10 KB) from the start needs to be downloaded:
以下是从网络获取 12 MB 文件尺寸的示例,其中只需下载一开始的一小部分(小于 10 KB):
curl --silent http://www.jhepple.com/support/SampleMovies/MPEG-2.mpg \
| head --bytes 10K > temp.mpg
mediainfo '--Inform=Video;%Width%x%Height%' temp.mpg
回答by David542
To do this, I needed to re-compile from source using '--with-libcurl' option.
为此,我需要使用“--with-libcurl”选项从源代码重新编译。
$ ./CLI_Compile.sh --with-libcurl
$ cd MediaInfo/Project/GNU/CLI
$ make install
Then I used this command to get video dimensions via http:
然后我使用这个命令通过http获取视频尺寸:
$ mediainfo '--Inform=Video;%Width%x%Height%' 'http://url/lawandorder.mov'
Note, this took a considerable amount of time to return the results. I'd recommend using ffmpegif the file is not local.
请注意,这需要相当长的时间来返回结果。ffmpeg如果文件不是本地的,我建议使用。

