JBe*_*rdo 101 parsing json ffmpeg
每当我尝试用ffmpeg获取有关我的视频文件的一些信息时,它就会把很多无用的信息与好东西混在一起.
我正在使用ffmpeg -i name_of_the_video.mpg
.
有可能以友好的方式获得它吗?我的意思是JSON会很棒(甚至丑陋的XML也很好).
到目前为止,我让我的应用程序使用正则表达式解析数据,但在某些特定的视频文件中出现了许多令人讨厌的角落.我修复了我遇到的所有问题,但可能会有更多.
我想要的东西:
{
"Stream 0": {
"type": "Video",
"codec": "h264",
"resolution": "720x480"
},
"Stream 1": {
"type": "Audio",
"bitrate": "128 kbps",
"channels": 2
}
}
Run Code Online (Sandbox Code Playgroud)
Ire*_*tus 275
有点晚了,但也许仍然与某人有关..
ffprobe
确实是一个很好的方式.但是请注意,你需要告诉ffprobe
你想要什么信息就显示(与-show_format
,-show_packets
和-show_streams
选项),或者它会只给你空白输出(如你在你的评论人提).
例如,ffprobe -v quiet -print_format json -show_format -show_streams somefile.asf
会产生类似以下内容:
{
"streams": [{
"index": 0,
"codec_name": "wmv3",
"codec_long_name": "Windows Media Video 9",
"codec_type": "video",
"codec_time_base": "1/1000",
"codec_tag_string": "WMV3",
"codec_tag": "0x33564d57",
"width": 320,
"height": 240,
"has_b_frames": 0,
"pix_fmt": "yuv420p",
"level": -99,
"r_frame_rate": "30000/1001",
"avg_frame_rate": "0/0",
"time_base": "1/1000",
"start_time": "0.000",
"duration": "300.066",
"tags": {
"language": "eng"
}
}],
"format": {
"filename": "somefile.asf",
"nb_streams": 1,
"format_name": "asf",
"format_long_name": "ASF format",
"start_time": "0.000",
"duration": "300.066",
"tags": {
"WMFSDKVersion": "10.00.00.3646",
"WMFSDKNeeded": "0.0.0.0000",
"IsVBR": "0"
}
}
}
Run Code Online (Sandbox Code Playgroud)
NT3*_*3RP 13
你可以试试ffprobe
.获取JSON输出的正确命令应如下所示:
ffprobe ... -print_format json
Run Code Online (Sandbox Code Playgroud)
Ole*_*rpa 10
现在可以用来-progress -
打印格式化的友好信息key=value
.
ffmpeg -i video.mp4 .......-s 1920x1080 -progress - -y out.mp4
speed=5.75x
frame=697
fps=167.7
stream_0_0_q=39.0
bitrate=2337.0kbits/s
total_size=6979778
out_time_ms=23893333
out_time=00:00:23.893333
dup_frames=0
drop_frames=0
Run Code Online (Sandbox Code Playgroud)
它的另一种用法ffprobe
很容易解析:
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate,bit_rate,codec_name,duration -of csv=p=0:s=x video.mp4
Run Code Online (Sandbox Code Playgroud)
结果是:
h264x600x480x25/1x385.680000x542326
-select_streams v:0
仅选择第一个视频流。如果删除该参数,每个流都会得到一行。
归档时间: |
|
查看次数: |
65538 次 |
最近记录: |