Continuously play the gif on image using FFmpeg - android

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.

Related

FFMpeg Text Animation

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"

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).

Xamarin Android Player - Can't play this video

I'm using Android's VideoView to play an embedded video in my app. It works fine on my device but I keep getting a "Can't play this video" message and a black screen in the Xamarin Android Player.
The corresponding error log looks like this:
Unable to play video
[MediaPlayer] Error (1,-38)
[VideoView] Error: 1,-38
I found a few posts regarding this error but none of them helped me solving this issue and I'm not able to find a proper description for this status code.
My C# code looks like this:
videoView = new VideoView (Context);
base.SetNativeControl (videoView);
videoView.SetOnErrorListener (new ErrorListener ());
string fileName = e.NewElement.FileSource;
fileName = fileName.ToLower ().Substring (0, fileName.LastIndexOf ("."));
int resourceID = Context.Resources.GetIdentifier (fileName, "raw", Context.PackageName);
var fullPath = String.Format ("android.resource://{0}/{1}", Context.PackageName, resourceID);
videoView.SetVideoPath (fullPath);
videoView.RequestFocus ();
videoView.Start ();
Seems to be an issue with the type of encoding that the emulator supports, if you install ffmpeg, if your on a mac by running these commands:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install ffmpeg
then process your video file with:
ffmpeg -i big_buck_bunny_720p_1mb.mp4 -c:v libx264 -profile:v baseline -c:a aac -strict -2 -b:a 128k output.mp4
and try to play the output it wont show that error but it will be a blank video (just a black screen). So I think the issue is just getting the right encoding, have tried some different encodings but all seems to just show a black screen.
Will do some more digging but for the time being it seems to be just the emulator does not support your encoding.
EDIT
Ok so I got the videoplay working, I processed the video with:
ffmpeg -i SampleVideo_1080x720_1mb.mp4 -codec:v libx264 -profile:v baseline -preset slow -b:v 250k -maxrate 250k -bufsize 500k -vf scale=-1:360 -threads 0 -codec:a aac -strict -2 -b:a 96k output.mp4
Check this site for the ffmpeg parameters.
I setup my VideoView like so:
public class Activity1 : Activity
{
VideoView videoView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
videoView = FindViewById<VideoView> (Resource.Id.SampleVideoView);
videoView.SetMediaController(new MediaController(this));
videoView.SetVideoPath ($"android.resource://{PackageName}/{Resource.Raw.output}");
videoView.RequestFocus ();
videoView.Start ();
}
}
This seems to work on the Xamarin Android Player but only for API versions 16(JellyBean) and 19(Kitkat). 21 (lollipop) just doesn't load the video.
Then I downloaded the GenyMotion Emulator (need to create an account but its free for personal use) to check if it was the Xamarin Player or not. It works on all (16,17,18,19,20 + 22) apart from 21(lollipop). looks like something is wrong with the emulators for 21, I did all my testing on nexus 4 emulators. So if you want tot est video playback I would try to avoid emulators with API 21.
Different Android OS versions support different combinations of audio and video encodings within the video container. So it depends what version your Android Player is emulating. For the table see http://developer.android.com/guide/appendix/media-formats.html#core

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