Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add osd/srt support #53

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VERSION_STRING := $(shell date +"%Y%m%d_%H%M%S")
CFLAGS ?=
CFLAGS += -Wno-address-of-packed-member -DVERSION_STRING="\"$(VERSION_STRING)\""

SRCS := compat.c msposd.c bmp/bitmap.c bmp/region.c bmp/lib/schrift.c bmp/text.c osd/net/network.c osd/msp/msp.c osd/msp/msp_displayport.c libpng/lodepng.c osd/util/interface.c osd/util/settings.c osd/util/ini_parser.c osd/msp/vtxmenu.c
SRCS := compat.c msposd.c bmp/bitmap.c bmp/region.c bmp/lib/schrift.c bmp/text.c osd/net/network.c osd/msp/msp.c osd/msp/msp_displayport.c libpng/lodepng.c osd/util/interface.c osd/util/settings.c osd/util/ini_parser.c osd/msp/vtxmenu.c osd/util/subtitle.c
OUTPUT ?= $(PWD)
BUILD = $(CC) $(SRCS) -I $(SDK)/include -I$(TOOLCHAIN)/usr/include -I$(PWD) -L$(DRV) $(CFLAGS) $(LIB) -levent_core -Os -s $(CFLAGS) -o $(OUTPUT)

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Usage: msposd [OPTIONS]
-a --ahi Draw graphic AHI, mode [0-No, 2-Simple 1-Ladder, 3-LadderEx (home indicator on ladder)]
-x --matrix OSD matrix [0- 53:20 , 1- 50:18 chars, 11- Variable font size, 9-bottom align 720p mode, 8-center align 720p mode]
--mspvtx Enable alpha mspvtx functionality
--subtitle <path> Enable OSD/SRT recording
-v --verbose Show debug info
--help Display this help
```
Expand Down Expand Up @@ -88,6 +89,23 @@ Use `Exit Camera menu` stick command (one or more times) to exit all flightcontr

msposd has **alpha** support for mspVTX to Betaflight. use the `--mspvtx` switch to activate this. This will configure Betaflight vtx tables with the supported channles by the vtx. You can switch channels from within Betaflight menu, Betaflight Configurator, SpeedyBee App, ELRS VTXAdmin.


## OSD/SRT Recoding

msposd supports recording MSP DisplayPort messages to an OSD file. This can later be used to overlay the OSD if the video was recorded without it.
The OSD file is compatible with the [walksnail-osd-tool](https://github.com/avsaase/walksnail-osd-tool).
The SRT file records the additional MSPOSD.msg. This is not supported by walksnail-osd-tool but can be used in later video editing pipeline tools.

This feature monitors the recording directory for newly started .mp4 files.
Once detected, the SRT and OSD files will be created with the same name.
As soon as the MP4 file is closed, the recording of SRT and OSD files stops as well.

Air side needs special config to detect recordings. No recursive file watching is implmented.
Therefor majestic needs to record to a flat directory layout.

`cli -i /etc/majestic.yaml -s .records.path /mnt/mmcblk0p1/%F/..`


## Options.
Forwarding of MSP packets via UDP.
Can monitor RC Channels values in FC and call the script `channels.sh` (located at /usr/bin or /usr/sbin).Will passing the channel number and its value to it as $1 and $2 parameters. This allows for controlling the camera via the Remote Control Transmitter.
Expand Down
58 changes: 51 additions & 7 deletions msposd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <sys/inotify.h>

#include <event2/buffer.h>
#include <event2/bufferevent.h>
Expand Down Expand Up @@ -47,6 +48,7 @@ bool ParseMSP = true;
bool DrawOSD = false;
bool mspVTXenabled = false;
bool vtxMenuEnabled = false;
extern char* recording_dir;

// libevent base main loop
struct event_base *base = NULL;
Expand Down Expand Up @@ -107,6 +109,7 @@ static void print_usage() {
" -x --matrix OSD matrix (0: 53:20, 1: 50:18 chars)\n"
" -z --size Set OSD resolution\n"
" --mspvtx Enable mspvtx support\n"
" --subtitle <path> Enable OSD/SRT recording\n"
" -v --verbose Show debug info\n"
" -h --help Display this help\n",
default_master, default_baudrate, default_out_addr);
Expand Down Expand Up @@ -1194,6 +1197,40 @@ static int handle_data(const char *port_name, int baudrate, const char *out_addr
event_add(stdin_event, NULL);
#endif

//SRT/OSD Recording
if (recording_dir) {
printf("SRT/OSD recording enabled for directory: %s\n",recording_dir);

int inotify_fd, watch_fd;

// Initialize inotify
inotify_fd = inotify_init();
if (inotify_fd < 0) {
perror("inotify_init");
return 1;
}

// Add a watch for the directory
watch_fd = inotify_add_watch(inotify_fd, recording_dir, IN_CREATE);
if (watch_fd < 0) {
perror("inotify_add_watch");
close(inotify_fd);
return 1;
}

// Create an event for the inotify file descriptor
struct event* inotify_event = event_new(base, inotify_fd, EV_READ | EV_PERSIST, inotify_callback, (void*) recording_dir);
if (!inotify_event) {
fprintf(stderr, "Could not create event!\n");
event_base_free(base);
close(inotify_fd);
return 1;
}

// Add the event to the event base
event_add(inotify_event, NULL);
}

if (temp) {
if (GetTempSigmaStar() > -90) {
temp = 2; // SigmaStar
Expand Down Expand Up @@ -1290,6 +1327,7 @@ int main(int argc, char **argv) {
{"matrix", required_argument, NULL, 'x'},
{"size", required_argument, NULL, 'z'},
{"mspvtx", no_argument, NULL, '1'},
{"subtitle", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
Expand Down Expand Up @@ -1386,20 +1424,26 @@ int main(int argc, char **argv) {
matrix_size = atoi(optarg);
break;

case 'z':
char buffer[16];
strncpy(buffer, optarg, sizeof(buffer));
char *limit = strchr(buffer, 'x');
if (limit) {
buffer[limit - buffer] = '\0';
set_resolution(atoi(buffer), atoi(limit + 1));
case 'z':
{
char buffer[16];
strncpy(buffer, optarg, sizeof(buffer));
char *limit = strchr(buffer, 'x');
if (limit) {
buffer[limit - buffer] = '\0';
set_resolution(atoi(buffer), atoi(limit + 1));
}
}
break;

case '1':
mspVTXenabled = true;
break;

case 's':
recording_dir = strdup(optarg);
break;

case 'v':
verbose = true;
printf("Verbose mode!\n");
Expand Down
18 changes: 17 additions & 1 deletion osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include "osd/util/interface.h"
#include "osd/util/settings.h"

#include "osd.h"
#include "osd/util/subtitle.h"

#define CPU_TEMP_PATH "/sys/devices/platform/soc/f0a00000.apb/f0a71000.omc/temp1"
#define AU_VOLTAGE_PATH "/sys/devices/platform/soc/f0a00000.apb/f0a71000.omc/voltage4"

Expand Down Expand Up @@ -96,7 +99,7 @@ char _port_name[80];

static uint8_t message_buffer[256]; // only needs to be the maximum size of an
// MSP packet, we only care to fwd MSP
static char current_fc_identifier[4];
char current_fc_identifier[4];
static char current_fc_identifier_end_of_string = 0x00;

/* For compressed full-frame transmission */
Expand Down Expand Up @@ -161,6 +164,9 @@ extern bool armed;
extern bool vtxInitDone;
extern bool DrawOSD;

// SRT/OSD
extern bool recording_running;

static void send_display_size(int serial_fd) {
uint8_t buffer[8];
uint8_t payload[2] = {MAX_DISPLAY_X, MAX_DISPLAY_Y};
Expand Down Expand Up @@ -1372,6 +1378,7 @@ void remove_carriage_returns(char *out) {
}

char osdmsg[180];
char ready_osdmsg[80];

bool DrawTextOnOSDBitmap(char *msg) {
char *font;
Expand Down Expand Up @@ -1441,6 +1448,9 @@ bool DrawTextOnOSDBitmap(char *msg) {
msg_buffer, MSP_CMD_DISPLAYPORT, &payload_buffer[0], 80, MSP_INBOUND);
sendto(out_sock, msg_buffer, 100, 0, (struct sockaddr *)&sin_out, sizeof(sin_out));

// store ready osdmsg to be used in subtitle srt writeing
memcpy(&ready_osdmsg[0], &out[0], msglen + 1);

// printf("Sent text msg : %s\n",out);
return false;
}
Expand Down Expand Up @@ -1922,6 +1932,12 @@ static void draw_complete() {
SetOSDMsg(msg);
}

if (recording_running) {
handle_osd_out();
write_srt_file();
check_recoding_file();
}

#ifdef _x86
// sfRenderWindow_display(window);
#endif
Expand Down
4 changes: 4 additions & 0 deletions osd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

extern char current_fc_identifier[4];

uint64_t get_time_ms();
Loading