在android中使用FFMpeg命令在视频上绘制文本时出错

时间:2017-08-03 10:10:48

标签: android android-ffmpeg

我实际上使用此命令在视频上叠加文字,但它无效。

String[] cmd = new String[]{ "-i", path.mp4, "-vf", "drawtext=fontfile=/home/mobihouse/hemanth-work-files/TwoTHumbSeekbarTest/app/src/main/assets/loto.ttf: text=hello","-preset", "-strict", destinationpath.mp4};

执行此命令时,我正面临:

08-03 14:42:28.133 32021-32021/test.mobihouse.twothumbseekbartest I/Choreographer: Skipped 1325 frames!  The application may be doing too much work on its main thread.

[ 08-03 14:42:28.167 32021:32021 D/         ]
onProgressffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers

[ 08-03 14:42:28.167 32021:32021 D/         ]
onProgress  built with gcc 4.8 (GCC)

[ 08-03 14:42:28.169 32021:32021 D/         ]
onProgress  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=

[ 08-03 14:42:28.170 32021:32021 D/         ]
onProgress  libavutil      55. 17.103 / 55. 17.103

[ 08-03 14:42:28.170 32021:32021 D/         ]
onProgress  libavcodec     57. 24.102 / 57. 24.102

[ 08-03 14:42:28.171 32021:32021 D/         ]
onProgress  libavformat    57. 25.100 / 57. 25.100

[ 08-03 14:42:28.172 32021:32021 D/         ]
onProgress  libavdevice    57.  0.101 / 57.  0.101

[ 08-03 14:42:28.172 32021:32021 D/         ]
onProgress  libavfilter     6. 31.100 /  6. 31.100

[ 08-03 14:42:28.176 32021:32021 D/         ]
onProgress  libswscale      4.  0.100 /  4.  0.100

[ 08-03 14:42:28.176 32021:32021 D/         ]
onProgress  libswresample   2.  0.101 /  2.  0.101

[ 08-03 14:42:28.176 32021:32021 D/         ]
onProgress  libpostproc    54.  0.100 / 54.  0.100

[ 08-03 14:42:28.216 32021:32021 D/         ]
onProgressInput #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Sample2.mp4':

[ 08-03 14:42:28.217 32021:32021 D/         ]
onProgress  Metadata:

[ 08-03 14:42:28.218 32021:32021 D/         ]
onProgress    major_brand     : isom

[ 08-03 14:42:28.219 32021:32021 D/         ]
onProgress    minor_version   : 512

[ 08-03 14:42:28.219 32021:32021 D/         ]
onProgress    compatible_brands: isomiso2avc1mp41

[ 08-03 14:42:28.220 32021:32021 D/         ]
onProgress    encoder         : Lavf57.25.100

[ 08-03 14:42:28.221 32021:32021 D/         ]
onProgress  Duration: 00:01:06.52, start: 0.023220, bitrate: 2357 kb/s

[ 08-03 14:42:28.222 32021:32021 D/         ]
onProgress    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 1:1 DAR 3:2], 2275 kb/s, 12 fps, 12 tbr, 12288 tbn, 24 tbc (default)

[ 08-03 14:42:28.223 32021:32021 D/         ]
onProgress    Metadata:

[ 08-03 14:42:28.228 32021:32021 D/         ]
onProgress      handler_name    : VideoHandler

[ 08-03 14:42:28.229 32021:32021 D/         ]
onProgress    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)

[ 08-03 14:42:28.229 32021:32021 D/         ]
onProgress    Metadata:

[ 08-03 14:42:28.229 32021:32021 D/         ]
onProgress      handler_name    : SoundHandler

[ 08-03 14:42:28.231 32021:32021 D/         ]
onProgressFontconfig error: Cannot load default config file

[ 08-03 14:42:28.232 32021:32021 D/         ]
onProgress[Parsed_drawtext_0 @ 0xadd991e0] impossible to init fontconfig

[ 08-03 14:42:28.234 32021:32021 D/         ]
onProgress[AVFilterGraph @ 0xadd8b080] Error initializing filter 'drawtext' with args 'Pthof ttf  file: text=hello'

[ 08-03 14:42:28.235 32021:32021 D/         ]
onProgressError opening filters!

[ 08-03 14:42:28.239 32021:32021 D/         ]
onFailureffmpeg 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 '/storage/emulated/0/Sample2.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf57.25.100
Duration: 00:01:06.52, start: 0.023220, bitrate: 2357 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 1:1 DAR 3:2], 2275 kb/s, 12 fps, 12 tbr, 12288 tbn, 24 tbc (default)
Metadata:
handler_name    : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
Metadata:
handler_name    : SoundHandler
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 @ 0xadd991e0] impossible to init fontconfig
[AVFilterGraph @ 0xadd8b080] Error initializing filter 'drawtext' with args 'Pthof ttf  file: text=hello'
Error opening filters!
08-03 14:42:32.653 32021-32026/test.mobihouse.twothumbseekbartest I/art: Do partial code cache collection, code=50KB, data=62KB
08-03 14:42:32.654 32021-32026/test.mobihouse.twothumbseekbartest I/art: After code cache collection, code=50KB, data=62KB
08-03 14:42:32.654 32021-32026/test.mobihouse.twothumbseekbartest I/art: Increasing code cache capacity to 256KB

1 个答案:

答案 0 :(得分:0)

Android 设备上的字体存储在“/system/fonts/Roboto-Regular.ttf”。所以命令看起来像这样。这在 Android 设备上对我有用。

val subtitlecommand = arrayOf(
                        "-y",
                        "-i",
                        videoPath,
                        "-vf",
                        "drawtext=fontfile=/system/fonts/Roboto-Regular.ttf:text='Super User':x=(w-text_w)/2:y=(h-text_h)/2:fontsize=24:fontcolor=white",
                        "-c:a",
                        "copy",
                        appDir
                    )