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=" ...
随机推荐
- Linux下DNS服务(Bind9)之Web管理利器-NamedManager部署说明
NamedManager 是一个基于Web的DNS管理系统,可用来添加.调整和删除DNS的zones/records数据.它使用Bind作为底层DNS服务,提供一个现代Ajax的Web界面,支持 IP ...
- kvm虚拟化关闭虚拟网卡virbr0的方法
我们知道:kvm虚拟化环境安装好后,ifconfig会发现多了一个虚拟网卡virbr0这是由于安装和启用了libvirt服务后生成的,libvirt在服务器(host)上生成一个 virtual ne ...
- 浏览器跨域请求之credentials
-时间起源- 前段时间,需要弄个简单的网站出来,访问远程的api服务. 我是这么做的.首先是在搭建一个nodejs服务来运行前端页面.在我请求登录的时候,能成功返回相应的成功信息.然后,当我再次请求读 ...
- C. Multiplicity
链接 [http://codeforces.com/contest/1061/problem/C] 题意 给你一个数组,让你找有多少个子串(并非连续,但相对位置不能换),满足bi%i==0; 分析 d ...
- springboot整合druid连接池、mybatis实现多数据源动态切换
demo环境: JDK 1.8 ,Spring boot 1.5.14 一 整合durid 1.添加druid连接池maven依赖 <dependency> <groupId> ...
- [转]java实现,输入数据,空格继续,回车结束输入
普通版:可输入,可输出.带详细的注释 import java.util.Scanner; public class SumDemo { public static void main(String[] ...
- JS 柯里化 (curry)
用 JS 理解柯里化 函数式编程风格,试图以函数作为参数传递(回调)和无副作用的返回函数(修改程序的状态). 很多语言采用了这种编程风格.JavaScript,Haskell,Clojure,Erla ...
- 二维数组转化为一维数组 contact 与apply 的结合
将多维数组(尤其是二维数组)转化为一维数组是业务开发中的常用逻辑,除了使用朴素的循环转换以外,我们还可以利用Javascript的语言特性实现更为简洁优雅的转换.本文将从朴素的循环转换开始,逐一介绍三 ...
- String系列-----String
jdk源码学习之String,手动实现一个String package com.amazing.jdk.string_2017_12_31; import java.io.Serializable; ...
- vue路由异步组件案例
最近研究了vue性能优化,涉及到vue异步组件.一番研究得出如下的解决方案. 原理:利用webpack对代码进行分割是异步调用组件前提.异步组件在优先级上让位同步组件.下面介绍的是怎么实现异步组件. ...