Hi,

In exactly which way is it not working? Do you get an exception, an
invalid video, a crash...

Rolf

On Fri, Sep 9, 2011 at 4:10 PM, mebsokmanager <[email protected]> wrote:
> Hi,
>
> I have 5 local image on local, and wanna create video from these images and
> post it to friends or share it on social media.
>
> I wrote as below but not working.Could you please help about it?
>
>
> /********************************************************/
>        void CreateVideo()
>                {
>                          SizeF size = new SizeF(480, 320);
>                          String betaCompressionDirectory = 
> IOManager.GetPath("Movie.m4v");
>
>
>
>                        IntPtr error;
>
>                                NSUrl 
> outputPath=NSUrl.FromFilename(betaCompressionDirectory);
>                                AVAssetWriter videoWriter;
>                                try{
>
> videoWriter=AVAssetWriter.FromUrl(outputPath,"com.apple.quicktime-movie",error);
>                                        if(videoWriter==null){
>                                                return;
>                                        }
>                                }catch(Exception ex)
>                                {
>                                        Console.WriteLine("Hata 1: " 
> +ex.Message);
>                                        return;
>                                }
>
>                                NSError nserror;
>                                if (error != IntPtr.Zero)
>                       nserror = (NSError) Runtime.GetNSObject (error);
>
>                                NSObject[] keys = new NSObject[]{
>                                                                               
>                          new NSString("AVVideoCodecKey")
>                                                                               
>                          ,new NSString("AVVideoWidthKey")
>                                                                ,new 
> NSString("AVVideoHeightKey")
>
>                                                                               
>          };
>
>                                NSObject[] objects = new NSObject[]{
>                                                                               
>                          new NSString("AVVideoCodecH264")
>                                                                               
>                          ,new NSNumber(480)
>                                                                ,new 
> NSNumber(320)
>
>                                                                               
>          };
>                        NSDictionary 
> videoSettings=NSDictionary.FromObjectsAndKeys(objects,keys);
>                        AVAssetWriterInput writerInput=new
> AVAssetWriterInput(AVMediaType.Video,videoSettings);
>
>
>                        NSDictionary sourcePixelBufferAttributesDictionary =
> NSDictionary.FromObjectAndKey(NSNumber.FromObject(CVPixelFormatType.CV32ARGB),CVPixelBuffer.PixelFormatTypeKey);
>
>                         AVAssetWriterInputPixelBufferAdaptor adaptor=new
> AVAssetWriterInputPixelBufferAdaptor(writerInput,sourcePixelBufferAttributesDictionary);
>
>                        if(writerInput!=null)
>                        {
>                                if(videoWriter.CanAddInput(writerInput))
>                                {
>
>                                        Console.WriteLine(@"I can add this 
> input");
>
>                                                
> videoWriter.AddInput(writerInput);
>                                            videoWriter.StartWriting();
>                                                
> videoWriter.StartSessionAtSourceTime(CMTime.Zero);
>
>
>                                                UIImage 
> img=UIImage.FromFile("images/4_1.png");
>                                                DispatchQueue dquee=new 
> DispatchQueue("mediaInputQueue");
>                                                int frame=0;
>
>                                        CVPixelBuffer 
> buffer=pixelBufferFromCGImage(img.CGImage,size);
>                                                        
> adaptor.AppendPixelBufferWithPresentationTime(buffer,CMTime.Zero);
>
>                                        for(int i=0;i<4;i++)
>                                        {
>                                                
> if(writerInput.ReadyForMoreMediaData==true)
>                                                {
>                                                        CMTime frameTime = new 
> CMTime(1, 20);
>                                                        CMTime lastTime = new 
> CMTime(i, 20);
>                                                        CMTime presentTime=new
> CMTime(frameTime.Value+lastTime.Value,frameTime.TimeScale+lastTime.TimeScale);
>
>                                                          
> buffer=pixelBufferFromCGImage(img.CGImage,size);
>
> Console.WriteLine(adaptor.AppendPixelBufferWithPresentationTime(buffer,presentTime));
>                                                }
>                                        }
>                                        writerInput.MarkAsFinished();
>                                        videoWriter.FinishWriting();
>
>
>
>
>                                }
>                                else
>                                {
>                                        Console.WriteLine(@"i can't add this 
> input");
>                                }
>                        }
>                }
>
>
>
> /**********************************************************/
> CVPixelBuffer pixelBufferFromCGImage(CGImage image,SizeF size)
>                {
>
>
>                 NSObject[] keys = new NSObject[]{
>                                                                               
>                  CVPixelBuffer.CGImageCompatibilityKey
>
>                                                                               
>                          ,
>                                                                               
>                  CVPixelBuffer.CGBitmapContextCompatibilityKey
>
>
>
>                                                                               
>          };
>
>                 NSObject[] objects = new NSObject[]{
>                                                                               
>                          new NSNumber(true)
>                                                                               
>                          ,new NSNumber(true)
>                                                        };
>                        NSDictionary 
> options=NSDictionary.FromObjectsAndKeys(objects,keys);
>                        CVPixelBuffer pxbuffer=new
>
> CVPixelBuffer((int)size.Width,(int)size.Height,CVPixelFormatType.CV32ARGB,options);
>                        if(pxbuffer!=null)
>                        {
>                                pxbuffer.Lock (0);
>                                IntPtr pxdata=pxbuffer.BaseAddress;
>                                if(pxdata!=IntPtr.Zero)
>                                {
>                                         using(var rgbColorSpace = 
> CGColorSpace.CreateDeviceRGB())
>                                {
>                                                using(CGBitmapContext context=
>                                                        new
> CGBitmapContext(pxdata,(int)size.Width,(int)size.Height,8,4*(int)size.Width,
>
> rgbColorSpace,CGImageAlphaInfo.PremultipliedFirst)){
>                                                        if(context != null)
>                                                        {
>                                                                
> context.DrawImage(new
> RectangleF(0,0,image.Width,image.Height),image);
>                                                                
> imgBufferdanGelen.Image=UIImage.FromImage(context.ToImage());
>                                                                
> Console.WriteLine("Yeni image olusturuluyor...");
>                                                        }
>                                                }
>                                        }
>                                }
>                                pxbuffer.Unlock(0);
>
>                        }
>                        return pxbuffer;
>
>
> }
>                }
>
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/Create-Video-from-image-sequences-IOS-tp3801785p3801785.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to