示例#1
0
        public void check_uploader()
        {
            string rnd      = this.random();
            string mp4Key   = GetTimeStamp() + "/" + rnd + ".mp4";
            string filepath = "H:/手机备份/手机/图片/VID_20170407_171319.mp4";

            Upoader up = new Upoader();

            up.init();
            string retstring = up.PutFile(mp4Key, filepath);

            if (retstring == "")
            {
                //删除目标文件。已经上传成功,不需要保留了。
                //回调

                string    filecode = this.fcode;
                string    status   = "1";
                WebClient client   = new System.Net.WebClient();
                string    uri      = "http://www.jianpianzi.com/cloud/transcodeStatus?status=1&filecode=" + filecode + "&mp4file=http://cdn.jianpianzi.com/" + mp4Key;
                byte[]    bt       = client.DownloadData(uri);
                Conn.ExecuteNonQuery("update ov_files set stat=2 where id=" + this.id);

                this.statini.WriteString("encoder", "uploadret", "url=" + uri);
                //System.IO.FileStream fs = System.IO.File.Create("c:\\encoderupload.txt");
                //fs.Write(bt, 0, bt.Length);
                //fs.Close();
                //修改数据库的地址为七牛
                this.AppendLog("encoder" + "uploadret" + "url=" + uri);
            }
        }
