22
22
}
23
23
'''
24
24
from objc_util import *
25
- import ui ,time
26
- file = os .path .expanduser ('~/Documents/capturedvideo.MOV' )
27
- if not os .path .exists (file ):
28
- raise IOError
29
- asset = ObjCClass ('AVURLAsset' ).alloc ().initWithURL_options_ (nsurl (file ),None )
30
- generator = ObjCClass ('AVAssetImageGenerator' ).alloc ().initWithAsset_ (asset )
25
+ import ui ,time ,os ,photos
31
26
27
+ assets = photos .get_assets (media_type = 'video' )
28
+ #print(len(assets))
29
+ asset = photos .pick_asset (assets )
30
+ duration = asset .duration
31
+ #asset.get_image().show()
32
+ print (asset .duration )
33
+ print (asset .local_id )
32
34
33
- from ctypes import c_int32 ,c_uint32 , c_int64 ,byref ,POINTER ,c_void_p ,pointer ,addressof
35
+ #file=os.path.expanduser('~/Documents/capturedvideo.MOV')
36
+ #with open(file,'wb') as f:
37
+ # f.write(asset.get_image_data().getvalue())
38
+ #if not os.path.exists(file):
39
+ # raise IOError
40
+ phasset = ObjCInstance (asset )
41
+ asseturl = 'assets-library://asset/asset.MOV?id={}&ext=MOV' .format (str (phasset .localIdentifier ()).split ('/' )[0 ])
42
+ asseturl = ObjCClass ('AVURLAsset' ).alloc ().initWithURL_options_ (nsurl (asseturl ),None )
43
+ generator = ObjCClass ('AVAssetImageGenerator' ).alloc ().initWithAsset_ (asseturl )
44
+
45
+
46
+ from ctypes import c_int32 ,c_uint32 , c_int64 ,byref ,POINTER ,c_void_p ,pointer ,addressof , c_double
34
47
35
48
CMTimeValue = c_int64
36
49
CMTimeScale = c_int32
@@ -46,6 +59,8 @@ def __init__(self,value=0,timescale=1,flags=0,epoch=0):
46
59
self .timescale = timescale
47
60
self .flags = flags
48
61
self .epoch = epoch
62
+ c .CMTimeGetSeconds .argtypes = [CMTime ]
63
+ c .CMTimeGetSeconds .restype = c_double
49
64
z = CMTime (0 ,24 )
50
65
51
66
generator .setRequestedTimeToleranceAfter_ (z ,restype = None ,argtypes = [CMTime ])
@@ -63,7 +78,9 @@ def __init__(self,value=0,timescale=1,flags=0,epoch=0):
63
78
lastimage = None # in case we need to be careful with references
64
79
tactual = CMTime (0 ,1 ) #return value
65
80
t = CMTime (0 ,1 ) # timescale is the important bit
66
- for i in range (0 ,10 ):
81
+
82
+
83
+ for i in range (0 ,int (duration )):
67
84
t .value = i
68
85
cgimage_obj = generator .copyCGImageAtTime_actualTime_error_ (t ,byref (tactual ),None ,restype = c_void_p ,argtypes = [CMTime ,POINTER (CMTime ),POINTER (c_void_p )])
69
86
@@ -81,4 +98,4 @@ def setimage():
81
98
82
99
83
100
84
-
101
+
0 commit comments