IOS video exploded images, image compositing videos

Source: Internet
Author: User

In iOS video processing, video exploded images and image compositing videos are frequently encountered problems in iOS video processing. This blog on the two parts of the iOS video image of the mutual conversion to do a bit of analysis.

(1) Video decomposition image

Here the video exploded images using a Avassetimagegenerator. using this class can be very convenient to achieve a different time between the Poke, video frame capture. Note that in general, the method of decomposing picture frames is placed in a child thread, and the UI update operation is placed in the main thread.

Take a look at the core code:

    _imagegenerator = [[ Avassetimagegenerator alloc " initwithasset : Span style= "COLOR: #4f8187" >_asset ];

images = [[nsmutablearrayalloc]initwithcapacity: Ten ];

_imagegenerator. MaximumSize = thumbnail_size ;

cmtime duration = _asset. duration;

cmtimevalue intervalseconds = Duration. value /3;

cmtime Time = Kcmtimezero;

nsmutablearray *times = [nsmutablearrayarray];

for (nsuinteger i =0; i < 3; i++) {

[Timesaddobject: [nsvaluevaluewithcmtime: Time]];

Time =Cmtimeadd(time, cmtimemake(intervalseconds, duration. Timescale));

}

    [ _imagegenerator generatecgimagesasynchronouslyfortimes:times Completionhandler:^ ( cmtime Requestedtime,                         & nbsp                          ,         &NB Sp                         cgimageref Cgimage,

cmtime Actualtime,

Avassetimagegeneratorresult result,

nserror *error) {

if (Cgimage) {

UIImage *image = [UIImageimagewithcgimage: cgimage];

[imagesaddobject: image];

}

if (images. count = =3) {

dispatch_async(dispatch_get_main_queue(), ^{

Self. Imageview1. image = [imagesobjectatindex:0];

Self. imageview2. image = [imagesobjectatindex:1];

Self. imageview3. image = [imagesobjectatindex:2];

});

}

}];

The frame effect after decomposition is as follows: Picture compositing video effects such as the following:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "width=" 311 "height=" 574 ">

(2) image synthesis Video

The method of image synthesis video is a bit more complicated. Our main use of the class is this:

Avassetwriterinputpixelbufferadaptor.

The difference is that we also have to set the various parameters of the image synthesis video, such as frame rate, encoding method and so on.

2.1 Set File Encapsulation type

Avfiletypequicktimemovie

2.2 Format Picture

Kcvpixelformattype_32argb

2.3 Setting the encoding method, image size

Nsdictionary *videosettings =@{avvideocodeckey : AVVideoCodecH264 ,

avvideowidthkey : [nsnumbernumberwithint:(int) width],

avvideoheightkey : [nsnumbernumberwithint:(int) height]};

2.4 Image Synthesis starts

cmtime lasttime =cmtimemake(i, self. Frametime. timescale);

cmtime presenttime =cmtimeadd(lasttime, self. Frametime);

[Self. Bufferadapter appendpixelbuffer: Samplebuffer withpresentationtime:p resenttime];





IOS video exploded images, image compositing videos

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.