forked from egao1980/PyAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcctx_encode.py
More file actions
50 lines (32 loc) · 950 Bytes
/
Copy pathcctx_encode.py
File metadata and controls
50 lines (32 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import print_function
import logging
from PIL import Image, ImageFont, ImageDraw
logging.basicConfig()
import av
from av.codec import CodecContext
from av.video import VideoFrame
from tests.common import fate_suite
cc = CodecContext.create('flv', 'w')
print(cc)
base_img = Image.open(fate_suite('png1/lena-rgb24.png'))
font = ImageFont.truetype("/System/Library/Fonts/Menlo.ttc", 15)
fh = open('test.flv', 'w')
for i in range(30):
print(i)
img = base_img.copy()
draw = ImageDraw.Draw(img)
draw.text((10, 10), "FRAME %02d" % i, font=font)
frame = VideoFrame.from_image(img)
frame = frame.reformat(format='yuv420p')
print(' ', frame)
packet = cc.encode(frame)
print(' ', packet)
fh.write(str(buffer(packet)))
print('Flushing...')
while True:
packet = cc.encode()
if not packet:
break
print(' ', packet)
fh.write(str(buffer(packet)))
print('Done!')