From 87fc210c72d4abb991adf8f97fa54eb9115cec35 Mon Sep 17 00:00:00 2001 From: Manglemix Date: Fri, 22 Sep 2023 18:54:07 -0600 Subject: [PATCH] Switched to webp --- lunabase/ffmpeg.gd | 115 ----------------------------------------- lunabase/lunabot.gd | 7 ++- lunabase/project.godot | 1 - 3 files changed, 5 insertions(+), 118 deletions(-) delete mode 100644 lunabase/ffmpeg.gd diff --git a/lunabase/ffmpeg.gd b/lunabase/ffmpeg.gd deleted file mode 100644 index 780a887f..00000000 --- a/lunabase/ffmpeg.gd +++ /dev/null @@ -1,115 +0,0 @@ -extends Node - - -signal image_received(Image) - - -const IMAGE_WIDTH := 1280 -const IMAGE_HEIGHT := 720 -const IMAGE_SIZE := IMAGE_HEIGHT * IMAGE_WIDTH * 3 - -#var thr := Thread.new() -#var udp_sender := PacketPeerUDP.new() -var tcp_server := TCPServer.new() -var ffmpeg_tcp: StreamPeerTCP -var buffer := PackedByteArray() - -var send_from: int -#var send_to: int - - -func subprocess(): - var output := [] - var err := OS.execute( - "ffmpeg", -# [ -# "-f", "mpegts", -# "-c:v", "libvpx-vp9", -# "-i", "udp://127.0.0.1:%s" % send_to, -# "-f", "rawvideo", -# "-pix_fmt", "rgb24", -# "udp://127.0.0.1:%s" % send_from -# ], - [ - "-f", "mpegts", - "-c:v", "libvpx-vp9", - "-b:v", "1500k", - "-i", "tcp://127.0.0.1:%s" % send_from, - "-c", "copy", - "-map", "0", - "-f", "segment", - "-segment_time", "5", - "-segment_format", "matroska", - "capture-%03d.mkv", - - ], -# output, -# true - [], - false, - true - ) - - if err != OK: - push_error(output[0]) - - -func _ready() -> void: - send_from = randi_range(10000, 65000) -# send_to = randi_range(10000, 65000) - if tcp_server.listen(send_from, "127.0.0.1") != OK: - push_error("Failed to start FFMPEG TCP Server") -# udp_sender.bind(send_from, "127.0.0.1") -# udp_sender.set_dest_address("127.0.0.1", send_to) -# thr.start(subprocess) - OS.create_process( - "ffmpeg", -# [ -# "-f", "mpegts", -# "-c:v", "libvpx-vp9", -# "-i", "udp://127.0.0.1:%s" % send_to, -# "-f", "rawvideo", -# "-pix_fmt", "rgb24", -# "udp://127.0.0.1:%s" % send_from -# ], - [ - "-v", "debug", -# "-f", "mpegts", -# "-c:v", "libvpx-vp9", - "-i", "tcp://127.0.0.1:%s" % send_from, - "-f", "matroska", - "out.mkv" - ], - true - ) - - -func _process(_delta: float) -> void: - if ffmpeg_tcp == null and tcp_server.is_connection_available(): - ffmpeg_tcp = tcp_server.take_connection() -# if udp_sender.get_available_packet_count() == 0: -# return -# -# print_debug("receivedee") -# for _i in range(udp_sender.get_available_packet_count()): -# buffer.append_array(udp_sender.get_packet()) -# if buffer.size() >= IMAGE_SIZE: -# var img := Image.create_from_data(IMAGE_WIDTH, IMAGE_HEIGHT, false,Image.FORMAT_RGB8, buffer.slice(0, IMAGE_SIZE)) -# buffer = buffer.slice(IMAGE_SIZE) -# image_received.emit(img) -# print_debug("received") - - -func process_data(data: PackedByteArray): - if ffmpeg_tcp == null: - push_error("Failed to send to FFMPEG") - return - ffmpeg_tcp.put_data(data) -# ffmpeg_tcp.disconnect_from_host() -# ffmpeg_tcp = null - - -func _exit_tree() -> void: - if ffmpeg_tcp != null: - ffmpeg_tcp.disconnect_from_host() -# thr.wait_to_finish() diff --git a/lunabase/lunabot.gd b/lunabase/lunabot.gd index fd06df5c..8657acf4 100644 --- a/lunabase/lunabot.gd +++ b/lunabase/lunabot.gd @@ -34,7 +34,6 @@ func _ready() -> void: if err != OK: push_error("Failed to start ENet Server: " + str(err)) return -# server.compress(ENetConnection.COMPRESS_ZLIB) thread.start(_run_thr) @@ -137,7 +136,11 @@ func _on_receive(channel: int) -> void: pass Channels.CAMERA: - Ffmpeg.process_data(data) + var img := Image.new() + var err := img.load_webp_from_buffer(data) + if err != OK: + push_error("Error parsing camera frame: %s" % err) + call_deferred("emit_signal", "camera_frame_received", img) Channels.ODOMETRY: var x := data.decode_float(0) diff --git a/lunabase/project.godot b/lunabase/project.godot index 34d22f65..df0dca02 100644 --- a/lunabase/project.godot +++ b/lunabase/project.godot @@ -18,7 +18,6 @@ config/icon="res://icon.png" [autoload] Lunabot="*res://lunabot.gd" -Ffmpeg="*res://ffmpeg.gd" [display]