FFMPEG : Adding font to Video gives error

2019-10-04 11:53发布

问题:

I am trying to execute ffmpeg on android. I have successfully executed 2-3 commands also. But i am stuck at one point where i am adding text to the video.

Here is the command i am executing.

NOT WORKING : because the text argument has a space between two words.

"-i "+path+"out.mp4 -vf drawtext=fontfile="+path+"f1.ttf:text='Stack OverFlow' -y -c:v libx264 -c:a copy -movflags +faststart "+path+"output.mp4"

WORKING : just removed space.

"-i "+path+"out.mp4 -vf drawtext=fontfile="+path+"f1.ttf:text='StackOverFlow' -y -c:v libx264 -c:a copy -movflags +faststart "+path+"output.mp4"

Here path contains my external Sd card's path. out.mp4 and f1.ttf exists in my folder.

My Question is why it is not working with space.

Here is the stack trace i am getting.

FAILED with output : WARNING: linker: /data/data/com.github.hiteshsondhi88.sampleffmpeg/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix.
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/i686-linux-android- --arch=x86 --cpu=i686 --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/x86 --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -march=i686' --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/Testing/out.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf57.25.100
Duration: 00:00:05.00, start: 0.000000, bitrate: 117 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 300x300 [SAR 40:33 DAR 40:33], 113 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name    : VideoHandler
[NULL @ 0xb585f000] Unable to find a suitable output format for 'text='Stack'
text='Stack: Invalid argument

Why it is saying invalid argument. It will be great if any ffmpeg expert can guide me in what i am doing wrong here.

I have refered this Question of SO : Text on video ffmpeg

回答1:

SOLVED

I used text file for inserting space between characters in ffmpeg command. As the direct space was not working as i said in question.

So build a text file text.txt. The contents will be the text you want on your video.

Then build the command like this :

"-i "+path+"out.mp4 -vf drawtext=fontfile="+path+"f1.ttf:textfile="+path+"text.ttf -y -c:v libx264 -c:a copy -movflags +faststart "+path+"output.mp4"

It will get run successfully.



回答2:

i did this but with a different logic a put the text in editext and then take its screen shot--> saved that btmap of edittext screen shot on sd card and then use that image as a watermark on video using this command
String[] complexCommand = {"ffmpeg", "-y", "-i", filePath, "-strict", "experimental", "-vf", "movie=" + editTextScreenShotFliePath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]", "-s", "640x480", "-r", "30", "-b", "15496k", "-vcodec", "mpeg4", "-ab", "48000", "-ac", "2", "-ar", "22050", mCurrentVideoFile.getAbsolutePath()};