smasis
07-27-2005, 11:21 PM
Hi there,
The following Macromedia url:
http://www.macromedia.com/devnet/mx/flash/articles/video_primer.html
shows a "sophisticated example of a web page containing Flash Video synchronized to text and graphics". This is precisely what I am trying to achieve. I'm doing this by:
Preloading the SWF with the "text and graphics" animations (anim.swf) into an empty movieclip (instance name: anim_mc).
Attempting first NetConnect to Flash Communications Server 1.5 in order to check bandwidth. If this is successful, then I proceed to the next step.
NetConnect to another application with the desired FLV video (video.flv) and immediately NetStream (instance name: video_ns) to empty embedded video object.
Synchronize anim_mc with video_ns.
All this works well till step four. I first attempted this by simply checking the video_ns.time variable whenever the status of the NetStream changed and then making sure the anim_mc gotoAndStop'd or gotoAndPlay'd to the same timecode where video_ns.time was - this didnt work because streaming didn’t always play at the 12 fps but rather fluctuated so much that by the end of the 71 seconds (that’s how long the video is) there was usually 1-3 second offsets in the synchronization. What I ended up doing is probably very processor intensive but accurate (or so I thought!):
I had already setup an interval that checked video_ns.time and video_ns.bufferLength to make sure the bar with the controls refreshed the position of the playback and loading. I set this for every 500 milliseconds. I reduced this to 1000/12 milliseconds so that it played approximately every time there was a frame change and added this line of code into the intervaled function:
anim_mc.gotoAndStop(Math.round(video_ns.time*12))
so the anim_mc is actually never playing - its following the pace of the stream 12 times per second and each of these stopping its own playback till the next 1/12th of the second. It's not a very elegant solution to my problem but it worked.
Then, I realized that when I paused and the resumed the video on certain lower bandwidth version of my stream it restarts the video all over again but doesn’t restart the timecode (video_ns.time, that is) so since I coordinate the current frame in the mediaclip with the timecode then it become all very out of synch. It is very odd because I use the video_ns.pause(false) command to resume and not video_ns.seek(0) nor video_ns.play(“video”,0). I found it had to do with the lack of timely key frames within the FLV file itself due to lower bandwidth nature - a setting I wasn’t aware of in my Sorenson compressing software when I generated those files in the first place. I reduced the key frame separation to 30 frames and that problem was solved.
Another more serious problem came up when I finally ran the main SWF (that is, the one that streams video.flv and synchronizes it to anim.swf) in the localhost instead of testing it from with Flash. BTW, the other two components: video.flv and anim.swf were already working from a remote server and streaming/preloading into the main SWF correctly. Anyway, to make this story short, the main SWF doesn’t synch the other two components correctly when working from http://localhost (up to 5 second offsets) but synchs when working from file://... In this case, it shouldn't make a difference. Right?
In any case, I can’t trust my code anymore because I need some real tried and tested answers rather than the outcome of my trial and error. I was going to use the VideoPlayback components but I haven’t found any tutorials on how to: 1) synchronize it with other animations and text 2) skin it (not nearly as important as number 1).
I am getting very frustrated :confused:. How can I effectively synchronize? I would greatly appreciate any answers. Thanks.
The following Macromedia url:
http://www.macromedia.com/devnet/mx/flash/articles/video_primer.html
shows a "sophisticated example of a web page containing Flash Video synchronized to text and graphics". This is precisely what I am trying to achieve. I'm doing this by:
Preloading the SWF with the "text and graphics" animations (anim.swf) into an empty movieclip (instance name: anim_mc).
Attempting first NetConnect to Flash Communications Server 1.5 in order to check bandwidth. If this is successful, then I proceed to the next step.
NetConnect to another application with the desired FLV video (video.flv) and immediately NetStream (instance name: video_ns) to empty embedded video object.
Synchronize anim_mc with video_ns.
All this works well till step four. I first attempted this by simply checking the video_ns.time variable whenever the status of the NetStream changed and then making sure the anim_mc gotoAndStop'd or gotoAndPlay'd to the same timecode where video_ns.time was - this didnt work because streaming didn’t always play at the 12 fps but rather fluctuated so much that by the end of the 71 seconds (that’s how long the video is) there was usually 1-3 second offsets in the synchronization. What I ended up doing is probably very processor intensive but accurate (or so I thought!):
I had already setup an interval that checked video_ns.time and video_ns.bufferLength to make sure the bar with the controls refreshed the position of the playback and loading. I set this for every 500 milliseconds. I reduced this to 1000/12 milliseconds so that it played approximately every time there was a frame change and added this line of code into the intervaled function:
anim_mc.gotoAndStop(Math.round(video_ns.time*12))
so the anim_mc is actually never playing - its following the pace of the stream 12 times per second and each of these stopping its own playback till the next 1/12th of the second. It's not a very elegant solution to my problem but it worked.
Then, I realized that when I paused and the resumed the video on certain lower bandwidth version of my stream it restarts the video all over again but doesn’t restart the timecode (video_ns.time, that is) so since I coordinate the current frame in the mediaclip with the timecode then it become all very out of synch. It is very odd because I use the video_ns.pause(false) command to resume and not video_ns.seek(0) nor video_ns.play(“video”,0). I found it had to do with the lack of timely key frames within the FLV file itself due to lower bandwidth nature - a setting I wasn’t aware of in my Sorenson compressing software when I generated those files in the first place. I reduced the key frame separation to 30 frames and that problem was solved.
Another more serious problem came up when I finally ran the main SWF (that is, the one that streams video.flv and synchronizes it to anim.swf) in the localhost instead of testing it from with Flash. BTW, the other two components: video.flv and anim.swf were already working from a remote server and streaming/preloading into the main SWF correctly. Anyway, to make this story short, the main SWF doesn’t synch the other two components correctly when working from http://localhost (up to 5 second offsets) but synchs when working from file://... In this case, it shouldn't make a difference. Right?
In any case, I can’t trust my code anymore because I need some real tried and tested answers rather than the outcome of my trial and error. I was going to use the VideoPlayback components but I haven’t found any tutorials on how to: 1) synchronize it with other animations and text 2) skin it (not nearly as important as number 1).
I am getting very frustrated :confused:. How can I effectively synchronize? I would greatly appreciate any answers. Thanks.