IOS video exploded images, image compositing videos

Source: Internet
Author: User

In iOS video processing, video decomposition images and image compositing videos are frequently encountered in iOS video processing, and this blog post analyzes the conversion of iOS video images to two parts.

(1) Video decomposition image

Here the video decomposition images using Avassetimagegenerator, using this class can be easily implemented under different time stamps, video frame capture. Note that this method of video decomposition of picture frames is placed in child threads, and UI update operations are placed in the main thread. Here's a look at the core code:

_imagegenerator = [[Avassetimagegenerator alloc] initwithasset:_asset];

images = [[Nsmutablearray alloc]initwithcapacity:10];

_imagegenerator.maximumsize = thumbnail_size;

Cmtime duration = _asset.duration;

Cmtimevalue intervalseconds = DURATION.VALUE/3;

Cmtime time = Kcmtimezero;

Nsmutablearray *times = [Nsmutablearray array];

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

[Times Addobject:[nsvalue Valuewithcmtime:time];

Time = Cmtimeadd (time, Cmtimemake (Intervalseconds, Duration.timescale));

}

[_imagegenerator generatecgimagesasynchronouslyfortimes:times completionhandler:^ (CMTime requestedTime, Cgimagerefcgimage,

Cmtime Actualtime,

Avassetimagegeneratorresult result,

Nserror *error) {

if (cgimage) {

UIImage *image = [UIImage imagewithcgimage:cgimage];

[Images Addobject:image];

}

if (Images.count = = 3) {

Dispatch_async (Dispatch_get_main_queue (), ^{

Self.imageview1.image = [images objectatindex:0];

Self.imageview2.image = [images objectatindex:1];

Self.imageview3.image = [images objectatindex:2];

});

}

}];

After the decomposition of the frame effect is as follows: Image composition video effects are as follows:

(2) Image synthesis video

The method of image synthesis video is relatively more complicated, and the main class we use is this:

Avassetwriterinputpixelbufferadaptor. The difference is that we also set up 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: [NSNumber numberwithint: (int) width],

Avvideoheightkey: [NSNumber numberwithint: (int) height]};

2.4 Image Synthesis started

Cmtime lasttime = Cmtimemake (i, Self.frameTime.timescale);

Cmtime presenttime = Cmtimeadd (Lasttime, self.frametime);

[Self.bufferadapter Appendpixelbuffer:samplebuffer Withpresentationtime:presenttime];

IOS video exploded picture, picture compositing video

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.