专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-963-0016      微信咨询  |  联系我们

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

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 0:47:25       共计:3611 浏览

1.项目结构:


2.代码:

		
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace WebFFmpeg
  9. {
  10. public partial class _Default : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14.  
  15. }
  16.  
  17. protected void Button1_Click(object sender, EventArgs e)
  18. {
  19. string pathString = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  20. Process p = new Process();
  21. p.StartInfo.FileName = pathString + "\\FFmpeg\\ffmpeg.exe";
  22. p.StartInfo.Arguments = @"-y -r 1 -i " +
  23. pathString + @"FFmpeg\pic\img%2d.jpg -i " +
  24. pathString + @"FFmpeg\music\02.mp3 -s 800x800 -vcodec mpeg4" +
  25. pathString + @"FFmpeg\vedio\out.mp4";
  26. p.StartInfo.UseShellExecute = false;
  27. p.StartInfo.RedirectStandardError = true;
  28. p.StartInfo.Crea teNoWindow = true;
  29. p.ErrorDataReceived += new DataReceivedEventHandler((s, message) => { Response.Write(message.Data); });//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  30. p.Start();//启动线程
  31. p.BeginErrorReadLine();//开始异步读取
  32. p.WaitForExit();//阻塞等待进程结束
  33. p.Close();//关闭进程
  34. p.Dispose();//释放资源
  35.  
  36. Response.Write("<a href='FFmpeg/vedio/out.mp4'>下载</a>");
  37. }
  38. }
  39. }

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:ffmpeg 视频转ts切片 生成m3u8视频播放列表 | ·下一条:批处理ffmpeg将avi视频格式转换成mp4文件同时生成m3u8文件

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有