'Merge one vido and images using ffmpeg
I'm want to compile one .mp4 file that contain this:
10 seconds showing mp4 file 4 seconds showing image1.jpg ... 4 seconds showing image{n}.jpg
and I want to fade between video and images . thanks a lot
Solution 1:[1]
I found solution for my code in c#
List<string> tempimg = new List<string>();
var c = (int)Math.Ceiling(item.Users.Count / 6.0);
for (int i = 1; i <= c; i++)
{
//DO ADD IMAGE INTO tempimg
}
string video = "5small.mp4";
string output = $"{Guid.NewGuid()}.mp4";
IMediaInfo mediaInfo = FFmpeg.GetMediaInfo(video).Result;
var videoDuration = (int)mediaInfo.VideoStreams.First().Duration.TotalSeconds - 2;
int count = tempimg.Count;
string cmd = $@" -i {video} " + Environment.NewLine;
for (var i = 1; i <= count; i++)
cmd += $"-loop 1 -t 5 -i {tempimg[i - 1]} " + Environment.NewLine;
cmd += "-i 1.mp3 " + Environment.NewLine;
cmd += $@"-f lavfi -t 0.1 -i anullsrc=channel_layout=stereo:sample_rate=44100
-filter_complex "" " + Environment.NewLine;
for (int i = 1; i <= count; i++)
{
cmd += $@"[{i}]format = yuva444p,fade = d = 1:t =in:alpha = 1,setpts = PTS - STARTPTS + {videoDuration + (i * 3)} / TB[f{i - 1}];" + Environment.NewLine;
}
cmd += "[0][f0]overlay[bg1];" + Environment.NewLine;
for (int i = 1; i < count - 1; i++)
{
cmd += $@"[bg{i}][f{i}]overlay[bg{i + 1}];" + Environment.NewLine;
}
cmd += $@"[bg{count - 1}][f{count - 1}]overlay,format = yuv420p[v]"" -map ""[v]"" -map {count + 1}:a -shortest -movflags +faststart { output}";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pouria Anushiravani |
