Xojo Conferences
XDCMay2019MiamiUSA

splicing QT tracks (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: System Font in OS X
Next thread: Determine volume kind


What type of File am I?   -   Edward Cox
  splicing QT tracks   -   Jarvis Badgley
   Re: splicing QT tracks   -   Benjamin J. Schneider
    Re: splicing QT tracks   -   Jarvis Badgley
     Re: splicing QT tracks   -   Jarvis Badgley
      Re: splicing QT tracks   -   Benjamin J. Schneider
       Re: splicing QT tracks   -   Jarvis Badgley
        Re: splicing QT tracks   -   Benjamin J. Schneider
         Re: splicing QT tracks   -   Jarvis Badgley

splicing QT tracks
Date: 07.08.02 16:38 (Wed, 7 Aug 2002 08:38:37 -0700)
From: Jarvis Badgley
I'm got this program I've been writing which joins multiple quicktime
files together, allowing for easy splicing. Initially I tried using
AppendMovieSegment, but it's come to my attention that this does not
work the way it's supposed to, so I re-wrote my code to use
newvideotrack and other such items. I managed to get my code to work,
and the tracks splice together fine... but the audio gets out of sync
with the video, and I cant figure out why. I'm hoping somebody on the
list can notice something I missed.

MyMovie and MyFile are global properties. EditableMovie and FolderItem
respectively.
SouceFiles is an array of movieSegmentObjects, which is broken down
thusly:
file as folderitem
source as editablemovie
SpliceEnd as double
SpliceStart as double


Sub RenderMovie()
dim i,c,x,y as integer, seg as movieSegmentObject
dim qtv,qtvSource as QTVideoTrack, qts, qtsSource as QTSoundTrack
dim totalDir, thisDir as double

c = ubound(SourceFiles)
if c>-1 then
MyFile = temporaryFolder.child(self.title+".mov")
MyMovie = MyFile.CreateMovie
qts = Mymovie.newsoundTrack
qtv =
mymovie.newvideoTrack(SourceFiles(i).source.moviewidth,SourceFiles(i).source.
movieheight,SourceFiles(i).source.timescale)

for ito c
qtssource = nil
qtvsource = nil
seg = SourceFiles(i)

y=seg.Source.TrackCount
for x = 1 to y
if seg.source.Track(x).MediaType = "vide" then
qtvsource = seg.source.VideoTrack(x)
exit // if you're looking for the first videotrack, then
dump
end
next

for x = 1 to y
if seg.source.Track(x).MediaType = "soun" then
qtssource = seg.source.SoundTrack(x)
exit // if you're looking for the first soundtrack, then
dump
end
next

thisDir = 0
if qtvsource<>nil then
if qtvsource.Duration < seg.splicestart + seg.spliceend then
thisdir = qtvsource.duration - seg.splicestart
else
thisdir = seg.spliceend
end
qtv.appendVideoTrackSegment qtvsource, seg.splicestart,
thisDir, true, true

If qtssource<>nil then
if qtssource.duration-seg.splicestart < thisDir
then //more video then audio, fill gap with empty space
qts.appendSoundTrackSegment qtssource,
seg.splicestart, qtssource.duration-seg.splicestart, true, true
qts.InsertEmptySoundTrackSegment totalDir +
(qtssource.duration-seg.splicestart), thisDir - (qtssource.duration-
seg.spliceStart)
else
qts.appendSoundTrackSegment qtssource,
seg.splicestart, thisdir, true, true
end
else //no audio track, insert empty sound
qts.InsertEmptySoundTrackSegment totalDir, thisDir
end
end

totalDir = totalDir + thisDir
next
if mymovie.commitChanges then
setplayerMovie mymovie
end
end
End Sub

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 07.08.02 18:41 (Wed, 07 Aug 2002 13:41:47 -0400)
From: Benjamin J. Schneider
Hi Jarvis,

There are probably several good solutions to your sync problem. I can't say
what the best solution is without actually working with your project and
doing some experimentation but I can't see any reason that you shouldn't be
able to successfully do what you're trying to do using the QTSoundTracks and
QTVideoTracks. It's just a matter of figuring out what is causing you to
lose sync. I'd guess that it's because you're trying to account for the
possibility that the source soundtrack's duration and the source
videotrack's duration don't match. If they don't match, or if they did
match and you make a mathmatical error which causes them to not match when
you make the append calls, you'll lose sync that way. What I mean here is
that as long as the duration of the soundtracksegment and the
videotracksegment that you are trying to append to an empty movie match,
then they will remain in sync. If, however, those source durations don't
match, or the destination tracks already don't match in duration, then
you'll lose sync. You could either figure out what doesn't match by
checking the incoming and the existing durations or you could switch to
using the InsertVideoTrackSegment and InsertSoundTrackSegment methods
instead (passing the same destinationPosition value for both audio and
video) so that even if the durations don't match, they'll start at the same
time. This will mean that if the durations don't match, you'll have silence
at the end of each segment (if the soundtrack segment is shorter) or no
video at the end of each segment (if the videotrack segment is shorter) but
that they'll be in sync at times where both audio and video exist.

Also, the AppendMovieSegment and InsertMovieSegment methods have been fixed
with RB 4.5.1 fc1, so if it's an option for you to switch back to that
technique without messing up your project, then that should now work for
you.

Take care,

Ben

on 8/7/02 11:38 AM, Jarvis Badgley at <email address removed> wrote:

> I'm got this program I've been writing which joins multiple quicktime
> files together, allowing for easy splicing. Initially I tried using
> AppendMovieSegment, but it's come to my attention that this does not
> work the way it's supposed to, so I re-wrote my code to use
> newvideotrack and other such items. I managed to get my code to work,
> and the tracks splice together fine... but the audio gets out of sync
> with the video, and I cant figure out why. I'm hoping somebody on the
> list can notice something I missed.
>
> MyMovie and MyFile are global properties. EditableMovie and FolderItem
> respectively.
> SouceFiles is an array of movieSegmentObjects, which is broken down
> thusly:
> file as folderitem
> source as editablemovie
> SpliceEnd as double
> SpliceStart as double
>
> Sub RenderMovie()
> dim i,c,x,y as integer, seg as movieSegmentObject
> dim qtv,qtvSource as QTVideoTrack, qts, qtsSource as QTSoundTrack
> dim totalDir, thisDir as double
>
> c = ubound(SourceFiles)
> if c>-1 then
> MyFile = temporaryFolder.child(self.title+".mov")
> MyMovie = MyFile.CreateMovie
> qts = Mymovie.newsoundTrack
> qtv =
> mymovie.newvideoTrack(SourceFiles(i).source.moviewidth,SourceFiles(i).source.
> movieheight,SourceFiles(i).source.timescale)
>
> for ito c
> qtssource = nil
> qtvsource = nil
> seg = SourceFiles(i)
>
> y=seg.Source.TrackCount
> for x = 1 to y
> if seg.source.Track(x).MediaType = "vide" then
> qtvsource = seg.source.VideoTrack(x)
> exit // if you're looking for the first videotrack, then
> dump
> end
> next
>
> for x = 1 to y
> if seg.source.Track(x).MediaType = "soun" then
> qtssource = seg.source.SoundTrack(x)
> exit // if you're looking for the first soundtrack, then
> dump
> end
> next
>
> thisDir = 0
> if qtvsource<>nil then
> if qtvsource.Duration < seg.splicestart + seg.spliceend then
> thisdir = qtvsource.duration - seg.splicestart
> else
> thisdir = seg.spliceend
> end
> qtv.appendVideoTrackSegment qtvsource, seg.splicestart,
> thisDir, true, true
>
> If qtssource<>nil then
> if qtssource.duration-seg.splicestart < thisDir
> then //more video then audio, fill gap with empty space
> qts.appendSoundTrackSegment qtssource,
> seg.splicestart, qtssource.duration-seg.splicestart, true, true
> qts.InsertEmptySoundTrackSegment totalDir +
> (qtssource.duration-seg.splicestart), thisDir - (qtssource.duration-
> seg.spliceStart)
> else
> qts.appendSoundTrackSegment qtssource,
> seg.splicestart, thisdir, true, true
> end
> else //no audio track, insert empty sound
> qts.InsertEmptySoundTrackSegment totalDir, thisDir
> end
> end
>
> totalDir = totalDir + thisDir
> next
> if mymovie.commitChanges then
> setplayerMovie mymovie
> end
> end
> End Sub
>
> ---
> Subscribe to the digest:
> <mailto:<email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 08.08.02 01:16 (Wed, 7 Aug 2002 17:16:18 -0700)
From: Jarvis Badgley
> you'll lose sync. You could either figure out what doesn't match by
> checking the incoming and the existing durations or you could switch to
> using the InsertVideoTrackSegment and InsertSoundTrackSegment methods
> instead (passing the same destinationPosition value for both audio and
> video) so that even if the durations don't match, they'll start at the
> same
> time. This will mean that if the durations don't match, you'll have
> silence
> at the end of each segment (if the soundtrack segment is shorter) or no
> video at the end of each segment (if the videotrack segment is shorter)
> but
> that they'll be in sync at times where both audio and video exist.

Excellent, I tried this and it works great, thank you.
Now here's my other question. I want it to show a progress bar while
the splicing is taking place, so I have quicktime display a progress
dialog, and also have my own progress dialog behind it showing how many
tracks have been rendered. This isnt very clean, and it's very
difficult to cancel the rendering process. Is there a way to handle the
QT insert indicator myself? Or at least to detect if the insert was
canceled?

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 08.08.02 01:28 (Wed, 7 Aug 2002 17:28:08 -0700)
From: Jarvis Badgley
Ignore that last question, I found a better way to do this.
New question tho, editablemovie.flatten. Does this create a self
contained movie? Does it copy all the referenced video into a new file.

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 08.08.02 02:40 (Wed, 07 Aug 2002 21:40:44 -0400)
From: Benjamin J. Schneider
Hi Jarvis,

Yes the flatten method will make the movie self contained. The flatten
method also allows you to put the movie resource in the data fork (for
Windows compatibility) and to enable the faststart feature for internet
streaming. Keep in mind, however, that using editableMovie.Flatten will
create a new file. The original file will not be modified. If when you use
the Insert... methods, setting the copymedia parameter to true will make the
movie self contained as well.

Take care,

Ben

on 8/7/02 8:28 PM, Jarvis Badgley at <email address removed> wrote:

> Ignore that last question, I found a better way to do this.
> New question tho, editablemovie.flatten. Does this create a self
> contained movie? Does it copy all the referenced video into a new file.
>
> ---
> Subscribe to the digest:
> <mailto:<email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 08.08.02 02:58 (Wed, 7 Aug 2002 18:58:01 -0700)
From: Jarvis Badgley
> Yes the flatten method will make the movie self contained. The flatten
> method also allows you to put the movie resource in the data fork (for
> Windows compatibility) and to enable the faststart feature for internet
> streaming. Keep in mind, however, that using editableMovie.Flatten will
> create a new file. The original file will not be modified. If when
> you use
> the Insert... methods, setting the copymedia parameter to true will
> make the
> movie self contained as well.

ok, thank you. Originally that's what I was doing, but then it occurred
to me that it's much faster if I assemble the file with references, and
THEN flatten.

Everything seems to be working fine, except for that the last track's
audio is always skipping, but I need to do more testing with other files
first.

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 08.08.02 03:02 (Wed, 07 Aug 2002 22:02:17 -0400)
From: Benjamin J. Schneider
Did you download RB 4.5.1fc1? It also fixes a bug where soundtracks that
were not sampled at 44.1kHz would not playback properly. This could be the
"skipping" you're hearing if that last track has a samplerate other than
44.1kHz.

Take care,

Ben

on 8/7/02 9:58 PM, Jarvis Badgley at <email address removed> wrote:
> ok, thank you. Originally that's what I was doing, but then it occurred
> to me that it's much faster if I assemble the file with references, and
> THEN flatten.
>
> Everything seems to be working fine, except for that the last track's
> audio is always skipping, but I need to do more testing with other files
> first.

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: splicing QT tracks
Date: 08.08.02 03:27 (Wed, 7 Aug 2002 19:27:15 -0700)
From: Jarvis Badgley

On Wednesday, August 7, 2002, at 07:02 PM, Benjamin J. Schneider wrote:

> Did you download RB 4.5.1fc1? It also fixes a bug where soundtracks
> that
> were not sampled at 44.1kHz would not playback properly. This could be
> the
> "skipping" you're hearing if that last track has a samplerate other than
> 44.1kHz.

yes, this is 4.5.1, and all these tracks have the same settings (they
were encoded at the same time)

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>