I need to know what is the issue with my FFmpeg command for overlaying text to a video in android.
command = new String[]{"ffmpeg", "-i", original_path, "-vf", "drawtext=text='SiteName.local': fontsize=18: fontcolor=white: x=10:y=h-th-10", "-acodec", "copy", "-y", dest.getAbsolutePath()};
I am trying to create a video with a text overlay. However, i'm getting an error
[NULL # 0xea699600] Unable to find a suitable output format for 'ffmpeg'
ffmpeg: Invalid argument
I have tested for the input file and output file using different command for trimming videos and it worked. However, the FFmpeg command for overlaying text does not work. I kindly ask for help.
Besides, i also need to know how i can animate the text to scroll from left to right, bounce using FFmpeg commands in android etc
Finally i managed solving the issue over a long search. Drawtext can't work without including the fontfile. So the below code is what managed to settle my scores
command = new String[]{"-i", original_path, "-vf", "drawtext=fontfile=/system/fonts/DroidSans.ttf:text='SiteName hulluway':fontsize=40:fontcolor=black: x=w-(t-4.5)*(w+tw)/5.5:y=100", "-acodec", "copy", "-y", dest.getAbsolutePath()};
Related
So, I am trying to combine an image and an audio file and convert it to a video using ffmpeg in flutter using flutter-ffmpeg but I am getting this error when I am trying to use executewithareguments() function.
I am getting this error ->
I suspected that maybe I should remove the double quotes but even that is giving an error. It would be very helpful if someone tells me what I am doing wrong.
Also, I was using min-gpl version of ffmpeg, I thought that was causing the problem, so I changed it to full-gpl but the error still remains. Any form of help would be great.
val cmd = arrayOf("-i",
inputVideoPath,
"-i",
inputVideo2Path,
"-y",
"-filter_complex",
"[1]scale=${1200}:${800}[b];[0][b] overlay=${imageXPosition}:${imageYPosition}",
"-pix_fmt",
"yuv420p",
"-c:a",
"copy",
"-preset",
"ultrafast",
outputVideoPath)
i want add text over video and i am using ffmpeg android lib but edited successfully but output video shows me black screen only
String addtextcommand[] = {
"-i",
inputpath,
"-strict",
"-2",
"-vf",
"drawtext=text=\'onLine1\': fontcolor=white", "-map", "0:a",
"-codec:v", "libx264", "-codec:a", "copy",
output
};
I am not going to give you and solution I prefer to figure out your command and find a solution by your self I m going to explain you command here
-i inputpath --> for Input (Video/GIF/IMAGES/MUSIC)
-strict -2 --> strictly conform to all the things in the spec no matter what consequences -2 for experimental
-vf --> for videofilter alternativaly you can use -filter_complex
drawtext=text='onLine1': fontcolor=white --> for draw text over on any med file like image or video
-map 0:a --> to map out with 1'st input auido 0:a stands for 1'st input audio
-codec:v --> for video codec
libx264 ---> specify video codec
-codec:a copy --> for audio codec , here you get audio codec from input copy stand s fro get codc from input
output --> final Output
try below code:
-i video.mp4 -filter_complex "drawtext=text=Vinesh Chauhan:fontcolor=#000000:fontsize=14:x=43:y=103:fontfile=FACEBOLF.OTF" -y output.mp4
for android your command should be
String[] cmd = new String[]{"-i",""+inputpath, "-filter_complex", "drawtext=text=Vinesh Chauhan:fontcolor=#000000:fontsize=14:x=43:y=103:fontfile="+fontPATH, "-y" ,""+outputpath};
now i think you can find your solution by your self if any query comment below will surely help you
The problem is in "-map", "0:a" you are ignoring video from inputpath. Try command without that.
I am using MediaMuxer and MediaExtractor to transcode video. Now i want to add text on video at certain position. How can i achieve this? Basically i am recording video and transcode it in lower resolution now i want to add text overlay without using ffmpeg. I tried to add watermark by using ffmpeg but it takes too much time. I am using this library.This is my command:
String[] complexCommand = {"-y" ,"-i", "/storage/emulated/0/Download/VID.mp4","-strict",
"experimental", "-vf", "movie="
+"/storage/emulated/0/Download/iqm_logo.png [watermark]; [in][watermark] overlay=main_w/2-overlay_w/2:450 [out]",
"-b:v", "1540k", "-c:v", "libx264","-threads","30","-preset","ultrafast","-r", "30","-s", "1080x1920","-c:a", "copy",
"/storage/emulated/0/Download/watermark.mp4"};
I recorded a Video for limited time. Now i want to fetch all frames of video. I am using the below code and by using it i am able to get frames but i am not getting all video frames. 3 to 4 frames are repeated then i got a different frame. But as we all know we can get 25- 30 frames in a second to display smooth video. How to get all frames.
for (int i = 0; i < 30; i++) {
Bitmap bArray = mediaMetadataRetriever.getFrameAtTime(
1000000 * i,
MediaMetadataRetriever.OPTION_CLOSEST);
savebitmap(bArray, 33333 * i);
}
I don't want to use NDK. I got this link don't know what should be the value for "argb8888". I am getting error here. Can anyone explain how to do it.
Getting frames from Video Image in Android
I faced the same problem before and the Android's MediaMetadataRetriever seems not appropriated for this task since it doesn't have a good precision.
I used a library called "FFmpegMediaMetadataRetriever" in android studio:
Add this line in your build.graddle under module app:
compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
Rebuild your project.
Use the FFmpegMediaMetadataRetriever class to grab frames with higher
precision:
FFmpegMediaMetadataRetriever med = new FFmpegMediaMetadataRetriever();
med.setDataSource("your data source");
and in your loop you can grab frame using:
Bitmap bmp = med.getFrameAtTime(i*1000000, FFmpegMediaMetadataRetriever.OPTION_CLOSEST);
To get image frames from video we can use ffmpeg.For integrating FFmpeg in android we can use precompiled libraries like ffmpeg-android.
To extract image frames from a video we can use below command
String[] complexCommand = {"-y", "-i", inputFileAbsolutePath, "-an",
"-r", "1/2", "-ss", "" + startMs / 1000, "-t", "" + (endMs - startMs)
/ 1000, outputFileAbsolutePath};
Here,
-y
Overwrite output files
-i
ffmpeg reads from an arbitrary number of input “files” specified by the -i option
-an
Disable audio recording.
-r
Set frame rate
-ss
seeks to position
-t
limit the duration of data read from the input file
Here in place of inputFileAbsolutePath you have to specify the absolute path of video file from which you want to extract images.
For complete code check out this on my repository .Inside extractImagesVideo() method I am running command for extracting images from video.
For complete tutorial regarding integration of ffmpeg library and using ffmpeg commands to edit videos, check out this post which I have written on my blog.
You need to do :
Decode the video.
Present the decoded images at least as fast as 24 images / second. I
suppose you can skip this step.
Save the decoded images.
It appears that decoding the video would be the most challenging step. People and companies have spent years developing codecs (encoder / decoder) for various video formats.
Use this library JMF for FFMPEG.
I am using FFmpeg for video editing in android. I am able to trim, crop and add overlay using below commands:
For trim:
command = new String[]{"-i",inputVideoFilePath,"-ss","00:00:30.0","-c","copy","-t","00:00:10.0",outputVideoFilePath};
For crop:
command = new String[]{"-i",inputVideoFilePath,"-preset", "ultrafast","-filter:v","crop=400:400:0:0","-c:a","copy", outputVideoFilePath};
For overlay:
command = new String[]{"-i",inputVideoFilePath, "-i",overlayImagePath,"-preset", "ultrafast","-filter_complex", "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2", "-codec:a", "copy", outputVideoFilePath};
but I'm unable to merge these commands into a single command.
Please help me.
Use
command = new String[]{"-ss", "00:00:30.0", "-t", "00:00:10.0", "-i",inputVideoFilePath,
"-i",overlayImagePath, "-filter_complex",
"[0]crop=400:400:0:0[a];[a][1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2",
"-preset", "ultrafast", "-codec:a", "copy", outputVideoFilePath};
A filter_complex allows one to perform multiple filtering operations on different inputs in series or in parallel.