欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)為視頻添加水印

 更新時(shí)間:2023年01月09日 14:19:46   作者:Csharp小記  
這篇文章主要為大家詳細(xì)介紹了C#如何使用ffmpeg命令,分別實(shí)現(xiàn)給視頻添加圖片水印以及文字水印,文中的示例代講解詳細(xì),感興趣的可以了解一下

文章描述

以下主要還是使用到了ffmpeg命令,分別實(shí)現(xiàn)了給視頻添加圖片水印以及文字水印。

開發(fā)環(huán)境

.NET Framework版本:4.5

開發(fā)工具

Visual Studio 2013

實(shí)現(xiàn)代碼

 public static void Run(string cmd)
        {
            try
            {
                string ffmpeg = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe";
                ProcessStartInfo startInfo = new ProcessStartInfo(ffmpeg);
                startInfo.UseShellExecute = false;
                startInfo.CreateNoWindow = true;
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.Arguments = cmd;
                Process process = Process.Start(startInfo);
                process.WaitForExit(3000);
                process.Kill();
            }
            catch { }
        }
 /// <summary>
        /// 按時(shí)間獲取某幀圖片
        /// </summary>
        /// <param name="videoPath">視頻路徑</param>
        /// <param name="outPath">輸出路徑</param>
        /// <param name="frameTime">時(shí)間(格式:00:00:01)</param>
        public static void GetFrame(string videoPath, string outPath, string frameTime)
        {
            Run(string.Format("-ss 00:00:01 -i {1} {2}", frameTime, videoPath, outPath));
        }

        /// <summary>
        /// 批量添加圖片水印
        /// </summary>
        /// <param name="videoPath"></param>
        /// <param name="outPath"></param>
        /// <param name="listImg"></param>
        public static void AddImageMark(string videoPath, string outPath, List<ImgMark> listImg)
        {
            string imgs = "", postions = "";
            foreach (ImgMark mark in listImg)
            {
                imgs += " -i " + mark.ImgPath;
                postions += "overlay=" + mark.Postion.X + ":" + mark.Postion.Y+",";
            }
            postions = postions.Remove(postions.Length - 1);
            Run(string.Format("-i {0}{1} -filter_complex \"{2}\" {3}", videoPath, imgs, postions, outPath));
        }

        /// <summary>
        /// 添加文字水印
        /// </summary>
        /// <param name="videoPath">視頻路徑</param>
        /// <param name="outPath">輸出路徑</param>
        /// <param name="textMark">水印屬性</param>
        public static void AddTextMark(string videoPath, string outPath, TextMark textMark)
        {
            Run(string.Format(" -i {0}  -vf \"drawtext=fontfile={1}: text='{2}':x={3}:y={4}:fontsize={5}:fontcolor={6}\" {7}", videoPath, textMark.FontFile, textMark.Text, textMark.X, textMark.Y, textMark.FontSize, textMark.FontColor.Name.ToLower(), outPath));
            //@"%{localtime\:%Y\-%m\-%d %H-%M-%S}"
        }
 private void btn_select_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "視頻|*.mp4;*.avi";
            ofd.Title = "請(qǐng)選擇視頻文件";
            ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = ofd.FileName;
            }
        }

        private void btn_text_Click(object sender, EventArgs e)
        {
            if (!File.Exists(axWindowsMediaPlayer1.URL))
            {
                MessageBox.Show("未選擇視頻");
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "視頻|*.mp4";
            sfd.AddExtension = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                TextMark mark = new TextMark
                {
                    Text = "這里是水印",
                    FontColor = Color.Red,
                    FontFile = "simsun.ttc",
                    FontSize = 100,
                    X = 80,
                    Y = 60
                };
                FFmpegUtil.AddTextMark(axWindowsMediaPlayer1.URL, sfd.FileName, mark);
                axWindowsMediaPlayer2.URL = sfd.FileName;
            }
        }

        private void btn_img_Click(object sender, EventArgs e)
        {
            if (!File.Exists(axWindowsMediaPlayer1.URL))
            {
                MessageBox.Show("未選擇視頻");
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "視頻|*.mp4";
            sfd.AddExtension = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                FFmpegUtil.AddImageMark(axWindowsMediaPlayer1.URL, sfd.FileName, new List<ImgMark>{
                    new ImgMark {
                    ImgPath=@"C:\Users\Zero\Desktop\a\\1.png",                   Postion=new Point(60,60)},
                    new ImgMark {ImgPath=@"C:\Users\Zero\Desktop\a\\1.png",             Postion=new Point(60,200)}});
                axWindowsMediaPlayer2.URL = sfd.FileName;
            }
        }

