[翻译] SCRecorder

简介:

SCRecorder

https://github.com/rFlex/SCRecorder

 

An easy Vine/Instagram like video and/or audio recorder class with Core Image filters support.

类似于 Vine/Instagram 视频或者音频的录制的类,使用 Core Image 作为滤镜。

 

A Vine/Instagram like audio/video recorder in Objective-C.

In short, here is a short list of the cool things you can do:

  • Record multiple video segments 
  • Remove any record segment that you don't want
  • Display the result into a convenient video player
  • Add a video filter using Core Image
  • Merge and export the video using fine tunings that you choose

简单而言,他可以做到如下这些:

* 记录分段的录像

* 移除你所不需要的录像片段

* 可以方便的显示你编辑的视频

* 使用 Core Image 当做视频滤镜

* 合并并输出你所选择的视频

 

These classes allow the recording of a video with pause/resume function. Although the project was initially made for the sake of taking videos only, you can now take pictures as well with some very useful utility functions that make the project totally suitable for a standalone camera engine. They are highly configurable, all the classes provide a lot of properties so we are quite sure that it should meet your needs :).

这些类允许你录制的时候暂停以及恢复。虽然这个项目是专门用来处理视频的,但你也可以用它来处理照相机功能。它高度定制,所有的类都提供了大量的属性供你定制:)。

 

Examples for iOS are provided.

Want something easy to create your filters in this project? Checkout https://github.com/rFlex/CoreImageShop

Framework needed:

  • CoreVideo
  • AudioToolbox
  • GLKit

想让滤镜使用起来更方便?看看这个地方https://github.com/rFlex/CoreImageShop

需要的框架:

* CoreVideo

* AudioToolbox

* GlKit (OpenGLES)

 

Podfile

If you are using cocoapods, you can use this project with the following Podfile

platform :ios, '7.0'
pod "SCRecorder", "~> 2.0"

Getting started

SCRecorder is the main class that connect the inputs and outputs together. It will handle all the underlying AVFoundation stuffs.

// Create the recorder
SCRecorder *recorder = [SCRecorder recorder];

// Set the sessionPreset used by the AVCaptureSession
recorder.sessionPreset = AVCaptureSessionPresetHigh;

// Listen to some messages from the recorder!
recorder.delegate = self;

// Initialize the audio and video inputs using the parameters set in the SCRecorder
[recorder openSession: ^(NSError *sessionError, NSError *audioError, NSError *videoError, NSError *photoError) {
    // Start the flow of inputs
    [recorder startRunningSession: ^{
        // Session is now started!


    }];
}];

Begin the recording

The second class we are gonna see is SCRecordSession, which is the class that process the inputs and append them into an output file. A record session can contains one or several record segments. A record segment is just a continuous video and/or audio file, represented as a NSURL. It starts when you hold the record button and end when you release it, if you implemented the record button the same way as instagram and vine did. When you end the SCRecordSession, it will merge the record segments (if needed). If the record is started on the SCRecorder, setting a SCRecordSession inside it will automatically start a record segment. If you don't want this to happen, you must remove the SCRecordSession from the SCRecorder while manipulating it.

// Creating the recordSession
SCRecordSession *recordSession = [SCRecordSession recordSession];

// Before setting it to the recorder, you can configure many things on the recordSession,
// like the audio/video compression, the maximum record duration time, the output file url...

recorder.recordSession = recordSession;

[recorder record];

Finishing the record

You can call endSession on the SCRecordSession to stop the current recording segment, merge every record segments and delete the underlying files used by the record segments. Only one file will be remaining after calling this method, which will be contained in the outputUrl. Note that this property is automatically generated, but you can set one if you want to record to a specific location.

SCRecordSession *recordSession = recorder.recordSession;
recorder.recordSession = nil;

[recordSession endSession:^(NSError *error) {
    if (error == nil) {
        NSURL *fileUrl = recordSession.outputUrl;
        // Do something with the output file :)
    } else {
        // Handle the error
    }
}];

And start doing the cool stuffs!

// You can read each record segments individually
SCRecordSession *recordSession = recorder.recordSession;
for (NSURL *recordSegment in recordSession.recordSegments) {
    // Do something cool with it
}

// You can remove a record segment at anytime
// Setting deleteFile to YES will delete the underlying file
[recordSession removeSegmentAtIndex:1 deleteFile:YES];

// Record a square video like Vine/Instagram
recordSession.videoSizeAsSquare = YES;

// Or add a random record segment that you made before
[recordSession insertSegment:fileUrl atIndex:0];

// You can read the recordSegments easily without having to merge them
AVAsset *recordSessionAsset = [recordSession assetRepresentingRecordSegments];

// Record in slow motion!
recordSession.videoTimeScale = 4;

// Get a dictionary representation of the record session
// And save it somewhere, so you can use it later!
NSDictionary *dictionaryRepresentation = [recordSession dictionaryRepresentation];
[[NSUserDefaults standardUserDefaults] setObject:dictionaryRepresentation forKey:@"RecordSession"];

