更新:请参阅底部的编辑部分
有没有办法通过设置选项或处理输出来限制 ffmpeg 的控制台输出?我查看了文档,并设置了可用的选项来限制输出,但我希望还有其他方法可以进一步限制它。我还查看了我能找到的关于 ffmpeg 详细程度的帖子,例如这讨论 -loglevel 选项,但它没有提供足够的控制。
这是在没有使用 -loglevel 错误选项完全抑制输出的情况下我可以得到的最不详细的输出,但这不是我想要的。
ffmpeg -hide_banner -i input.mkv -c:v libx265 -crf 26 -x265-params log-level=error -vtag hvc1 -c:a ac3 -c:s mov_text output.mp4
Input #0, matroska,webm, from './input.mkv':
Metadata:
encoder : no_variable_data
creation_time : 1970-01-01T00:00:00.000000Z
Duration: 00:48:46.48, start: 0.000000, bitrate: 9619 kb/s
Chapter #0:0: start 0.000000, end 326.409000
Metadata:
title : 00:00:00.000
Chapter #0:1: start 326.409000, end 1037.912000
Metadata:
title : 00:05:26.409
Chapter #0:2: start 1037.912000, end 1516.640000
Metadata:
title : 00:17:17.912
Chapter #0:3: start 1516.640000, end 2359.732000
Metadata:
title : 00:25:16.640
Chapter #0:4: start 2359.732000, end 2887.009000
Metadata:
title : 00:39:19.732
Chapter #0:5: start 2887.009000, end 2926.475000
Metadata:
title : 00:48:07.009
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
BPS : 8107717
BPS-eng : 8107717
DURATION : 00:48:46.466000000
DURATION-eng : 00:48:46.466000000
NUMBER_OF_FRAMES: 70165
NUMBER_OF_FRAMES-eng: 70165
NUMBER_OF_BYTES : 2965869890
NUMBER_OF_BYTES-eng: 2965869890
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
Metadata:
BPS : 1508999
BPS-eng : 1508999
DURATION : 00:48:46.475000000
DURATION-eng : 00:48:46.475000000
NUMBER_OF_FRAMES: 274357
NUMBER_OF_FRAMES-eng: 274357
NUMBER_OF_BYTES : 552006284
NUMBER_OF_BYTES-eng: 552006284
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2(eng): Subtitle: subrip (default) (forced)
Metadata:
title : Forced
BPS : 105
BPS-eng : 105
DURATION : 00:00:18.518000000
DURATION-eng : 00:00:18.518000000
NUMBER_OF_FRAMES: 6
NUMBER_OF_FRAMES-eng: 6
NUMBER_OF_BYTES : 245
NUMBER_OF_BYTES-eng: 245
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:3(eng): Subtitle: subrip
Metadata:
BPS : 61
BPS-eng : 61
DURATION : 00:47:20.754000000
DURATION-eng : 00:47:20.754000000
NUMBER_OF_FRAMES: 584
NUMBER_OF_FRAMES-eng: 584
NUMBER_OF_BYTES : 21796
NUMBER_OF_BYTES-eng: 21796
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:4(eng): Subtitle: subrip
Metadata:
title : SDH
BPS : 62
BPS-eng : 62
DURATION : 00:48:07.176000000
DURATION-eng : 00:48:07.176000000
NUMBER_OF_FRAMES: 619
NUMBER_OF_FRAMES-eng: 619
NUMBER_OF_BYTES : 22653
NUMBER_OF_BYTES-eng: 22653
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
Stream #0:1 -> #0:1 (dts (dca) -> ac3 (native))
Stream #0:2 -> #0:2 (subrip (srt) -> mov_text (native))
Press [q] to stop, [?] for help
Output #0, mp4, to './output.mp4':
Chapter #0:0: start 0.000000, end 326.409000
Metadata:
title : 00:00:00.000
Chapter #0:1: start 326.409000, end 1037.912000
Metadata:
title : 00:05:26.409
Chapter #0:2: start 1037.912000, end 1516.640000
Metadata:
title : 00:17:17.912
Chapter #0:3: start 1516.640000, end 2359.732000
Metadata:
title : 00:25:16.640
Chapter #0:4: start 2359.732000, end 2887.009000
Metadata:
title : 00:39:19.732
Chapter #0:5: start 2887.009000, end 2926.475000
Metadata:
title : 00:48:07.009
Stream #0:0: Video: hevc (libx265) (hvc1 / 0x31637668), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 23.98 fps, 24k tbn, 23.98 tbc (default)
Metadata:
BPS : 8107717
BPS-eng : 8107717
DURATION : 00:48:46.466000000
DURATION-eng : 00:48:46.466000000
NUMBER_OF_FRAMES: 70165
NUMBER_OF_FRAMES-eng: 70165
NUMBER_OF_BYTES : 2965869890
NUMBER_OF_BYTES-eng: 2965869890
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
encoder : Lavc libx265
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
Metadata:
BPS : 1508999
BPS-eng : 1508999
DURATION : 00:48:46.475000000
DURATION-eng : 00:48:46.475000000
NUMBER_OF_FRAMES: 274357
NUMBER_OF_FRAMES-eng: 274357
NUMBER_OF_BYTES : 552006284
NUMBER_OF_BYTES-eng: 552006284
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
encoder : Lavc ac3
Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874) (default) (forced)
Metadata:
title : Forced
BPS : 105
BPS-eng : 105
DURATION : 00:00:18.518000000
DURATION-eng : 00:00:18.518000000
NUMBER_OF_FRAMES: 6
NUMBER_OF_FRAMES-eng: 6
NUMBER_OF_BYTES : 245
NUMBER_OF_BYTES-eng: 245
_STATISTICS_WRITING_APP: no_variable_data
_STATISTICS_WRITING_APP-eng: no_variable_data
_STATISTICS_WRITING_DATE_UTC: 1970-01-01 00:00:00
_STATISTICS_WRITING_DATE_UTC-eng: 1970-01-01 00:00:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
encoder : Lavc mov_text
frame= 1047 fps= 58 q=33.7 size= 2560kB time=00:00:44.37 bitrate= 472.6kbits/s speed=2.48x
这是我理想中的情况:
ffmpeg -hide_banner -i input.mkv -c:v libx265 -crf 26 -x265-params log-level=error -vtag hvc1 -c:a ac3 -c:s mov_text output.mp4
Input #0, matroska,webm, from './input.mkv':
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
Stream #0:2(eng): Subtitle: subrip (default) (forced)
Stream #0:3(eng): Subtitle: subrip
Stream #0:4(eng): Subtitle: subrip
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
Stream #0:1 -> #0:1 (dts (dca) -> ac3 (native))
Stream #0:2 -> #0:2 (subrip (srt) -> mov_text (native))
Press [q] to stop, [?] for help
Output #0, mp4, to './output.mp4':
Stream #0:0: Video: hevc (libx265) (hvc1 / 0x31637668), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 23.98 fps, 24k tbn, 23.98 tbc (default)
Stream #0:1(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874) (default) (forced)
frame= 1047 fps= 58 q=33.7 size= 2560kB time=00:00:44.37 bitrate= 472.6kbits/s speed=2.48x
如果没有办法用 ffmpeg 来做到这一点,如果有人能给出一个如何从输出中过滤掉所有不需要的文本的例子就好了。
编辑:根据使用 grep 的建议,我想出了这个,它几乎让我做到了。唯一剩下的问题是 grep 使进度出现在连续的新行上,而我无法对此进行过滤。
ffmpeg -progress pipe:1 -i input.mkv -c:v libx265 -vtag hvc1 -c:a copy -c:s mov_text output.mp4 2>&1 | egrep "Input.*|Duration.*|Stream.*|Output.*|frame=.*"
给出以下输出:
Input #0, matroska,webm, from './input.mkv':
Duration: 00:43:04.59, start: 0.000000, bitrate: 7253 kb/s
Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
Stream #0:2(eng): Subtitle: subrip (default) (forced)
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (subrip (srt) -> mov_text (native))
Output #0, mp4, to '/output.mp4':
Stream #0:0(eng): Video: hevc (libx265) (hvc1 / 0x31637668), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 23.98 fps, 13978 tbn, 23.98 tbc (default)
Stream #0:1(eng): Audio: dts (DTS) (mp4a / 0x6134706D), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874) (default) (forced)
frame=92 92 fps=0.0 q=29.8 size= 0kB time=00:00:04.52 bitrate= 0.4kbits/s speed=9.01x
frame=17676 fps=174 q=31.2 size= 0kB time=00:00:08.04 bitrate= 0.3kbits/s speed=7.94x
frame=25555 fps=168 q=35.8 size= 256kB time=00:00:11.38 bitrate= 184.4kbits/s speed=7.48x
frame=29191 fps=143 q=34.4 size= 512kB time=00:00:12.88 bitrate= 325.7kbits/s speed=6.34x
答案1
由于您想要创建自己的日志记录级别,因此您需要自行执行此操作。
例如,您可以使用类似以下内容:
unbuffer ffmpeg … | unbuffer grep PATTERN
其中 PATTERN 是一个正则表达式,它定义您希望传递的输出行。