コード例 #1
0
 private void SetMark(IWMEncSourceGroup2 sg)
 {
     foreach (WMENC_SOURCE_TYPE stype in new WMENC_SOURCE_TYPE[] { WMENC_SOURCE_TYPE.WMENC_AUDIO, WMENC_SOURCE_TYPE.WMENC_VIDEO })
     {
         if (sg.get_SourceCount(stype) > 0)
         {
             IWMEncSource src = sg.get_Source(stype, 0);
             src.MarkIn  = this.markIn;
             src.MarkOut = this.markOut;
         }
     }
 }
コード例 #2
0
 private static void SetMark(IWMEncSourceGroup2 sg, int start, int end)
 {
     foreach (WMENC_SOURCE_TYPE stype in new WMENC_SOURCE_TYPE[] { WMENC_SOURCE_TYPE.WMENC_AUDIO, WMENC_SOURCE_TYPE.WMENC_VIDEO })
     {
         if (sg.get_SourceCount(stype) > 0)
         {
             IWMEncSource src = sg.get_Source(stype, 0);
             src.MarkIn  = start;
             src.MarkOut = end;
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// 分割されたメディアファイルを結合する
        /// </summary>
        /// <param name="profileName"></param>
        private static void CombineParts(string profileName)
        {
            WMEncoderApp app = new WMEncoderAppClass();
            IWMEncoder2  enc = app.Encoder as IWMEncoder2;

            IWMEncSourceGroupCollection sgcol = enc.SourceGroupCollection;

            IWMEncProfile      profile = SelectProfile(enc, profileName);
            int                index   = 0;
            IWMEncSourceGroup2 sg2     = null;

            foreach (FileInfo fi in new DirectoryInfo(".").GetFiles("dest*.wmv"))
            {
                sg2 = sgcol.Add("sg" + index) as IWMEncSourceGroup2;
                sg2.set_Profile(profile);
                sg2.AutoSetFileSource(fi.FullName);

                if (index > 0)
                {
                    sg2.SetAutoRollover(-1, "sg" + (index - 1));
                }

                index++;
            }

            sgcol.Active = sg2;

            FileInfo destFile = new FileInfo("default_all.wmv");

            destFile.Delete();

            enc.File.LocalFileName = destFile.FullName;

            enc.PrepareToEncode(true);
            enc.Start();

            Console.WriteLine("combine start");

            while (enc.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)
            {
                Thread.Sleep(2000);
            }

            Console.WriteLine("combine end");

            Marshal.ReleaseComObject(profile);
            Marshal.ReleaseComObject(sgcol);
            Marshal.ReleaseComObject(enc);
            Marshal.ReleaseComObject(app);
        }
コード例 #4
0
        /// <summary>
        /// 順番に分割処理を実施する
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="profileName"></param>
        /// <param name="duration"></param>
        /// <param name="num"></param>
        private static void OrderTrim(string inputFile, string profileName, int duration, int num)
        {
            WMEncoderApp app = new WMEncoderAppClass();
            IWMEncoder2  enc = app.Encoder as IWMEncoder2;

            IWMEncSourceGroupCollection sgcol = enc.SourceGroupCollection;

            IWMEncProfile profile = SelectProfile(enc, profileName);

            for (int i = 0; i < num; i++)
            {
                if (sgcol.Count > 0)
                {
                    sgcol.Remove("sg1");
                }

                IWMEncSourceGroup2 sg = sgcol.Add("sg1") as IWMEncSourceGroup2;
                sg.AutoSetFileSource(inputFile);

                int start = (duration * i) / num;
                int end   = (duration * (i + 1) / num) - 30000;

                SetMark(sg, start, end);

                sg.set_Profile(profile);

                enc.File.LocalFileName = new FileInfo(string.Format("dest{0}.wmv", i)).FullName;
                enc.PrepareToEncode(true);

                enc.Start();

                Console.WriteLine("encode start : {0} - start:{1}, end:{2}", i, start, end);

                while (enc.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)
                {
                    Thread.Sleep(2000);
                }

                Console.WriteLine("encode end : {0}", i);
            }

            Marshal.ReleaseComObject(profile);
            Marshal.ReleaseComObject(sgcol);
            Marshal.ReleaseComObject(enc);
            Marshal.ReleaseComObject(app);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            IWMEncSourceGroup2 sg = sgcol.Add("sg" + this.GetHashCode().ToString()) as IWMEncSourceGroup2;

            sg.AutoSetFileSource(inputFile);

            SetMark(sg);

            sg.set_Profile(this.profile);

            enc.PrepareToEncode(true);

            enc.Start();

            while (enc.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)
            {
                Thread.Sleep(1000);
            }

            this.sgcol.Remove(sg.Name);

            Marshal.ReleaseComObject(sg);
        }
コード例 #6
0
ファイル: Encoder.cs プロジェクト: huangjie18/isabel
        /**
         * Constructor.
         */
        public Encoder()
        {
            this.enableRecording = false;
            this.chopNumber      = 0;
            this.chopLength      = -1;

            this.choppingTimer                = new System.Timers.Timer();
            this.choppingTimer.Elapsed       += this.OnRecordTimeElapsed;
            this.archiveState                 = WMENC_ARCHIVE_STATE.WMENC_ARCHIVE_STOPPED;
            this.stateChangeWaitHandle        = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);
            this.archiveStateChangeWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);

            // Audio and video sources
            this.audioSource = null;
            this.videoSource = null;

            // Windows Media Encoder
            this.wmEncoder        = new WMEncoderClass();
            this.sourceGroup      = (IWMEncSourceGroup2)this.wmEncoder.SourceGroupCollection.Add("SG_1");
            this.wmEncoderProfile = new WMEncProfile2();

            // For now, we only listen these events
            this.wmEncoder.OnStateChange        += this.OnStateChange;
            this.wmEncoder.OnError              += this.OnError;
            this.wmEncoder.OnArchiveStateChange += this.OnArchiveStateChange;

            // Set recording props.
            this.wmEncoder.EnableAutoArchive = false;
            this.wmEncoder.AutoIndex         = false;

            // Set default profile values
            this.wmEncoderProfile.ValidateMode = true;
            this.wmEncoderProfile.ProfileName  = "Windows Media Encoder Profile";
            this.wmEncoderProfile.ContentType  = 17;                                        // Audio + Video
            this.wmEncoderAudience             = this.wmEncoderProfile.AddAudience(100000); // Initial bitrate = 100 kbps, will change automatically
            // when user sets video and audio params.
        }
コード例 #7
0
ファイル: Encoder.cs プロジェクト: ejgarcia/isabel
        /**
         * Constructor.
         */
        public Encoder()
        {
            this.enableRecording = false;
            this.chopNumber = 0;
            this.chopLength = -1;

            this.choppingTimer = new System.Timers.Timer();
            this.choppingTimer.Elapsed += this.OnRecordTimeElapsed;
            this.archiveState = WMENC_ARCHIVE_STATE.WMENC_ARCHIVE_STOPPED;
            this.stateChangeWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);
            this.archiveStateChangeWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);

            // Audio and video sources
            this.audioSource = null;
            this.videoSource = null;

            // Windows Media Encoder
            this.wmEncoder = new WMEncoderClass();
            this.sourceGroup = (IWMEncSourceGroup2)this.wmEncoder.SourceGroupCollection.Add("SG_1");
            this.wmEncoderProfile = new WMEncProfile2();

            // For now, we only listen these events
            this.wmEncoder.OnStateChange += this.OnStateChange;
            this.wmEncoder.OnError += this.OnError;
            this.wmEncoder.OnArchiveStateChange += this.OnArchiveStateChange;

            // Set recording props.
            this.wmEncoder.EnableAutoArchive = false;
            this.wmEncoder.AutoIndex = false;

            // Set default profile values
            this.wmEncoderProfile.ValidateMode = true;
            this.wmEncoderProfile.ProfileName = "Windows Media Encoder Profile";
            this.wmEncoderProfile.ContentType = 17; // Audio + Video
            this.wmEncoderAudience = this.wmEncoderProfile.AddAudience(100000); // Initial bitrate = 100 kbps, will change automatically
            // when user sets video and audio params.
        }