示例#2
0
        private void run_getimg(object sender, EventArgs e)
        {
            if (!File.Exists(this.file_out))
            {
                if (string.Compare(this.runtype, "ffmpeg", true) == 0)
                {
                    this.AppendLog("无文件退出,错误+1,尝试使用额外插件转码");
                    run_transcode_plug(null, null);
                    return;
                }
                this.AppendLog("无文件退出,错误+1");
                Conn.ExecuteNonQuery("update ov_files set stat=0,errcount=errcount+1 where id=" + this.id);
                this.run_Canceled(null, null);
            }
            else
            {
                string    str    = "";
                int       num    = this.configini.ReadInteger("encoder", "maxcap", 6);
                int       width  = this.configini.ReadInteger("encoder", "capwidth", 160);
                int       height = this.configini.ReadInteger("encoder", "cap_height", 120);
                MediaInfo info   = new MediaInfo();
                info.Open(this.file_out);
                int num4 = func.GetInt(info.Get(StreamKind.General, 0, "Duration").ToString()) / 0x3e8;
                ProcessStartInfo startInfo = new ProcessStartInfo();

                if ((num4 > 0) && !this.m_isAudio)
                {
                    int num5;
                    this.statini.WriteString("encoder", "enmsg", "正在截图...");
                    int num6 = 0;
                    int num7 = 0;
                    int num8 = 0;
                    if (this.m_Width > 0)
                    {
                        num5 = (this.m_Height * width) / this.m_Width;
                    }
                    else
                    {
                        num5 = 0;
                    }
                    if ((num5 % 2) != 0)
                    {
                        num5--;
                    }
                    if (num5 <= 0)
                    {
                        width = this.m_Width;
                        num5  = this.m_Height;
                    }
                    while (num6 < num4)
                    {
                        num8++;
                        num7 = num6;
                        startInfo.FileName = Application.StartupPath + @"\ffmpeg\ffmpeg.exe";
                        string thumbnailPath = this.imgdir + this.fcode + "_" + num8.ToString() + ".jpg";
                        string path          = thumbnailPath + "_b.jpg";
                        startInfo.Arguments       = string.Concat(new object[] { "-ss ", num7, " -i ", this.file_out, " -f image2 -vframes 1 ", path });
                        startInfo.CreateNoWindow  = true;
                        startInfo.UseShellExecute = false;
                        this.AppendLog("开始截图:" + startInfo.FileName + " " + startInfo.Arguments);
                        Process.Start(startInfo).WaitForExit();
                        if (File.Exists(path))
                        {
                            func.imgResize(path, thumbnailPath, width, height, "CUT");
                        }
                        if (string.IsNullOrEmpty(str))
                        {
                            str = num8.ToString();
                        }
                        else
                        {
                            str = str + "," + num8.ToString();
                        }
                        num6 += func.GetInt(num4 / num);
                        if (num8 == num)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    str = "-1";
                }
                if (File.Exists(this.file_swf))
                {
                    startInfo.FileName        = Application.StartupPath + @"\swftools\swfrender.exe";
                    startInfo.Arguments       = string.Concat(new object[] { "\"", this.file_in, "\" -X ", width, " -o \"", this.imgdir, this.fcode, "_1.jpg\"" });
                    startInfo.CreateNoWindow  = true;
                    startInfo.UseShellExecute = false;
                    this.AppendLog("开始截图:" + startInfo.FileName + " " + startInfo.Arguments);
                    this.statini.WriteString("encoder", "enmsg", "正在对swf截图:1");
                    Process.Start(startInfo).WaitForExit();
                    str = "1";
                }
                if ((num4 > 0) || File.Exists(this.file_swf))
                {
                    FileInfo info3  = new FileInfo(this.file_out);
                    long     length = info3.Length;
                    Conn.ExecuteNonQuery(string.Concat(new object[] { "update ov_files set stat=1,sendok=0,times=", num4, ",flvsize=", length, ",autoimg='", str, "' where id=", this.id }));
                    try
                    {
                        File.Delete(this.file_ff);
                    }
                    catch
                    {
                        this.statini.WriteString("encoder", "delfile_ff", "删除文件失败:" + this.file_ff);
                    }
                    try
                    {
                        File.Delete(this.file_me);
                    }
                    catch
                    {
                        this.statini.WriteString("encoder", "delfile_me", "删除文件失败:" + this.file_me);
                    }
                    try
                    {
                        File.Delete(this.file_log);
                    }
                    catch
                    {
                        this.statini.WriteString("encoder", "delfile_log", "删除文件失败:" + this.file_log);
                    }
                    try
                    {
                        if (this.configini.ReadBool("encoder", "autodel", false))
                        {
                            File.Delete(this.file_in);
                        }
                    }
                    catch
                    {
                        this.statini.WriteString("encoder", "delfile_in", "删除文件失败:" + this.file_in);
                    }
                    this.statini.WriteString("encoder", "enmsg", "处理文件成功");
                    this.AppendLog("处理文件成功:" + this.file_in);
                    //处理文件成功在这里添加一个测试方法 看是否成功
                    string imgPath    = this.imgdir + this.fcode + "_" + "3.jpg";
                    string bigimgpath = imgPath + "_b.jpg";
                    // postFile(imgPath,bigimgpath);
                }
                else
                {
                    this.statini.WriteString("encoder", "enmsg", "处理文件失败");
                    this.AppendLog("处理文件错误,错误+1:" + this.file_in);
                    Conn.ExecuteNonQuery("update ov_files set stat=0,errcount=errcount+1 where id=" + this.id);
                }
                this.tmchk.Enabled = true;
            }
            try
            {
                //上传七牛 - 上传前判断如果是mp4,需要过一遍qt-faststart.exe
                if (this.outfiletype == "mp4")
                {
                    this.statini.WriteString("encoder", "mp4streamconvert_begin", "开始调用qt-faststart流化MP4");
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = Application.StartupPath + @"\qt-faststart.exe";
                    string dstMP4File = this.file_out.Replace(".mp4", "_dst.mp4");
                    startInfo.Arguments       = string.Concat(new object[] { this.file_out, " ", dstMP4File });
                    startInfo.CreateNoWindow  = true;
                    startInfo.UseShellExecute = false;
                    Process.Start(startInfo).WaitForExit();
                    if (System.IO.File.Exists(dstMP4File))
                    {
                        System.IO.File.Delete(this.file_out); //删除原文件
                        this.file_out = dstMP4File;
                    }
                    this.statini.WriteString("encoder", "mp4streamconvert_end", "结束调用qt-faststart流化MP4");
                }

                string rnd      = this.random();
                string mp4Key   = GetTimeStamp() + "/" + rnd + ".mp4";
                string filepath = this.file_out.Replace("////", "\\").Replace("/", "\\");
                this.statini.WriteString("encoder", "qiniu1", "开始上传七牛:mp4Key=" + mp4Key + ",filepath=" + filepath);
                Upoader up = new Upoader();
                up.init();
                string retstring = up.PutFile(mp4Key, filepath);
                if (retstring == "")
                {
                    this.statini.WriteString("encoder", "qiniuret", "上传成功!mp4Key = " + mp4Key);
                    //删除目标文件。已经上传成功,不需要保留了。
                    System.IO.File.Delete(filepath);
                }
                else
                {
                    this.statini.WriteString("encoder", "qiniuret", "上传失败,返回字符串为:" + retstring);
                }
                this.statini.WriteString("encoder", "qiniuret2", "上传调用完成!返回字符串:" + retstring);
                //回调
                string    filecode = this.fcode;
                string    status   = "1";
                WebClient client   = new System.Net.WebClient();
                string    uri      = "http://www.jianpianzi.com/cloud/transcodeStatus?status=1&filecode=" + filecode + "&mp4file=http://7xl6yy.com1.z0.glb.clouddn.com/" + mp4Key;
                byte[]    bt       = client.DownloadData(uri);
                this.statini.WriteString("encoder", "uploadret", "url=" + uri);
                //System.IO.FileStream fs = System.IO.File.Create("c:\\encoderupload.txt");
                //fs.Write(bt, 0, bt.Length);
                //fs.Close();
                //修改数据库的地址为七牛
            }
            catch (Exception ex)
            {
                this.statini.WriteString("encoder", "qiniuret3", "有异常,日志存入c:\\log.txt");
                System.IO.FileStream fs = System.IO.File.Create("c:\\log.txt");
                byte[] btarr            = System.Text.Encoding.Default.GetBytes(ex.ToString());
                fs.Write(btarr, 0, btarr.Length);
                fs.Close();
            }
        }