海康威视监控下载下来的mp4格式的视频,小类别MPEG

您所在的位置:网站首页 浏览器下载的视频打不开了 海康威视监控下载下来的mp4格式的视频,小类别MPEG

海康威视监控下载下来的mp4格式的视频,小类别MPEG

2023-07-23 21:20| 来源: 网络整理| 查看: 265

 

海康下载视频格式:用mediainfo查看

普通mp4格式用mediainfo查看

自己试了很多方法,html5的 Video控件没法播放,ckplayer没法播放。

 

作者已经解决这个问题,下面是自动转码用的C#代码供大家参考。使用的转码工具是:ffmpeg

界面代码:

namespace zhuanmale {     partial class Form1     {         ///         /// 必需的设计器变量。         ///         private System.ComponentModel.IContainer components = null;

        ///         /// 清理所有正在使用的资源。         ///         /// 如果应释放托管资源,为 true;否则为 false。         protected override void Dispose(bool disposing)         {             if (disposing && (components != null))             {                 components.Dispose();             }             base.Dispose(disposing);         }

        #region Windows 窗体设计器生成的代码

        ///         /// 设计器支持所需的方法 - 不要修改         /// 使用代码编辑器修改此方法的内容。         ///         private void InitializeComponent()         {             this.components = new System.ComponentModel.Container();             this.timer1 = new System.Windows.Forms.Timer(this.components);             this.button1 = new System.Windows.Forms.Button();             this.SuspendLayout();             //              // timer1             //              this.timer1.Enabled = true;             this.timer1.Interval = 200000;             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);             //              // button1             //              this.button1.Location = new System.Drawing.Point(83, 103);             this.button1.Name = "button1";             this.button1.Size = new System.Drawing.Size(75, 23);             this.button1.TabIndex = 0;             this.button1.Text = "处理1个";             this.button1.UseVisualStyleBackColor = true;             this.button1.Click += new System.EventHandler(this.button1_Click);             //              // Form1             //              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;             this.ClientSize = new System.Drawing.Size(284, 262);             this.Controls.Add(this.button1);             this.Name = "Form1";             this.Text = "自动转码2";             this.Load += new System.EventHandler(this.Form1_Load_1);             this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Timer timer1;         private System.Windows.Forms.Button button1;     } }

 

 

实际代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

namespace zhuanmale {     public partial class Form1 : Form     {

        string path = AppDomain.CurrentDomain.BaseDirectory;         // static string saveurl = "";         string pathVedio = "";         public static string state = "0";         ExecuteSql ex = new ExecuteSql();         ReadXmls rx = new ReadXmls();         public Form1()         {             InitializeComponent();         }

        //字节数组转16进制字符串         private static string byteToHexStr(byte[] bytes, int length)         {             string returnStr = "";             if (bytes != null)             {                 for (int i = 0; i < length; i++)                 {                     returnStr += bytes[i].ToString("X2");                 }             }             return returnStr;         }         //转码         private void ChuLi(string saveurl, string filename, string id)         {             //try             //{

                Process p = new Process();

                p.StartInfo.FileName = path + "ffmpeg.exe";

                p.StartInfo.UseShellExecute = false;                 string srcFileName = "";                 string destFileName = "";                 srcFileName = saveurl + filename;

                string[] strs = new string[2];                 strs = filename.Split('.');

                string newfilename = strs[0] + "_code.mp4";

                //先标记后处理                 string upsql1 = "update job_shipin_chuli set flag=1,updatetime='" + DateTime.Now.ToString() + "' where id=" + id + ";";

              int i=  ex.ExecuteUpdateOrDelete(upsql1);                              //先标记后处理                 //处理完成后插入文件表                 string upsql2 = "UPDATE dbo.sys_file SET imgname='" + newfilename + "' " + " , imgurl = REPLACE(imgurl, '" + filename + "', '" + newfilename + "') " + " WHERE imgname = '" + filename + "'; ";                 ex.ExecuteUpdateOrDelete(upsql2);

                destFileName = saveurl + newfilename;

                p.StartInfo.Arguments = "-i " + srcFileName + " -y  -vcodec h264 -b 500000 " + destFileName;    //执行参数

                p.StartInfo.UseShellExecute = false;  不使用系统外壳程序启动进程                 p.StartInfo.CreateNoWindow = true;  //不显示dos程序窗口

                p.StartInfo.RedirectStandardInput = true;

                p.StartInfo.RedirectStandardOutput = true;

                p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中

                p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);

                p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);

                p.StartInfo.UseShellExecute = false;

                p.Start();

                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                p.BeginErrorReadLine();//开始异步读取

                // p.WaitForExit(900000);//阻塞15分钟等待进程结束

                while (!p.HasExited)                 {                     Application.DoEvents();                     System.Threading.Thread.Sleep(100);                 }                 //暂时换成这句试验试验

                p.Close();//关闭进程

                p.Dispose();//释放资源

            //}             //catch(Exception e)             //{

            //    MessageBox.Show(e.Message);

            //}

        }         private static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)         {

            //  Console.WriteLine(e.Data);

        }

        private static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)         {

            // Console.WriteLine(e.Data);

        }

        private void timer1_Tick(object sender, EventArgs e)         {             if (state == "0")             {

                string sql1 = "SELECT TOP 1 id,filename  FROM job_shipin_chuli WHERE flag=0 and  inserttime



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3