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
Related
I m using below ffmpeg command to generate video(slideshow) from list of images,but the issue is that its only displaying first image.
ffmpeg -loop 1 -t 3 -i image1.jpg -i image2.jpg -i image3.jpg -filter_complex [v][v1][v2] concat=n=3:v=1,format=yuv422p[a] -map [a] out.mp4
Any help will be appreciate.
Thanks.
Finally after lot of practices got the solution and better ffmpeg command then above command.
ffmpeg -f concat -safe 0 -i img-list.txt -f concat -safe 0 -i audio-list.txt -c:a aac -pix_fmt yuv420p -crf 23 -r 24 -shortest -y -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4
in above command input.txt will contains path of image files seperated with new line.
input.txt
file '*/image1.jpg'
file '*/image2.jpg'
file '*/image3.jpg'
Using Ffmpeg on Android to make a video from Single image merged with an Audio file, it works but the output video is not seeking to any time stamps
ex - always starts from 0:00, on seeking the video ahead it just restarts the whole video from start.
The command I used is -
-y -framerate 30 -i "+ImagePath+" -i "+AudioPath+" -vsync vfr -c:v libx264 -codec:a copy -pix_fmt yuv420p -crf 23 "+OutputVideoPath
can this be due to single frame only? (one image in video)
if so what can be used to convert a single image to seekable video.
This command will work to make a seekable MP4 (using input from image file and MP3 audio).
ffmpeg -y -i AUDIO.file -f image2 -loop 1 -r 2 -i IMAGE.file -shortest -c:a copy -c:v libx264 -crf 18 -framerate 30 -preset veryfast -movflags +faststart OUTPUT.mp4
Just replace AUDIO.file and IMAGE.fileand OUTPUT.mp4 with your custom file names.
Try this in your Android code:
-y -i "+AudioPath+" -f image2 -loop 1 -r 2 -i "+ImagePath+" -shortest -c:a copy -c:v libx264 -crf 18 -framerate 30 -preset veryfast -movflags +faststart "+OutputVideoPath+"
Try setting up your code like this:
"-y -i "+AudioPath+" -f image2 -loop 1 -r 2 -i "+ImagePath+" -shortest -c:a copy -c:v libx264 -crf 18 -framerate 30 -preset veryfast -movflags +faststart "+OutputVideoPath
I have used this command to concate multiple images with transition effects to create video.
"-y -f concat -safe 0 -i <txt file path> -filter_complex [0:0][1:0]concat=n=2:v=0:a=1[out] -map [v] -shortest -vf fps=40 -pix_fmt yuv420p <video path>"
But it is showing error :
Stream specifier ':0' in filtergraph description [0:0][1:0]concat=n=2:v=0:a=1[out] matches no streams.
Here is my txt file
file '/storage/emulated/0/image1.jpg'
duration 5
file '/storage/emulated/0/image2.jpg'
duration 5
file '/storage/emulated/0/image3.jpg'
However if i am not applying any filter effect, it is successfully creating a video.
Following command creates the video at a frame rate of 1 frame for 5 seconds.
ffmpeg -y -r 1/5 -i image1.jpg -i image2.jpg -i image3.jpg -filter_complex 'concat=n=3:v=1:a=0 [out]' -map [out] -c:v libx264 output.mp4
I am using below command to apply effect,its take 6-8 minutes to apply effect for 2 min video. Please help me to improve effective time for ffmpeg commands.
String commandStr = "ffmpeg -y -i "
+ mVideoData.getPath()
+ " -strict experimental -vf curves=vintage -s 640x480 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k -vcodec mpeg4 /sdcard/videokit/curve.mp4";
I am playing with video compression by using ffmpeg. I can compress the video e.g. with this line:
String commandStr = "ffmpeg -y -i /sdcard/videokit3/Dani.mp4 -strict experimental -s 320x240-r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 512k /sdcard/videokit3/Dani2.mp4";
In this line the path is hardcoded, so I did
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "videokit3/Dani.mp4";
which results in /mnt/sdcard/videokit3/Dani.mp4
This seems to be different from /sdcard/videokit3/Dani.mp4 so this line runs to error (I see the difference, I just don't get it):
String commandStr = "ffmpeg -y -i " + path + " -strict experimental -s 320x240 -r 30 -ab 48000 -ac 2 -ar 22050 -b 512k /sdcard/videokit3/Dani4.mp4";
Can you help?
The easiest way to get around would be replace the string and trim "/mnt" out before inserting into the statement. The reason why the external SDcard absolute path returns as "mounted" drive is available here on SO: stackoverflow.com/a/5695129/2777098