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=" ...
随机推荐
- [开源 .NET 跨平台 Crawler 数据采集 爬虫框架: DotnetSpider] [二] 基本使用
[DotnetSpider 系列目录] 一.初衷与架构设计 二.基本使用 三.配置式爬虫 四.JSON数据解析与配置系统 五.如何做全站采集 使用环境 Visual Studio 2017 .NET ...
- Asp.Net_ 服务端向客户端写JavaScript脚本
在Asp.net 服务端处理脚本,一般都用 ClientScriptManager ,即web窗体服务端的this.ClientScript.该对象比较常用的方法: 1.RegisterArrayDe ...
- 11.13 Daily Scrum
今天在实现餐厅列表时,原来使用的百度地图poi搜索接口无法返回餐厅的具体信息. 经过一番周折,找到了一个返回餐厅url的接口.我们调整了一下实现,在点击餐厅列表的某一项点击直接跳到和该餐厅信息有关的网 ...
- 补充照片:某基同学使用Bing词典
某基同学使用Bing词典的照片
- 基于Spring3 MVC实现基于form表单文件上传
http://blog.csdn.net/jia20003/article/details/8474374/
- 实例详解Java中如何对方法进行调用
原文源自http://www.jb51.net/article/73827.htm 方法调用Java支持两种调用方法的方式,根据方法是否返回值来选择. 当程序调用一个方法时,程序的控制权交给了被调用的 ...
- 开源RabbitMQ操作组件
开源RabbitMQ操作组件 对于目前大多的.NET项目,其实使用的技术栈都是差不多,估计现在很少用控件开发项目的了,毕竟一大堆问题.对.NET的项目,目前比较适合的架构ASP.NET MVC,ASP ...
- Flask-论坛开发-5-memcached缓存系统
对Flask感兴趣的,可以看下这个视频教程:http://study.163.com/course/courseLearn.htm?courseId=1004091002 ### 介绍:哪些情况下适合 ...
- Resolved validation conflict with readonly
/** * Bug绕过去方案WorkAround * Bug描述: * JQuery的Validation的和form的input元素设为readonly,一对不可调和的矛盾: * 一个设置为requ ...
- 命令行批量修改IP并ping测试
@echo off set ip=0 :beginset /a ip=%ip%+1netsh interface ip set address "本地连接" static 172. ...