找传奇、传世资源到传世资源站!

ffmpeg示例demo

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C#视频示例

演示C#如何调用ffmpeg API

ffmpeg版本需要和FFmpeg.AutoGen对应,这里使用3.4版本
from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace FFmpegDemo{ public partial class frmPlayer : Form { public frmPlayer() { InitializeComponent(); } tstRtmp rtmp = new tstRtmp(); Thread thPlayer; public String exePath = Application.StartupPath; private void btnStart_Click(object sender, EventArgs e) { btnStart.Enabled = false; if (thPlayer != null) { rtmp.Stop(); thPlayer = null; } else { thPlayer = new Thread(DeCoding); thPlayer.IsBackground = true; thPlayer.Start(); btnStart.Text = "停止播放"; btnStart.Enabled = true; } } /// <summary> /// 播放线程执行方法 /// </summary> private unsafe void DeCoding() { try { Console.WriteLine("DeCoding run..."); Bitmap oldBmp = null; // 更新图片显示 tstRtmp.ShowBitmap show = (bmp) => { this.Invoke(new MethodInvoker(() => { this.pic.Image = bmp; if (oldBmp != null) { oldBmp.Dispose(); } oldBmp = bmp; })); }; rtmp.Start(show, txtUrl.Text.Trim()); } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.WriteLine("DeCoding exit"); rtmp.Stop(); thPlayer = null; this.Invoke(new MethodInvoker(() => { btnStart.Text = "开始播放"; btnStart.Enabled = true; })); } } private void button1_Click(object sender, EventArgs e) { GetImge(); } private void GetImge() { DirectoryInfo dir = new DirectoryInfo(@"images"); FileInfo[] fileInfo = dir.GetFiles(); List<string> fileNames = new List<string>(); foreach (FileInfo item in fileInfo) { fileNames.Add(item.Name); } //图片展示 for (int i = 0; i < fileNames.Count; i ) { string fileName = fileNames[i]; PictureBox newpic = new PictureBox { BackColor = System.Drawing.Color.Transparent, BackgroundImageLayout = ImageLayout.Stretch, Width = 75, Height = 90, BackgroundImage = Image.FromFile(exePath "../images/" fileName) }; double value = i / 6; int num = (int)Math.Floor(value); newpic.Location = new Point(10 75 * (i%6) 10 * (i % 6), 90*num 10* num); this.panel2.Controls.Add(newpic) ; } } private void frmPlayer_Shown(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { frmSetting f = new frmSetting(); f.ShowDialog(); } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复