上海千语创想科技有限公司
 175-2108-6175
网站建设资讯详细

短视频app开发,北京制作短视频app专业技术流程

日期:2021-05-22  作者:千语创想  浏览:2331
短视频app开发最关键的步骤是分为三个步骤,我将教你把每个动作点一层一层地保持在这三个步骤下,动作点API可以根据需要启用:
一、短视频app开发录像功能:
a.创业
B.拍摄的音乐背景
C.刚开始
D.添加美丽
e.加ps过滤器
F.添加面纸
G.按段加速执行
h.完成
二、短视频app视频剪辑
a.一开始就编写
b.增加音乐背景
c.增加案文效果
D.增加地震的特殊影响

2.1 APP启动拍摄

首先包含七牛短视频 SDK 头文件 PLShortVideoKit.h :

#import <PLShortVideoKit/PLShortVideoKit.h>

然后添加一个 PLShortVideoRecorder 属性:

@property (nonatomic,strong) PLShortVideoRecorder *shortVideoRecorder;

创建音视频的采集和编码配置对象,这里我们使用默认配置,开发者可以根据自己的需求修改配置:

PLSVideoConfiguration *videoConfiguration = [PLSVideoConfiguration defaultConfiguration];  PLSAudioConfiguration *audioConfiguration = [PLSAudioConfiguration defaultConfiguration];

创建拍摄 shortVideoRecorder 对象:

self.shortVideoRecorder = [[PLShortVideoRecorder alloc] initWithVideoConfiguration:videoConfiguration audioConfiguration:audioConfiguration]; self.shortVideoRecorder.delegate = self;

添加摄像头预览视图:

[self.view addSubview:self.shortVideoRecorder.previewView];

至此,基本配置完成,我们可以启动摄像头预览:

[self.shortVideoRecorder startCaptureSession];

2.2APP给拍摄添加背景音乐

在开始录制之前,我们可以添加背景音乐:

NSURL *audioURL = [NSURL fileURLWithString:@"PATH TO AUDIO"]; [self.shortVideoRecorder mixAudio:audioURL];

背景音乐只能在开始录制之前添加,一旦录制开始了,不能再添加,此时只有删除已经录制的视频文件,才能添加背景音乐。

2.3APP开始拍摄

录制的视频存放路径由 SDK 内部自动生成:

[self.shortVideoRecorder startRecording];

开发者也可以自己传入录制的视频存放路径:

[self.shortVideoRecorder startRecording:customFileURL];

2.4APP添加美颜

七牛短视频 SDK 提供了美颜功能,开发者只需要一个简单的参数设置即可以打开美颜功能:

[self.shortVideoRecorder setBeautifyModeOn:YES];

2.5APP添加滤镜

七牛短视频 SDK 内部提供了 30 多种滤镜格式,开发者使用滤镜需要在工程中包含 PLShortVideoKit.bundle,这里面存放了滤镜的图片资源,开发者还可以添加自己的滤镜图片。

初始化滤镜:

// 初始化滤镜 self.filter = [[PLSFilter alloc] init];// 设置滤镜色彩图片路径 NSString *bundlePath = [NSBundle mainBundle].bundlePath; NSString *colorImagePath = [bundlePath stringByAppendingString:@"/PLShortVideoKit.bundle/colorFilter/candy/filter.png"]; self.filter.colorImagePath = colorImagePath;

在短视频数据回调方法中,我们可以用上面初始化好的滤镜:

