Exemple #1
0
        /// <summary>
        /// add Source to video group
        /// </summary>
        private void AddSource(IAMTimelineTrack myTrack, string SourceFile, long StartTime, long EndTime)
        {
            int            hr;
            IAMTimelineObj pSource1Obj;

            // create the timeline source object
            hr = m_pTimeline.CreateEmptyNode(out pSource1Obj, TimelineMajorType.Source);
            DESError.ThrowExceptionForHR(hr);

            try
            {
                // set up source length
                hr = pSource1Obj.SetStartStop(StartTime, EndTime);
                DESError.ThrowExceptionForHR(hr);
                IAMTimelineSrc pSource1Src = (IAMTimelineSrc)pSource1Obj;
                // Set the file name
                hr = pSource1Src.SetMediaName(SourceFile);
                DESError.ThrowExceptionForHR(hr);
                // Set the start/end
                hr = pSource1Src.SetMediaLength(EndTime - StartTime);
                DESError.ThrowExceptionForHR(hr);
                hr = pSource1Src.SetStretchMode(0);
                // Set the times, get back the times adjusted to fit the frame rate
                hr = pSource1Src.FixMediaTimes(ref StartTime, ref EndTime);
                DESError.ThrowExceptionForHR(hr);
                // Connect the track to the source
                hr = myTrack.SrcAdd(pSource1Obj);
                DESError.ThrowExceptionForHR(hr);
            }
            finally
            {
                Marshal.ReleaseComObject(pSource1Obj);
            }
        }
        private void TestFixMedia()
        {
            int hr;

            long start, stop;

            start = 1243;
            stop  = 10000000000;

            hr = m_pSource1Src.SetMediaName("foo.avi");
            DESError.ThrowExceptionForHR(hr);

            hr = ((IAMTimelineObj)m_pSource1Src).SetStartStop(0, 1234563053945);
            DESError.ThrowExceptionForHR(hr);

            // Connect the track to the source
            hr = m_VideoTrack.SrcAdd((IAMTimelineObj)m_pSource1Src);
            DESError.ThrowExceptionForHR(hr);

            hr = m_pSource1Src.FixMediaTimes(ref start, ref stop);
            DESError.ThrowExceptionForHR(hr);

            Debug.Assert(stop != 10000000000, "FixMediaTimes");
        }
Exemple #3
0
        /// <summary>
        /// Add a file to the group
        /// </summary>
        /// <param name="sName">File name+path to add</param>
        /// <param name="lStart">Start point in source file in UNITS</param>
        /// <param name="lEnd">End point in source file in UNITS or -1 to add entire file</param>
        public void Add(string sName, long lStart, long lEnd)
        {
            int  hr;
            long lLength;

            // Create a mediafile object to hold the file
            MediaFile mf = new MediaFile(sName);

            // Add it to the list of files
            m_Files.Add(mf);

            // If the endpoint is -1, find the real file length
            if (lEnd < 0)
            {
                lEnd = mf.Length;
            }
            lLength = lEnd - lStart;

            // create the timeline source object
            IAMTimelineObj pSource1Obj;

            hr = m_pTimeline.CreateEmptyNode(out pSource1Obj, TimelineMajorType.Source);
            DESError.ThrowExceptionForHR(hr);

            // Create track
            IAMTimelineObj pTrack1Obj;

            hr = m_pTimeline.CreateEmptyNode(out pTrack1Obj, TimelineMajorType.Track);
            DESError.ThrowExceptionForHR(hr);

            try
            {
                // Set start and stop time of the file in the target timeline
                hr = pSource1Obj.SetStartStop(m_Length, lLength + m_Length);
                DESError.ThrowExceptionForHR(hr);

                IAMTimelineSrc pSource1Src = (IAMTimelineSrc)pSource1Obj;

                // Set the file name
                hr = pSource1Src.SetMediaName(mf.FileName);
                DESError.ThrowExceptionForHR(hr);

                // Set the start/end
                hr = pSource1Src.SetMediaTimes(lStart, lEnd);
                DESError.ThrowExceptionForHR(hr);


                // tell the composition about the track
                IAMTimelineComp pRootComp = (IAMTimelineComp)m_pGroup;
                hr = pRootComp.VTrackInsBefore(pTrack1Obj, -1);
                DESError.ThrowExceptionForHR(hr);

                IAMTimelineTrack pTrack = (IAMTimelineTrack)pTrack1Obj;

                // Connect the track to the source
                hr = pTrack.SrcAdd(pSource1Obj);
                DESError.ThrowExceptionForHR(hr);

                // Set the times, get back the times adjusted to fit the frame rate
                hr = pSource1Src.FixMediaTimes(ref lStart, ref lEnd);
                DESError.ThrowExceptionForHR(hr);

                // Calculate the last frame number for the file
                double d1 = (lEnd - lStart);
                double d2 = (DESCombine.UNITS / m_FPS);
                double d3 = d1 / d2;
                int    d4 = (int)Math.Round(d3);

                // Update the MediaFile (used to see when we've walked past
                // the end of a file)
                mf.LengthInFrames = d4;
            }
            finally
            {
                Marshal.ReleaseComObject(pSource1Obj);
                Marshal.ReleaseComObject(pTrack1Obj);
            }

            m_Length += lLength;
        }