如何使用FFMPEG组合/合并视频和gif? [英] How to combine/merge a video and a gif using FFMPEG?
本文介绍了如何使用FFMPEG组合/合并视频和gif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想合并视频和Gif。
我的视频是45秒内的图片和歌曲,我的Gif是均衡器动画。
我想把视频和Gif结合起来,Gif不透明度是50%。
我找不到任何解决方案但是我尝试用C#来做也不行。
非常感谢。
我尝试过:
I want to merge a video and Gif.
My video is a picture and a song during 45 seconds and my Gif is a equalizer animation.
I want to combine video and Gif , Gif opacity be 50%.
I can't find any solution but I try do it by C# it doesn't work too.
Thanks a lot.
What I have tried:
private void button2_Click(object sender, EventArgs e)
{
string[] files = Directory.GetFiles(@"D:\Temp\tmp");
//combine them into one image
System.Drawing.Bitmap stitchedImage = Combine(files);
//save the new image
stitchedImage.Save(@"D:\stitchedImage.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
public static System.Drawing.Bitmap Combine(string[] files)
{
//read all images into memory
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
System.Drawing.Bitmap finalImage = null;
try
{
int width = 0;
int height = 0;
foreach (string image in files)
{
//create a Bitmap from the file and add it to the list
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
//update the size of the final bitmap
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
images.Add(bitmap);
}
//create a bitmap to hold the combined image
finalImage = new System.Drawing.Bitmap(width, height);
//get a graphics object from the image so we can draw on it
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
//set background color
g.Clear(System.Drawing.Color.Black);
//go through each image and draw it on the final image
int offset = 0;
foreach (System.Drawing.Bitmap image in images)
{
g.DrawImage(image,
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
offset += image.Width;
}
}
return finalImage;
}
catch (Exception ex)
{
if (finalImage != null)
finalImage.Dispose();
throw ex;
}
finally
{
//clean up memory
foreach (System.Drawing.Bitmap image in images)
{
image.Dispose();
}
}
}
推荐答案
请参阅此link 。
我希望这会有所帮助。
Please refer to this link.
I hope this helps.
这篇关于如何使用FFMPEG组合/合并视频和gif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文