我在 C 中有这段代码:
#include <X11/X.h>
#include <X11/Xlib.h>
#include <mpv/client.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Handle MPV errors
void checkMPV(int status) {
if (status < 0) {
printf("MPV error: %s\n", mpv_error_string(status));
exit(1);
}
}
int main(void) {
Display *display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
// Create X11 window
int screen = DefaultScreen(display);
Window window = XCreateSimpleWindow(
display, RootWindow(display, screen), 10, 10, 100, 100, 1,
BlackPixel(display, screen), WhitePixel(display, screen));
XSelectInput(display, window, ExposureMask);
XMapWindow(display, window);
// Create MPV context
mpv_handle *ctx = mpv_create();
if (!ctx) {
printf("failed to create context\n");
return 1;
}
// bind MPV to master window
char wid[64];
sprintf(wid, "0x%lx", window);
checkMPV(mpv_set_option_string(ctx, "wid", wid));
// configure MPV
checkMPV(mpv_set_option_string(ctx, "keepaspect", "no"));
checkMPV(mpv_set_option_string(ctx, "x11-bypass-compositor", "no"));
checkMPV(mpv_set_option_string(ctx, "gapless-audio", "yes"));
checkMPV(mpv_set_option_string(ctx, "aid", "no"));
checkMPV(mpv_set_option_string(ctx, "vo", "xv"));
checkMPV(mpv_set_option_string(ctx, "hwdec", "auto"));
checkMPV(mpv_set_option_string(ctx, "input-default-bindings", "no"));
checkMPV(mpv_set_option_string(ctx, "input-vo-keyboard", "no"));
int flag = 0;
checkMPV(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &flag));
// Initialize MPV
checkMPV(mpv_initialize(ctx));
// Play video
const char *cmd[] = {"loadfile", "video.mp4", NULL};
checkMPV(mpv_command(ctx, cmd));
// Draw rectangle in loop
XEvent event;
while (1) {
XNextEvent(display, &event);
XClearWindow(display, window);
XFillRectangle(display, window, DefaultGC(display, screen), 10, 10, 300,
300);
}
// Cleanup
mpv_terminate_destroy(ctx);
XCloseDisplay(display);
return 0;
}
它将 MPV 窗口附加到 X11 窗口。它看起来像这样(只是一个视频帧):
问题是,我可以让 MPV 窗口半透明(例如,70%),所以用 XFillRectangle(display, window, DefaultGC(display, screen), 10, 10, 300, 300) 绘制的矩形;会有点明显吗?它看起来像这样:
不使用opengl之类的东西有可能吗?