Skip to content

Commit c8f1342

Browse files
committed
Initial commit with the implementation of AVAssetImageGenerator
1 parent e5a6bf6 commit c8f1342

File tree

19 files changed

+1149
-22
lines changed

19 files changed

+1149
-22
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ DerivedData
2323
.bundle
2424

2525
# Add this line if you want to avoid checking in source code from Carthage dependencies.
26-
# Carthage/Checkouts
27-
28-
Carthage/Build
26+
Carthage/
2927

3028
# We recommend against adding the Pods directory to your .gitignore. However
3129
# you should judge for yourself, the pros and cons are mentioned at:
@@ -34,4 +32,4 @@ Carthage/Build
3432
# Note: if you ignore the Pods directory, make sure to uncomment
3533
# `pod install` in .travis.yml
3634
#
37-
# Pods/
35+
Pods/

Cartfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github "SDWebImage/SDWebImage" ~> 5.3

Cartfile.resolved

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github "SDWebImage/SDWebImage" "5.3.1"

Example/Podfile.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PODS:
2+
- SDWebImage (5.3.1):
3+
- SDWebImage/Core (= 5.3.1)
4+
- SDWebImage/Core (5.3.1)
5+
- SDWebImageVideoCoder (0.1.0):
6+
- SDWebImage (~> 5.3)
7+
8+
DEPENDENCIES:
9+
- SDWebImageVideoCoder (from `../`)
10+
11+
SPEC REPOS:
12+
trunk:
13+
- SDWebImage
14+
15+
EXTERNAL SOURCES:
16+
SDWebImageVideoCoder:
17+
:path: "../"
18+
19+
SPEC CHECKSUMS:
20+
SDWebImage: 7137d57385fb632129838c1e6ab9528a22c666cc
21+
SDWebImageVideoCoder: e60bfc97d644f6fafe3f16c3eafc4c626d55e962
22+
23+
PODFILE CHECKSUM: f74263dcdd6f9f9df152726d6934aca467cf2b39
24+
25+
COCOAPODS: 1.8.4

Example/SDWebImageVideoCoder.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,12 @@
346346
);
347347
inputPaths = (
348348
"${PODS_ROOT}/Target Support Files/Pods-SDWebImageVideoCoder_Example/Pods-SDWebImageVideoCoder_Example-frameworks.sh",
349+
"${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework",
349350
"${BUILT_PRODUCTS_DIR}/SDWebImageVideoCoder/SDWebImageVideoCoder.framework",
350351
);
351352
name = "[CP] Embed Pods Frameworks";
352353
outputPaths = (
354+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework",
353355
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageVideoCoder.framework",
354356
);
355357
runOnlyForDeploymentPostprocessing = 0;

Example/SDWebImageVideoCoder.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SDWebImageVideoCoder/SDViewController.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,40 @@
77
//
88

99
#import "SDViewController.h"
10+
#import <SDWebImage/SDWebImage.h>
11+
#import <SDWebImageVideoCoder/SDWebImageVideoCoder.h>
1012

1113
@interface SDViewController ()
1214

15+
@property (nonatomic, strong) SDAnimatedImageView *imageView;
16+
1317
@end
1418

1519
@implementation SDViewController
1620

1721
- (void)viewDidLoad
1822
{
1923
[super viewDidLoad];
20-
// Do any additional setup after loading the view, typically from a nib.
24+
[SDImageCodersManager.sharedManager addCoder:SDImageVideoCoder.sharedCoder];
25+
26+
self.imageView = [SDAnimatedImageView new];
27+
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
28+
[self.view addSubview:self.imageView];
29+
30+
NSURL *gifvURL = [NSURL URLWithString:@"https://i.imgur.com/FY1AbSo.mp4"];
31+
32+
[self.imageView sd_setImageWithURL:gifvURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
33+
if (image) {
34+
NSLog(@"GIFV load success");
35+
} else {
36+
NSLog(@"Error: %@", error);
37+
}
38+
}];
39+
}
40+
41+
- (void)viewDidLayoutSubviews {
42+
[super viewDidLayoutSubviews];
43+
self.imageView.frame = self.view.bounds;
2144
}
2245

2346
- (void)didReceiveMemoryWarning

Example/Screenshot/MP4Demo.png

2.35 MB
Loading

