示例#1
0
        public void Convert(Mencoder.VideoType vidType, Mencoder.AudioType audType, string videoToConvertFilePath, string outputFilePath)
        {
            // http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-selecting-codec.html

            StringBuilder cmd = new StringBuilder();

            // mencoder.exe


            cmd.Append("-ovc");  // video codec for encoding
            cmd.Append(" ");

            bool lavcVideoSelected = false;
            bool lavcAudioSelected = false;

            if (vidType == Mencoder.VideoType.x264)
            {
                cmd.Append("x264");
            }
            else if (vidType == Mencoder.VideoType.xvid)
            {
                cmd.Append("xvid");
            }
            else
            {
                lavcVideoSelected = true;
                cmd.Append("lavc");  // use one of libavcodec's video codecs
            }
            cmd.Append(" ");

            cmd.Append("-oac");  // audio codec for encoding
            cmd.Append(" ");

            if (audType == Mencoder.AudioType.mp3)
            {
                cmd.Append("mp3lame");
            }
            else
            {
                lavcAudioSelected = true;
                cmd.Append("lavc");  // use one of libavcodec's audio codecs
            }
            cmd.Append(" ");


            cmd.Append('"' + videoToConvertFilePath + '"');
            cmd.Append(" ");

            if (vidType == Mencoder.VideoType.webm)
            {
                cmd.Append("-ffourcc");
                cmd.Append(" ");
                cmd.Append("VP80");
                cmd.Append(" ");
            }


            if (lavcAudioSelected == true || lavcVideoSelected == true)
            {
                cmd.Append("-lavcopts");
                cmd.Append(" ");
            }

            if (lavcVideoSelected)   // Using builtin codes from lavc

            // setup the selected video format
            {
                if (vidType == Mencoder.VideoType.webm)
                {
                    cmd.Append("vcodec=libvpx");
                }
                else if (vidType == Mencoder.VideoType.mpeg4)
                {
                    cmd.Append("vcodec=mpeg4");
                }
                else if (vidType == Mencoder.VideoType.wmv1)
                {
                    cmd.Append("vcodec=wmv1");
                }
                else if (vidType == Mencoder.VideoType.wmv2)
                {
                    cmd.Append("vcodec=wmv2");
                }
                cmd.Append(" ");
            }

            if (lavcAudioSelected)
            {
                // setup the selected audio format
                if (audType == Mencoder.AudioType.vorbis)
                {
                    cmd.Append("acodec=libvorbis");
                }
                else if (audType == Mencoder.AudioType.ac3)
                {
                    cmd.Append("acodec=ac3");
                }
                else if (audType == Mencoder.AudioType.flac)
                {
                    cmd.Append("acodec=flac");
                }
                else if (audType == Mencoder.AudioType.mp2)
                {
                    cmd.Append("acodec=mp2");
                }
                else if (audType == Mencoder.AudioType.wmav1)
                {
                    cmd.Append("acodec=wmav1");
                }
                else if (audType == Mencoder.AudioType.wmav2)
                {
                    cmd.Append("acodec=wmav2");
                }
                cmd.Append(" ");
            }

            cmd.Append("-vf harddup");  // avoid audio/video sync issues
            cmd.Append(" ");

            cmd.Append("-o");
            cmd.Append(" ");
            cmd.Append('"' + outputFilePath + '"');

            Convert(cmd.ToString());
        }
示例#2
0
 public Task ConvertAsync(Mencoder.VideoType vidType, Mencoder.AudioType audType, string videoToConvertFilePath, string outputFilePath)
 {
     return(Task.Run(() => Convert(vidType, audType, videoToConvertFilePath, outputFilePath)));
 }