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
8c18b56d
Commit
8c18b56d
authored
Oct 18, 2016
by
banchichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正导出视频的转向信息
parent
7d3ba46b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
5 deletions
+76
-5
TZImagePickerController/Info.plist
TZImagePickerController/Info.plist
+1
-1
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+73
-2
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
...troller/TZImagePickerController/TZImagePickerController.h
+1
-1
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+1
-1
No files found.
TZImagePickerController/Info.plist
View file @
8c18b56d
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<key>
CFBundlePackageType
</key>
<key>
CFBundlePackageType
</key>
<string>
APPL
</string>
<string>
APPL
</string>
<key>
CFBundleShortVersionString
</key>
<key>
CFBundleShortVersionString
</key>
<string>
1.6.
9
</string>
<string>
1.6.
10
</string>
<key>
CFBundleSignature
</key>
<key>
CFBundleSignature
</key>
<string>
????
</string>
<string>
????
</string>
<key>
CFBundleVersion
</key>
<key>
CFBundleVersion
</key>
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
8c18b56d
...
@@ -647,7 +647,7 @@ static CGFloat TZScreenScale;
...
@@ -647,7 +647,7 @@ static CGFloat TZScreenScale;
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
NSURL
*
videoURL
=
[
asset
valueForProperty
:
ALAssetPropertyAssetURL
];
// ALAssetPropertyURLs
NSURL
*
videoURL
=
[
asset
valueForProperty
:
ALAssetPropertyAssetURL
];
// ALAssetPropertyURLs
#pragma clang diagnostic pop
#pragma clang diagnostic pop
AVURLAsset
*
videoAsset
=
[[
AVURLAsset
alloc
]
initWithURL
:
videoURL
options
:
nil
];
AVURLAsset
*
videoAsset
=
[[
AVURLAsset
alloc
]
initWithURL
:
videoURL
options
:
nil
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
completion
:
completion
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
completion
:
completion
];
}
}
}
}
...
@@ -685,7 +685,10 @@ static CGFloat TZScreenScale;
...
@@ -685,7 +685,10 @@ static CGFloat TZScreenScale;
if
(
!
[[
NSFileManager
defaultManager
]
fileExistsAtPath
:[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp"
]])
{
if
(
!
[[
NSFileManager
defaultManager
]
fileExistsAtPath
:[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp"
]])
{
[[
NSFileManager
defaultManager
]
createDirectoryAtPath
:[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp"
]
withIntermediateDirectories
:
YES
attributes
:
nil
error
:
nil
];
[[
NSFileManager
defaultManager
]
createDirectoryAtPath
:[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp"
]
withIntermediateDirectories
:
YES
attributes
:
nil
error
:
nil
];
}
}
// 修正视频转向
session
.
videoComposition
=
[
self
fixedCompositionWithAsset
:
videoAsset
];
// Begin to export video to the output path asynchronously.
// Begin to export video to the output path asynchronously.
[
session
exportAsynchronouslyWithCompletionHandler
:
^
(
void
)
{
[
session
exportAsynchronouslyWithCompletionHandler
:
^
(
void
)
{
switch
(
session
.
status
)
{
switch
(
session
.
status
)
{
...
@@ -795,6 +798,74 @@ static CGFloat TZScreenScale;
...
@@ -795,6 +798,74 @@ static CGFloat TZScreenScale;
return
orientation
;
return
orientation
;
}
}
/// 获取优化后的视频转向信息
-
(
AVMutableVideoComposition
*
)
fixedCompositionWithAsset
:(
AVAsset
*
)
videoAsset
{
AVMutableVideoComposition
*
videoComposition
=
[
AVMutableVideoComposition
videoComposition
];
// 视频转向
int
degrees
=
[
self
degressFromVideoFileWithAsset
:
videoAsset
];
if
(
degrees
!=
0
)
{
CGAffineTransform
translateToCenter
;
CGAffineTransform
mixedTransform
;
videoComposition
.
frameDuration
=
CMTimeMake
(
1
,
30
);
NSArray
*
tracks
=
[
videoAsset
tracksWithMediaType
:
AVMediaTypeVideo
];
AVAssetTrack
*
videoTrack
=
[
tracks
objectAtIndex
:
0
];
if
(
degrees
==
90
)
{
// 顺时针旋转90°
translateToCenter
=
CGAffineTransformMakeTranslation
(
videoTrack
.
naturalSize
.
height
,
0
.
0
);
mixedTransform
=
CGAffineTransformRotate
(
translateToCenter
,
M_PI_2
);
videoComposition
.
renderSize
=
CGSizeMake
(
videoTrack
.
naturalSize
.
height
,
videoTrack
.
naturalSize
.
width
);
}
else
if
(
degrees
==
180
){
// 顺时针旋转180°
translateToCenter
=
CGAffineTransformMakeTranslation
(
videoTrack
.
naturalSize
.
width
,
videoTrack
.
naturalSize
.
height
);
mixedTransform
=
CGAffineTransformRotate
(
translateToCenter
,
M_PI
);
videoComposition
.
renderSize
=
CGSizeMake
(
videoTrack
.
naturalSize
.
width
,
videoTrack
.
naturalSize
.
height
);
}
else
if
(
degrees
==
270
){
// 顺时针旋转270°
translateToCenter
=
CGAffineTransformMakeTranslation
(
0
.
0
,
videoTrack
.
naturalSize
.
width
);
mixedTransform
=
CGAffineTransformRotate
(
translateToCenter
,
M_PI_2
*
3
.
0
);
videoComposition
.
renderSize
=
CGSizeMake
(
videoTrack
.
naturalSize
.
height
,
videoTrack
.
naturalSize
.
width
);
}
AVMutableVideoCompositionInstruction
*
roateInstruction
=
[
AVMutableVideoCompositionInstruction
videoCompositionInstruction
];
roateInstruction
.
timeRange
=
CMTimeRangeMake
(
kCMTimeZero
,
[
videoAsset
duration
]);
AVMutableVideoCompositionLayerInstruction
*
roateLayerInstruction
=
[
AVMutableVideoCompositionLayerInstruction
videoCompositionLayerInstructionWithAssetTrack
:
videoTrack
];
[
roateLayerInstruction
setTransform
:
mixedTransform
atTime
:
kCMTimeZero
];
roateInstruction
.
layerInstructions
=
@[
roateLayerInstruction
];
// 加入视频方向信息
videoComposition
.
instructions
=
@[
roateInstruction
];
}
return
videoComposition
;
}
/// 获取视频角度
-
(
int
)
degressFromVideoFileWithAsset
:(
AVAsset
*
)
asset
{
int
degress
=
0
;
NSArray
*
tracks
=
[
asset
tracksWithMediaType
:
AVMediaTypeVideo
];
if
([
tracks
count
]
>
0
)
{
AVAssetTrack
*
videoTrack
=
[
tracks
objectAtIndex
:
0
];
CGAffineTransform
t
=
videoTrack
.
preferredTransform
;
if
(
t
.
a
==
0
&&
t
.
b
==
1
.
0
&&
t
.
c
==
-
1
.
0
&&
t
.
d
==
0
){
// Portrait
degress
=
90
;
}
else
if
(
t
.
a
==
0
&&
t
.
b
==
-
1
.
0
&&
t
.
c
==
1
.
0
&&
t
.
d
==
0
){
// PortraitUpsideDown
degress
=
270
;
}
else
if
(
t
.
a
==
1
.
0
&&
t
.
b
==
0
&&
t
.
c
==
0
&&
t
.
d
==
1
.
0
){
// LandscapeRight
degress
=
0
;
}
else
if
(
t
.
a
==
-
1
.
0
&&
t
.
b
==
0
&&
t
.
c
==
0
&&
t
.
d
==
-
1
.
0
){
// LandscapeLeft
degress
=
180
;
}
}
return
degress
;
}
/// 修正图片转向
-
(
UIImage
*
)
fixOrientation
:(
UIImage
*
)
aImage
{
-
(
UIImage
*
)
fixOrientation
:(
UIImage
*
)
aImage
{
if
(
!
self
.
shouldFixOrientation
)
return
aImage
;
if
(
!
self
.
shouldFixOrientation
)
return
aImage
;
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
View file @
8c18b56d
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
//
//
// Created by 谭真 on 15/12/24.
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// Copyright © 2015年 谭真. All rights reserved.
// version 1.6.10 - 2016.10.1
7
// version 1.6.10 - 2016.10.1
8
/*
/*
经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右)
经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右)
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
8c18b56d
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
//
//
// Created by 谭真 on 15/12/24.
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// Copyright © 2015年 谭真. All rights reserved.
// version 1.6.10 - 2016.10.1
7
// version 1.6.10 - 2016.10.1
8
#import "TZImagePickerController.h"
#import "TZImagePickerController.h"
#import "TZPhotoPickerController.h"
#import "TZPhotoPickerController.h"
...
...
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