基本信息
源码名称:ffmpeg示例demo
源码大小:46.71M
文件格式:.zip
开发语言:C#
更新时间:2021-01-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 3 元 
   源码介绍

C#视频示例

演示C#如何调用ffmpeg API

ffmpeg版本需要和FFmpeg.AutoGen对应,这里使用3.4版本

using 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();
        }
    }
}