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

时间:2014-09-16 22:27:03

标签: android video ffmpeg java-native-interface overlay

我终于设法构建了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

我首先使用ffmpeg.exe在Windows上尝试过,结果与预期一致。

我在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会强制进行新的视频编码。

1 个答案:

答案 0 :(得分:2)

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

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

另见: