Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dz_TZImagePickerController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shuijing
dz_TZImagePickerController
Commits
1ab7b5a8
Commit
1ab7b5a8
authored
Nov 15, 2017
by
yuzheng.tz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化视频导出方法,可以设置presetName
parent
88b5f37f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
+17
-7
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+2
-1
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+14
-5
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+1
-1
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
1ab7b5a8
...
...
@@ -80,8 +80,9 @@
-
(
void
)
getVideoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getVideoWithAsset
:(
id
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:(
void
(
^
)(
AVPlayerItem
*
,
NSDictionary
*
))
completion
;
/// Export video 导出视频
/// Export video 导出视频
presetName: 预设名字,默认值是AVAssetExportPreset640x480
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
presetName
:(
NSString
*
)
presetName
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
__attribute__
((
deprecated
(
"Use -getVideoOutputPathWithAsset:failure:success:"
)));
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
1ab7b5a8
...
...
@@ -715,6 +715,10 @@ static dispatch_once_t onceToken;
/// Export Video / 导出视频
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
{
[
self
getVideoOutputPathWithAsset
:
asset
presetName
:
AVAssetExportPreset640x480
success
:
success
failure
:
failure
];
}
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
presetName
:(
NSString
*
)
presetName
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHVideoRequestOptions
*
options
=
[[
PHVideoRequestOptions
alloc
]
init
];
options
.
version
=
PHVideoRequestOptionsVersionOriginal
;
...
...
@@ -724,12 +728,12 @@ static dispatch_once_t onceToken;
// NSLog(@"Info:\n%@",info);
AVURLAsset
*
videoAsset
=
(
AVURLAsset
*
)
avasset
;
// NSLog(@"AVAsset URL: %@",myAsset.URL);
[
self
startExportVideoWithVideoAsset
:
videoAsset
success
:
success
failure
:
failure
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
presetName
:
presetName
success
:
success
failure
:
failure
];
}];
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
NSURL
*
videoURL
=
[
asset
valueForProperty
:
ALAssetPropertyAssetURL
];
// ALAssetPropertyURLs
AVURLAsset
*
videoAsset
=
[[
AVURLAsset
alloc
]
initWithURL
:
videoURL
options
:
nil
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
success
:
success
failure
:
failure
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
presetName
:
presetName
success
:
success
failure
:
failure
];
}
}
...
...
@@ -738,7 +742,7 @@ static dispatch_once_t onceToken;
[
self
getVideoOutputPathWithAsset
:
asset
success
:
completion
failure
:
nil
];
}
-
(
void
)
startExportVideoWithVideoAsset
:(
AVURLAsset
*
)
videoAsset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
{
-
(
void
)
startExportVideoWithVideoAsset
:(
AVURLAsset
*
)
videoAsset
presetName
:(
NSString
*
)
presetName
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
{
// Find compatible presets by video asset.
NSArray
*
presets
=
[
AVAssetExportSession
exportPresetsCompatibleWithAsset
:
videoAsset
];
...
...
@@ -746,8 +750,8 @@ static dispatch_once_t onceToken;
// Now we just compress to low resolution if it supports
// If you need to upload to the server, but server does't support to upload by streaming,
// You can compress the resolution to lower. Or you can support more higher resolution.
if
([
presets
containsObject
:
AVAssetExportPreset640x480
])
{
AVAssetExportSession
*
session
=
[[
AVAssetExportSession
alloc
]
initWithAsset
:
videoAsset
presetName
:
AVAssetExportPreset640x480
];
if
([
presets
containsObject
:
presetName
])
{
AVAssetExportSession
*
session
=
[[
AVAssetExportSession
alloc
]
initWithAsset
:
videoAsset
presetName
:
presetName
];
NSDateFormatter
*
formater
=
[[
NSDateFormatter
alloc
]
init
];
[
formater
setDateFormat
:
@"yyyy-MM-dd-HH:mm:ss-SSS"
];
...
...
@@ -816,6 +820,11 @@ static dispatch_once_t onceToken;
}
});
}];
}
else
{
if
(
failure
)
{
NSString
*
errorMessage
=
[
NSString
stringWithFormat
:
@"当前设备不支持该预设:%@"
,
presetName
];
failure
(
errorMessage
,
nil
);
}
}
}
...
...
TZImagePickerController/ViewController.m
View file @
1ab7b5a8
...
...
@@ -496,7 +496,7 @@
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:@[
coverImage
]];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:@[
asset
]];
// open this code to send video / 打开这段代码发送视频
[[
TZImageManager
manager
]
getVideoOutputPathWithAsset
:
asset
success
:
^
(
NSString
*
outputPath
)
{
[[
TZImageManager
manager
]
getVideoOutputPathWithAsset
:
asset
presetName
:
AVAssetExportPreset640x480
success
:^
(
NSString
*
outputPath
)
{
NSLog
(
@"视频导出到本地完成,沙盒路径为:%@"
,
outputPath
);
// Export completed, send video here, send by outputPath or NSData
// 导出完成,在这里写上传代码,通过路径或者通过NSData上传
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment