gpt4 book ai didi

android - 过滤器复杂应用于 ffmpeg for android 输出低质量视频

转载 作者:行者123 更新时间:2023-11-29 21:01:45 25 4
gpt4 key购买 nike

我终于成功构建了 ffmpeg,详见此处:https://enoent.fr/blog/2014/06/20/compile-ffmpeg-for-android/最后,我有一个 ffmpeg 库,它接受命令参数。

我正在尝试在视频上应用水印图像,因此我正在使用准备此 ffmpeg 命令:

ffmpeg -i input.avi -i logo.png -filter_complex 'overlay=10:main_h-overlay_h-10' output.avi

我首先在 Windows 上使用 ffmpeg.exe 进行了尝试,结果符合预期。

我在android上用编译过的android试过,输出如下:

09-17 01:16:57.156: I/Videokit(1229): Loading native library compiled at 22:33:10 Sep 15 2014
09-17 01:16:57.156: I/Videokit(1229): Option: ffmpeg
09-17 01:16:57.156: I/Videokit(1229): Option: -loglevel
09-17 01:16:57.156: I/Videokit(1229): Option: debug
09-17 01:16:57.156: I/Videokit(1229): Option: -i
09-17 01:16:57.156: I/Videokit(1229): Option: /storage/emulated/0/mute.mp4
09-17 01:16:57.156: I/Videokit(1229): Option: -i
09-17 01:16:57.156: I/Videokit(1229): Option: /storage/emulated/0/logo.png
09-17 01:16:57.156: I/Videokit(1229): Option: -filter_complex
09-17 01:16:57.156: I/Videokit(1229): Option: overlay=10:main_h-overlay_h-10
09-17 01:16:57.156: I/Videokit(1229): Option: /storage/emulated/0/outVid.mp4
09-17 01:16:57.156: I/Videokit(1229): Running main
09-17 01:16:57.163: D/Videokit(1229): Splitting the commandline.
09-17 01:16:57.163: D/Videokit(1229): Reading option '-loglevel' ...
09-17 01:16:57.163: D/Videokit(1229): matched as option 'loglevel' (set logging level) with argument 'debug'.
09-17 01:16:57.163: D/Videokit(1229): Reading option '-i' ...
09-17 01:16:57.163: D/Videokit(1229): matched as input file with argument '/storage/emulated/0/mute.mp4'.
09-17 01:16:57.163: D/Videokit(1229): Reading option '-i' ...
09-17 01:16:57.163: D/Videokit(1229): matched as input file with argument '/storage/emulated/0/logo.png'.
09-17 01:16:57.163: D/Videokit(1229): Reading option '-filter_complex' ...
09-17 01:16:57.163: D/Videokit(1229): matched as option 'filter_complex' (create a complex filtergraph) with argument 'overlay=10:main_h-overlay_h-10'.
09-17 01:16:57.163: D/Videokit(1229): Reading option '/storage/emulated/0/outVid.mp4' ...
09-17 01:16:57.163: D/Videokit(1229): matched as output file.
09-17 01:16:57.163: D/Videokit(1229): Finished splitting the commandline.
09-17 01:16:57.163: D/Videokit(1229): Parsing a group of options: global .
09-17 01:16:57.163: D/Videokit(1229): Applying option loglevel (set logging level) with argument debug.
09-17 01:16:57.163: D/Videokit(1229): Applying option filter_complex (create a complex filtergraph) with argument overlay=10:main_h-overlay_h-10.
09-17 01:16:57.163: D/Videokit(1229): Successfully parsed a group of options.
09-17 01:16:57.163: D/Videokit(1229): Parsing a group of options: input file /storage/emulated/0/mute.mp4.
09-17 01:16:57.163: D/Videokit(1229): Successfully parsed a group of options.
09-17 01:16:57.163: D/Videokit(1229): Opening an input file: /storage/emulated/0/mute.mp4.
09-17 01:16:57.296: D/Videokit(1229): Successfully opened the file.
09-17 01:16:57.296: D/Videokit(1229): Parsing a group of options: input file /storage/emulated/0/logo.png.
09-17 01:16:57.296: D/Videokit(1229): Successfully parsed a group of options.
09-17 01:16:57.296: D/Videokit(1229): Opening an input file: /storage/emulated/0/logo.png.
09-17 01:16:57.304: D/Videokit(1229): Successfully opened the file.
09-17 01:16:57.304: D/Videokit(1229): Parsing a group of options: output file /storage/emulated/0/outVid.mp4.
09-17 01:16:57.304: D/Videokit(1229): Successfully parsed a group of options.
09-17 01:16:57.304: D/Videokit(1229): Opening an output file: /storage/emulated/0/outVid.mp4.
09-17 01:16:57.312: D/Videokit(1229): Successfully opened the file.
09-17 01:16:57.351: I/Videokit(1229): Stream mapping:
09-17 01:16:57.351: I/Videokit(1229): Stream #0:0 (h264) -> overlay:main
09-17 01:16:57.351: I/Videokit(1229): Stream #1:0 (png) -> overlay:overlay
09-17 01:16:57.351: I/Videokit(1229): overlay
09-17 01:16:57.351: I/Videokit(1229): -> Stream #0:0 (mpeg4)
09-17 01:16:57.351: I/Videokit(1229): Press [q] to stop, [?] for help
09-17 01:16:57.890: I/Videokit(1229): frame= 12 fps=0.0 q=24.3 size= 113kB time=00:00:00.40 bitrate=2314.9kbits/s
09-17 01:16:58.413: I/Videokit(1229): frame= 26 fps= 25 q=31.0 size= 154kB time=00:00:00.86 bitrate=1455.1kbits/s
09-17 01:16:58.953: I/Videokit(1229): frame= 38 fps= 24 q=31.0 size= 180kB time=00:00:01.26 bitrate=1165.0kbits/s
09-17 01:17:00.085: I/Videokit(1229): frame= 50 fps= 24 q=31.0 size= 205kB time=00:00:01.66 bitrate=1006.8kbits/s
09-17 01:17:00.163: I/Videokit(1229): frame= 51 fps= 19 q=31.0 size= 206kB time=00:00:01.70 bitrate= 992.8kbits/s
09-17 01:17:00.632: I/Videokit(1229): frame= 64 fps= 20 q=31.0 size= 230kB time=00:00:02.13 bitrate= 883.9kbits/s
09-17 01:17:01.156: I/Videokit(1229): frame= 78 fps= 21 q=31.0 size= 254kB time=00:00:02.60 bitrate= 798.5kbits/s
09-17 01:17:01.679: I/Videokit(1229): frame= 92 fps= 21 q=31.0 size= 275kB time=00:00:03.06 bitrate= 734.7kbits/s
09-17 01:17:02.179: I/Videokit(1229): frame= 106 fps= 22 q=31.0 size= 296kB time=00:00:03.53 bitrate= 684.8kbits/s
09-17 01:17:02.726: I/Videokit(1229): frame= 121 fps= 23 q=24.8 size= 325kB time=00:00:04.03 bitrate= 660.1kbits/s
09-17 01:17:03.249: I/Videokit(1229): frame= 134 fps= 23 q=31.0 size= 344kB time=00:00:04.47 bitrate= 629.8kbits/s
09-17 01:17:03.781: I/Videokit(1229): frame= 147 fps= 23 q=31.0 size= 368kB time=00:00:04.90 bitrate= 614.2kbits/s
09-17 01:17:04.335: I/Videokit(1229): frame= 159 fps= 23 q=31.0 size= 390kB time=00:00:05.30 bitrate= 602.1kbits/s
09-17 01:17:04.921: I/Videokit(1229): frame= 171 fps= 23 q=31.0 size= 412kB time=00:00:05.70 bitrate= 591.3kbits/s
09-17 01:17:05.437: I/Videokit(1229): frame= 183 fps= 23 q=31.0 size= 432kB time=00:00:06.10 bitrate= 579.8kbits/s
09-17 01:17:05.937: I/Videokit(1229): frame= 196 fps= 23 q=31.0 size= 453kB time=00:00:06.53 bitrate= 568.0kbits/s
09-17 01:17:06.453: I/Videokit(1229): frame= 210 fps= 23 q=31.0 size= 483kB time=00:00:07.00 bitrate= 565.2kbits/s
09-17 01:17:06.976: I/Videokit(1229): frame= 224 fps= 23 q=31.0 size= 513kB time=00:00:07.47 bitrate= 562.3kbits/s
09-17 01:17:07.515: I/Videokit(1229): frame= 239 fps= 24 q=31.0 size= 538kB time=00:00:07.97 bitrate= 553.1kbits/s
09-17 01:17:08.007: I/Videokit(1229): frame= 249 fps= 23 q=31.0 size= 559kB time=00:00:08.30 bitrate= 551.2kbits/s
09-17 01:17:08.531: I/Videokit(1229): frame= 262 fps= 24 q=31.0 size= 581kB time=00:00:08.74 bitrate= 544.6kbits/s
09-17 01:17:09.359: I/Videokit(1229): frame= 272 fps= 23 q=31.0 size= 602kB time=00:00:09.07 bitrate= 543.1kbits/s
09-17 01:17:09.882: I/Videokit(1229): frame= 284 fps= 23 q=31.0 size= 624kB time=00:00:09.47 bitrate= 539.5kbits/s
09-17 01:17:10.374: I/Videokit(1229): frame= 296 fps= 23 q=31.0 size= 651kB time=00:00:09.87 bitrate= 540.2kbits/s
09-17 01:17:10.898: I/Videokit(1229): frame= 309 fps= 23 q=31.0 size= 682kB time=00:00:10.31 bitrate= 542.1kbits/s
09-17 01:17:11.406: I/Videokit(1229): frame= 324 fps= 23 q=31.0 size= 710kB time=00:00:10.81 bitrate= 538.3kbits/s
09-17 01:17:11.929: I/Videokit(1229): frame= 343 fps= 24 q=31.0 size= 749kB time=00:00:11.44 bitrate= 536.2kbits/s
09-17 01:17:12.437: I/Videokit(1229): frame= 361 fps= 24 q=24.8 size= 787kB time=00:00:12.04 bitrate= 535.3kbits/s
09-17 01:17:12.953: I/Videokit(1229): frame= 379 fps= 24 q=31.0 size= 821kB time=00:00:12.64 bitrate= 531.8kbits/s
09-17 01:17:13.460: I/Videokit(1229): frame= 397 fps= 25 q=24.8 size= 869kB time=00:00:13.24 bitrate= 537.2kbits/s
09-17 01:17:13.960: I/Videokit(1229): frame= 413 fps= 25 q=31.0 size= 903kB time=00:00:13.78 bitrate= 537.0kbits/s
09-17 01:17:14.468: I/Videokit(1229): frame= 430 fps= 25 q=31.0 size= 942kB time=00:00:14.34 bitrate= 537.7kbits/s
09-17 01:17:14.601: V/Videokit(1229): No more output streams to write to, finishing.
09-17 01:17:14.609: I/Videokit(1229): frame= 435 fps= 25 q=31.0 Lsize= 959kB time=00:00:14.51 bitrate= 541.2kbits/s
09-17 01:17:14.609: I/Videokit(1229): video:956kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead 0.275524%
09-17 01:17:14.609: D/Videokit(1229): 439 frames successfully decoded, 0 decoding errors
09-17 01:17:14.617: I/Videokit(1229): Main ended with status 0

问题是 android 上的输出质量很差如何让 ffmpeg 构建质量接近原始文件的视频。我假设 filter_complex 会强制进行新的视频编码。

最佳答案

过滤需要重新编码。对于您使用的编码器 (mpeg4):

  • 使用比默认值更高的比特率 (-b:v 200k)
  • 或从 1-31 中选择一个 -qscale:v 值,其中较低的值会导致较高的比特率,因此通常质量会更好

另见:

关于android - 过滤器复杂应用于 ffmpeg for android 输出低质量视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25879386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com