質問編集履歴
12
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -49,7 +49,9 @@
|
|
49
49
|
```Swift
|
50
50
|
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
|
51
51
|
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
|
52
|
+
if mediaType == kUTTypeMovie {
|
52
|
-
|
53
|
+
let urlM: NSURL = info[UIImagePickerControllerMediaURL] as! NSURL
|
54
|
+
}
|
53
55
|
|
54
56
|
let filePath = NSTemporaryDirectory().stringByAppendingString(filename)
|
55
57
|
let filename = "testVideo.mp4"
|
11
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -52,7 +52,7 @@
|
|
52
52
|
let urlM: NSURL = info[UIImagePickerControllerMediaURL] as! NSURL
|
53
53
|
|
54
54
|
let filePath = NSTemporaryDirectory().stringByAppendingString(filename)
|
55
|
-
let filename =
|
55
|
+
let filename = "testVideo.mp4"
|
56
56
|
let outputURL = NSURL(fileURLWithPath: filePath)
|
57
57
|
|
58
58
|
let avAsset = AVURLAsset(URL: myUrl, options: nil)
|
10
誤字
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
9
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -42,4 +42,44 @@
|
|
42
42
|
|
43
43
|
実行してもエラーはでないものの、ローカルにも保存されていません。
|
44
44
|
outputURLで管理場所を指定しているにもかかわらずその場所に~.mp4が入らない原因はなぜでしょうか。
|
45
|
-
どなたか教えていただけると助かります。
|
45
|
+
どなたか教えていただけると助かります。
|
46
|
+
|
47
|
+
下記のコードがimagePickerController内で上記の内容を行ったものになります。
|
48
|
+
|
49
|
+
```Swift
|
50
|
+
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
|
51
|
+
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
|
52
|
+
let urlM: NSURL = info[UIImagePickerControllerMediaURL] as! NSURL
|
53
|
+
|
54
|
+
let filePath = NSTemporaryDirectory().stringByAppendingString(filename)
|
55
|
+
let filename = “testVideo.mp4"
|
56
|
+
let outputURL = NSURL(fileURLWithPath: filePath)
|
57
|
+
|
58
|
+
let avAsset = AVURLAsset(URL: myUrl, options: nil)
|
59
|
+
let exportSession = AVAssetExportSession(asset: avAsset, presetName: AVAssetExportPresetPassthrough)
|
60
|
+
|
61
|
+
exportSession!.outputFileType = AVFileTypeMPEG4
|
62
|
+
exportSession!.outputURL = outputURL
|
63
|
+
|
64
|
+
exportSession!.exportAsynchronouslyWithCompletionHandler { () -> Void in
|
65
|
+
do {
|
66
|
+
try NSFileManager.defaultManager().removeItemAtPath(filePath)
|
67
|
+
switch exportSession!.status {
|
68
|
+
case AVAssetExportSessionStatus.Completed:
|
69
|
+
PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(fileURLWithPath: urlR)) // エラー
|
70
|
+
break
|
71
|
+
case AVAssetExportSessionStatus.Failed:
|
72
|
+
print("failed \(exportSession?.error)")
|
73
|
+
break
|
74
|
+
case AVAssetExportSessionStatus.Cancelled:
|
75
|
+
print("cancelled \(exportSession?.error)")
|
76
|
+
break
|
77
|
+
default:
|
78
|
+
break
|
79
|
+
}
|
80
|
+
} catch {
|
81
|
+
print("Error")
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
```
|
8
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,8 +26,10 @@
|
|
26
26
|
PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(fileURLWithPath: self.moviePath))
|
27
27
|
break
|
28
28
|
case AVAssetExportSessionStatus.Failed:
|
29
|
+
print("failed \(exportSession?.error)")
|
29
30
|
break
|
30
31
|
case AVAssetExportSessionStatus.Cancelled:
|
32
|
+
print("cancelled \(exportSession?.error)")
|
31
33
|
break
|
32
34
|
default:
|
33
35
|
break
|
7
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
// mp4変換
|
9
9
|
let filename = "testVideo.mp4"
|
10
10
|
|
11
|
-
let
|
11
|
+
let filePath = NSTemporaryDirectory().stringByAppendingString(filename)
|
12
|
-
let outputURL = NSURL(fileURLWithPath:
|
12
|
+
let outputURL = NSURL(fileURLWithPath: filePath)
|
13
13
|
|
14
14
|
let myUrl: NSURL = NSURL(string: moviePath)!
|
15
15
|
let avAsset = AVURLAsset(URL: myUrl, options: nil)
|
6
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,7 +24,6 @@
|
|
24
24
|
switch exportSession!.status {
|
25
25
|
case AVAssetExportSessionStatus.Completed:
|
26
26
|
PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(fileURLWithPath: self.moviePath))
|
27
|
-
print(self.moviePath)
|
28
27
|
break
|
29
28
|
case AVAssetExportSessionStatus.Failed:
|
30
29
|
break
|
5
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,7 +23,6 @@
|
|
23
23
|
try NSFileManager.defaultManager().removeItemAtPath(filePath)
|
24
24
|
switch exportSession!.status {
|
25
25
|
case AVAssetExportSessionStatus.Completed:
|
26
|
-
//let phphotoLib = PHPhotoLibrary()
|
27
26
|
PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(fileURLWithPath: self.moviePath))
|
28
27
|
print(self.moviePath)
|
29
28
|
break
|
4
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,6 +17,27 @@
|
|
17
17
|
|
18
18
|
exportSession!.outputFileType = AVFileTypeMPEG4 // ファイルタイプの指定
|
19
19
|
exportSession!.outputURL = outputURL // 保管場所を指定
|
20
|
+
|
21
|
+
exportSession!.exportAsynchronouslyWithCompletionHandler { () -> Void in
|
22
|
+
do {
|
23
|
+
try NSFileManager.defaultManager().removeItemAtPath(filePath)
|
24
|
+
switch exportSession!.status {
|
25
|
+
case AVAssetExportSessionStatus.Completed:
|
26
|
+
//let phphotoLib = PHPhotoLibrary()
|
27
|
+
PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(fileURLWithPath: self.moviePath))
|
28
|
+
print(self.moviePath)
|
29
|
+
break
|
30
|
+
case AVAssetExportSessionStatus.Failed:
|
31
|
+
break
|
32
|
+
case AVAssetExportSessionStatus.Cancelled:
|
33
|
+
break
|
34
|
+
default:
|
35
|
+
break
|
36
|
+
}
|
37
|
+
} catch {
|
38
|
+
print("Error")
|
39
|
+
}
|
40
|
+
}
|
20
41
|
```
|
21
42
|
|
22
43
|
実行してもエラーはでないものの、ローカルにも保存されていません。
|
3
質問内容の訂正
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
2
質問の仕方の訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
Swiftでカメラロールにある動画を取り出した(~.movの)ものをmp4に変換したいと思い調べていると、
|
2
|
-
下記の記事を見つけて実装してみましたが記載されている内容を理解できずにコードを書いてしまっており、
|
3
|
-
|
2
|
+
下記の記事を見つけて実装してみましたが変換がうまくいかなかったので質問させていただきました。
|
4
3
|
[Swift で録画したビデオ(mov)を MP4 に変換する](http://qiita.com/takecian/items/2083a61f07167a67e792)
|
5
4
|
|
6
5
|
コード内の moviePath はString型で既にカメラロールから選択した動画のパスが入っている状態です。
|
@@ -21,5 +20,5 @@
|
|
21
20
|
```
|
22
21
|
|
23
22
|
実行してもエラーはでないものの、ローカルにも保存されていません。
|
24
|
-
|
23
|
+
outputURLで管理場所を指定しているにもかかわらずその場所に~.mp4が入らない原因はなぜでしょうか。
|
25
24
|
どなたか教えていただけると助かります。
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,6 +20,6 @@
|
|
20
20
|
exportSession!.outputURL = outputURL // 保管場所を指定
|
21
21
|
```
|
22
22
|
|
23
|
-
実行してもエラーはでないもの、ローカルにも保存されていません。
|
23
|
+
実行してもエラーはでないものの、ローカルにも保存されていません。
|
24
24
|
どんな記述が足りないのか、またこの方法であっているのかどうかわかりません。
|
25
25
|
どなたか教えていただけると助かります。
|