1. 程式人生 > >VLC播放攝像頭或者網路攝像頭通過rtsp流讀取視訊

VLC播放攝像頭或者網路攝像頭通過rtsp流讀取視訊

#include <stdio.h>  
#include <stdint.h>  
#include <math.h>  
#include <stdlib.h>  
#include <assert.h>  


#define SDL_MAIN_HANDLED
#include "SDL.h"
#include "SDL_mutex.h"
#include <vlc/vlc.h>  


#pragma comment(lib,"libvlc.lib")
#pragma comment(lib,"libvlccore.lib")
#pragma comment(lib,"SDL2.lib")
#pragma comment(lib,"SDL2main.lib")
#pragma comment(lib,"SDL2test.lib")






#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;
};




//const char* rtspAddress = "rtsp://admin:
[email protected]
";
const char* rtspAddress = "dshow://";


// 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.
"--rtsp-frame-buffer-size=1000000",   //RTSP幀緩衝大小,預設大小為100000
 // 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");
m = libvlc_media_new_location(libvlc, rtspAddress);


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_video_set_format(mp, "RV24", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 3);
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播放攝像頭或者網路攝像頭通過rtsp讀取視訊

#include <stdio.h>   #include <stdint.h>   #include <math.h>   #include <stdlib.h>   #include <assert.h>  

安卓端/iOS端如何播放4K分辨率的RTMP/RTSP

rtmp hub hls live tex 水平 rtm 分享 色彩 關於4K分辨率 4K分辨率即4096×2160的像素分辨率,它是2K投影機和高清電視分辨率的4倍,屬於超高清分辨率。在此分辨率下,觀眾將可以看清畫面中的每一個細節,每一個特寫。影院如果采用驚人的4096×

通過FFmpeg將rtsp攝像頭視訊轉碼為rtmp播放

注意:用這種方式可以顯示攝像頭視訊,但是存在諸多問題,無法正常投入使用,包括卡頓跟延遲,請想要借鑑的朋友慎重使用。        前幾天經理給我安排了一個新任務,將網路攝像頭用rtsp協議在頁面播放,因為我以前做的是http協議的,根據攝像頭的API來實現的,

利用vlc外掛將IP攝像頭嵌入網頁和網頁播放RTSP

1. 描述  最近有一個專案需要將IP攝像機的畫面嵌入到web網頁中,考慮到減少開發成本,使用vlc外掛播放攝像頭提供的RTSP流。在videolan wiki的官網詳細介紹了關於vlc web plugin的使用方法。  有一點需要注意的是,vlc2

VLC讀取攝像頭產生RTSP,DSS主動取流轉發(一)

sdp nco con alt 分享 pad 流轉 publish enc 用VLC讀取攝像頭產生RTSP流,DSS主動取流轉發(一) 攝像機地址是192.1.101.51,VLC運行在192.1.101.77上,DSS服務器架設在192.1.101.