README.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55
[![License](https://img.shields.io/cocoapods/l/SDWebImageVideoCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageVideoCoder)
66
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageVideoCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageVideoCoder)
77

8-
## Example
8+
## What's for
99

10-
To run the example project, clone the repo, and run `pod install` from the Example directory first.
10+
This is just a toy coder plugin for [SDWebImage](https://github.com/SDWebImage). Which aim to provide a demo usage that how SDWeImage combined the Animated Image View and Player and let it works for generic usage and customization.
11+
12+
**Important**: This project is just a toy, which means, it does not provide any production ready features, and the performances is really slow.
13+
14+
For real world rendering for small video files (like [Imgur's GIFV format](https://help.imgur.com/hc/en-us/articles/208606616-What-is-GIFV-)). You should always prefers to use the video player and rendering components, like AVKit's [AVPlayerViewController](https://developer.apple.com/documentation/avkit/avplayerviewcontroller) .
15+
16+
This coder plugin, provide the animation loading support for video format, including:
17+
18+
+ MP4 (MPEG/4)
19+
+ MOV (QuickTime Movie)
20+
+ AVI (Audio Video Interleave)
1121

1222
## Requirements
1323

24+
+ iOS 8+
25+
+ macOS 10.10+
26+
+ tvOS 9+
27+
1428
## Installation
1529

1630
SDWebImageVideoCoder is available through [CocoaPods](https://cocoapods.org). To install
@@ -20,9 +34,78 @@ it, simply add the following line to your Podfile:
2034
pod 'SDWebImageVideoCoder'
2135
```
2236

37+
## Usage
38+
39+
### Load Video URL
40+
41+
For coder plugin usage, see [Wiki - Coder Usage](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#coder-usage)
42+
43+
+ Objective-C
44+
45+
```objective-c
46+
SDAnimatedImageView *imageView;
47+
NSURL *videoURL = [NSURL URLWithString:@"https://i.imgur.com/FY1AbSo.mp4"];
48+
[imageView sd_setImageWithURL:videoURL];
49+
```
50+
51+
+ Swift
52+
53+
```swift
54+
let imageView: SDAnimatedImageView
55+
let url = URL(string: "https://i.imgur.com/FY1AbSo.mp4")
56+
imageView.sd_setImage(url: url)
57+
```
58+
59+
### AVAsset player usage
60+
61+
For player usage, see [Wiki - Animated Image Player](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-player-530)
62+
63+
+ Objective-C
64+
65+
```objective-c
66+
// AVAsset
67+
AVAsset *asset;
68+
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
69+
generator.appliesPreferredTrackTransform = YES;
70+
generator.requestedTimeToleranceBefore = kCMTimeZero;
71+
generator.requestedTimeToleranceAfter = kCMTimeZero;
72+
// Player
73+
SDAnimatedImagePlayer *player = [SDAnimatedImagePlayer playerWithProvider:generator];
74+
player.animationFrameHandler = ^(NSUInteger index, UIImage * frame) {
75+
// frames
76+
};
77+
[player seekToFrameAtIndex:5 loopCount:0];
78+
[player play];
79+
```
80+
81+
+ Swift
82+
83+
```swift
84+
let asset: AVAsset
85+
let generator = AVAssetImageGenerator(asset: asset)
86+
generator.appliesPreferredTrackTransform = true
87+
generator.requestedTimeToleranceBefore = .zero
88+
generator.requestedTimeToleranceAfter = .zero
89+
// Player
90+
let player = SDAnimatedImagePlayer(provider: generator)
91+
player.animationFrameHandler = { (index, frame) in
92+
// frames
93+
}
94+
player.seekToFrame(at: 5, loopCount: 0)
95+
player.play()
96+
```
97+
98+
## Example
99+
100+
To run the example project, clone the repo, and run `pod install` from the Example directory first.
101+
102+
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageVideoCoder/master/Example/Screenshot/MP4Demo.png" width="600" />
103+
104+
These MP4 video is from [Imgur](https://imgur.com/).
105+
23106
## Author
24107

25-
lizhuoli1126@126.com, lizhuoli1126@126.com
108+
DreamPiggy, lizhuoli1126@126.com
26109

27110
## License
28111

SDWebImageVideoCoder.podspec

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,15 @@ Pod::Spec.new do |s|
2121
TODO: Add long description of the pod here.
2222
DESC
2323

24-
s.homepage = 'https://github.com/lizhuoli1126@126.com/SDWebImageVideoCoder'
25-
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
24+
s.homepage = 'https://github.com/SDWebImage/SDWebImageVideoCoder'
2625
s.license = { :type => 'MIT', :file => 'LICENSE' }
27-
s.author = { 'lizhuoli1126@126.com' => 'lizhuoli1126@126.com' }
28-
s.source = { :git => 'https://github.com/lizhuoli1126@126.com/SDWebImageVideoCoder.git', :tag => s.version.to_s }
29-
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
26+
s.author = { 'DreamPiggy' => 'lizhuoli1126@126.com' }
27+
s.source = { :git => 'https://github.com/SDWebImage/SDWebImageVideoCoder.git', :tag => s.version.to_s }
3028

3129
s.ios.deployment_target = '8.0'
30+
s.osx.deployment_target = '10.10'
31+
s.tvos.deployment_target = '9.0'
3232

33-
s.source_files = 'SDWebImageVideoCoder/Classes/**/*'
34-
35-
# s.resource_bundles = {
36-
# 'SDWebImageVideoCoder' => ['SDWebImageVideoCoder/Assets/*.png']
37-
# }
38-
39-
# s.public_header_files = 'Pod/Classes/**/*.h'
40-
# s.frameworks = 'UIKit', 'MapKit'
41-
# s.dependency 'AFNetworking', '~> 2.3'
33+
s.source_files = 'SDWebImageVideoCoder/Classes/**/*', 'SDWebImageVideoCoder/Module/SDWebImageVideoCoder.h'
34+
s.dependency 'SDWebImage', '~> 5.3'
4235
end

0 commit comments

Comments
 (0)