- (CVPixelBufferRef)shortVideoRecorder:(PLShortVideoRecorder *)recorder cameraSourceDidGetPixelBuffer:(CVPixelBufferRef)pixelBuffer { // 进行滤镜处理 pixelBuffer = [self.filter process:pixelBuffer];  return pixelBuffer; }

2.6 短视频app添加人脸贴纸

七牛短视频 SDK 没有提供人脸识别的贴纸功能,但是我们 SDK 能很容易的接入友商的贴纸功能,我们以添加 涂图 的贴纸举例说明

包含涂图的头文件:

#import <TuSDKVideo/TuSDKVideo.h> #import "StickerScrollView.h"

增加贴纸添加器和贴纸选择 view:

@property (nonatomic, strong) TuSDKFilterProcessor *filterProcessor; @property (nonatomic, strong) StickerScrollView *stickerView;

初始化贴纸添加的实例:

self.filterProcessor = [[TuSDKFilterProcessor alloc] initWithFormatType:kCVPixelFormatType_32BGRA isOriginalOrientation:NO]; self.filterProcessor.outputPixelFormatType = lsqFormatTypeBGRA; // TuSDKFilterProcessor 默认不启用贴纸,这里需要主动启用贴纸功能 [self.filterProcessor setEnableLiveSticker:YES]; self.stickerView = [[StickerScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 300)]; self.stickerView.stickerDelegate = self; self.stickerView.cameraStickerType = lsqCameraStickersTypeSquare;

选择贴纸。在贴纸选择的回调,处理贴纸:

(void)clickStickerViewWith:(TuSDKPFStickerGroup *)stickGroup { if (!stickGroup) { // 为nil时 移除已有贴纸组; [_filterProcessor removeMediaEffectsWithType:TuSDKMediaEffectDataTypeSticker]; } else { // 选中了某个贴纸,将其添加到 filterProcessor 中 [self.filterProcessor showGroupSticker:stickGroup];  } }

贴纸选择完成之后,我们可以将贴纸应用到视频录制中。和滤镜处理类似,在短视频拍摄的视频数据回调中,应用贴纸:

- (CVPixelBufferRef)shortVideoRecorder:(PLShortVideoRecorder *)recorder cameraSourceDidGetPixelBuffer:(CVPixelBufferRef)pixelBuffer { // 进行滤镜处理 pixelBuffer = [self.filter process:pixelBuffer];  // TuSDK 进行贴纸处理 pixelBuffer = [self.filterProcessor syncProcessPixelBuffer:pixelBuffer]; [self.filterProcessor destroyFrameData];  return pixelBuffer; }

2.7短视频app分段变速拍摄

如果想拍摄的视频以快速或者慢速播放,可以设置拍摄速率:

self.shortVideoRecorder.recoderRate = PLSVideoRecoderRateTopFast;

2.8短视频app结束拍摄

如果要结束某一段视频的录制,可以调用停止录制方法:

[self.shortVideoRecorder stopRecording];

调用停止录制之后,保存的视频会通过录制完成回调返回出来:

- (void)shortVideoRecorder:(PLShortVideoRecorder *)recorder didFinishRecordingToOutputFileAtURL:(NSURL *)fileURL fileDuration:(CGFloat)fileDuration totalDuration:(CGFloat)totalDuration {  }

停止音视频采集。如果不再需要拍摄视频,可以调用停止采集方法来结束拍摄:

[self.shortVideoRecorder stopCaptureSession];

视频编辑

3.1短视频app开始编辑

编辑类 PLShortVideoEditor 支持渲染音视频、水印、滤镜、背景音乐、MV 特效等功能

初始化和启动编辑:

self.shortVideoEditor = [[PLShortVideoEditor alloc] initWithAsset:asset videoSize:CGSizeZero]; self.shortVideoEditor.delegate = self; self.shortVideoEditor.loopEnabled = YES; [self.view addSubview:self.shortVideoEditor.preview];  [self.shortVideoEditor startEditing];

3.2短视频app添加app在线制作背景音乐

添加背景音乐

[self.shortVideoEditor addMusic:musicURL timeRange:timeRange volume:1.0];

调节背景音乐音量

[self.shortVideoEditor updateMusic:timeRange volume:0.5];

3.3短视频app添加文字特效

添加文字的逻辑和添加贴纸使用的是同一个逻辑,用户可以使用七牛短视频 Demo 中已经包装好的添加文字、贴纸的类 PLSStickerView:

PLSStickerView *stickerView = [[PLSStickerView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];   // 以字典的形式,保存 stickerView 信息 NSMutableDictionary *stickerSettings = [[NSMutableDictionary alloc] init]; stickerSettings[PLSStickerKey] = stickerView; stickerSettings[PLSSizeKey] = [NSValue valueWithCGSize:viewSize]; stickerSettings[PLSPointKey] = [NSValue valueWithCGPoint:viewPoint]; CGFloat rotation = atan2f(transform.b, transform.a); rotation = rotation * (180 / M_PI); stickerSettings[PLSRotationKey] = [NSNumber numberWithFloat:rotation];  [self.stickerSettingsArray addObject:stickerSettings];

3.4短视频app添加抖音特效

七牛短视频 SDK 没有集成特效,但是和人脸贴纸一样,可以轻松的接入第三方的特效。下面我们还以添加 涂图 的特效为例,演示特效的添加方式

首先,初始化特效添加器:

self.filterProcessor = [[TuSDKFilterProcessor alloc] initWithFormatType:kCVPixelFormatType_32BGRA isOriginalOrientation:isOriginalOrientation]; self.filterProcessor.delegate = self; self.filterProcessor.mediaEffectDelegate = self; // 默认关闭动态贴纸功能,即关闭人脸识别功能 self.filterProcessor.enableLiveSticker = NO;

添加灵魂出窍特效:

TuSDKMediaSceneEffectData *effectData = [[TuSDKMediaSceneEffectData alloc] initWithEffectsCode:@"LiveSoulOut01"];effectData.atTimeRange = [TuSDKTimeRange makeTimeRangeWithStart:kCMTimeZero end:CMTimeMake(INTMAX_MAX, 1)];[self.filterProcessor addMediaEffect:effectData];

应用特效。在短视频编辑视频数据回调里面,将特效应用,以便预览特效效果:

- (CVPixelBufferRef)shortVideoEditor:(PLShortVideoEditor *)editor didGetOriginPixelBuffer:(CVPixelBufferRef)pixelBuffer timestamp:(CMTime)timestamp { // 应用特效 pixelBuffer = [self.filterProcessor syncProcessPixelBuffer:pixelBuffer frameTime:timestamp]; [self.filterProcessor destroyFrameData];  return pixelBuffer; }

视频导出

上面我们的短视频编辑就完成了,现在我们将编辑的视频使用 PLSAVAssetExportSession

导出来保存到本地相册

初始化视频导出器:

NSMutableDictionary *outputSettings = [[NSMutableDictionary alloc] init]; NSMutableDictionary *movieSettings = [[NSMutableDictionary alloc] init]; NSMutableDictionary *backgroundAudioSettings = [NSMutableDictionary alloc] init]; NSMutableArray *stickerSettingsArray = [[NSMutableArray alloc] init]; NSMutableArray *audioSettingsArray = [[NSMutableArray alloc] init];  // 将导出信息设置到 outputSettings 中 // do setting...  AVAsset *asset = movieSettings[PLSAssetKey]; PLSAVAssetExportSession *exportSession = [[PLSAVAssetExportSession alloc] initWithAsset:asset]; exportSession.outputFileType = PLSFileTypeMPEG4; exportSession.shouldOptimizeForNetworkUse = YES; exportSession.outputSettings = self.outputSettings; exportSession.delegate = self; exportSession.isExportMovieToPhotosAlbum = YES;

设置导出视频相关 block:

__weak typeof(self) weakSelf = self;  [exportSession setCompletionBlock:^(NSURL *url) { NSLog(@"视频已保存到相册中"); }];  [exportSession setFailureBlock:^(NSError *error) { NSLog(@"导出视频失败"); }];  [exportSession setProcessingBlock:^(float progress) { NSLog(@"视频导出完成百分比: %f", process); }];

实现 PLSAVAssetExportSessionDelegate 的视频数据回调方法,进行特效处理:

- (CVPixelBufferRef)assetExportSession:(PLSAVAssetExportSession *)assetExportSession didOutputPixelBuffer:(CVPixelBufferRef)pixelBuffer timestamp:(CMTime)timestamp {  // 特效处理  pixelBuffer = [self.filterProcessor syncProcessPixelBuffer:pixelBuffer frameTime:timestamp]; [self.filterProcessor destroyFrameData];  return pixelBuffer; }

总结

短视频app开发,北京短视频app制作专业技术流程,掌握以上短视频app技术开发要点,开发一个优秀的短视频app绝对没有问题。短视频直播带货app开发,2020年4月,非常流行短视频带货直播电商app市场火爆,非常值得进入的短视频朝阳产业。



转载请注明来自:https://www.qianyuthink.com/news/2011.html

填写您的项目需求给我们

或者直接拨打 7×12小时一对一咨询电话

175 2108 6175

请填写需求信息,我们会在10分钟内与您取得联系

请认真填写需求信息,我们会在10分钟内与您取得联系

×
客服二维码
咨询技术总监
175-2108-6175
客服二维码
技术总监微信
客服二维码