[翻译] 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...
}]

 

时间: 2024-10-14 14:11:30

[翻译] SCRecorder的相关文章

[翻译]JDK 8 兼容性指南

翻译官方文档,删除部分可忽略. 译者:坤谷,井桐,激酶 兼容性是一个复杂的问题. 本文介绍了Java平台潜在的三种不兼容问题: 源码: 源码兼容性问题关注Java源代码转换成class文件是否兼容,包括代码是否仍然可编译. 二进制: 在Java语言规范中,二进制兼容性定义为:"类的改变是二进制兼容的(或者不破坏二进制兼容性),是指如果改变前的类的二进制在链接时没有错误,那么改变后的类在链接时仍然没有错误." 行为 : 行为兼容性包括在运行时执行的代码的语义. 欲了解更多信息,请参阅Op

java.security.Guard翻译

  Overview Package  Class Use Tree Deprecated Index Help JavaTM 2 PlatformStd. Ed. v1.4.2  PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD java.security Interface Gua

翻译CFSSL相关操作文档

我发现国内这个CFSSL资料蛮少的. 但如果深入到K8S认证之后,这块知识又必不可少. (OPENSSL也可实现,但好像不是主流) 于是花了两天快速翻译了一下几个文档. 贡献给有需要的同仁. 如有错误(肯定有!),欢迎提正. 百度网盘共享地址: https://pan.baidu.com/s/1skAQtAH

如何这段C#代码翻译成VB代码?谢谢!

问题描述 如何这段C#代码翻译成VB代码?谢谢! private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //自动点击弹出确认或弹出提示 IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument; vDocument.parentWindow.execScrip

php-java和PHP有纯中文的官方手册吗?还是只有部分的翻译?

问题描述 java和PHP有纯中文的官方手册吗?还是只有部分的翻译? java和PHP有纯中文的官方手册吗?还是只有部分的翻译?我英文不好,能不能学呢? 解决方案 http://cn2.php.net/manual/zh/index.php 解决方案二: java的JDK有中文版的API,PHP网上也有中文手册.现在网络资源这么丰富,只有肯上心,学东西还是很容易的. 选定一个完整的视频教程,跟着练习,上手是很容易的. 我就是2010年暑假跟着传智播客视频教程自学的Java,现在已经很熟练了.祝好

傲游浏览器怎么翻译网页

  步骤一:没有傲游浏览器的童鞋 步骤二:点开下拉====勾选"翻译". 步骤三:输入你想要的翻译的网址,选定你想翻译的内容 步骤四:耐心等待翻译结果

Word 2010中的“翻译字典”

  1.打开一篇文字文档,并且里面与你有需要翻译的文字,例如,我们这里先选择一篇中文散文; 2.在功能区点击"审阅"选项卡,选择"语言"区域的"翻译"选项组,单击"翻译所选文字"; 3.单击"审阅"功能卡,点击"语言"区域的"翻译"选项组,在弹出的下拉菜单中选择"选择转换语言"; 4.此时窗口会弹出一个"翻译语言选项"的对话框,

Word每一页的左边显示英语右边显示中文翻译

  现在,您想实现的效果是,在每一页里面,左边是英文,右边是对应的翻译好的中文.像这样的排版方式,可以方便我们更好的学习英语. ①使用分栏的是不科学的 要解决这个问题,很多人第一时间就会想到分栏,想把英文放在栏的左边,中文放在栏的右边.然而,这是可行的,却是不科学的. 因为,使用Word里面的自动分栏,原文英文和翻译后的中文,很难一一对应,造成学习上的困难.另外,如果您想再排版实现一一对应,那么,难度是非常大. ②使用文本框也是不合理的 以上方法难以实现.很多人会想到使用文本框的办法. 即在Wo

360浏览器如何翻译英文网页

  整个网页翻译: 1.打开360浏览器,在浏览器中打开你想浏览的英文网站,选择浏览器上面的翻译三角符号. 2.选择第一项,翻译当前网页,就会开始翻译了. 3.翻译完后,就可以看到全部是中文了. 单个句子翻译: 1.同样选择浏览器上面的翻译,选择第二项翻译文字. 2.在弹出的翻译对话框中,将要翻译的英文复制到文本框中,点击下面的翻译. 3.翻译完后,翻译的结果就在下面了,很方便的.