C# 调用FFmpeg 根据图片合成视频

本文介绍了如何在C#项目中调用FFmpeg库,将一系列图片组合成一个视频。提供了项目结构说明及代码示例,并附带了Demo的下载链接。

1.项目结构:

 

2.代码:

  

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebFFmpeg
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string pathString = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            Process p = new Process();
            p.StartInfo.FileName = pathString + "\\FFmpeg\\ffmpeg.exe";
            p.StartInfo.Arguments = @"-y -r 1 -i " +
                                    pathString + @"FFmpeg\pic\img%2d.jpg -i " +
                                    pathString + @"FFmpeg\music\02.mp3 -s 800x800 -vcodec mpeg4" +
                                    pathString + @"FFmpeg\vedio\out.mp4";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.Crea teNoWindow = true;
            p.ErrorDataReceived += new DataReceivedEventHandler((s, message) => { Response.Write(message.Data); });//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
            p.Start();//启动线程
            p.BeginErrorReadLine();//开始异步读取
            p.WaitForExit();//阻塞等待进程结束
            p.Close();//关闭进程
            p.Dispose();//释放资源

            Response.Write("<a href='FFmpeg/vedio/out.mp4'>下载</a>");
        }
    }
}

3.Demo 连接

  http://share.weiyun.com/581ce7da333c175841c90931fdfd1756

 

posted on 2014-10-16 18:14  铭轩同学 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/mingxuantongxue/p/4029426.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值