File size: 892 Bytes
12d535c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import ffmpeg
import numpy as np
from dora import Node
import pyarrow as pa
import cv2

node = Node()

in_filename = "tcp://192.168.2.1:40921"
# Global variables, change it to adapt your needs
CAMERA_WIDTH = 960
CAMERA_HEIGHT = 540

process1 = (
    ffmpeg.input(in_filename)
    .output("pipe:", format="rawvideo", pix_fmt="rgb24")
    .run_async(pipe_stdout=True)
)

audio = ffmpeg.input(in_filename).audio

while True:
    in_bytes = process1.stdout.read(1280 * 720 * 3)
    if not in_bytes:
        break
    in_frame = np.frombuffer(in_bytes, np.uint8).reshape([720, 1280, 3])

    ## RGB to BGR
    in_frame = in_frame[..., ::-1]

    in_frame = cv2.resize(in_frame, (CAMERA_WIDTH, CAMERA_HEIGHT))
    # out_frame = in_frame * 0.5  # do some processing
    node.send_output("image", pa.array(in_frame.ravel()))
    node.send_output("audio", pa.array(in_frame.ravel()))

process1.wait()