swift - I would like to convert an NSImage into an mp4 -


adam jensen has done fantastic job @ crafting swift code convert image mov.

https://gist.github.com/acj/6ae90aa1ebb8cad6b47b

the above works great, job device more cpu , real storage average ipad need run under os x. easier said done.

first got no uikit, replaced cocoa. no uiimage, replaced nsimage. making stab in dark corrections; fixed/skipped reduced 31 errors down 5. need bit.

func fillpixelbufferfromimage(image: nsimage, pixelbuffer: cvpixelbuffer, contentmode:uiviewcontentmode){  cvpixelbufferlockbaseaddress(pixelbuffer, 0)  let data = cvpixelbuffergetbaseaddress(pixelbuffer) let rgbcolorspace = cgcolorspacecreatedevicergb() let context = cgbitmapcontextcreate(data, int(self.outputsize.width), int(self.outputsize.height), 8, cvpixelbuffergetbytesperrow(pixelbuffer), rgbcolorspace, cgimagealphainfo.premultipliedfirst.rawvalue)  cgcontextclearrect(context, cgrectmake(0, 0, cgfloat(self.outputsize.width), cgfloat(self.outputsize.height)))  let horizontalratio = cgfloat(self.outputsize.width) / image.size.width let verticalratio = cgfloat(self.outputsize.height) / image.size.height var ratio: cgfloat = 1  switch(contentmode) { case .scaleaspectfill:   ratio = max(horizontalratio, verticalratio) case .scaleaspectfit:   ratio = min(horizontalratio, verticalratio) default:   ratio = min(horizontalratio, verticalratio) }  let newsize:cgsize = cgsizemake(image.size.width * ratio, image.size.height * ratio)  let x = newsize.width < self.outputsize.width ? (self.outputsize.width - newsize.width) / 2 : 0 let y = newsize.height < self.outputsize.height ? (self.outputsize.height - newsize.height) / 2 : 0  cgcontextdrawimage(context, cgrectmake(x, y, newsize.width, newsize.height), image.cgimage)  cvpixelbufferunlockbaseaddress(pixelbuffer, 0) } 

i got cgiimage loaded directly quartz2d library.

    let realurl = nsurl(string: urlstring)     if let image = cgimagesourcecreatewithurl(realurl!, nil) {     var pixelbuffer: cvpixelbuffer? = nil     let status: cvreturn = cvpixelbufferpoolcreatepixelbuffer(kcfallocatordefault, pixelbufferadaptor.pixelbufferpool!, &pixelbuffer)      if let pixelbuffer = pixelbuffer status == 0 {       let managedpixelbuffer = pixelbuffer 

but need in understanding how extract pixels in populate pixelbuffer me thinks. start that?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -