#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> struct context {
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_mutex *mutex;
int n; uint32_t *pixels; 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); c->pixels = (uint16_t *) *p_pixels; 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; 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; SDL_Rect displayrect; uint32_t *pixels = ctx->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 * ctx->window_w + x] = 0xffffffff;
} else {
// RV16 = 5+6+5 pixels per color, BGR.
pixels[y * ctx->window_w + x] = 0x02ff02ff;
}
}
} displayrect.x = 0;
displayrect.y = 0;
displayrect.w = ctx->window_w;
displayrect.h = ctx->window_h;
// printf("----%d, %d\n", displayrect.w, displayrect.h); SDL_SetRenderDrawColor(ctx->renderer, 0, 0, 0, 128);
SDL_RenderClear(ctx->renderer);
SDL_RenderCopy(ctx->renderer, ctx->texture, NULL, &displayrect);
SDL_RenderPresent(ctx->renderer);
} static void quit(int c) {
SDL_Quit();
exit(c);
} int main_video(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.
"-vvv",
// "--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;
unsigned video_w = 0, video_h = 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;
} 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.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, "./test5.mp4");
mp = libvlc_media_player_new_from_media(m);
libvlc_media_parse(m); //get file information
libvlc_video_get_size(mp, 0, &video_w, &video_h);
printf("----%d, %d\n", video_w, video_h);
if (video_w == 0) {
printf("cannot get video size\n");
exit(-1);
}
//init w,h
ctx.window_w = video_w;
ctx.window_h = video_h; libvlc_media_release(m); //initialize window and render
// Create SDL graphics objects.
SDL_Window * window = SDL_CreateWindow("Fartplayer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, video_w, video_h,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (!window) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
quit(3);
} ctx.renderer = SDL_CreateRenderer(window, 1, 0);
if (!ctx.renderer) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
quit(4);
} //init texture
ctx.texture = SDL_CreateTexture(ctx.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, video_w, video_h);
if (!ctx.texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
quit(5);
} libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
libvlc_video_set_format(mp, "RV32", video_w, video_h, video_w * 4);
// libvlc_video_set_format(mp, "UYVY", 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.window_w = event.window.data1;
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 sdl2.0 播放示例的更多相关文章

  1. 最简单的基于FFMPEG+SDL的音频播放器 ver2 (采用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

  2. 最简单的基于FFMPEG+SDL的音频播放器 ver2 (採用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

  3. SDL2.0 VLC ubuntu安装和黑屏问题

    开发环境安装: 1,执行:"sudo apt-get build-dep libsdl1.2",确定依赖库都装全了. sdl2.0没有正式发布到ubuntu,使用下面方法安装: h ...

  4. 最简单的视音频播放示例7:SDL2播放RGB/YUV

    本文记录SDL播放视频的技术.在这里使用的版本是SDL2.实际上SDL本身并不提供视音频播放的功能,它只是封装了视音频播放的底层API.在Windows平台下,SDL封装了Direct3D这类的API ...

  5. 最简单的视音频播放示例9:SDL2播放PCM

    本文记录SDL播放音频的技术.在这里使用的版本是SDL2.实际上SDL本身并不提供视音频播放的功能,它只是封装了视音频播放的底层API.在Windows平台下,SDL封装了Direct3D这类的API ...

  6. 演示基于SDL2.0+FFmpeg的播放器

    SDL是一个跨平台的渲染组件,眼下已经推出到2.0.3版本号,支持Win/Linux/OSX/Android.网上非常多介绍大多是基于SDL1.2版本号的,与2.0版本号有一定的区别,本文演示怎样用S ...

  7. 最简单的视音频播放示例8:DirectSound播放PCM

    本文记录DirectSound播放音频的技术.DirectSound是Windows下最常见的音频播放技术.目前大部分的音频播放应用都是通过DirectSound来播放的.本文记录一个使用Direct ...

  8. 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)

    本文记录OpenGL播放视频的技术.上一篇文章中,介绍了一种简单的使用OpenGL显示视频的方式.但是那还不是OpenGL显示视频技术的精髓.和Direct3D一样,OpenGL更好的显示视频的方式也 ...

  9. 最简单的视音频播放示例5:OpenGL播放RGB/YUV

    本文记录OpenGL播放视频的技术.OpenGL是一个和Direct3D同一层面的技术.相比于Direct3D,OpenGL具有跨平台的优势.尽管在游戏领域,DirectX的影响力已渐渐超越OpenG ...

随机推荐

  1. subprocess.Popen指令包含中文导致乱码问题解决

    其实解决起来非常简单,如果了解到Windows中文系统编码为GB2312的话 只需将你包含中文的指令字符串编码为GB2312即可 cmd = u'cd 我的文档' cmd.encode('gb2312 ...

  2. Webpack 2 视频教程 005 - Webpack 编译输出日志

    原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...

  3. ruby安装及升级

    在centos6.x下执行上面的"gem install redis"操作可能会报错,坑很多!默认yum安装的ruby版本是1.8.7,版本太低,需要升级到ruby2.2以上,否则 ...

  4. nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理

    Nginx除了可以用作web服务器外,他还可以用来做高性能的反向代理服务器,它能提供稳定高效的负载均衡解决方案.nginx可以用轮询.IP哈希.URL哈希等方式调度后端服务器,同时也能提供健康检查功能 ...

  5. python基础知识小结-运维笔记

    接触python已有一段时间了,下面针对python基础知识的使用做一完整梳理:1)避免‘\n’等特殊字符的两种方式: a)利用转义字符‘\’ b)利用原始字符‘r’ print r'c:\now' ...

  6. memcached程序端口监控脚本

    线上memcached服务器启动了很多实例,端口很多,需要对这些端口进行监控,并在端口关闭的情况下自启动.监控脚本如下: [root@memcache2 ~]# ps -ef|grep /usr/bi ...

  7. Node 系列之url模块

    引入 url: const url = require("url"); 用于URL解析.处理等操作的解决方案 1.url.parse(urlStr[, parseQueryStri ...

  8. Wannafly挑战赛25 B.面积并

    链接 [https://www.nowcoder.com/acm/contest/197/B] 分析 特殊优先考虑 首先考虑r>=l这种情况就是圆的面积了 第二就是r<=内切圆的半径,这个 ...

  9. 领跑衫获奖感言 & 课程总结

    很荣幸在最后一次课获得了黄色领跑衫.在此,我要感谢教师杨贵福,感谢<构建之法>的作者邹欣老师和出版人周筠老师,感谢“耐撕”团队的队员们. 作为旁听生,最后一堂课,有些不舍.不多说,先上图, ...

  10. 《Linux内核分析》第五周学习总结

    <Linux内核分析>第五周学习总结                                  ——扒开系统调用的三层皮(下) 姓名:王玮怡 学号:20135116 1.给menu ...