Invalid argument Unable to print text using drawtext using ffmpeg - android

I am trying to add text and time stamp on video but not able to print the simple text on it.
String[] complexCommand = {"-f", "3gp", "-i", videoPath, "-s", height + "x" + width, "-r",
"17", "drawtext=fontfile='file://android_asset/font_eight.ttf':fontsize=20:text='test':x=10:y=100",
"-vcodec", "libx264", "-vb", "2000k", "-preset", "fast", "-f", "3gp", dir.getAbsolutePath() + "/out.3gp"};
ffmpeg -f 3gp -i /storage/emulated/0/DCIM/Camera/VID_20171211_105946.3gp -s 1920x1080
-r 17 drawtext='fontfile=file://android_asset/font_eight.ttf:fontsize=20:text=test:x=10:y=100
-vcodec libx264 -vb 2000k -preset fast -f 3gp /storage/emulated/0/Pictures/Video/out.3gp
-- Edited Question ---
Error:
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 # 0xf5ba0730] impossible to init fontconfig
[AVFilterGraph # 0xf5b89040] Error initializing filter 'drawtext' with args 'fontfile=file://android_asset/font_eight.ttf:fontsize=32:text=test:fontcolor=white:x=0:y=0'
Error opening filters!
Same command runs on windows with no error, But when I converted it for mobile device and tested getting error of font-path.

drawtext is a video filter, so it has to be passed as an argument to -vf or -filter_complex (used when filtering multiple streams).
So,
-vf drawtext=fontsize=20:=text='aaa':x=10:y=100

Related

How to drawtext colon with pts gmtime using ffmpeg?

I am adding timestamp to video using FFMPEG where i am using below command:
ffmpeg -y -i input.mp4 -vf "drawtext=fontfile=roboto.ttf:fontsize=36:fontcolor=yellow:text='%{pts\:gmtime\:1575526882\:%d/%m/%y %H:%M}'" -preset ultrafast -f mp4 output.mp4
in this command i am using : between %H and %M in text attribute of drawtext
text='%{pts\:gmtime\:1575526882\:%d/%m/%y %H:%M}'
because i want to print time like this 06:25
it show me this error:
Unterminated %{} near '{pts:gmtime:1575526882:%d/%m/%y %H'
how can i print : between %H and %M where %H is for hours and %M is for minutes?
Lazy method is to use %R:
text='%{pts\:gmtime\:1575526882\:%d/%m/%y %R}'
Otherwise you'll have to deal with the annoyance of escaping:
text='%{pts\:gmtime\:1575526882\:%d/%m/%y %H\\\\\:%M}'
You may have to vary the number of backslashes depending on your environment.

Speed up a video without audio to 2x with FFmpeg in android

I am working on a project in which I need to speed up a mute video. I did a little digging around and found the following command.
ffmpeg -i input.mkv -filter:v "setpts=PTS/2" output.mkv
Tried to use it in android as follows.
new String[]{"-y", "-i", inputFileAbsolutePath, "-filter_complex", "setpts=PTS/2", "-map", "[v]", "-map", "[a]", "-b:v", "2097k", "-r", "60", "-vcodec", "mpeg4", fileOutput};
It doesn't even show anything in the Logcat.
I have also tried a few other solutions but no luck.
Any help would be appreciated.
Thanks.
If you were to view the log from the ffmpeg process it would provide an error:
Output with label 'v' does not exist in any defined filter graph, or was already used elsewhere.
So either properly label and map the filter output:
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/2[v]" -map "[v]" -b:v 2097k -r 60 -vcodec mpeg4 output.mp4
...or omit the labels and rely on the default stream selection behavior.
ffmpeg -i input.mp4 -filter_complex setpts=PTS/2 -b:v 2097k -r 60 -vcodec mpeg4 output.mp4

Unable to find a suitable output format for "-i ... "

I am using writemind's ffmpeg module (running ffmpeg v3.0.2)
http://writingminds.github.io/ffmpeg-android-java/
But I am getting the follow error when executing the command
[NULL # 0xe93aa000] Unable to find a suitable output format for ' -i
"/storage/emulated/0/Android/data/com.charaku.popsical.tv/cache/video_recording.mp4"
-i "/storage/emulated/0/Download/132859_aac-group-2.mp4" -c:v copy -filter_complex '[1:a] adelay=2500|2500 [delayed]; [0:a] [delayed] amix [out]' -map 0:v -map '[out]'
"/storage/emulated/0/Android/data/com.charaku.popsical.tv/cache/mixed_test2.mp4"'
-i "/storage/emulated/0/Android/data/com.charaku.popsical.tv/cache/video_recording.mp4"
-i "/storage/emulated/0/Download/132859_aac-group-2.mp4" -c:v copy -filter_complex '[1:a] adelay=2500|2500 [delayed]; [0:a] [delayed] amix [out]' -map 0:v -map '[out]'
"/storage/emulated/0/Android/data/com.charaku.popsical.tv/cache/mixed_test2.mp4":
Invalid argument
The command is supposed to mix the audio of a video file with the audio of another audio file to produce a new video file.
Able to get pass this error by following the suggestion in this link
FFmpeg error Output file #0 does not contain any stream
Basically putting each argument in its own array element

Android ffmpeg just convert an image file to video file

I want to make a sample video file into video for 30 seconds to show. But I can not do it because I'm not good enough with FFmpeg.
My code :
String command[]={
"-y",
"-r",
"1/5",
"-i",
src.getAbsolutePath(), // only one image file path
"-c:v",
"libx264",
"-vf",
"fps=25",
"-pix_fmt",
"yuv420p",
imagesvideoOutput
};
Simple command for 30 second video from a single image:
ffmpeg -loop 1 -i image.png -vf format=yuv420p -t 30 output.mp4
Faster, but somewhat more complicated method:
ffmpeg -loop 1 -framerate 1 -i image.png -vf fps=25,format=yuv420p -t 30 output.mp4

How to Compress video file in android

I want to compress video file before uploading to server.I gone through this link
How to compress a video to maximum level android, but i did not get an answer. Can anyone help me ??
Give this a try
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setVideoEncodingBitRate(690000 );
We can compress video using ffmpeg in android.
For integrating FFmpeg in android we can use precompiled libraries like ffmpeg-android.
You can use below command to compress video
String[] command = {"-y", "-i", inputFileAbsolutePath, "-s", "160x120", "-r", "25", "-vcodec", "mpeg4", "-b:v", "150k", "-b:a", "48000", "-ac", "2", "-ar", "22050", outputFileAbsolutePath};
Here,
-y
Overwrite output files without asking.
-i
ffmpeg reads from an arbitrary number of input “files” specified by the -i option
-s
video output size
-r
Set frame rate
-vcodec
Set the video codec.
-b:v
Set the video bitrate
-b:a
Set the audio bitrate
-ac
Set the number of audio channels.
-ar
sets the sampling rate for audio streams if encoded
For detailed explanation and code on using ffmpeg in android to edit videos,check out below ffmpeg video editor tutorial link on my blog which includes compressing video using ffmpeg-
https://androidlearnersite.wordpress.com/2017/03/17/ffmpeg-video-editor/
You have to use ffmpeg lib to compress your video:-
ffmpeg -i input.mp4 -acodec mp2 output.mp4

Categories

Resources