Ejemplo n.º 1
0
 def _processFrames(self, iterable):
     for frame in super()._processFrames(iterable):
         im = frame.to_image()
         im = im.resize((self.width, self.height), self.resample, self.box)
         newframe = VideoFrame.from_image(im)
         newframe.time_base = frame.time_base
         newframe.pts = frame.pts
         newframe.pict_type = frame.pict_type
         yield newframe
Ejemplo n.º 2
0
    def processFrames(self, frames, prev_start):
        def torgb(frame):
            return (frame.to_rgb() if frame.format.name != "rgb24" else frame)

        def totuple(frame):
            return (frame.to_ndarray(), frame.format.name,
                    frame.pict_type.name, frame.pts, frame.time_base)

        rgb = map(torgb, frames)
        tuples = map(totuple, rgb)

        for (A, fmt, pict_type, pts, time_base) in map(self._processOneFrame,
                                                       tuples):
            frame = VideoFrame.from_ndarray(A, fmt)
            frame.pict_type = pict_type
            frame.pts = pts
            frame.time_base = time_base
            yield frame
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
    def _pullupBlock(self, frames, frames_yuv, inv_matrix, dest_index, fields):
        framesreturned = False
        for (e, o), row, k in zip(fields, inv_matrix, dest_index):
            """Do we have the data to create this frame?"""
            if e == o:
                try:
                    if frames[e] is None:
                        raise IndexError

                except IndexError:
                    if framesreturned:
                        break

                    continue

                frame = frames[e]
                frame.time_base = self.parent.time_base

                try:
                    frame.pts = self.pts[k - self.dest_start]

                except Exception:
                    raise

                yield frame
                framesreturned = True

            else:
                try:
                    if (self.yblend or self.uvblend):
                        for j, w in enumerate(row):
                            if w != 0 and frames[j] is None:
                                raise IndexError

                    if frames[e] is None or frames[o] is None:
                        raise IndexError

                except IndexError:
                    if framesreturned:
                        break

                    continue

                eframe = frames_yuv[e]
                H, W = eframe.shape
                H = H * 2 / 3
                H = int(H)
                W = int(W)
                oframe = frames_yuv[o]

                if self.yblend:
                    Y = numpy.sum([
                        w * frame[:H]
                        for (w, frame) in zip(row, frames_yuv) if w != 0
                    ],
                                  axis=0)
                    Y = numpy.uint8(Y.clip(min=0, max=255) + 0.5)

                else:
                    Ye = eframe[:H:2]
                    Yo = oframe[1:H:2]
                    Y = numpy.moveaxis([Ye, Yo], 0, 1).reshape(H, W)

                if self.uvblend:
                    UV = numpy.sum([
                        w * frame[H:]
                        for (w, frame) in zip(row, frames_yuv) if w != 0
                    ],
                                   axis=0)
                    UV = numpy.uint8(UV.clip(min=0, max=255) + 0.5)

                else:
                    Ue = eframe[H:5 * H // 4, :W // 2]
                    Uo = oframe[H:5 * H // 4, W // 2:]
                    U = numpy.concatenate([Ue, Uo], axis=1)
                    Ve = eframe[5 * H // 4:, :W // 2]
                    Vo = oframe[5 * H // 4:, W // 2:]
                    V = numpy.concatenate([Ve, Vo], axis=1)
                    UV = numpy.concatenate([U, V], axis=0)

                YUV = numpy.concatenate((Y, UV), axis=0)
                frame = VideoFrame.from_ndarray(YUV, format="yuv420p")

                frame.time_base = self.parent.time_base
                frame.pts = self.pts[k - self.dest_start]

                yield frame
                framesreturned = True