refer to code:
..
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <vdpau/vdpau.h>
#include <vdpau/vdpau_x11.h>
using namespace std;
int main(int argc, char **argv) {
if (argc < 2) {
cerr << "Usage: " << argv[0] << " <video file>" << endl;
exit(1);
}
VdpDevice device;
VdpStatus status;
status = vdp_device_create_x11(DefaultDisplay(), DefaultScreen(DefaultDisplay()), &device, nullptr);
if (status != VDP_STATUS_OK) {
cerr << "vdp_device_create_x11 failed: " << status << endl;
exit(1);
}
VdpVideoSurface surface;
status = vdp_video_surface_create(device, VDP_CHROMA_TYPE_420, 8192, 4320, &surface);
if (status != VDP_STATUS_OK) {
cerr << "vdp_video_surface_create failed: " << status << endl;
exit(1);
}
VdpDecoder decoder;
status = vdp_decoder_create(device, VDP_DECODER_PROFILE_H264_HIGH, 8192, 4320, 16, &decoder);
if (status != VDP_STATUS_OK) {
cerr << "vdp_decoder_create failed: " << status << endl;
exit(1);
}
FILE *file = fopen(argv[1], "rb");
if (!file) {
cerr << "Failed to open video file: " << argv[1] << endl;
exit(1);
}
uint8_t *buf = new uint8_t[65536];
while (!feof(file)) {
size_t n = fread(buf, 1, 65536, file);
VdpBitstream bitstream = { buf, n };
status = vdp_decoder_decode(decoder, surface, &bitstream, 0, 0);
if (status != VDP_STATUS_OK) {
cerr << "vdp_decoder_decode failed: " << status << endl;
exit(1);
}
}
fclose(file);
VdpPresentationQueue presentation_queue;
status = vdp_presentation_queue_create(device, DefaultVisual(DefaultDisplay(), DefaultScreen(DefaultDisplay())), &presentation_queue);
if (status != VDP_STATUS_OK) {
cerr << "vdp_presentation_queue_create failed: " << status << endl;
exit(1);
}
VdpOutputSurface output_surface;
status = vdp_output_surface_create(device, VDP_RGBA_FORMAT_B8G8R8A8, 8192, 4320, &output_surface);
if (status != VDP_STATUS_OK) {
cerr << "vdp_output_surface_create failed: " << status << endl;
exit(1);
}
VdpPresentationQueueTarget presentation_queue_target;
status = vdp_presentation_queue_target_create_x11(presentation_queue, DefaultScreen(DefaultDisplay()), DefaultVisual(DefaultDisplay(), DefaultScreen(DefaultDisplay())), &presentation_queue_target);
if (status != VDP_STATUS_OK) {
cerr << "vdp_presentation_queue_target_create_x11 failed: " << status << endl;
exit(1);
}
VdpTimebase timebase;
status = vdp_timebase_create(device, 1, &timebase);
if (status != VDP_STATUS_OK) {
cerr << "vdp_timebase_create failed: " << status << endl;
exit(1);
}
VdpOutputSurfaceRenderBlendState blend_state = { VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_OPAQUE };
VdpOutputSurfaceRenderBlendState blend_state_array[1] = { blend_state };
VdpOutputSurfaceRenderBlendState *blend_states = blend_state_array;
VdpColor color = { 0, 0, 0, 0 };
VdpRect src_rect = { 0, 0, 8192, 4320 };
VdpRect dst_rect = { 0, 0, 1920, 1080 };
VdpTime presentation_time = 0;
while (true) {
status = vdp_presentation_queue_block_until_surface_idle(presentation_queue, output_surface, &presentation_time);
if (status != VDP_STATUS_OK) {
cerr << "vdp_presentation_queue_block_until_surface_idle failed: " << status << endl;
exit(1);
}
status = vdp_output_surface_render_output_surface(output_surface, &src_rect, surface, &dst_rect, blend_states, 1, &color);
if (status != VDP_STATUS_OK) {
cerr << "vdp_output_surface_render_output_surface failed: " << status << endl;
exit(1);
}
status = vdp_presentation_queue_display(presentation_queue, presentation_queue_target, presentation_time, timebase);
if (status != VDP_STATUS_OK) {
cerr << "vdp_presentation_queue_display failed: " << status << endl;
exit(1);
}
}
return 0;
}
..
this code creates the presentation queue and target, sets up the output surface rendering, and then enters a loop that continuously displays the video frames using the vdp_presentation_queue_display
function.
Please note that this code is just an example and may need to be modified to fit your specific needs.
Thank you.
🙇🏻♂️
www.marearts.com
No comments:
Post a Comment