예제 #1
0
        private void btnEac3toAAC_Click(object sender, EventArgs e)
        {
            string filename = txtFileEac.Text;
            string q        = txtEac3toQuality.Text;
            string tracker  = txtEacTracker.Text;

            Task.Factory.StartNew(() =>
            {
                string output = Path.GetFileNameWithoutExtension(filename);
                string dir    = Path.GetDirectoryName(filename);
                Eac3toCommand.ConvertMusic(filename, FileUtility.GetNoSameNameFile(Path.Combine(dir, output + ".m4a")), q, tracker);
            });
        }
예제 #2
0
        private void StartOneThread()
        {
            int isHandling = -1;

            while (true)
            {
                int          thisstate  = -1;
                ListViewItem item       = null;
                FileConfig   fileConfig = null;
                try
                {
                    lock (handledlock)
                    {
                        if (isHandling >= listView2.Items.Count - 1)
                        {
                            return;
                        }
                        hasHandle++;
                        isHandling = hasHandle;

                        this.Invoke((Action) delegate()
                        {
                            item       = listView2.Items[isHandling];
                            fileConfig = item.Tag as FileConfig;
                            if (fileConfig.state != -1)
                            {
                                thisstate = -10;
                            }
                            listView2.Items[isHandling].SubItems["States"].Text = "视频转码中";

                            fileConfig.state++;
                        });
                        if (thisstate == -10)
                        {
                            continue;
                        }

                        this.Invoke((Action) delegate()
                        {
                            if (fileConfig.InputType == InputType.AvisynthScriptFile || fileConfig.InputType == InputType.AvisynthScript)
                            {
                                EncoderTaskInfoForm form = new EncoderTaskInfoForm();
                                form.fileConfig          = fileConfig;
                                form.lbFile.Text         = fileConfig.FullName;
                                form.Text = fileConfig.FullName;
                                fileConfig.EncoderTaskInfo.infoForm = form;
                                form.Show();
                            }
                        });
                    }


                    string outputfile = "";
                    string copyto     = string.Empty;
                    string ralative   = string.Empty;
                    //仅输出视频部分
                    if (fileConfig.KeepDirection)
                    {//保持目录树结构
                        ralative = FileUtility.MakeRelativePath(fileConfig.DirPath + "/", Path.GetDirectoryName(fileConfig.FullName));
                        string outpath = Path.Combine(fileConfig.OutputPath, ralative);
                        outputfile = Path.Combine(outpath, Path.GetFileNameWithoutExtension(fileConfig.FullName));
                    }
                    else if (fileConfig.OutputPath != "")
                    {//有输出目录
                        outputfile = Path.Combine(fileConfig.OutputPath, Path.GetFileNameWithoutExtension(fileConfig.FullName));
                    }
                    else
                    {//输出原路径
                        outputfile = Path.Combine(Path.GetDirectoryName(fileConfig.FullName), Path.GetFileNameWithoutExtension(fileConfig.FullName));
                    }
                    if (fileConfig.CompleteDo && !string.IsNullOrEmpty(fileConfig.CompleteActionDir))
                    {
                        if (fileConfig.KeepDirection)
                        {//保持目录树结构
                            copyto = Path.Combine(fileConfig.CompleteActionDir, ralative, Path.GetFileNameWithoutExtension(fileConfig.FullName));
                        }
                        else
                        {
                            copyto = Path.Combine(fileConfig.CompleteActionDir, Path.GetFileNameWithoutExtension(fileConfig.FullName));
                        }
                    }
                    else
                    {
                        fileConfig.CompleteDo = false;
                    }


                    fileConfig.OutputFile = outputfile;


                    VedioConfig vedioconfig     = fileConfig.VedioConfig;
                    string      vedioOutputFile = string.Empty;
                    try
                    {
                        if (vedioconfig.Encoder == Encoder.x264)
                        {
                            if (fileConfig.InputType == InputType.Vedio)
                            {
                                fileConfig.mediaInfo = new MediaInfo(fileConfig.FullName);
                                vedioOutputFile      = X264Command.RunX264Command(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.AvisynthScriptFile)
                            {
                                vedioOutputFile = X264Command.RunAvsx264mod(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.AvisynthScript)
                            {
                                fileConfig.mediaInfo = new MediaInfo(fileConfig.FullName);
                                string avsfilename = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".avs"));
                                File.WriteAllText(avsfilename, vedioconfig.AvsScript, System.Text.Encoding.Default);
                                fileConfig.AvsFileFullName = avsfilename;
                                fileConfig.InputType       = InputType.AvisynthScriptFile;
                                vedioOutputFile            = X264Command.RunAvsx264mod(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.VapoursynthScriptFile)
                            {
                                vedioOutputFile = X264Command.RunVSx265(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.VapoursynthScript)
                            {
                                fileConfig.mediaInfo = new MediaInfo(fileConfig.FullName);
                                string avsfilename = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".vpy"));
                                File.WriteAllText(avsfilename, vedioconfig.VapoursynthScript, System.Text.Encoding.UTF8);
                                fileConfig.VapoursynthFileFullName = avsfilename;
                                fileConfig.InputType = InputType.VapoursynthScriptFile;
                                vedioOutputFile      = X264Command.RunVSx265(fileConfig);
                            }
                        }
                        else if (vedioconfig.Encoder == Encoder.x265)
                        {
                            if (fileConfig.InputType == InputType.Vedio)
                            {
                                fileConfig.mediaInfo = new MediaInfo(fileConfig.FullName);
                                vedioOutputFile      = X265Command.RunX265Command(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.AvisynthScriptFile)
                            {
                                vedioOutputFile = X265Command.RunAvsx264mod(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.AvisynthScript)
                            {
                                fileConfig.mediaInfo = new MediaInfo(fileConfig.FullName);
                                string avsfilename = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".avs"));
                                File.WriteAllText(avsfilename, vedioconfig.AvsScript, System.Text.Encoding.Default);
                                fileConfig.AvsFileFullName = avsfilename;
                                fileConfig.InputType       = InputType.AvisynthScriptFile;
                                vedioOutputFile            = X265Command.RunAvsx264mod(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.VapoursynthScriptFile)
                            {
                                vedioOutputFile = X265Command.RunVSx265(fileConfig);
                            }
                            else if (fileConfig.InputType == InputType.VapoursynthScript)
                            {
                                fileConfig.mediaInfo = new MediaInfo(fileConfig.FullName);
                                string avsfilename = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".vpy"));
                                File.WriteAllText(avsfilename, vedioconfig.VapoursynthScript, System.Text.Encoding.UTF8);
                                fileConfig.VapoursynthFileFullName = avsfilename;
                                fileConfig.InputType = InputType.VapoursynthScriptFile;
                                vedioOutputFile      = X265Command.RunVSx265(fileConfig);
                            }
                        }
                    }
                    catch (EncoderException e)
                    {
                        this.Invoke((Action) delegate()
                        {
                            listView2.Items[isHandling].SubItems["States"].Text = e.Message;
                        });
                        fileConfig.state = -10;
                        continue;
                    }

                    if (!File.Exists(vedioOutputFile))
                    {
                        this.Invoke((Action) delegate()
                        {
                            listView2.Items[isHandling].SubItems["States"].Text = "视频编码失败";
                        });
                        fileConfig.state = -10;
                        continue;
                    }

                    if (fileConfig.AudioConfig.Enabled && fileConfig.state != 10)
                    {
                        if (fileConfig.InputType == InputType.Vedio && fileConfig.AudioConfig.CopyStream)
                        {
                            //直接由x264处理掉了
                        }
                        else
                        {
                            this.Invoke((Action) delegate()
                            {
                                item = listView2.Items[isHandling];
                                item.SubItems["States"].Text = "音频转码中";
                            });

                            string audiofile = string.Empty;
                            if (fileConfig.AudioConfig.CopyStream)
                            {
                                audiofile = CommandHelper.DemuxAudio(fileConfig);
                            }
                            else
                            {
                                if (fileConfig.AudioConfig.UseEac3to)
                                {
                                    if (fileConfig.AudioConfig.Encoder == AudioEncoder.aac)
                                    {
                                        audiofile = Eac3toCommand.ConvertMusic(fileConfig);
                                    }
                                    else
                                    {
                                        audiofile = Eac3toCommand.ConvertAudioTOpus(fileConfig);
                                    }
                                }
                                else
                                {
                                    if (fileConfig.AudioConfig.Encoder == AudioEncoder.aac)
                                    {
                                        audiofile = CommandHelper.RunFFmpegToAAC(fileConfig);
                                    }
                                    else
                                    {
                                        audiofile = CommandHelper.RunFFmpegToOpus(fileConfig);
                                    }
                                }
                            }


                            this.Invoke((Action) delegate()
                            {
                                item = listView2.Items[isHandling];
                                item.SubItems["States"].Text = "封装中";
                            });
                            int delay = 0;
                            if (fileConfig.mediaInfo != null)
                            {
                                delay = fileConfig.mediaInfo.DelayRelativeToVideo;
                                delay = delay - 67;
                            }
                            if (fileConfig.Muxer == "mkv")
                            {
                                vedioOutputFile = CommandHelper.MKVmergin(fileConfig, vedioOutputFile, audiofile, delay);
                            }
                            else if (fileConfig.Muxer == "mp4")
                            {
                                vedioOutputFile = CommandHelper.mp4box(fileConfig, vedioOutputFile, audiofile, delay);
                            }
                            else if (fileConfig.Muxer == "flv")
                            {
                                vedioOutputFile = CommandHelper.ffmpegmux(fileConfig, vedioOutputFile, audiofile, fileConfig.Muxer);
                                if (fileConfig.sinablack)
                                {
                                    FlvMain flvbugger = new FlvMain();
                                    flvbugger.addFile(vedioOutputFile);
                                    flvbugger.ExecuteBlack(999d, -1, Path.ChangeExtension(vedioOutputFile, ".black.flv"));
                                }
                                else if (fileConfig.sinaPreblack)
                                {
                                    FlvMain flvbugger = new FlvMain();
                                    flvbugger.addFile(vedioOutputFile);
                                    flvbugger.ExecuteTime(999d, -1, Path.ChangeExtension(vedioOutputFile, ".speed.flv"));
                                }
                            }
                        }
                    }

                    if (fileConfig.CompleteDo && fileConfig.state != 10)
                    {
                        try
                        {
                            copyto = copyto + Path.GetExtension(vedioOutputFile);
                            copyto = FileUtility.GetNoSameNameFile(copyto);
                            if (fileConfig.CompleteAction == "拷贝到")
                            {
                                this.Invoke((Action) delegate()
                                {
                                    listView2.Items[isHandling].SubItems["States"].Text = "拷贝中";
                                });

                                File.Copy(vedioOutputFile, copyto, true);
                            }
                            else if (fileConfig.CompleteAction == "剪切到")
                            {
                                this.Invoke((Action) delegate()
                                {
                                    listView2.Items[isHandling].SubItems["States"].Text = "剪切中";
                                });

                                File.Move(vedioOutputFile, copyto);
                            }
                        }
                        catch { }
                    }

                    this.Invoke((Action) delegate()
                    {
                        if (fileConfig.state == -10)
                        {
                            listView2.Items[isHandling].SubItems["States"].Text = "失败";
                        }
                        else
                        {
                            listView2.Items[isHandling].SubItems["States"].Text = "完成";
                        }
                    });
                }
                catch (Exception ex)
                {
                    this.Invoke((Action) delegate()
                    {
                        listView2.Items[isHandling].SubItems["States"].Text = "失败:" + ex.Message;
                    });
                }
            }
        }