SDL2.0 VLC ubuntu安装和黑屏问题
开发环境安装:
1,执行:"sudo apt-get build-dep libsdl1.2",确定依赖库都装全了。
sdl2.0没有正式发布到ubuntu,使用下面方法安装:
https://launchpad.net/~zoogie/+archive/sdl2-snapshots
sudo apt-add-repository ppa:zoogie/sdl2-snapshots
sudo apt-get install libsdl2 libsdl2-dbg libsdl2-dev libsdl2-image libsdl2-image-dev libsdl2-ttf libsdl2-ttf-dev libsdl2-mixer libsdl2-mixer-dev
(在ubuntu 13.10 中,依赖库: sudo apt-get build-dep libsdl2)
2, vlc的安装
sudo apt-get install libvlc-dev
3,运行示例代码
// libSDL and libVLC sample code.
// License: [http://en.wikipedia.org/wiki/WTFPL WTFPL] #include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h> #include "SDL/SDL.h"
#include "SDL/SDL_mutex.h" #include "vlc/vlc.h" #define WIDTH 640
#define HEIGHT 480 #define VIDEOWIDTH 320
#define VIDEOHEIGHT 240 struct context {
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_mutex *mutex;
int n;
}; // VLC prepares to render a video frame.
static void *lock(void *data, void **p_pixels) { struct context *c = (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 = (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 *c = (context *)data; SDL_Rect rect;
rect.w = VIDEOWIDTH;
rect.h = VIDEOHEIGHT;
rect.x = (int)((1. + .5 * sin(0.03 * c->n)) * (WIDTH - VIDEOWIDTH) / 2);
rect.y = (int)((1. + .5 * cos(0.03 * c->n)) * (HEIGHT - VIDEOHEIGHT) / 2); SDL_SetRenderDrawColor(c->renderer, 0, 80, 0, 255);
SDL_RenderClear(c->renderer);
SDL_RenderCopy(c->renderer, c->texture, NULL, &rect);
SDL_RenderPresent(c->renderer);
} static void quit(int c) {
SDL_Quit();
exit(c);
} int main(int argc, char *argv[]) { 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; struct context context; 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,
WIDTH, HEIGHT,
SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE);
if (!window) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
quit(3);
} context.renderer = SDL_CreateRenderer(window, -1, 0);
if (!context.renderer) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
quit(4);
} context.texture = SDL_CreateTexture(
context.renderer,
SDL_PIXELFORMAT_BGR565, SDL_TEXTUREACCESS_STREAMING,
VIDEOWIDTH, VIDEOHEIGHT);
if (!context.texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
quit(5);
} context.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, argv[1]);
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m); libvlc_video_set_callbacks(mp, lock, unlock, display, &context);
libvlc_video_set_format(mp, "RV16", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH*2);
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_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) { context.n++; } SDL_Delay(1000/10);
} // 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(context.mutex);
SDL_DestroyRenderer(context.renderer); quit(0); return 0;
}
显示上是黑屏。没有视频显示。
后修改代码测试:
将struct context context; 放到全局。在display回调里面用全局render fill rect。在main循环里面也用同样的代码画方框。结果main中的方框可以画出。从vlc回调回的display画方框无法显示。
#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 WIDTH 640
#define HEIGHT 480 #define VIDEOWIDTH 320
#define VIDEOHEIGHT 240 struct context {
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_mutex *mutex;
int n;
}; struct context context; // VLC prepares to render a video frame.
static void *lock(void *data, void **p_pixels) { struct context *c = &context; 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 = &context; 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);
} void draw(SDL_Rect *rect) {
SDL_SetRenderDrawColor(context.renderer, rand() % 240, rand() % 240, rand() % 240, 0);
// SDL_RenderClear(context.renderer);
// SDL_RenderCopy(context.renderer, context.texture, NULL, rect);
SDL_RenderFillRect(context.renderer, rect); } // VLC wants to display a video frame.
static void display(void *data, void *id) { printf("================================\n");
SDL_Rect rect;
rect.w = VIDEOWIDTH;
rect.h = VIDEOHEIGHT;
rect.x = 0;
rect.y = 0;
draw(&rect);
SDL_RenderPresent(context.renderer);
SDL_Delay(3000);
} static void quit(int c) {
SDL_Quit();
exit(c);
} int main(int argc, char *argv[]) { libvlc_instance_t *libvlc;
libvlc_media_t *m;
libvlc_media_player_t *mp;
char const *vlc_argv[] = { "-vvv", "--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, WIDTH, HEIGHT,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (!window) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
quit(3);
} context.renderer = SDL_CreateRenderer(window, 1, 0);
if (!context.renderer) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
quit(4);
} context.texture = SDL_CreateTexture(context.renderer, SDL_PIXELFORMAT_BGR565, SDL_TEXTUREACCESS_STREAMING, VIDEOWIDTH, VIDEOHEIGHT);
if (!context.texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
quit(5);
} context.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, &context);
libvlc_video_set_format(mp, "RV16", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 2);
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_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) {
context.n++;
} SDL_Rect rect;
rect.w = VIDEOWIDTH;
rect.h = VIDEOHEIGHT;
rect.x = VIDEOWIDTH;
rect.y = VIDEOHEIGHT;
draw(&rect);
SDL_RenderPresent(context.renderer); SDL_Delay(3000);
} // 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(context.mutex);
SDL_DestroyRenderer(context.renderer); quit(0); return 0;
}
单步跟踪后,发现render infor里面是opengl。将
context.renderer = SDL_CreateRenderer(window, -1, 0);
改成context.renderer = SDL_CreateRenderer(window, 1, 0);后,可以正常播放。
可以打印出所有 render 信息:
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);
}
————————————————————————————
When you build SDL2, make sure that when you run the initial cmake
step that all the video options are marked as ON, including
VIDEO_OPENGL and VIDEO_X11_*.
A quick way to make sure you've got all the dependencies you need is
to run "sudo apt-get build-dep libsdl1.2"; this installs the list of
build prerequisites for Ubuntu's SDL 1.2 package, which are more or
less unchanged for SDL2. I believe it's libgl1-mesa-dev which contains
the OpenGL headers.
sudo apt-get purge unity unity-2d unity-2d-common unity-2d-panel unity-2d-shell unity-2d-spread unity-asset-pool unity-common unity-lens-applications unity-lens-files unity-lens-music unity-lens-video unity-scope-musicstores unity-scope-video-remote unity-services indicator-messages indicator-status-provider-mc5 appmenu-qt appmenu-gtk appmenu-gtk3 lightdm unity-greeter overlay-scrollbar zeitgeist zeitgeist-core zeitgeist-datahub activity-log-manager-common activity-log-manager-control-center
ensure that SDL2 has full OpenGL and X support
sudo apt install build-essential xorg-dev libudev-dev libts-dev libgl1-mesa-dev libglu1-mesa-dev libasound2-dev libpulse-dev libopenal-dev libogg-dev libvorbis-dev libaudiofile-dev libpng12-dev libfreetype6-dev libusb-dev libdbus-1-dev zlib1g-dev libdirectfb-dev
VLC 源码编译参考:
sudo apt-get install git libtool build-essential pkg-config autoconf
sudo apt-get build-dep vlc
SDL2.0 VLC ubuntu安装和黑屏问题的更多相关文章
- ubuntu 安装遇到黑屏
1.安装了ubuntu之后,进入登录页面,然后用输入密码后就黑屏了,按ctrl+alt+f1都没用,也进不去命令界面,查找资料后发现是必须在虚拟机->设置->硬件->显示器,上把加速 ...
- ubuntu 16.04(Windows 10双系统+grub引导)无法进入tt1~tt6(NVIDIA驱动安装相关-黑屏,login loop,分辨率)
目录 前言回顾 最终解决: 0.关闭x服务 1.禁用nouveau 2.加入 3.更新 4.查找匹配驱动 5.选择推荐版本 6.等待安装后重启,nvidia-smi查看是否安装成功,或者lsmod | ...
- 安装ubuntu后启动黑屏
我是在windows7上的一个空暇盘上安装ubuntu 14.安装后重新启动没有ubuntu的启动项,然后用easybcd生成启动项,重新启动发现果然有,可是选择之后黑屏. 百度半天无果.后来无意发现 ...
- ubuntu VNC server 黑屏 yum源更新(ubuntu16.04)
更新yum源,备份/etc/apt/sources.list root@mgw-virtual-machine:~# nano /etc/apt/sources.list #添加源 # deb c ...
- VMware学习笔记之在虚拟机中使用Ghost系统盘安装xp黑屏卡在光标闪无法进入系统
使用ghost安装后,无法进入系统,卡在光标闪动,请参考如下: https://www.cnblogs.com/mq0036/p/3588058.html https://wenku.baidu.co ...
- ubuntu黑屏无法进入系统【Recovery Mode急救】
一.问题 前言:因为一次美化配置ubuntu导致系统启动黑屏,无法进入系统.之前并没有系统备份,后果严重还好修复了,记录下修复步骤备用. 事件:就是因为修改了 /usr/share/gnome-sh ...
- Ubuntu 16.04+GTX970 黑屏无法安装解决方法
参考http://www.linuxidc.com/Linux/2017-01/139318.htm http://blog.sciencenet.cn/blog-655584-877622.html ...
- Y460 安装ubuntu 12.04系统黑屏,登录界面黑屏
ubuntu 12.04系统黑屏,登录界面黑屏,但是命令行界面可以登录,也可以正常使用,当时在装CVS,装完重启就这样了,可能是因为前一天装更新时,突然断电导致图形界面损坏,参考他人方法,终于修复,总 ...
- win7下用U盘装ubuntu双系统 安装完后进入ubuntu黑屏光标问题
背景:原有win7系统,电脑中有ssd固态硬盘和电脑自带硬盘,win7是装在ssd盘上的 U盘安装ubuntu:已有之前保存的ubunbu镜像文件.iso U盘一块至少1G(我的是4G),将U盘资料备 ...
随机推荐
- BTrace 初探
BTrace 是一款java诊断工具,在解决现场问题的时候非常有用. 今天使用的时候碰到几个坑,先记录一下. 下载下来以后直接运行报错 root@iZ2ze89756yjbvq7le6obdZ:~/b ...
- jdbc操作根据bean类自动组装sql,天啦,我感觉我实现了hibernate
场景:需要将从ODPS数仓中计算得到的大额可疑交易信息导入到业务系统的mysql中供业务系统审核.最简单的方式是用阿里云的组件自动进行数据同步了.但是本系统是开放是为了产品化,要保证不同环境的可移植性 ...
- LeetCode之Add Two Numbers
Add Two Numbers 方法一: 考虑到有进位的问题,首先想到的思路是: 先分位求总和得到 totalsum,然后再将totalsum按位拆分转成链表: ListNode* addTwoNum ...
- Week 3 结对编程
Group: 杜正远 潘礼鹏 结对编程: 优点: 集体荣誉感.你们已经是一个集体了,一定得为对方着想负责. 1.看对方的代码,彼此会互相学习到一些奇妙的方法. 2.结对编程能把两个事情分开,降低复杂度 ...
- 软件工程实践作业2 --梭哈游戏(java) 实践报告
一,题目简介: 1.创建一副扑克牌 7------k 加入到集合对象中2.对扑克牌洗牌3.定义参与游戏的玩家的人,通过键盘输入,限定人数2-54.人数符合要求继续执行,不符合退出5.对玩家发牌,每个人 ...
- Maven遇到github引用的项目有bug怎么办?
Maven遇到github引用的项目有bug,自己想要修复/作者已经修复了但是还没有版本出来. 一个maven的做法 git clone 该项目(可能直接下载zip比较快). 在项目中mvn inst ...
- Beta之后的想法
软件工程如果没选实践,单纯在理论课上面对教条化的理论,这些理论都是很有指导意义的,但没有实践课带来的切实的多人团队合作开发项目的实际体会,很难能领会到其中的深意.知行合一,才能发现软件工程里的知识都是 ...
- spring mvc的工作原理
该文转载自:http://blog.csdn.net/u012191627/article/details/41943393 SpringMVC框架介绍 1) spring MVC属于SpringFr ...
- 6-Python3从入门到实战—基础之数据类型(元组-Tuple)
Python从入门到实战系列--目录 元组的定义 定义元组只需要在括号中添加元素,并使用逗号隔开即可 tup = ('Python','Java','C++','Kotlin') 元组与列表的区别 P ...
- shell脚本--循环结构
shell的循环结构有while和for两种 for循环 #!/bin/bash #文件名:test.sh i=4 for i in 2 4 6 8 10 do echo $i done echo $ ...