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).
Related
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.
I am trying to place multiple gif on image and save as gif using FFmpeg. I had achieved placing of multiple gif but all gif doesnot play continuously i.e Second gif repeat only once first gif finish and started again ..the second gif stop and start again only when first gif finishes.
command_try[0]="-i";
command_try[1]=input;
command_try[2]="-i";
command_try[3]=gifthumbnail;
command_try[4]="-i";
command_try[5]=gifthumbnail;
command_try[6]="-i";
command_try[7]=thumbnail;
command_try[8]="-i";
command_try[9]=thumbnail2;
command_try[10]="-filter_complex";
command_try[11]="[0:v]scale=0:0[base];[1:v]scale=300:-1[img1];[2:v]scale=720:-1290[img2];[3:v]scale=80:-1[img3];[4:v]scale=50:-1[img4];[img1]rotate=45:c=black#0:ow=rotw(45):oh=roth(45)[r1];[img2]rotate=0:c=black#0:ow=rotw(0):oh=roth(0)[r2];" +
"[img3]rotate=0:c=black#0:ow=rotw(0):oh=roth(0)[r3];[img4]rotate=0:c=black#0:ow=rotw(0):oh=roth(0)[r4];[base][r1]overlay=100:70[tmp1];"+
"[tmp1][r2]overlay=55:55[tmp2];[tmp2][r3]overlay=65:65[tmp3];[tmp3][r4]overlay=30:30";
command_try[12]="-preset";
command_try[13]="veryfast";
command_try[14]="/storage/emulated/0/Pictures/imggif.gif";
As I am recently started working on FFmpeg need help to play gif continuously independently.
Use the -stream_loop -1 input option and add the shortest=1 option to any overlay with an infinitely looping GIF as an input.
Simplified example:
ffmpeg -i video.mp4 -stream_loop -1 -i 1.gif -filter_complex "overlay=shortest=1:format=auto" output.mp4
To avoid the yellow lines add the palettegen and paletteuse filters:
ffmpeg -i video.mp4 -stream_loop -1 -i 1.gif -filter_complex "overlay=shortest=1:format=auto,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
You are using FFmpeg 3.0.1 which is really old so you will have to change auto to rgb.
How to add text with animation on video in ffmpeg?
Now I am trying to add video management function on android app.
If you have a experiences on it, please help me.
I added the visible, marquee,several text lines animation on video in ffmpeg.
It works well.
Here is my code.
ffmpeg -i input.mp4 -vf "[in]drawtext=fontfile=/path/to/font.ttf: text='First Line': fontcolor=red: fontsize=40: x=(w-text_w)/2: y=if(lt(t\,3)\,(-h+((3*h-200)*t/6))\,(h-200)/2):enable='between(t,2.9,50)',drawtext=fontfile=/path/to/font.ttf: text='Second Line': fontcolor=yellow: fontsize=30: x=if(lt(t\,4)\,(-w+((3*w-tw)*t/8))\,(w-tw)/2): y=(h-100)/2:enable='between(t,3.5,50)',drawtext=fontfile=/path/to/font.ttf: text='Third Line': fontcolor=blue: fontsize=50: x=if(lt(t\,5)\,(2*w-((3*w+tw)*t/10))\,(w-tw)/2): y=h/2:enable='between(t,4.5,50)',drawtext=fontfile=/path/to/font.ttf: text='Fourth Line': fontcolor=black: fontsize=20: x=(w-text_w)/2: y=if(lt(t\,6)\,(2*h-((3*h-100)*t/12))\,(h+100)/2):enable='between(t,5.5,50)'[out]" out.mp4
Here "input.mp4" is your input video file and it will output with the name "out.mp4"
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};
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. :)