Skip to content

Commit

Permalink
优化视频导出格式,删除3gp格式
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Dec 13, 2017
1 parent ef1c119 commit 7325169
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 34 deletions.
27 changes: 2 additions & 25 deletions PhotoBrowser/ZLCustomCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <AVFoundation/AVFoundation.h>
#import <CoreMotion/CoreMotion.h>
#import "ZLPlayer.h"
#import "ZLPhotoManager.h"


#define kTopViewScale .5
Expand Down Expand Up @@ -777,7 +778,7 @@ - (void)onStartRecord
movieConnection.videoOrientation = self.orientation;
[movieConnection setVideoScaleAndCropFactor:1.0];
if (![self.movieFileOutPut isRecording]) {
NSURL *url = [self getVideoFileUrl];
NSURL *url = [NSURL fileURLWithPath:[ZLPhotoManager getVideoExportFilePath:self.videoType]];
[self.movieFileOutPut startRecordingToOutputFileURL:url recordingDelegate:self];
}
}
Expand Down Expand Up @@ -817,30 +818,6 @@ - (void)onDismiss
});
}

- (NSURL *)getVideoFileUrl
{
NSString *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, NO).firstObject;
NSString *format = self.videoType == ZLExportVideoTypeMov ? @"mov" : self.videoType == ZLExportVideoTypeMp4 ? @"mp4" : @"3gp";

filePath = [NSTemporaryDirectory() stringByAppendingString:[NSString stringWithFormat:@"%@.%@", [self getUniqueStrByUUID], format]];
return [NSURL fileURLWithPath:filePath];
}

- (NSString *)getUniqueStrByUUID
{
CFUUIDRef uuidObj = CFUUIDCreate(nil);//create a new UUID

//get the string representation of the UUID
CFStringRef uuidString = CFUUIDCreateString(nil, uuidObj);

NSString *str = [NSString stringWithString:(__bridge NSString *)uuidString];

CFRelease(uuidObj);
CFRelease(uuidString);

return [str lowercaseString];
}

- (void)playVideo
{
if (!_playerView) {
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ typedef NS_ENUM(NSUInteger, ZLCaptureSessionPreset) {
};

typedef NS_ENUM(NSUInteger, ZLExportVideoType) {
//default
ZLExportVideoTypeMov,
ZLExportVideoTypeMp4,
ZLExportVideoType3gp,
};

static inline void SetViewWidth(UIView *view, CGFloat width) {
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLPhotoActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by long on 15/11/25.
// Copyright © 2015年 long. All rights reserved.
//
//pods version 2.5.4 - 2017.12.5 update
//pods version 2.5.5 - 2017.12.13 update

#import <UIKit/UIKit.h>
#import "ZLPhotoConfiguration.h"
Expand Down
7 changes: 7 additions & 0 deletions PhotoBrowser/ZLPhotoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@
*/
+ (void)exportVideoForAsset:(PHAsset *)asset type:(ZLExportVideoType)type presetName:(NSString *)presetName complete:(void (^)(NSString *exportFilePath, NSError *error))complete;


/**
获取保存视频的路径
*/
+ (NSString *)getVideoExportFilePath:(ZLExportVideoType)type;


#pragma mark - 相册、相机、麦克风权限相关
/**
是否有相册访问权限
Expand Down
23 changes: 18 additions & 5 deletions PhotoBrowser/ZLPhotoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ + (void)export:(AVAsset *)asset range:(CMTimeRange)range type:(ZLExportVideoType
NSURL *exportFileUrl = [NSURL fileURLWithPath:exportFilePath];

exportSession.outputURL = exportFileUrl;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.outputFileType = (type == ZLExportVideoTypeMov ? AVFileTypeQuickTimeMovie : AVFileTypeMPEG4);
exportSession.timeRange = range;

[exportSession exportAsynchronouslyWithCompletionHandler:^{
Expand Down Expand Up @@ -865,15 +865,28 @@ + (void)export:(AVAsset *)asset range:(CMTimeRange)range type:(ZLExportVideoType

+ (NSString *)getVideoExportFilePath:(ZLExportVideoType)type
{
NSTimeInterval interval = [[[NSDate alloc] init] timeIntervalSince1970];
NSString *format = (type == ZLExportVideoTypeMov ? @"mov" : @"mp4");

NSString *format = type == ZLExportVideoTypeMov ? @"mov" : type == ZLExportVideoTypeMp4 ? @"mp4" : @"3gp";

NSString *exportFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%f.%@", interval, format]];
NSString *exportFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [self getUniqueStrByUUID], format]];

return exportFilePath;
}

+ (NSString *)getUniqueStrByUUID
{
CFUUIDRef uuidObj = CFUUIDCreate(nil);//create a new UUID

//get the string representation of the UUID
CFStringRef uuidString = CFUUIDCreateString(nil, uuidObj);

NSString *str = [NSString stringWithString:(__bridge NSString *)uuidString];

CFRelease(uuidObj);
CFRelease(uuidString);

return [str lowercaseString];
}

#pragma mark - 权限相关
+ (BOOL)havePhotoLibraryAuthority
{
Expand Down
Binary file modified PhotoBrowser/resource/ZLPhotoBrowser.bundle/btn_selected.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PhotoBrowser/resource/ZLPhotoBrowser.bundle/[email protected]
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PhotoBrowser/resource/ZLPhotoBrowser.bundle/[email protected]
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
### 更新日志
```
● 2.5.5: 视频导出方法中添加压缩设置参数; 支持app名字国际化的获取; fix #157;
● 2.5.5: 视频导出方法中添加压缩设置参数; 支持app名字国际化的获取; 删除视频导出3gp格式; fix #157;
● 2.5.4: 新增视频导出功能; 新增获取图片路径api; 优化自定义相机,当相机消失后恢复其他音乐软件的播放;
● 2.5.3: 拍摄视频及编辑视频支持多种格式(mov, mp4, 3gp); 新增相册名字等多语言,以完善手动设置语言时相册名字跟随系统的问题; 简化相册调用,configuration 由必传参数修改为非必传参数;
● 2.5.2: 提取相册配置参数独立为'ZLPhotoConfiguration'对象; 新增状态栏样式api; 优化部分代码;
Expand Down
2 changes: 1 addition & 1 deletion ZLPhotoBrowser/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.5.4</string>
<string>2.5.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

1 comment on commit 7325169

@chuankelpf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我用的你的框架,现在有些问题想请教下 主要是短视频 和 视频保存出问题 方便的话加下我的好友吧 1054266852

Please sign in to comment.