Common下MadieHelper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;


namespace Common
{
    public class MadieHelper : System.Web.UI.Page
    {
        //文件路径
        public static string ffmpegtool = ConfigurationManager.AppSettings["ffmpeg"];
        public static string mencodertool = ConfigurationManager.AppSettings["mencoder"];
        public static string upFile = ConfigurationManager.AppSettings["upfile"] + "/";
        public static string imgFile = ConfigurationManager.AppSettings["imgfile"] + "/";
        public static string playFile = ConfigurationManager.AppSettings["playfile"] + "/";
        //文件图片大小
        public static string sizeOfImg = ConfigurationManager.AppSettings["CatchFlvImgSize"];
        //文件大小
        public static string widthOfFile = ConfigurationManager.AppSettings["widthSize"];
        public static string heightOfFile = ConfigurationManager.AppSettings["heightSize"];
        //   // //获取文件的名字
        public static string GetFileName(string fileName)
        {
            int i = fileName.LastIndexOf("//") + 1;
            string Name = fileName.Substring(i);
            return Name;
        }
        //获取文件扩展名
        public static string GetExtension(string fileName)
        {
            int i = fileName.LastIndexOf(".") + 1;
            string Name = fileName.Substring(i);
            return Name;
        }
        //
        #region //运行FFMpeg的视频解码,(这里是绝对路径)
        /// <summary>
        /// 转换文件并保存在指定文件夹下面(这里是绝对路径)
        /// </summary>
        /// <param name="fileName">上传视频文件的路径(原文件)</param>
        /// <param name="playFile">转换后的文件的路径(网络播放文件)</param>
        /// <param name="imgFile">从视频文件中抓取的图片路径</param>
        /// <returns>成功:返回图片虚拟地址;   失败:返回空字符串</returns>
        public string ChangeFilePhy(string fileName, string playFile, string imgFile)
        {
            //取得ffmpeg.exe的路径,路径配置在Web.Config中,如:<add   key="ffmpeg"   value="E:/aspx1/ffmpeg.exe"   />  
            string ffmpeg = Server.MapPath(ffmpegtool);
            if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
            {
                return "";
            }

            //获得图片和(.flv)文件相对路径/最后存储到数据库的路径,如:/Web/User1/00001.jpg  

            string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv");


            //截图的尺寸大小,配置在Web.Config中,如:<add   key="CatchFlvImgSize"   value="240x180"   />  
            string FlvImgSize =sizeOfImg;

            System.Diagnostics.ProcessStartInfo FilestartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);

            FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            FilestartInfo.Arguments = " -i " + fileName + " -ab 56 -ar 22050 -b 500 -r 15 -s " + widthOfFile + "x" + heightOfFile + " " + flv_file;
            //ImgstartInfo.Arguments = "   -i   " + fileName + "   -y   -f   image2   -t   0.05   -s   " + FlvImgSize + "   " + flv_img;

            try
            {
                //转换
                System.Diagnostics.Process.Start(FilestartInfo);
               
                //截图
                return CatchImg(fileName, imgFile);
                //System.Diagnostics.Process.Start(ImgstartInfo);
            }
            catch
            {
                return "";
            }
           
        }
        //
        public string CatchImg(string fileName, string imgFile)
        {
            //
            string ffmpeg = Server.MapPath(ffmpegtool);
            //
            string flv_img = imgFile + ".jpg";
            //
            string FlvImgSize = sizeOfImg;
            //
            System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
            ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            //
            ImgstartInfo.Arguments = "   -i   " + fileName + "  -y  -f  image2   -ss 2 -vframes 1  -s   " + FlvImgSize + "   " + flv_img;
            try
            {
                System.Diagnostics.Process.Start(ImgstartInfo);
            }
            catch
            {
                return "";
            }
            //
            if (System.IO.File.Exists(flv_img))
            {
                return flv_img;
            }

            return "";
        }
        #endregion
        //
        #region
        /// <summary>
        /// 转换文件并保存在指定文件夹下面(这里是相对路径)
        /// </summary>
        /// <param name="fileName">上传视频文件的路径(原文件)</param>
        /// <param name="playFile">转换后的文件的路径(网络播放文件)</param>
        /// <param name="imgFile">从视频文件中抓取的图片路径</param>
        /// <returns>成功:返回图片虚拟地址;   失败:返回空字符串</returns>
        public string ChangeFileVir(string fileName, string playFile, string imgFile)
        {
            //取得ffmpeg.exe的路径,路径配置在Web.Config中,如:<add   key="ffmpeg"   value="E:/aspx1/ffmpeg.exe"   />  
            string ffmpeg = Server.MapPath(ffmpegtool);
            if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
            {
                return "";
            }

            //获得图片和(.flv)文件相对路径/最后存储到数据库的路径,如:/Web/User1/00001.jpg  
            string flv_img = System.IO.Path.ChangeExtension(Server.MapPath(imgFile), ".jpg");
            string flv_file = System.IO.Path.ChangeExtension(Server.MapPath(playFile), ".flv");


            //截图的尺寸大小,配置在Web.Config中,如:<add   key="CatchFlvImgSize"   value="240x180"   />  
            string FlvImgSize = sizeOfImg;

            System.Diagnostics.ProcessStartInfo FilestartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
            System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);

            FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            //此处组合成ffmpeg.exe文件需要的参数即可,此处命令在ffmpeg   0.4.9调试通过
            //ffmpeg -i F:/01.wmv -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:/test.flv
            FilestartInfo.Arguments = " -i " + fileName + " -ab 56 -ar 22050 -b 500 -r 15 -s " + widthOfFile + "x" + heightOfFile + " " + flv_file;
            ImgstartInfo.Arguments = "   -i   " + fileName + "   -y   -f   image2   -t   0.001   -s   " + FlvImgSize + "   " + flv_img;

            try
            {
                System.Diagnostics.Process.Start(FilestartInfo);
                System.Diagnostics.Process.Start(ImgstartInfo);
            }
            catch
            {
                return "";
            }

            /**/
            ///注意:图片截取成功后,数据由内存缓存写到磁盘需要时间较长,大概在3,4秒甚至更长;  
            ///这儿需要延时后再检测,我服务器延时8秒,即如果超过8秒图片仍不存在,认为截图失败;  
            ///此处略去延时代码.如有那位知道如何捕捉ffmpeg.exe截图失败消息,请告知,先谢过!  
            if (System.IO.File.Exists(flv_img))
            {
                return flv_img;
            }

            return "";
        }
        #endregion

        #region
        /// <summary>
        /// 运行mencoder的视频解码器转换(这里是(绝对路径))
        /// </summary>
        /// <param name="vFileName"></param>
        /// <param name="playFile"></param>
        /// <param name="imgFile"></param>
        /// <returns></returns>
        public string MChangeFilePhy(string vFileName, string playFile, string imgFile)
        {
            string tool = Server.MapPath(mencodertool);
            //string mplaytool = Server.MapPath(PublicMethod.ffmpegtool);

            if ((!System.IO.File.Exists(tool)) || (!System.IO.File.Exists(vFileName)))
            {
                return "";
            }

            string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv");


            //截图的尺寸大小,配置在Web.Config中,如:<add   key="CatchFlvImgSize"   value="240x180"   />  
            string FlvImgSize =sizeOfImg;

            System.Diagnostics.ProcessStartInfo FilestartInfo = new System.Diagnostics.ProcessStartInfo(tool);

            FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            FilestartInfo.Arguments = " " + vFileName + " -o " + flv_file + " -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=200:mbd=2:mv0:trell:v4mv:cbp:last_pred=1:dia=-1:cmp=0:vb_strategy=1 -vf scale=" + widthOfFile + ":" + heightOfFile + " -ofps 12 -srate 22050";
            try
            {
                System.Diagnostics.Process.Start(FilestartInfo);
                return CatchImg(flv_file, imgFile);
            }
            catch
            {
                return "";
            }
        }
        #endregion

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NullReferenceException: Object reference not set to an instance of an object BattleStageControl.OpenBattleRewardNext () (at Assets/0.C#/Battle/BattleStageControl.cs:102) BattleStageControl.OpenBattleReward () (at Assets/0.C#/Battle/BattleStageControl.cs:70) EventCenter.Broadcast (MeventType MeventType) (at Assets/0.C#/Common/EventCenter.cs:162) FuguiState.DeleteFugui02 (System.String site, System.String FuguiName) (at Assets/0.C#/Map/FuguiState.cs:231) EventCenter.Broadcast[T,X] (MeventType MeventType, T arg1, X arg2) (at Assets/0.C#/Common/EventCenter.cs:196) SaveDataManager.DeleteFugui01 (System.String site, System.String FuguiName) (at Assets/0.C#/Common/SaveDataManager.cs:517) EventCenter.Broadcast[T,X] (MeventType MeventType, T arg1, X arg2) (at Assets/0.C#/Common/EventCenter.cs:196) FuguiActionTriger.clickToDelete () (at Assets/0.C#/Battle/FuguiActionTriger.cs:519) UnityEngine.Events.InvokableCall.Invoke () (at <c6956609c5d74f5d8e6ed4e5e5f40cc2>:0) UnityEngine.Events.UnityEvent.Invoke () (at <c6956609c5d74f5d8e6ed4e5e5f40cc2>:0) UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272) UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)什么意思
最新发布
05-31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值