vlc sdl 播放视频可随窗口改变大小
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_mutex.h> #include <vlc/vlc.h> #define VIDEOWIDTH 1920
#define VIDEOHEIGHT 1080 struct context {
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_mutex *mutex;
int n; SDL_Rect displayrect;
int window_w;
int window_h;
}; // VLC prepares to render a video frame.
static void *lock(void *data, void **p_pixels) { struct context *c = (struct context *) data; int pitch;
SDL_LockMutex(c->mutex);
SDL_LockTexture(c->texture, NULL, p_pixels, &pitch); return NULL ; // Picture identifier, not needed here.
} // VLC just rendered a video frame.
static void unlock(void *data, void *id, void * const *p_pixels) { struct context *c = (struct context *) data;
/* uint16_t *pixels = (uint16_t *) *p_pixels; // We can also render stuff.
int x, y;
for (y = 10; y < 40; y++) {
for (x = 10; x < 40; x++) {
if (x < 13 || y < 13 || x > 36 || y > 36) {
pixels[y * VIDEOWIDTH + x] = 0xffff;
} else {
// RV16 = 5+6+5 pixels per color, BGR.
pixels[y * VIDEOWIDTH + x] = 0x02ff;
}
}
}
*/ SDL_UnlockTexture(c->texture);
SDL_UnlockMutex(c->mutex);
} // VLC wants to display a video frame.
static void display(void *data, void *id) { struct context *ctx = (struct context *) data;
ctx->displayrect.x = 0;
ctx->displayrect.y = 0;
ctx->displayrect.w = ctx->window_w;
ctx->displayrect.h = ctx->window_h; // SDL_SetRenderDrawColor(c->renderer, 0, 80, 0, 255);
SDL_RenderClear(ctx->renderer);
SDL_RenderCopy(ctx->renderer, ctx->texture, NULL, &ctx->displayrect);
SDL_RenderPresent(ctx->renderer);
} static void quit(int c) {
SDL_Quit();
exit(c);
} int main(int argc, char *argv[]) { struct context ctx; libvlc_instance_t *libvlc;
libvlc_media_t *m;
libvlc_media_player_t *mp;
char const *vlc_argv[] = { "--no-audio", // Don't play audio.
"--no-xlib", // Don't use Xlib. // Apply a video filter.
//"--video-filter", "sepia",
//"--sepia-intensity=200"
};
int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv); SDL_Event event;
int done = 0, action = 0, pause = 0, n = 0; // if(argc < 2) {
// printf("Usage: %s <filename>\n", argv[0]);
// return EXIT_FAILURE;
// } // Initialise libSDL.
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Could not initialize SDL: %s.\n", SDL_GetError());
return EXIT_FAILURE;
} // Create SDL graphics objects.
SDL_Window * window = SDL_CreateWindow("Fartplayer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
ctx.window_w = 1280;
ctx.window_h = 720; if (!window) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
quit(3);
} int nRenderDrivers = SDL_GetNumRenderDrivers();
int i = 0;
for (; i < nRenderDrivers; i++) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info); //d3d
printf("====info name %d: %s =====\n", i, info.name);
printf("====max_texture_height %d =====\n", i, info.max_texture_height);
printf("====max_texture_width %d =====\n", i, info.max_texture_width); } SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); ctx.renderer = SDL_CreateRenderer(window, 1, 0);
if (!ctx.renderer) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
quit(4);
} ctx.texture = SDL_CreateTexture(ctx.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, VIDEOWIDTH, VIDEOHEIGHT);
if (!ctx.texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
quit(5);
} ctx.mutex = SDL_CreateMutex(); // If you don't have this variable set you must have plugins directory
// with the executable or libvlc_new() will not work!
printf("VLC_PLUGIN_PATH=%s\n", getenv("VLC_PLUGIN_PATH")); // Initialise libVLC.
libvlc = libvlc_new(vlc_argc, vlc_argv);
if (NULL == libvlc) {
printf("LibVLC initialization failure.\n");
return EXIT_FAILURE;
} m = libvlc_media_new_path(libvlc, "./test.mp4");
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m); libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
libvlc_video_set_format(mp, "RV32", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4);
libvlc_media_player_play(mp); // Main loop.
while (!done ) { action = 0; // Keys: enter (fullscreen), space (pause), escape (quit).
while (SDL_PollEvent(&event)) { switch (event.type) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_RenderSetViewport(ctx.renderer, NULL );
ctx.displayrect.w = ctx.window_w = event.window.data1;
ctx.displayrect.h = ctx.window_h = event.window.data2;
}
break;
case SDL_QUIT:
done = 1;
break;
case SDL_KEYDOWN:
action = event.key.keysym.sym;
break;
}
} switch (action) {
case SDLK_ESCAPE:
case SDLK_q:
done = 1;
break;
case ' ':
printf("Pause toggle.\n");
pause = !pause;
break;
}
if (!pause) {
ctx.n++;
} SDL_Delay(100);
} // Stop stream and clean up libVLC.
libvlc_media_player_stop(mp);
libvlc_media_player_release(mp);
libvlc_release(libvlc); // Close window and clean up libSDL.
SDL_DestroyMutex(ctx.mutex);
SDL_DestroyRenderer(ctx.renderer); quit(0); return 0;
}
vlc sdl 播放视频可随窗口改变大小的更多相关文章
- SDL的基础知识以及利用SDL播放视频
原文地址:http://blog.csdn.net/i_scream_/article/details/52714378 此博文相关知识点从雷神的博客以及视频学习,截图也是用了他的课件, 雷神博客地址 ...
- SDL播放视频
// PlayVideo.cpp : Defines the entry point for the console application. // extern "C" { #i ...
- 用vlc SDK创建一个播放视频文件和RTSP流视频的Demo
#include <stdio.h> #include <tchar.h> #include <time.h> #include <windows.h> ...
- IPTV小窗口播放视频 页面焦点无法移动的解决方法
在IPTV高清页面中,小窗口播放视频时,在某些机顶盒上(如高清中兴.高清大亚4904)会出现焦点无法移动现象,即按键无响应.被这个bug困扰了很久,虽然我知道解决方法,但只知其然,不知其所以然.今天做 ...
- Android内嵌VLC实现播放网络视频,网络音频
1.在对应模块的build.gradle文件中,添加依赖 //VlC implementation "de.mrmaffen:vlc-android-sdk:2.0.6" 2.布局 ...
- web网页中使用vlc插件播放相机rtsp流视频
可参考: 使用vlc播放器做rtsp服务器 使用vlc播放器播放rtsp视频 使用vlc进行二次开发做自己的播放器 vlc功能还是很强大的,有很多的现成的二次开发接口,不需配置太多即可轻松做客户端播放 ...
- 用MCI处置WAV视频时,怎样才能让视频在当前窗口播放
用MCI处理WAV视频时,怎样才能让视频在当前窗口播放MCI播放视频默认是新开一个窗口播放,播放完毕返回原来的窗口,想着原来窗口播放如何做? mciSendCommand或mciSendString怎 ...
- 嵌入式 vlc从接收到数据流到播放视频的过程分析(经典)
个人整理: Vlc流播放流程 vlc源码目录树: 目录名称 说明 bindings Java, CIL 和Python绑定 doc 帮助文档 (不是更新的) extras 另叙. include VL ...
- 视频 embed标签动态改变Src的值,局部刷新播放其他视频的javascript方法
看图: 视频处html代码: <div id="mod_player" class="mod_player"> <embed id=" ...
随机推荐
- GeForce Experience关闭自动更新
GeForce Experience驱动更新很烦,而且有时更新后就打不开了,找到种方法关闭更新 1.安装并登陆 2.打开 C:\ProgramData\NVIDIA Corporation 3.进入D ...
- SpringBoot笔记--FastJson
FastJson配置 ObjectId class ObjectIdSerializer : ObjectSerializer { override fun write(serializer: JSO ...
- react-创建react元素
前言 react 元素,即JSX语法. const Nav, Profile; // 输入(JSX): const app = <Nav color="blue">&l ...
- javascript DOM操作中的insertAdjacentHTML方法
插入HTML内容与文本内容以前用的是innerHTML与innerText方法,今天看到insertAdjacentHTML和 insertAdjacentText两个API,特地学习一下: inse ...
- week4--系统调用的工作机制
潘恒 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.使用库函数AP ...
- 实践——ELF文件格式分析
一.分析文件头 1. 段入口类型定义(/usr/include/elf.h)下面产生的hello是32位的 使用命令#Hexdump –x ELF_1.o 第一行: 前4字节,蓝色部分,是一个魔数,表 ...
- 第七组团队项目——专业课程资源共享平台——需求分析&原型设计
一.项目目标.定位需求: (1)目标:在教师.学生之间建立一个综合的.全面的.快捷的.高效的免费课程和学习资源共享.交流与推荐的开放性平台,实现多维和动态的推荐与分类检索服务. (2)定位:学生与教师 ...
- servlet请求转发
来源:http://www.2cto.com/kf/201610/554591.html 请求转发:Servlet(源组件)先对客户请求做一些预处理操作(数据处理),然后把请求转发给其他Web组件(目 ...
- yum install 报错[Errno 14] curl#37 - Couldn't open file /mnt/repodata/repomd.xml
1.然后按照网上的一些修改,先是执行: yum cleam all 然后 yum makecache,问题还是没解决,继续报错. 其实这两条命令就是清空缓存,然后再重新缓存的意思,有时候可能有效. 2 ...
- ionic3.x开发小坑记录(一)
自定义font的时候,在assets中创建的文件夹名字别用fonts,会与ionic默认样式冲突,在浏览器中调试是正常的,到手机上就出问题了. 在html中写img的src直接如图 assets前面 ...