Пример #1
0
        /// <summary>
        /// 运行mencoder的视频解码器转换
        /// </summary>
        public string MChangeFilePhy(string vFileName, string playFile, string imgFile)
        {
            string tool = MachineHelper.MapPath(VideoConvert.mencodertool);

            if ((!System.IO.File.Exists(tool)) || (!System.IO.File.Exists(vFileName)))
            {
                return(string.Empty);
            }
            string flv_file   = System.IO.Path.ChangeExtension(playFile, ".flv");
            string FlvImgSize = VideoConvert.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);
                CatchImg(flv_file, imgFile);
            }
            catch
            {
                return(string.Empty);
            }
            return(string.Empty);
        }
Пример #2
0
        public string CatchImg(string fileName, string imgFile)
        {
            string ffmpeg       = MachineHelper.MapPath(ffmpegtool);
            string flvImg       = imgFile + ".jpg";
            string flvImgSize   = sizeOfImg;
            var    imgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg)
            {
                WindowStyle =
                    System.Diagnostics
                    .ProcessWindowStyle.Hidden,
                Arguments =
                    "   -i   " + fileName
                    + "  -y  -f  image2   -ss 2 -vframes 1  -s   "
                    + flvImgSize + "   " + flvImg
            };

            try
            {
                System.Diagnostics.Process.Start(imgstartInfo);
            }
            catch
            {
                return(string.Empty);
            }
            if (System.IO.File.Exists(flvImg))
            {
                return(flvImg);
            }
            return(string.Empty);
        }
Пример #3
0
        /// <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)
        {
            string ffmpeg = MachineHelper.MapPath(ffmpegtool);

            if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
            {
                return(string.Empty);
            }
            string flvFile       = System.IO.Path.ChangeExtension(playFile, ".flv");
            var    filestartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg)
            {
                WindowStyle =
                    System.Diagnostics
                    .ProcessWindowStyle.Hidden,
                Arguments =
                    " -i " + fileName
                    + " -ab 56 -ar 22050 -b 500 -r 15 -s "
                    + widthOfFile + "x"
                    + heightOfFile + " " + flvFile
            };

            try
            {
                System.Diagnostics.Process.Start(filestartInfo); // 转换
                this.CatchImg(fileName, imgFile);                // 截图
            }
            catch
            {
                return(string.Empty);
            }

            return(string.Empty);
        }
Пример #4
0
        /// <summary>
        /// 将一个对象按XML序列化的方式写入到一个文件
        /// </summary>
        /// <remarks>
        ///  2014年01月09日 11:47 Created By iceStone
        /// </remarks>
        /// <param name="obj">要序列化的对象</param>
        /// <param name="virtualPath">虚拟路径</param>
        /// <param name="encoding">编码方式</param>
        /// <exception cref="System.ArgumentNullException">path</exception>
        public static void SerializeToFile(object obj, string virtualPath, Encoding encoding)
        {
            if (string.IsNullOrEmpty(virtualPath))
            {
                throw new ArgumentNullException("virtualPath");
            }

            var path = MachineHelper.MapPath(virtualPath);

            using (var file = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                Serialize(file, obj, encoding);
            }
        }
Пример #5
0
        /// <summary>
        /// 获取语言化字符串
        /// </summary>
        /// <param name="key">原文键</param>
        /// <param name="culture">区域</param>
        /// <returns>语言化字符串</returns>
        public static string GetCultureString(this string key, string culture = "zh-CN")
        {
            if (resourceSet != null)
            {
                var res = resourceSet.GetString(key);
                return(string.IsNullOrEmpty(res) ? key : res);
            }

            lock ("CultureHelper")
            {
                if (resourceSet != null)
                {
                    var res = resourceSet.GetString(key);
                    return(string.IsNullOrEmpty(res) ? key : res);
                }

                if (HttpContext.Current == null)
                {
                    return(key);
                }

                var vPath = string.Format(Config.GetString("lang_path_format"), culture);
                var fPath = MachineHelper.MapPath(vPath);

                if (!File.Exists(fPath))
                {
                    fPath = MachineHelper.MapPath(Config.GetString("lang_default_path"));
                }

                if (!File.Exists(fPath))
                {
                    return(key);
                }

                // using (var set = new ResourceSet(fPath))
                // {
                //     //CacheHelper.SetCache(vPath, set);
                //     var res = set.GetString(key);
                //     return string.IsNullOrEmpty(res) ? key : res;
                // }
                resourceSet = new ResourceSet(fPath);
            }
            var res2 = resourceSet.GetString(key);

            return(string.IsNullOrEmpty(res2) ? key : res2);
        }
Пример #6
0
        /// <summary>
        /// 读入一个文件,并按XML的方式反序列化对象。
        /// </summary>
        /// <remarks>
        ///  2014年01月09日 11:47 Created By iceStone
        /// </remarks>
        /// <typeparam name="T">结果对象类型</typeparam>
        /// <param name="virtualPath">虚拟路径</param>
        /// <param name="encoding">编码方式</param>
        /// <returns>反序列化得到的对象</returns>
        /// <exception cref="System.ArgumentNullException">
        /// path
        /// or
        /// encoding
        /// </exception>
        public static T DeserializeFromFile <T>(string virtualPath, Encoding encoding)
        {
            if (string.IsNullOrEmpty(virtualPath))
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            var path = MachineHelper.MapPath(virtualPath);

            if (!File.Exists(path))
            {
                return(default(T));
            }
            string xml = File.ReadAllText(path, encoding);

            return(Deserialize <T>(xml, encoding));
        }
Пример #7
0
        /// <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)
        {
            string ffmpeg = MachineHelper.MapPath(VideoConvert.ffmpegtool);

            if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
            {
                return(string.Empty);
            }
            string flv_img    = System.IO.Path.ChangeExtension(MachineHelper.MapPath(imgFile), ".jpg");
            string flv_file   = System.IO.Path.ChangeExtension(MachineHelper.MapPath(playFile), ".flv");
            string FlvImgSize = VideoConvert.sizeOfImg;

            System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
            ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            ImgstartInfo.Arguments   = "   -i   " + fileName + "   -y   -f   image2   -t   0.001   -s   " + FlvImgSize + "   " + flv_img;

            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;
            try
            {
                System.Diagnostics.Process.Start(FilestartInfo);
                System.Diagnostics.Process.Start(ImgstartInfo);
            }
            catch
            {
                return(string.Empty);
            }

            ///注意:图片截取成功后,数据由内存缓存写到磁盘需要时间较长,大概在3,4秒甚至更长;
            ///这儿需要延时后再检测,我服务器延时8秒,即如果超过8秒图片仍不存在,认为截图失败;
            if (System.IO.File.Exists(flv_img))
            {
                return(flv_img);
            }
            return(string.Empty);
        }