// Restore a record session from a saved dictionary representation
NSDictionary *dictionaryRepresentation = [[NSUserDefaults standardUserDefaults] objectForKey:@"RecordSession"];
SCRecordSession *recordSession = [SCRecordSession recordSession:dictionaryRepresentation];

// Limiting the record duration
// When the record reaches this value, the recorder will remove the recordSession and call
// recorder:didCompleteRecordSession: on the SCRecorder delegate. It's up to you
// to do whatever you want with the recordSession after (the recordSegments won't be merge nor deleted, but
// the current recordSegment will be finished automatically)
recordSession.suggestedMaxRecordDuration = CMTimeMakeWithSeconds(7, 10000);

// Taking a picture
[recorder capturePhoto:^(NSError *error, UIImage *image) {
    if (image != nil) {
        // Do something cool with it!
    }
}];

// Display your recordSession
SCVideoPlayerView *videoPlayer = [[SCVideoPlayerView alloc] init];
[videoPlayer.player setItemByAsset:recordSessionAsset];

videoPlayer.frame = self.view.bounds;
[self.view addSubView:videoPlayer];
[videoPlayer.player play];

// Add a filter, in real time
CIFilter *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:@"inputBrightness", @0.0, @"inputContrast", @1.1, @"inputSaturation", @0.0, nil];
SCFilter *filter = [[SCFilter alloc] initWithCIFilter:blackAndWhite];
videoPlayer.player.filterGroup = [SCFilterGroup filterGroupWithFilter:filter];

// Import a filter made using CoreImageShop
NSURL *savedFilterGroupUrl = ...;
videoPlayer.player.filterGroup = [SCFilterGroup filterGroupWithContentsOfUrl:savedFilterGroupUrl];

// Export your final video with the filter
SCAssetExportSession exportSession = [[SCAssetExportSession alloc] initWithAsset:recordSessionAsset];
exportSession.keepVideoSize = YES;
exportSession.sessionPreset = SCAssetExportSessionPresetHighestQuality;
exportSession.fileType = AVFileTypeMPEG4;
exportSession.outputUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:@"_output.mp4"]];
exportSession.filterGroup = [SCFilterGroup filterGroupWithFilter:filter];

[exportSession exportAsynchronouslyWithCompletionHandler:^ {
    NSError *error = exportSession.error;

    // Etc...
}]

 

目录
相关文章
|
Cloud Native IDE Go
Protobuf在IDEA中的插件安装教程
Protobuf在IDEA中的插件安装教程
1373 0
|
存储 分布式计算 监控
应用层---网络模型
应用层---网络模型
329 3
|
数据安全/隐私保护
关于 OAuth 2.0 统一认证授权
随着互联网的巨头大佬逐渐积累了海量的用户与数据,用户的需求越来越多样化,为了满足用户在不同平台活动的需求,平台级的厂商则需要以接口的形式开放给第三方开发者,这样满足了用户的多样性需求,也可以让自己获得利益,让数据流动起来,形成给一个良性的生态环境,最终达到用户、平台商、第三方开发者共赢。
3334 0
|
SQL 消息中间件 Serverless
​Flink+Paimon+Hologres,面向未来的一体化实时湖仓平台架构设计
​Flink+Paimon+Hologres,面向未来的一体化实时湖仓平台架构设计
371 4
|
开发者 人工智能 自然语言处理
欢迎使用通义灵码
灵码使用指南!一键收藏。
145764 31
|
机器学习/深度学习 测试技术
大模型开发:描述交叉验证以及为什么在模型评估中使用它。
交叉验证是评估机器学习模型性能的方法,通过将数据集分成训练集和多份子集(折叠)进行多次训练验证。每次选择一份子集作为验证集,其余作训练,最后平均评估结果。这样能减少过拟合,提供可靠性能估计,用于参数调优,并减少小数据集或噪声带来的随机性影响。它是模型评估的关键技术,确保更准确的性能估计。
709 1
|
机器学习/深度学习 人工智能 监控
利用Python和OpenCV实现实时人脸识别系统
【8月更文挑战第31天】本文将引导您了解如何使用Python结合OpenCV库构建一个简易的实时人脸识别系统。通过分步讲解和示例代码,我们将探索如何从摄像头捕获视频流、进行人脸检测以及识别特定个体。本教程旨在为初学者提供一条明晰的学习路径,帮助他们快速入门并实践人脸识别技术。
|
网络协议 API 网络安全
发送TCP数据免费API接口教程
此API用于向指定主机发送TCP数据,支持POST/GET请求,需提供用户ID、KEY、接收IP、端口及数据内容。返回状态码和信息提示,示例如下:{"code":200,"msg":"发送成功!"}。详情见:https://www.apihz.cn/api/datacstcp.html
342 11

热门文章

最新文章