I am trying To add Watermark Like Tic Tok using FFMPEG but it's Not working
GeneralUtils.checkForPermissionsMAndAbove(MainActivity.this, true);
LoadJNI vk = new LoadJNI();
try {
//String complexCommand = "ffmpeg -y -i /storage/emulated/0/in.mp4 -strict experimental -vf transpose=1 -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k /storage/emulated/0/out.mp4";
/*String complexCommand = "ffmpeg -i /storage/emulated/0/in.mp4 -framerate 30000/1001 -loop 1 -i /storage/emulated/0/abcd.jpg -filter_complex\n" +
" \"[1:v] fade=out:st=30:d=1:alpha=1 [ov]; [0:v][ov] overlay=10:10 [v]\" -map \"[v]\"\n" +
" -map 0:a -c:v libx264 -c:a copy -shortest /storage/emulated/0/out.mp4";*/
//String complexCommand = "ffmpeg -y -i /storage/emulated/0/in.mp4 -strict experimental -vf movie=/storage/emulated/0/abcd.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out] -s 320x240 -r 30 -b 15496k -vcodec mpeg4 -ab 48000 -ac 2 -ar 22050 /storage/emulated/0/out.mp4";
String complexCommand = "ffmpeg -i /storage/emulated/0/in.mp4 -i /storage/emulated/0/abcd.jpg -filter_complex \\\n" +
"\"overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2\" \\\n" +
"-codec:a copy /storage/emulated/0/out.mp4";
String workFolder = getApplicationContext().getFilesDir().getAbsolutePath();
//String[] complexCommand = {"ffmpeg","-i", "/sdcard/videokit/in.mp4"};
vk.run(GeneralUtils.utilConvertToComplex(complexCommand) , workFolder , getApplicationContext());
Log.i("test", "ffmpeg4android finished successfully");
} catch (Throwable e) {
Log.e("test", "vk run exception.", e);
}
but noting work for me
as you can i have no knowledge about FFMPEG so if you give answere please write in brief.
thank you.
Its nothing to do with android but below are simple ffmpeg commands
Top-Left To Bottom-Right loop:
ffmpeg -i video.mp4 -i watermark.png -filter_complex \
"[0:v][1:v]overlay=x='if(lt(mod(t,10),5),10,W-w-10)':y='if(lt(mod(t,10),5),10,H-h-10)'" \
-codec:a copy out.mp4
Top-Right To Bottom-Left loop:
ffmpeg -i video.mp4 -i watermark.png -filter_complex \
"[0:v][1:v]overlay=x='if(lt(mod(t,10),5),W-w-10,10)':y='if(lt(mod(t,10),5),10,H-h-10)'" \
-codec:a copy out.mp4
Idea is very simple
Take every 10sec duration, get remainder sec i.e. mod(t,10)
if sec < 5, set top position else bottom position
START HERE https://drive.google.com/file/d/0B2aT0QoEmtuaN0VJZ2Z4ODY3T2s/view
File => New => import module => go find the folder downloaded at step1:
ffmpeg4android_demo_studio\ffmpeg4android_lib
Add permission in AndroidManifest.xml
if the version is higher than Android 6, add the following code in onCreate() of your Activity
GeneralUtils.checkForPermissionsMAndAbove(MainActivity.this, false);
Alt+Enter if encounter red font, AndroidStudio would help you to modify "build.gradle(Module)"
(Not sure if necessary) In build.gradle(Module)
Android{
.......
defaultConfig{
....
targetSdkVersion ...
ndk{
abiFilter "armeabi-v7a"
}
}
}
.....
dependencies{
...
compile project(':ffmpeg4android_lib')
}
add following code in "gradle.properties"
android.useDeprecatedNdk=true
and then async project
How to use WaterMarkHelper(by Johnny Tu) to add watermark on video
After import "WaterMarkHelper.java" in your project, declare the following in your Activity
WaterMarkHelper myHelper;
initialize myHelper with arguments
Arguments description:
String inputVideoPath (ex:"/sdcard/input.mp4")
String inputWaterMarkPath (ex:"/sdcard/waterMark.png")
String outputVideoPath (ex:"/sdcard/output.mp4")
String waterMarkX the X-coordinate
Video width: main_w, Video height: main_h, Image Width: overlay_w, Image Height: overlay_h
String waterMarkY
Download This
By using below command we can merge video and image together. I not an expert to build ffmpeg commands.
String cmd = "-t 5 -i " + videoPath +
" -loop 1 -t 5 -i " + imagePath +
" -f lavfi -t 5 -i anullsrc" +
" -filter_complex [1][0]scale2ref[2nd][ref];[ref][0:a][2nd][2:a]concat=n=2:v=1:a=1[v][a]" +
" -c:v libx264 -c:a aac -strict -2 -map [v] -map [a] -preset veryfast " + outputPath;
Any one who have idea to add a transition effect between video and image.
Please help me.
Thanks in advance.
I'm working with 2 videos and I want to make 3 different operations at same
execution with FFmpeg. Each command works separate but it'll much more efficient to make them all run at the same execution.
So for example I have:
Video 1
Video 2
First I want to cut both videos from starting point to end point:
cmd = -i video1Path -ss 00:00:30.0 -c copy -t 00:00:10.0 video1Output
cmd = -i video2Path -ss 00:00:30.0 -c copy -t 00:00:10.0 video2Output
Than resizing Video 1:
cmd = "-i " + video1Output+ " -vf scale=240:360" + resizedVideo1;
Now overlaying the resizedVideo1 on top of Video 2:
cmd = "-i " + video2Output + " -i " + resizedVideo1 + " -filter_complex [0:v][1:v]" + overlayCmd + " " + finalVideoPath;
I'm wondering if it's possible to achieve all this actions at the same FFMpeg executions using 1 filter_complex...
The combined command will be
ffmpeg -ss 30 -t 10 -i video2 -ss 30 -t 10 -i video1
-filter_complex
"[1]scale=240:360[v1];[0][v1]overlay"
output.mp4
I am trying to use ffmpeg library for mixing two MP3 or wav audio files using the commands available that I searched over Internet like given below:
ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex amerge -c:a libmp3lame -q:a 4 output.mp3
From link How to overlay two audio files using ffmpeg
Also, tried some many other solutions given on the different forms.
But none of them is working for the the library downloaded from link:
https://github.com/hiteshsondhi88/ffmpeg-android-java.
But when I am trying to run the commands available on the intener, in some commands I am getting different different error like,
-- Unable to find suitable output format for 'ffmpeg' ffmpeg: Invalid argument
And I also tried one more command,
String res = "ffmpeg -y -i " + a.getAbsolutePath() + " -i " + b.getAbsolutePath() + " -filter_complex '[0:0][1:0] amix=inputs=2:duration=longest' -c:a libmp3lame " + c.getAbsolutePath();
It's giving error, No such filter:" Error configuring filters.
What is your version of FFmpeg?
I believe it's old and that's why it's not working.
First setp download newest version from official site try if your command it's working if yes than find another (or build your own) compiled for android executable file
Well First check your FFmpeg version. The way you have used the amix filter have to be changed. amix filter mix audios. So following is what I'm suggesting.
ffmpeg -i input_audio1 -i input_audio2 -filter_complex "aevalsrc=0:d=10[s1];
[s1][1:a]concat=n=2:v=0:a=1[ac1];
[0:a][ac1]amix[aout]" -map [aout] -c:a libmp3lame output_audio
you can append a silent audio which duration is same as the first audio and them use amix over them. So the original audio's will not overlap. aevalsrc will create a silent audio with a duration of 10 sec. Also you need to select appropriate codec for your output accordingly. You can find those codec here.
Hope this helps!
I know it's been some time since this question was posted, but I think your main problem is that you shouldn't include "ffmpeg" on your string.
So your cmd line would be:
String res = "-y -i " + a.getAbsolutePath() + " -i " + b.getAbsolutePath() + " -filter_complex '[0:0][1:0] amix=inputs=2:duration=longest' -c:a libmp3lame " + c.getAbsolutePath();
I'm trying to make a mp4 from an app on Android, to do so i added the FFmpeg binary.
to create the mp3 i use a command :
ffmpegBinaryPath + " -r 24 -i " + inputImgPath + " -c:v libx264 -crf 23 -pix_fmt yuv420p -s 640x480 " + outputVideoPath;
But i want to add sound on this mp4 i use :
ffmpegBinaryPath + " -r 24 -i " + inputImgPath + " -i " + mp3Path + " -c:v libx264 -crf 23 -pix_fmt yuv420p -s 640x480 " + outputVideoPath;
But it does not work i have no error message and FFmpeg stop at the beginning.
I think i need a mp3 code or something like but i can't fin a way to make it works.
So any help will be appreciated.
Thank you.