RTSP協議轉換RTMP協議,直播網路攝像頭

  RTSP協議也是廣泛使用的直播/點播流媒體協議,以前的專案裡實現了一個RTSP協議轉換RTMP直播協議的程式,為的是可以接收遠端裝置或伺服器的多路RTSP直播資料,實時轉換為RTMP直播協議,推送到NginxRtmp等RTMP伺服器,可以在PC上實現flash觀看RTSP直播源(比如IP

實戰深度學習OpenCV(二):讀取播放本地或者攝像頭視訊

一.讀取並播放的程式碼如下: #include "pch.h" #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #in

實戰深度學習OpenCV(二):讀取播放本地或者攝像頭的視頻

spa cor enc waitkey pen return while apt size 一.讀取並播放的代碼如下: #include "pch.h" #include <iostream> #include <opencv2/core/cor

QML播放本地視訊網路攝像頭視訊

 (1)利用定時器,通過採集影象的方式  Image{        id:img        Timer{    &n

史上最全的基於ffmpeg+sdl網路攝像頭編解碼播放資料(包含交叉編譯過程,附帶完整原始碼)

原創博文,嚴禁私自轉載,轉載請註明出處!!! 近期,由於工作需要,要在開發板上跑一個攝像頭,攝像頭款式比較老,不支援rtsp格式,所以選擇編譯ffmpeg+sdl實現軟解碼播放攝像頭,特此記錄整個編譯過程(非常之艱辛,發文留念) 在ubuntu上交叉編譯環境的搭建:因為開發板上搭建的程式的執

用ffmpeg+nginx+海康威視網路攝像頭rtsp在手機端和電腦端實現直播

原料:海康威視攝像頭,nginx伺服器,ffmpeg。首先海康威視攝像頭,它的rtsp資料流的地址為:rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream說明:userna

android錄屏直播:VLC通過rtsp協議播放android錄屏實時視訊(Java實現)

首先說下為什麼要做這樣一個東西          在上家公司的時候,作為客戶端開發,一個月要給領導演示異常app的開發成果,當時用的策略是用錄屏類軟體,錄製成mp4,然後通過投影播放mp4檔案,來給領導看。這樣做帶來的問題是,要提前準備mp4需要時間,領導想要看除了mp4外的

opencv+qt通過CGI讀取網路攝像頭

工程程式碼:http://download.csdn.net/download/mjlsuccess/9461745 網路監控攝像頭比普通攝像頭的優勢在於它有云臺,可以調整角度。這兩天老闆讓我買個網路攝像頭看看效果如何,那麼這就涉及到監控攝像頭的二次開發問題,淘寶上買的大

海康、大華、星邦網路攝像頭RTSP協議 地址與格式

一、簡介1、RTSP(Real Time Streaming Protocol)是由Real Network和Netscape共同提出的如何有效地在IP網路上傳輸流媒體資料的應用層協議。RTSP對流媒體提供了諸如暫停,快進等控制,而它本身並不傳輸資料,RTSP的作用相當於流媒

VLC 播放RTSP 抓包分析

vlc 播放rtsp 抓包分析VLC 播放RTSP視頻抓包記錄:vlc -vvv rtsp://172.16.66.22/nuc.sdpOPTIONS: OPTIONS rtsp://172.16.66.22/nuc.sdp RTSP/1.0 CSeq: 2 User-Agent: LibVLC/2.2

在ROS中使用usb網路攝像頭(usb_cam,Arch linux,ROS JADE)

如題,在做香蕉派的影象處理時需要用到usb_cam這個ros node,在ubuntu上驗證之後,打算移植到Banana Pi的Archlinux ARM的時候卻發現了一個問題:不像ubuntu可以直接apt-get到,在Arch上不論pacman還是yaourt上都搜不到這個包。無奈,

OPENCV3.0開啟攝像頭或者視訊顯示畫面

OPENCV3.0大大的簡化了視訊流的讀取,用了>>流操作符來讀取幀。 獲取攝像頭畫面: #include <opencv2/opencv.hpp> using namespace cv; int main() { VideoCapture ca

shodan 收索網路攝像頭

通過shodan 收索網路攝像頭,進行弱密碼判斷,如何登陸成功,會寫入文字中 #coding=utf-8 import shodan import requests import base64 import threading import Queue import time q=Q

使用ONVIF Device Test Tool獲取網路攝像頭的音/視訊

軟/硬體準備 1、一個網路攝像頭(IPC),品牌必須支援ONVIF協議,具體哪些品牌支援不作為本教程介紹的重點,大家可自行度娘,我知道的有品牌大華和海康威視; 2、ONVIF Device Test Tool軟體下載,筆者使用的版本為15.06, 下載地址:https://downl

Opencv讀取USB網路攝像頭無法顯示,影象為空,顯示黑色?

利用Opencv讀取電腦的攝像頭,程式碼如下,一直無法正常執行,搜尋網上的解決方案,均未解決。程式碼語法沒有錯誤,攝像頭也可以開啟,但是就是無法讀取當前幀影象 #include <opencv.hpp> using namespace cv; int main() { Vid