我想将图像和视频(2160 x 3840)调整为相同的分辨率(540×960),然后将视频叠加在整个视频上。整个过程类似于捕获视频并为其添加标题,如快照聊天和保存。
由于我使用 FFMPEG库成功完成了此操作,但它在处理过程中耗费了大量时间。
我在互联网上搜索了其他更快的操作,但没有运气。我将发布我正在使用的命令。
//1st command (video size from 59MB to 4MB, about time 110secs)
-i sdcard/VID_20161228_174315.mp4 -vf scale=540:960 sdcard/output540.mp4
//2nd command (image file , size done, time : a sec hence ignored)
-i sdcard/capture.jpg -vf scale=540:960 sdcard/capture540.png
//3rd command (time 80sec)
-i sdcard/output540.mp4 -i sdcard/capture540.png -filter_complex overlay=0:0 -r 30 sdcard/output_overlay.mp4
所以这里使用-preset并从源代码复制相同的音频并没有按预期工作。
问题:
1)我应该使用特定的编解码器吗?
2)如何实现最短的处理时间?
3)应用多个线程会有帮助吗?如果是,那怎么样?即使app已关闭,我也希望此过程在后台运行。
4)所有其他选项可以结合起来以提供有效的解决方案吗?
记录第3个命令:
SUCCESS with output : ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sdcard/output540.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Duration: 00:00:10.09, start: 0.021333, bitrate: 2055 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 540x960 [SAR 1:1 DAR 9:16], 1930 kb/s, 16.75 fps, 16.75 tbr, 17152 tbn, 33.50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 119 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, png_pipe, from 'sdcard/output_540.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 540x960, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0xaca425f0] using SAR=1/1
[libx264 @ 0xaca425f0] using cpu capabilities: none!
[libx264 @ 0xaca425f0] profile High, level 3.1
[libx264 @ 0xaca425f0] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=9 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'sdcard/output_overlay_forlog.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.25.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 540x960 [SAR 1:1 DAR 9:16], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
encoder : Lavc57.24.102 libx264
Side data:
unknown side data type 10 (24 bytes)
Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc57.24.102 aac
Stream mapping:
Stream #0:0 (h264) -> overlay:main (graph 0)
Stream #1:0 (png) -> overlay:overlay (graph 0)
overlay (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 19 fps=0.0 q=0.0 size= 0kB time=00:00:00.88 bit
12-29 02:20:37.914 19213-19213/in.techzilla.happenning_client D/Ffmpeg: Finished command : ffmpeg [Ljava.lang.String;@1a223d4
这里还有一个用于完整输出的txt文件
https://drive.google.com/file/d/0B60iSiCrzaVkUXFpYVFpdGdKN2M/view?usp=drivesdk
答案 0 :(得分:0)
您可以使用一个命令而不是使用三个命令:
ffmpeg -i video.mp4 -i image.png -filter_complex "[0:v]scale=540:960[v0];[1:v]scale=540:960[v2];[v1][v2]overlay" -preset ultrafast -c:a copy output.mp4
-preset ultrafast
将使用最快的x264编码预设。-threads
,因为它会自动选择最佳数字。这表示您的x264未正确编译。对于典型的Android设备,它应该类似于using cpu capabilities: ARMv7 NEON
。您应该通过支持适当的CPU功能来显着提高编码速度。