0

I'm trying to make a QTMovie with picture in picture. I have two movies, one that is a video from a file, and one recorded with a camera.

I want the camera movie to show up above the other video and be slightly transparent. I can position the camera movie over the other video fine using a qttrack, but I don't know how to change the transparency of the qttrack on the video.

Is this possible using QTKit?

Here is an example of my code right now

   QTTimeRange fullMovieDuration = QTMakeTimeRange(QTZeroTime, [mCameraMovie duration]);
   QTTime startTime = QTMakeTime(0, [mCameraMovie currentTime].timeScale);

   QTTrack *cameraTrack = [[mCameraMovie tracks] objectAtIndex:0];

   NSRect newCameraRect = NSMakeRect(100, 100, 320, 240);

   [cameraTrack setAttribute:[NSValue valueWithRect:newCameraRect] forKey:QTTrackBoundsAttribute]; 

   [mMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
   [mMovie insertSegmentOfTrack:cameraTrack timeRange:fullMovieDuration atTime:startTime];

   [ibMovieView setMovie:mMovie];
Randall
  • 14,691
  • 7
  • 40
  • 60
  • Look at [this topic][1] [1]: http://stackoverflow.com/questions/1594381/cocoa-add-video-watermark-general-info – Davyd Geyl Sep 09 '11 at 00:40
  • That mentions adding an image, which already has transparency applied to a video. I want to add a new video. – Randall Sep 09 '11 at 12:16
  • As fas as I know you cannot do it in QTKit, it is very limited. It is possible in Quicktime framework, but you will be limited by 32-bit only. If you want to do it in Lion or iOS 4.0+ use AVFoundation. – Davyd Geyl Sep 10 '11 at 09:22

1 Answers1

2

I was able to do it using Quicktime.

Here's a category that got it done.

Header

#import <QTKit/QTKit.h>

@interface QTTrack (QTTrack_Opacity)

-(void)setOpacity:(float)opacity;

@end

Source File

@implementation QTTrack (QTTrack_Opacity)

-(void)setOpacity:(float)opacity
{
   MediaHandler mh = GetMediaHandler([[self media] quickTimeMedia]);
   RGBColor color = { (int)(opacity*255) << 8, (int)(opacity*255) << 8, (int)(opacity*255) << 8};
   MediaSetGraphicsMode(mh, graphicsModeStraightAlphaBlend, &color);

}

@end
Randall
  • 14,691
  • 7
  • 40
  • 60