コード例 #1
0
def main(flags):
    vid_uri = flags.pango
    vout_uri = flags.pangoOut

    vid = pango.VideoInput(vid_uri)
    vout = pango.VideoOutput(vout_uri) if vout_uri else None

    device_properties = vid.DeviceProperties()

    # print metadata
    print("Opened video uri: '{}' with {} x {} dimensions".format(
        vid_uri, vid.Width(), vid.Height()))

    # user specified initial frame
    vid.Seek(flags.startFrame)

    # show each frame
    streamsBitDepth = vid.GetStreamsBitDepth()

    for frame in vid:
        if vout:
            vout.WriteStreams(frame, streamsBitDepth, vid.FrameProperties(),
                              device_properties)

        # frame is a list of Images! One per stream
        # process(frame)

        # printing
        sys.stdout.write('\rframe: {} / {}'.format(vid.GetCurrentFrameId(),
                                                   vid.GetTotalFrames()))

    print('\nDONE')
コード例 #2
0
def main(flags):
    vid_uri = flags.pango
    vout_uri = flags.pangoOut
    stream = flags.stream
    if vout_uri is None:
        vout_uri = "pango://out.pango"

    vid = pango.VideoInput(vid_uri)
    print(vid.GetCurrentFrameId())
    vout = pango.VideoOutput(vout_uri)

    # print metadata
    print("Opened video uri: '{}' with {} x {} dimensions".format(
        vid_uri, vid.Width(), vid.Height()))
    fmt = vid.PixFormat()
    print("format: channels: {}, channel_bits: {}, planar: {}".format(
        fmt.channels, fmt.bpp, fmt.planar))

    # user specified initial frame
    vid.Seek(flags.startFrame)
    if flags.endFrame is None:
        flags.endFrame = vid.GetTotalFrames()

    # initialize display
    numStreams = vid.GetNumStreams()
    streams = [stream] if stream else list(range(numStreams))
    assert streams[
        -1] < numStreams, 'specified stream {} is out of bnd'.format(stream)

    fig, axes = plt.subplots(len(streams),
                             1,
                             figsize=(12, 12 * len(streams)),
                             squeeze=False)
    fig.show()

    # show each frame
    streamsBitDepth = vid.GetStreamsBitDepth()
    print('streamsBitDepth', streamsBitDepth)
    while (vid.GetCurrentFrameId() < flags.endFrame):
        # grab the next frame
        allStreams = vid.Grab()

        vout.WriteStreams(allStreams, streamsBitDepth)
        for i, s in enumerate(streams):
            arr = allStreams[s]
            # print(arr.shape)
            axes[i, 0].cla()
            if arr.shape[-1] == 1:
                axes[i, 0].imshow(np.squeeze(arr), cmap='Greys')
            else:
                axes[i, 0].imshow(arr)

        # update figures
        fig.canvas.draw()

        # printing
        if vid.GetCurrentFrameId() % 10 == 0:
            print('frame: {} / {}'.format(vid.GetCurrentFrameId(),
                                          vid.GetTotalFrames()))
コード例 #3
0
def main(flags):
    vid_uri = flags.pango
    vout_uri = flags.pangoOut
    stream = flags.stream
    if vout_uri is None:
        vout_uri = "pango://demo.pango"

    vid = pango.VideoInput(vid_uri)
    vout = pango.VideoOutput(vout_uri)

    # print metadata
    print("Opened video uri: '{}' with {} x {} dimensions".format(
        vid_uri, vid.Width(), vid.Height()))
    fmt = vid.PixFormat()
    print("format: channels: {}, channel_bits: {}, planar: {}".format(
        fmt.channels, fmt.bpp, fmt.planar))

    # initialize display
    allStreams = vid.Grab()
    numstreams = len(allStreams)

    streams = [stream] if stream else list(range(numstreams))
    assert streams[
        -1] < numstreams, 'specified stream {} is out of bnd'.format(stream)

    fig, axes = plt.subplots(len(streams),
                             1,
                             figsize=(12, 12 * len(streams)),
                             squeeze=False)
    fig.show()

    # show each frame
    frameCounter = 0
    while (allStreams):
        # if frameCounter > 20:
        # 	break
        vout.WriteStreams(allStreams)
        for i, s in enumerate(streams):
            arr = allStreams[s]
            # print(arr.shape)
            axes[i, 0].cla()
            if arr.shape[-1] == 1:
                axes[i, 0].imshow(np.squeeze(arr), cmap='Greys')
            else:
                axes[i, 0].imshow(arr)

        # grab the next frame
        allStreams = vid.Grab()
        frameCounter += 1

        # update figures
        fig.canvas.draw()

        # printing
        if frameCounter % 10 == 0:
            print('frame: {}'.format(frameCounter))
コード例 #4
0
ファイル: SimpleVideo.py プロジェクト: etola/Pangolin
def main(flags):
    vid_uri = flags.pango
    vout_uri = flags.pangoOut
    stream = flags.stream
    if vout_uri is None:
        vout_uri = "pango://out.pango"

    vid = pango.VideoInput(vid_uri)
    print(vid.GetCurrentFrameId())
    vout = pango.VideoOutput(vout_uri)

    # print metadata
    print("Opened video uri: '{}' with {} x {} dimensions".format(
        vid_uri,vid.Width(),vid.Height()))
    fmt = vid.PixFormat()
    print("format: channels: {}, channel_bits: {}, planar: {}".format(
        fmt.channels, fmt.bpp, fmt.planar))


    # user specified initial frame
    vid.Seek(flags.startFrame)
    if flags.endFrame is None:
        flags.endFrame = vid.GetTotalFrames()

    # initialize display
    numStreams = vid.GetNumStreams()
    streams = [stream] if stream else list(range(numStreams))
    assert streams[-1] < numStreams, 'specified stream {} is out of bnd'.format(stream)

    fig, axes = plt.subplots(len(streams), 1, figsize=(12, 12*len(streams)), squeeze=False)
    fig.show()

    # show each frame
    streamsBitDepth = vid.GetStreamsBitDepth()
    print('streamsBitDepth', streamsBitDepth)

    # To run over the whole sequence (starting from seeked frame) you could simply use:
    # for frame in vid:
    #     ...

    for i, frame in zip(range(flags.startFrame, flags.endFrame), vid):

        # Alternatively, frames can be grabbed manually until the returned list is empty:
        # frame = vid.Grab()

        vout.WriteStreams(frame, streamsBitDepth);
        for i, s in enumerate(streams):
            arr = frame[s]
            # print(arr.shape)
            axes[i,0].cla()
            if arr.shape[-1] == 1:
                axes[i,0].imshow(np.squeeze(arr), cmap='Greys')
            else:
                axes[i,0].imshow(arr)

        # update figures
        fig.canvas.draw()

        # printing
        print('frame: {} / {}'.format(
                vid.GetCurrentFrameId(), vid.GetTotalFrames()),
                end='\r', flush=True)