import import import import
argparse ctypes io os
import vapoursynth as vs from PIL import Image, ImageFont, ImageDraw, ImageColor # Configuration # Full path to the ffms2 library PATH_TO_FFMS2_DLL = r'C:\ffms2-2.19\x64\[Link]' # Below affects the OSD TEXT_COLOR = [Link]('yellow') FONT_SIZE = 18 OSD = '''Frame Number: {0} of {1} Picture Type: {2}'''
def main(source, frames=[], additional_text=[]): """Take some screenshots using vapoursynth Arguments: frames -- list of frame numbers additional_text -- self explanatory """ core = vs.get_core() [Link](path=PATH_TO_FFMS2_DLL) if not [Link](source + '.ffindex'): print('Indexing {0}'.format([Link](source))) print('This may take some time.') clip = [Link](source=source) # REQUIRES LIBASS # would be a good alternative to using PIL to draw text # clip = [Link](clip, 'ASSVAPOUR') clip = [Link](clip=clip, format=vs.RGB24) print(clip) for frame_num in frames: if frame_num >= clip.num_frames: print('ERROR:', frame_num, 'is out of bounds. Skipping.\n') continue frame = clip.get_frame(frame_num) print('Processing frame', frame_num) R = frame.get_read_ptr(0) G = frame.get_read_ptr(1) B = frame.get_read_ptr(2) r_data = ctypes.string_at([Link], [Link]*[Link]) g_data = ctypes.string_at([Link], [Link]*[Link]) b_data = ctypes.string_at([Link], [Link]*[Link]) # TODO: Make this suck less data = bytearray([Link] * [Link] * 3) for i in range([Link] * [Link]): data[i*3] = r_data[i] data[i*3+1] = g_data[i] data[i*3+2] = b_data[i]
data = [Link](data) data = [Link]() image = [Link]('RGB', ([Link], [Link]), data) font = [Link]('[Link]', FONT_SIZE) draw = [Link](image) x_offset = 8 draw_text(draw, x_offset, 0, [Link](frame_num, clip.num_frames, [Link]._PictType.decode()), font, TEXT_COLOR, 'black') for line, text in enumerate(additional_text): draw_text(draw, x_offset, FONT_SIZE + FONT_SIZE*line + 3*line, text, font, TEXT_COLOR, 'black') output = [Link](source) output = [Link](output)[0] + '-{0}'.format(frame_num) + '.png' [Link](output) def draw_text(draw, x, y, text, font, fill, border): # thin border [Link]((x-1, y), text, border, font) [Link]((x+1, y), text, border, font) [Link]((x, y-1), text, border, font) [Link]((x, y+1), text, border, font) # thicker border [Link]((x-1, y-1), text, border, font) [Link]((x+1, y-1), text, border, font) [Link]((x-1, y+1), text, border, font) [Link]((x+1, y+1), text, border, font) # inner text [Link]((x,y), text, fill, font) if __name__ == '__main__': DESCRIPTION = """Take screenshots using vapoursynth""" parser = [Link](description=DESCRIPTION) parser.add_argument('-i', '--input', dest='input', required=True, help='video file from which to take screenshots') parser.add_argument('-f', '--frames', dest='frames', required=True, default='', help='comma separated list of frame numbers') parser.add_argument('--text', dest='text', required=False, default="", help='Additional text to be written after the OSD, separate lines with \\n') args = parser.parse_args() source frames frames text = = [Link] = [Link](',') = [ int(frame) for frame in frames ] [Link]('\\n')
main(source, frames, text)