Skip to content

Commit a7a3bd5

Browse files
author
jon b
committed
update getframe
1 parent 0793ce3 commit a7a3bd5

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

getframes.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,28 @@
2222
}
2323
'''
2424
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
3126

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)
3234

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
3447

3548
CMTimeValue=c_int64
3649
CMTimeScale=c_int32
@@ -46,6 +59,8 @@ def __init__(self,value=0,timescale=1,flags=0,epoch=0):
4659
self.timescale=timescale
4760
self.flags=flags
4861
self.epoch=epoch
62+
c.CMTimeGetSeconds.argtypes=[CMTime]
63+
c.CMTimeGetSeconds.restype=c_double
4964
z=CMTime(0,24)
5065

5166
generator.setRequestedTimeToleranceAfter_(z,restype=None,argtypes=[CMTime])
@@ -63,7 +78,9 @@ def __init__(self,value=0,timescale=1,flags=0,epoch=0):
6378
lastimage=None # in case we need to be careful with references
6479
tactual=CMTime(0,1) #return value
6580
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)):
6784
t.value=i
6885
cgimage_obj=generator.copyCGImageAtTime_actualTime_error_(t,byref(tactual),None,restype=c_void_p,argtypes=[CMTime,POINTER(CMTime),POINTER(c_void_p)])
6986

@@ -81,4 +98,4 @@ def setimage():
8198

8299

83100

84-
101+

0 commit comments

Comments
 (0)