コード例 #8
0
 private void SetMark(IWMEncSourceGroup2 sg)
 {
     foreach (WMENC_SOURCE_TYPE stype in new WMENC_SOURCE_TYPE[] { WMENC_SOURCE_TYPE.WMENC_AUDIO, WMENC_SOURCE_TYPE.WMENC_VIDEO })
     {
         if (sg.get_SourceCount(stype) > 0)
         {
             IWMEncSource src = sg.get_Source(stype, 0);
             src.MarkIn = this.markIn;
             src.MarkOut = this.markOut;
         }
     }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: kirigishi123/try_samples
 private static void SetMark(IWMEncSourceGroup2 sg, int start, int end)
 {
     foreach (WMENC_SOURCE_TYPE stype in new WMENC_SOURCE_TYPE[] { WMENC_SOURCE_TYPE.WMENC_AUDIO, WMENC_SOURCE_TYPE.WMENC_VIDEO})
     {
         if (sg.get_SourceCount(stype) > 0)
         {
             IWMEncSource src = sg.get_Source(stype, 0);
             src.MarkIn = start;
             src.MarkOut = end;
         }
     }
 }
コード例 #10
0
        /// <summary>
        /// 分割されたメディアファイルを結合する
        /// </summary>
        /// <param name="profileName"></param>
        private static void CombineParts(string dir)
        {
            WMEncoderApp app = new WMEncoderAppClass();
            IWMEncoder2  enc = app.Encoder as IWMEncoder2;

            IWMEncSourceGroupCollection sgcol = enc.SourceGroupCollection;

            WMEncProfile2 pf = new WMEncProfile2Class();

            pf.LoadFromFile(dir + "/default.prx");

            int index = 0;
            IWMEncSourceGroup2 sg2 = null;

            foreach (FileInfo fi in new DirectoryInfo(dir).GetFiles("dest*.wmv"))
            {
                Console.WriteLine("target : {0}", fi.Name);

                sg2 = sgcol.Add("sg" + index) as IWMEncSourceGroup2;
                sg2.set_Profile(pf);

                IWMEncSource asrc = sg2.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
                asrc.SetInput(fi.FullName, "", "");

                IWMEncSource vsrc = sg2.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
                vsrc.SetInput(fi.FullName, "", "");

                //sg2.AutoSetFileSource(fi.FullName);

                if (index > 0)
                {
                    sg2.SetAutoRollover(-1, "sg" + (index - 1));
                }

                index++;
            }

            sgcol.Active = sg2;

            FileInfo destFile = new FileInfo("default_all.wmv");

            destFile.Delete();

            enc.File.LocalFileName = destFile.FullName;

            enc.PrepareToEncode(true);
            enc.Start();

            Console.WriteLine("combine start");

            while (enc.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)
            {
                Thread.Sleep(2000);
            }

            Console.WriteLine("combine end : 0x{0}", enc.ErrorState.ToString("X"));

            Marshal.ReleaseComObject(pf);
            Marshal.ReleaseComObject(sgcol);
            Marshal.ReleaseComObject(enc);
            Marshal.ReleaseComObject(app);
        }