用摄象头录制的视频太大了,想写程序压缩下传输到服务器,然后再解压缩播放.有相关源码参考吗?谢谢.

解决方案 »

  1.   

    视频压缩自已写肯定挺麻烦录制完用mpeg压缩,或者使用其他流媒体服务器了如 rtsp 流媒体视频服务器 ,FMS媒体服务器等
      

  2.   

    可以用mencoder或者ffmpeg转换为其他格式,一般大型的视频网站如优酷等都是转成FLV格式,然后用个FLASH播放器播放、
      

  3.   

    以前写的一段代码,楼主可以参考下。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Diagnostics;
    using System.IO;public partial class Admin_UpLoad : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
        }
        protected void Button_UpLoad_Click(object sender, EventArgs e)
        {
            if (InputFile1.ContentLength > 0)
            {
                try
                {
                    string User_name = Context.User.Identity.Name;
                    string ExtenName = System.IO.Path.GetExtension(this.InputFile1.FileName);//获取扩展名  
                    string temp = DateTime.Now.ToString("yyyy-MM-dd-HHmmssfff");
                    //合并两个路径为上传到服务器上的全路径 
                    string SaveFileName = System.IO.Path.Combine
                        (System.Web.HttpContext.Current.Request.MapPath("../uploads/UpLoadFiles/Admin"), temp + ExtenName);
                    //文件保存的路径  
                    string url = "";
                    if (DropDownList1.SelectedItem.Text == "视频教程")
                    {
                        url = "uploads/UpLoadFiles/Admin/" + temp + ".flv";
                        if (ExtenName == ".flv")
                        {
                            InputFile1.MoveTo(Server.MapPath("~/"+url), Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
                        }
                        else
                        {
                            string tempurl = Server.MapPath("~/uploads/UpLoadFiles/Admin/temp/1.a");
                            InputFile1.MoveTo(tempurl, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
                            MEConvertVideo(tempurl, Server.MapPath("~/"+url));
                        }
                    }
                    else
                    {
                        url = "uploads/UpLoadFiles/Admin/" + temp + ExtenName;
                        InputFile1.MoveTo(SaveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
                    }
                    //获取文件大小并保留小数点后一位,单位是M  
                    float FileSize = (float)System.Math.Round((float)InputFile1.ContentLength / 1024 / 1024, 3);                string FileSize1 = FileSize.ToString("f3");//fN 保留N位,四舍五入
                    DBClass db = new DBClass();
                    db.Conn.Open();
                    db.Comm.Connection = db.Conn;
                    db.Comm.CommandText = "INSERT INTO tFiles (FileName,FileSize,FileUpLoadtime,Fileinfo,FileUpLoadMan,FileRelativelyPath,FileClassID) VALUES" +
                        "(@FileName,@FileSize,@FileUpLoadtime,@Fileinfo,@FileUpLoadMan,@FileRelativelyPath,@FileClassID)";
                    db.Comm.Parameters.AddWithValue("@FileName", TextBox_title.Text);
                    db.Comm.Parameters.AddWithValue("@FileSize", FileSize1);
                    db.Comm.Parameters.AddWithValue("@FileUpLoadtime", DateTime.Now.ToString());
                    db.Comm.Parameters.AddWithValue("@Fileinfo", TextBox_information.Text);
                    db.Comm.Parameters.AddWithValue("@FileUpLoadMan", User_name);
                    db.Comm.Parameters.AddWithValue("@FileRelativelyPath", url);
                    db.Comm.Parameters.AddWithValue("@FileClassID", DropDownList1.SelectedValue);
                    db.Comm.ExecuteNonQuery();
                    Response.Write("<script language=javascript>alert('上传成功');</script>");
                }
                catch (Exception ex)
                {
                    Response.Write("<script language=javascript>alert('"+ex.Message+"');</script>");
                }        }
        }    public void MEConvertVideo(string vFileName, string playFile)
        {
            string tool = Server.MapPath("~/Tool/mencoder/mencoder.exe");
            if ((!System.IO.File.Exists(tool)) || (!System.IO.File.Exists(vFileName)))
            {
                return;
            }
            System.Diagnostics.ProcessStartInfo FilestartInfo = new System.Diagnostics.ProcessStartInfo(tool);
            FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            FilestartInfo.Arguments = " " + vFileName + " -o " + playFile + " -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=320:240 -ofps 12 -srate 22050";
            //FilestartInfo.Arguments = " -vf scale=320:240 -ffourcc FLV1 -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -ovc lavc -lavcopts vcodec=flv:vbitrate=200 -srate 22050 -oac lavc -lavcopts acodec=mp3:abitrate=56 " + vFileName + " -o " + playFile;
            System.Diagnostics.Process.Start(FilestartInfo);
        }
    }
      

  4.   

    可以采用H.264标准来压缩,开源源码FFMPEG能做到,请查看FFMPEG网站。