實(shí)現(xiàn)效果

代碼解析:著重介紹下添加文字水印的,由于很多時(shí)候我們需要添加的是中文,所以需要將字體包先放入到ffmepg的同級(jí)目錄,然后指定該字體。

到此這篇關(guān)于C#實(shí)現(xiàn)為視頻添加水印的文章就介紹到這了,更多相關(guān)C#視頻添加水印內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • c#中task與thread的區(qū)別及使用講解

    c#中task與thread的區(qū)別及使用講解

    這篇文章主要介紹了c#中task與thread的區(qū)別及使用講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • C#序列化與反序列化實(shí)例

    C#序列化與反序列化實(shí)例

    這篇文章主要介紹了C#序列化與反序列化的實(shí)現(xiàn)方法,實(shí)例分析了序列化與反序列化的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2015-01-01
  • C#實(shí)現(xiàn)IP代理池調(diào)度的示例代碼

    C#實(shí)現(xiàn)IP代理池調(diào)度的示例代碼

    這篇文章主要為大家介紹了C#實(shí)現(xiàn)IP代理池調(diào)度的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的參考與學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下
    2023-07-07
  • C#模擬MSN窗體抖動(dòng)的實(shí)現(xiàn)代碼

    C#模擬MSN窗體抖動(dòng)的實(shí)現(xiàn)代碼

    這篇文章主要介紹了C#模擬MSN窗體抖動(dòng)的實(shí)現(xiàn)代碼,非常實(shí)用的一個(gè)功能,需要的朋友可以參考下
    2014-08-08
  • C#文字換行的實(shí)現(xiàn)方法

    C#文字換行的實(shí)現(xiàn)方法

    這篇文章主要介紹了C#文字換行的實(shí)現(xiàn)方法,通過自定義函數(shù)實(shí)現(xiàn)針對(duì)特定字符串的換行長度處理,是比較實(shí)用的技巧,對(duì)于C#的深入學(xué)習(xí)具有一定的借鑒價(jià)值,需要的朋友可以參考下
    2014-12-12
  • 淺析C#中g(shù)oto跳轉(zhuǎn)語句的用法

    淺析C#中g(shù)oto跳轉(zhuǎn)語句的用法

    在我們?nèi)粘9ぷ髦谐S玫腃#跳轉(zhuǎn)語句有break、continue、return,但是還有一個(gè)C#跳轉(zhuǎn)語句很多同學(xué)可能都比較的陌生就是goto,下面我們就來看看goto跳轉(zhuǎn)語句的用法吧
    2024-03-03
  • C#創(chuàng)建SQLite控制臺(tái)應(yīng)用程序詳解

    C#創(chuàng)建SQLite控制臺(tái)應(yīng)用程序詳解

    這篇文章主要為大家詳細(xì)介紹了C#創(chuàng)建SQLite控制臺(tái)應(yīng)用程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • C#獲取CPU處理器核心數(shù)量的方法

    C#獲取CPU處理器核心數(shù)量的方法

    本文主要介紹了C#獲取CPU處理器核心數(shù)量的方法,代碼簡單易懂,具有很好的參考價(jià)值,需要的朋友可以看下
    2016-12-12
  • C#中new的用法及與override的區(qū)別分析

    C#中new的用法及與override的區(qū)別分析

    這篇文章主要介紹了C#中new的用法,及與override的區(qū)別,需要的朋友可以參考下
    2017-05-05
  • C#中+=是什么意思及+=的用法

    C#中+=是什么意思及+=的用法

    這篇文章主要介紹了C#中+=是什么意思及+=的用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02

最新評(píng)論