creating video from selected images using FFMPEG through command Line Android

*爱你&永不变心* 提交于 2021-02-08 04:52:12

问题


i am trying to make a video from selected images from command line using ffmpeg in android

using this project as my source i m trying to make video

this is the command i m trying to create video

   String[] ffmpegCommand = {ffmpegBin,
            "-y",
            "-qscale",
            "1",
            "-r", "" + frameRate,
            "-i", image1.getAbsolutePath(),
            "-t", "" + (((4) * 30) + 4), //"-s",heightwidth,
            "-i", image2.getAbsolutePath(),
            "-t", "" + (((4) * 30) + 4), //"-s",heightwidth,
            "-i", image3.getAbsolutePath(),
            "-t", "" + (((4) * 30) + 4), //"-s",heightwidth,
            "-i", image4.getAbsolutePath(),
            "-t", "" + (((4) * 30) + 4), //"-s",heightwidth,
            "-vcodec",
            "libx264",
            "-s",
            "640x480",
            outputFile.getAbsolutePath()};

but the video created shows only 1st image and video is created of less than a second

what is the problem in this statement ? and why only 1 image is shown in video?

sorry about my bad english


回答1:


Here i am creating video of 12 seconds from 4 images each of 3 seconds with fade in fade out effects.

Run below command and make sure that all the images having same height width.

String strCommand = "ffmpeg -loop 1 -t 3 -i " + /sdcard/videokit/1.jpg + " -loop 1 -t 3 -i " + /sdcard/videokit/2.jpg + " -loop 1 -t 3 -i " + /sdcard/videokit/3.jpg + " -loop 1 -t 3 -i " + /sdcard/videokit/4.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/videolit/output.mp4;



回答2:


This is the ffmpeg command that you should adapt into your string array:

ffmpeg -framerate 25 -t 124 -loop 1 -i image1
       -framerate 25 -t 124 -loop 1 -i image2
       -framerate 25 -t 124 -loop 1 -i image3
       -framerate 25 -t 124 -loop 1 -i image4
       -filter_complex "[0][1][2][3]concat=n=4"
       -c:v libx264 -s 640x480 outputfile

Rule is that input options (framerate, t..etc) go before the input entry.

The concat filter joins the image streams together. If they are different sizes, you should resize to make them the same.



来源:https://stackoverflow.com/questions/38843358/creating-video-from-selected-images-using-ffmpeg-through-command-line-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!