ffmpeg overlay issue with rotation - android

I want to execute a command using ffmpeg so it performs three tasks for me at once:
croping the video (OK)
rotate the video for 90° (OK) and
add an overlay
Unfortunately, the tasks 1 and 2 are performed, but the overlay isn't. Please help me.. Here's the command I'm using:
ffmpeg -i " + path + " -i /storage/emulated/0/image.png -filter_complex [0]crop=" + cut + ":" + cut + ":0:0 -metadata:s:v:0 rotate=90 -c:a [a];[a][1]overlay=10:10 -preset ultrafast -codec:a copy /storage/emulated/0/Nitin/" + videoFile;

By using the options -metadata:s:v:0 rotate=90, you were settings the rotate matrix in your video stream.
It seems your filters are not chained in your filter graph. You could achieve all your goals in a filter chain.
[in] ---> crop ---> transpose ---> overlay ---> [out]
^
|
---> movie -----------------|
The filter graph showed above can be specified with -vf option like below.
ffmpeg -i input.mp4 -vf "crop=200:200:12:34,transpose=1 [ct];movie=/path/to/the/overlay/image.png [movie];[ct] [movie]overlay=(W-w)/2:(H-h)/2" -c:a copy -c:v libx264 output.mp4
You should change crop parameters to yours, the transpose filter with 1 parameter will rotate clock wise by 90 degree, see here for more information.
Also change the movie filter parameter to the path of your image.
At last, these two outputs will centred overlay to generate final output.

Related

ffmpeg scale filter takes too long

I am using below command to scale and blur a video but it is very slow. Can anyone please help if i can improve the speed somehow.
"ffmpeg -i $inputPath -lavfi [0:v]split=2[original][copy];[copy]scale=ih*16/9:-1,crop=h=iw*9/16,boxblur=luma_radius=50:chroma_radius=25:luma_power=2[blurred];[blurred][original]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[final] -map [final] -map a:0 -g 2 -preset ultrafast $outputPath -y"
avgblur or gblur filters may be slightly faster, and stream copy the audio (-c:a copy) instead of re-encoding it.

How do i create video from images with any slideshow effects(like fadein fadeout,crossfade,slides) using ffmpeg in android

I want to create slideshow from bunch of images with the effects like fade-in fade-out, crossfade, slide from right to left, zoom-in zoom-out or any other slideshow effects and i want to create a video as a output from those images.
I have also tried with below FFMPEG command but it seems that it will work for only images having same resolution for different different resolution it doesn't.
String fourImage ="ffmpeg -loop 1 -t 3 -i /sdcard/videokit/one.jpg
-loop 1 -t 3 -i /sdcard/videokit/two.jpg -loop 1 -t 3 -i /sdcard/videokit/three.jpg -loop 1 -t 3 -i /sdcard/videokit/four.jpg
-filter_complex [0:v]trim=duration=3,fade=t=out:st=2.5:d=0.5[v0];[1:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v1];[2:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v2];[3:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v3];[v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p[v]
-map [v] -preset ultrafast /sdcard/videokit/fourImageSecond.mp4";
And also look at this link as i want to create same effects but it works for same resolution image only.
So my question is, how can I create video from images with slideshow effects using ffmpeg ?
Any help would be highly appreciable.
As official wiki says: All images in a series need to be the same size and format.
You need to resize all images you have using below code:
Bitmap yourBitmap;
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);
or:
resized = Bitmap.createScaledBitmap(yourBitmap,(int)(yourBitmap.getWidth()*0.8), (int)(yourBitmap.getHeight()*0.8), true);
After this step is completed read this repository.
Good luck :)
First, you have to make the same size file then you have to add effect
"[0:v]scale=1024x576:force_original_aspect_ratio=decrease, setdar=16/9,pad=1024:576:-1:-1,setsar=1,fps=30,format=yuv420p[v0];" +
"[1:v]scale=1024x576:force_original_aspect_ratio=decrease, setdar=16/9,pad=1024:576:-1:-1,setsar=1,fps=30,format=yuv420p[v1];" +
"[2:v]scale=1024x576:force_original_aspect_ratio=decrease, setdar=16/9,pad=1024:576:-1:-1,setsar=1,fps=30,format=yuv420p[v2];" +
"[v0]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v0];" +
"[v1]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v1];" +
"[v2]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v2];" +
"[v0][v1][v2]concat=n=3:v=1:a=0[v]", "-map", "[v]", "-preset",
strong text "ultrafast", pathsavaing};

generate transparent video overlay or another way?

my src files are lots of pngs, and b.mp4
What i want :
overlay pngs (as anim) on b.mp4
the way i have tried:
the size of 200 pngs are almost 40M,could not put into the android phone..
so I generate pngs to transparent video use this command:
"ffmpeg -i %04d.png -vcodec png a.mov "
then use
"ffmpeg -i b.mp4 -i a.mov -vf overlay=0:0:0 out.mp4",
it worked.
but the problem I got is that the size of a.mov is too big (200 pngs,each file is 100k, a.mov is about 100M ),and i tried -vcodec copy,rawvideo,qtle,also got a very big file. are there any idea to resolve this problem?
then I tried to find another way:I generate pngs to mp4,use
ffmpeg -i %04d.png -vcodec libx264 a.mp4
and I know libx264 with yuv420p(libx264 not support yuva420p) could not keep the alpha channel? but I still want to have a try.then I overlay a.mp4 on b.mov;
obviously,a black background under a.mp4 ....because it lost it's alpha channel?
then I tried blend filter, I find blend=all_mode=lighten looks a bit same as what i want?but it's still not as same as the effect (overlay)
any one who can help me ,thanks
You can overlay the png files directly over the video in one command. For example:
ffmpeg -i b.mp4 -framerate 30 -i %04d.png -filter_complex [0:v][1:v]overlay=format=yuv420[vid] -map [vid] -r 30 output.mp4
In the past, I've found that png files are better for overlays then a mov file. Make sure that you provide the frame rate for the png input, otherwise it will assume 25 fps (which may not be the same fps as video b.mp4).

How to put a text watermark on a video using ffmpeg command in android

I am trying to put watermark on the video file which i am compressing using ffmpeg library.
What exactly is the command that i need to put to put a text watermark on the video file??
I have tried using this command :
String commandStr = "ffmpeg -i " + inputpath
+" drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='Test Text' -strict experimental -s " + str_resolution
+ " -ac 2 -ar 44100 -b "+str_bitrate+" "
+ outvidpath;
After using this command the video does not get generated. What could possibly could go wrong in this command??
Please help! Thanks in advance!
My first preferences for watermarking with text and image use "Mencoder". it is better and simple that FFmpeg
I have looked in your command. it seems your video file name have black space, so use double quotes to enclose file name. or video file is not in the folder.

Creating video from images with FFmpeg4Android

I am using this http://androidwarzone.blogspot.in/2011/12/ffmpeg4android.html for implementing what I need.
My code for Creating video from images is:
for (int i = 1; i < 60; i++)
{
commandStr = "ffmpeg -y -r 1/5 -i /sdcard/TApp/Media/"+i+".jpg /sdcard/TApp/Media/out.mp4";
setCommand(commandStr);
runTranscoing();
}
And I`m not getting the right result. Why is that?
Firstly you have coded wrongly. You just have to specify the Image Series for making Video from images. That means all the images should have a name in series. Take a look at Ffmpeg Doc for a better understanding.
Also you have not specified the filter to be used for encoding the video.
Make a change like this to code
String cmnd ="ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4";
setCommand(cmnd);
runTranscoing();
Cheers. :)

Categories

Resources