• 大小: 12.39MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-19
  • 语言: C#
  • 标签: 视频截图  

资源简介

C# 获取视频时长,并且视频截图,代码清晰明了,使用了ffmpeg.exe工具。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.IO;
using System.Web;
namespace AUV5.Common
{
    public class FormatConverter
    {
        //FFmpeg配置信息
        private string ffmpegpath = “/FFmpeg/ffmpeg.exe“;//FFmpeg的服务器路径
        private string imgsize = “400*300“;     //视频截图大小
        private string videosize = “480*360“; //视频大小
        #region 也可将信息添加到配置文件中
        //public static string ffmpegpath = ConfigurationManager.AppSettings[“ffmpeg“];
        //public static string imgsize = ConfigurationManager.AppSettings[“imgsize“];
        //public static string videosize = ConfigurationManager.AppSettings[“videoize“];
        #endregion

        private string destVideo = ““;

        /// 
        /// 视频路径
        /// 

        public string DestVideo
        {
            get { return destVideo; }
            set { destVideo = value; }
        }
        private string destImage = ““;

        /// 
        /// 图片路径
        /// 

        public string DestImage
        {
            get { return destImage; }
            set { destImage = value; }
        }

        /// 
        /// 视频长度
        /// 

        public string VideoLength { get; set; }

        //文件类型
        public enum VideoType
        {
            [Description(“.avi“)]
            AVI
            [Description(“.mov“)]
            MOV
            [Description(“.mpg“)]
            MPG
            [Description(“.mp4“)]
            MP4
            [Description(“.flv“)]
            FLV
        }
        /// 
        /// 返回枚举类型的描述信息
        /// 

        /// 
        /// 
        private string GetDiscription(System.Enum myEnum)
        {

            System.Reflection.FieldInfo fieldInfo = myEnum.GetType().GetField(myEnum.ToString());
            object[] attrs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute) true);
            if (attrs != null && attrs.Length > 0)
            {
                DescriptionAttribute desc = attrs[0] as DescriptionAttribute;
                if (desc != null)
                {
                    return desc.Description.ToLower();
                }
            }
            return myEnum.ToString();
        }
        //将GetDescription定义为扩展方法需.net3.5
        //public static string Description(this Enum myEnum)
        //{
        //    return GetDiscription(myEnum);
        //}

        //构造函数
        //创建目录
        public FormatConverter()
        {
        }

        #region 使用FFmpeg进行格式转换

        /// 
        /// 运行格式转换
        /// 

        /// 要转换文件绝对路径
        /// 转换结果存储的相对路径
        /// 要转换成的文件类型
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       8704  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\bin\VideoDurationDemo.dll

     文件        340  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\bin\VideoDurationDemo.dll.config

     文件      22016  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\bin\VideoDurationDemo.pdb

     文件   12312576  2015-08-21 19:23  VideoDurationDemo\VideoDurationDemo\FFmpeg\ffmpeg.exe

     文件      10867  2015-08-21 20:41  VideoDurationDemo\VideoDurationDemo\FormatConverter.cs

     文件       8267  2015-08-21 20:41  VideoDurationDemo\VideoDurationDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        586  2015-08-21 19:25  VideoDurationDemo\VideoDurationDemo\obj\Debug\VideoDurationDemo.csproj.FileListAbsolute.txt

     文件       3320  2015-08-21 19:25  VideoDurationDemo\VideoDurationDemo\obj\Debug\VideoDurationDemo.csprojResolveAssemblyReference.cache

     文件       8704  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\obj\Debug\VideoDurationDemo.dll

     文件      22016  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\obj\Debug\VideoDurationDemo.pdb

     文件       1345  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\Properties\AssemblyInfo.cs

     文件        534  2015-08-21 19:26  VideoDurationDemo\VideoDurationDemo\temp.aspx

     文件        886  2015-08-21 20:48  VideoDurationDemo\VideoDurationDemo\temp.aspx.cs

     文件        809  2015-08-21 19:23  VideoDurationDemo\VideoDurationDemo\temp.aspx.designer.cs

     文件        536  2015-08-21 20:48  VideoDurationDemo\VideoDurationDemo\tempdetail.aspx

     文件        984  2015-08-21 20:48  VideoDurationDemo\VideoDurationDemo\tempdetail.aspx.cs

     文件        815  2015-08-21 20:41  VideoDurationDemo\VideoDurationDemo\tempdetail.aspx.designer.cs

     文件    9049738  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\UploadFile\20150821113001.mp4

     文件       5613  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\VideoDurationDemo.csproj

     文件       1084  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\VideoDurationDemo.csproj.user

     文件        340  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\Web.config

     文件       1245  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\Web.Debug.config

     文件       1306  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo\Web.Release.config

     文件       1020  2015-08-21 19:21  VideoDurationDemo\VideoDurationDemo.sln

    ..A..H.     43520  2015-08-21 19:27  VideoDurationDemo\VideoDurationDemo.v12.suo

    ..AD...         0  2015-08-21 20:48  VideoDurationDemo\VideoDurationDemo\obj\Debug\TempPE

     目录          0  2015-08-21 20:45  VideoDurationDemo\VideoDurationDemo\obj\Debug

............此处省略10个文件信息

评论

共有 条评论