I'm trying to get frames from video stream and use them as OpenCV Mat, but I have encountered a problem.
I don't know the resolution my video stream will have so I use
libvlc_video_set_format_callbacks
but then, after video starts playing, I hear audio, but I'm not getting an image, instead I get errors:
Bad dst image pointers.
Here's my code:
struct ctx
{
unsigned char *pixeldata;
std::mutex imagemutex;
};
static void *lock(void *data, void **p_pixels)
{
struct ctx *ctx = reinterpret_cast<struct ctx *>(data);
ctx->imagemutex.lock();
*p_pixels = ctx->pixeldata;
return NULL;
}
static void unlock(void *data, void *id, void *const *p_pixels)
{
struct ctx *ctx = reinterpret_cast<struct ctx *>(data);
ctx->imagemutex.unlock();
assert(id == NULL);
}
unsigned setup(void **opaque, char *chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines)
{
struct ctx *callback = reinterpret_cast<struct ctx *>(*opaque);
unsigned nWidth = (*width);
unsigned nHeight = (*height);
(*pitches) = nWidth * 3;
(*lines) = nHeight;
chroma = (char *)"RV24";
callback->pixeldata = new unsigned char[nWidth*nHeight*3];
return 1;
}
int main(int argc, char *argv[])
{
libvlc_instance_t *vlcInstance;
libvlc_media_player_t *_player;
libvlc_media_t *_media;
const char * const vlc_args[] = {
"-I", "dummy", // Don't use any interface
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // Log anything
"--verbose=2", // Be much more verbose then normal for debugging purpose
};
vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
_media = libvlc_media_new_location(vlcInstance , "rtsp://address");
_player = libvlc_media_player_new_from_media(_media);
struct ctx *callback = new struct ctx;
libvlc_video_set_callbacks(_player, lock, unlock, 0, callback);
libvlc_video_set_format_callbacks(_player, setup, 0);
libvlc_media_player_play(_player);
}
If I won't use libvlc_video_set_format_callbacks(_player, setup, 0); but instead set fixed parameters, eg. libvlc_video_set_format(_player, "RV24", 720, 404, 720 * 3); it works fine. Any idea what might be a problem?
Actually it was simple and stupid mistake.
Line:
chroma = (char *)"RV24";
needs to be replaced by:
memcpy(chroma, "RV24", 4);
Related
I have an app, running on Linux, which is comprised of a VkMainWindow and several VkWindows. The desired behavior is to keep the VkMainWindow always on the bottom (and hence, all the VkWindows always on top of the VkMainWindow). The existing code works as advertised on KDE, but the customer decided it needs to run under MWM. Running under MWM, the VkMainWindow raises above the VkWindows. Any ideas?
VkMainWindow:
MainWindow::MainWindow(MyContainer const &container, ArgList args, Cardinal argc)
:
BaseWindow("My Base Window", args, argc,
_statusWindow(new StatusWindow(container)),
m_helpDialog(new MainHelpDialog),
m_container(container),
m_frame(nullptr),
m_form(nullptr),
_button1(nullptr),
_widget1(nullptr),
m_button2(nullptr),
m_widget2(nullptr),
m_button2(nullptr),
m_widget3(nullptr),
m_button3(nullptr),
m_button4(nullptr),
m_button5(nullptr),
m_widget4(nullptr),
_label1(nullptr),
_label2(nullptr),
_label3(nullptr),
_label4(nullptr),
_label5(nullptr),
_label6(nullptr),
_label7(nullptr)
{
Display *mainDisplay;
mainDisplay = XOpenDisplay(0);
if (mainDisplay)
{
m_width = m_mainWindowWidth = 1280;
m_height = m_mainWindowHeight = 1024;
XCloseDisplay(mainDisplay);
}
XtVaSetValues(m_shellWidget, XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE, XmNx, 0, XmNy, 0, NULL);
m_configFile = currentWorkspace;
}
VkWindows:
BaseWindow::BaseWindow(string const &name, ArgList args, Cardinal argc,
unsigned int createOptions, bool createTabStack, bool removeCornerFunctions, bool scrollable, bool workspaceConfigurable)
:
VkWindow(name.c_str(), args, argc), _mainForm(0), _mainOffset(
MAIN_OFFSET), _buttonSpacing(BUTTON_SPACING), _createOptions(createOptions),
_createTabStack(createTabStack), _statusText(0), m_buttonBoxForm(0), m_helpForm(0),
m_okButton(0), m_cancelButton(0), m_applyButton(0), m_applyCb(0), m_okCb(0), m_cancelCb(0),
m_screenId(INVALID_SCREEN_ID), m_previousTab(0), _tabStack(0), _tabForm(0), m_initialized(false),
m_shellWidget(0), m_clipWindow(0), _isScrollable(scrollable), m_isValid(true), m_statusOnly(false),
m_validateOnOk(true), m_validateOnApply(true), m_widgetsMapped(false), m_fooLocked(false), m_isLocked(false),
m_currentSize(FULL), m_lastSize(0)
{
Widget parent = mainWindowWidget();
XtSetValues(parent, args, argc);
m_shellWidget = parent;
while (m_shellWidget && !XtIsShell(m_shellWidget))
{
m_shellWidget = XtParent(m_shellWidget);
}
if (removeCornerFunctions)
{
if (m_shellWidget)
{
XtVaSetValues(m_shellWidget,
XmNmwmFunctions, 22,
// MWM_FUNC_RESIZE | MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_CLOSE,
NULL);
XtAddEventHandler(m_shellWidget, StructureNotifyMask, false, resizeCb, this);
}
}
...
}
Main:
int main(int argc, char **argv)
{
...
Cardinal ac;
Arg args[20];
std::string title("My Client");
XrmOptionDescRec *optionList = NULL;
int numOptions = 0;
app = new VkApp(const_cast<char*>(title.c_str()), &argc, argv, optionList, numOptions);
...
app->run();
...
return (0);
}
The solution is to call VkWindow:lower() in the event loop for the main window.
I implemented the audio playback successfully but a frequent problem comes up where a sharp auditory glitch occurs when "next song" is clicked from JAVA. This sound glitch elapses approx. around 100ms. And occurs more frequently before the next song starts playing.
Please importantly note this:
I call "delete" on every variable class and "free" stereobuffers (setdestroyallthreads) at the end of every playback, then "process"(process) method before every playback starts.
From Java, the transition sequence looks like this;
PlayerClass.setDestroyAllThreads( );
PlayerClass.open("new_path", sampleRate, bufferSize );
PlayerClass.play( );
Here is my snippet;
static void playerEventCallbackA(void *clientData, SuperpoweredAdvancedAudioPlayerEvent event, void * __unused value) {
if (event == SuperpoweredAdvancedAudioPlayerEvent_LoadSuccess) {
SuperpoweredAdvancedAudioPlayer *player = *((SuperpoweredAdvancedAudioPlayer **)clientData);
}else if (event == SuperpoweredAdvancedAudioPlayerEvent_EOF) {
playerBass->pause();
playerB->pause();
finishedPlaying = true;
}else if (event == SuperpoweredAdvancedAudioPlayerEvent_LoadError) {
};
}
static bool audioProcessing(void *clientdata, short int *audioIO, int numberOfSamples, int __unused samplerate) {
return ((Eve *)clientdata)->process(audioIO, (unsigned int)numberOfSamples);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
Eve::Eve(const char *path,unsigned int samplerate,unsigned int buffersize) : activeFx(0), crossValue(0.0f), volBass(1.0f * headroom), volB(1.0f * headroom) {
stereoBuffer = (float *)memalign(16,(buffersize + 16) * sizeof(float) * 2);
playerBass = new SuperpoweredAdvancedAudioPlayer(&playerBass , playerEventCallbackA, samplerate, 0);
playerB = new SuperpoweredAdvancedAudioPlayer(&playerB, playerEventCallbackB, samplerate, 0);
filterb = new SuperpoweredFilter(SuperpoweredFilter_Resonant_Lowpass, samplerate*0.98);
spatializer = new SuperpoweredSpatializer(samplerate);
playerBass->open(path);
playerB->open(path);
finishedPlaying = false;
playerBass->syncMode = playerB->syncMode = SuperpoweredAdvancedAudioPlayerSyncMode_TempoAndBeat;
audioSystem = new SuperpoweredAndroidAudioIO(samplerate, buffersize, false, true, audioProcessing, this, -1, SL_ANDROID_STREAM_MEDIA, buffersize * 2);
}
Eve::~Eve() {
delete playerBass;
delete playerB;
delete spatializer;
delete filterb;
delete audioSystem;
finishedPlaying = false, playingNow = false, pausedNow = false, processed = false, hd = false;
}
void Eve::onPlay() {
playerBass->play(false);
playerB->play(false);
playingNow = true;
}
void Eve::setBassValue(int bass) {
filterb->setResonantParameters(floatToFrequency(0.2f),ebass);
filterb->enable(true);
}
void Eve::setDestroyAllThreads(){
delete playerBass;
delete playerB;
delete spatializer;
delete filterb;
delete audioSystem;
finishedPlaying = false, playingNow = false, pausedNow = false, processed = false, hd = false;
}
bool Eve::process(short int *output, unsigned int numberOfSamples) {
bool masterIsA = (crossValue <= 0.5f);
double masterBpm = masterIsA ? playerBass->currentBpm : playerB->currentBpm;
double msElapsedSinceLastBeatA = playerBass->msElapsedSinceLastBeat;
bool silence = !playerBass->process(stereoBuffer, false, numberOfSamples*1, volBass, masterBpm, playerB->msElapsedSinceLastBeat);
processed = true;
filterb->process(stereoBuffer, stereoBuffer, numberOfSamples);
if (playerB->process(stereoBuffer, !silence, numberOfSamples, volB, masterBpm, msElapsedSinceLastBeatA)) silence = false;
spatializer->process(stereoBuffer, stereoBuffer, (float*)output, (float*)output, numberOfSamples, true);
SuperpoweredFloatToShortInt(stereoBuffer, output, numberOfSamples);
return !silence;
}
static Eve *eve = NULL;
extern "C" JNIEXPORT void Java_com_EvePlayer_Eve(JNIEnv *javaEnvironment, jobject self, jstring songPath, jint samplerate, jint buffersize) {
const char *path = javaEnvironment->GetStringUTFChars(songPath, JNI_FALSE);
eve = new Eve(path,(unsigned int)samplerate,(unsigned int)buffersize);
javaEnvironment->ReleaseStringUTFChars(songPath, path);
}
extern "C" JNIEXPORT void Java_com_EvePlayer_SetTempFolder(JNIEnv *javaEnvironment, jobject __unused obj, jstring path) {
const char *str = javaEnvironment->GetStringUTFChars(path, 0);
SuperpoweredAdvancedAudioPlayer::setTempFolder(str);
javaEnvironment->ReleaseStringUTFChars(path, str);
}
extern "C" JNIEXPORT void Java_com_EvePlayer_evePlay(JNIEnv *javaEnvironment, jobject self){
eve->onPlay();
}
extern "C" JNIEXPORT void Java_com_EvePlayer_setDestroyAllThreads(JNIEnv *javaEnvironment, jobject self) {
eve->setDestroyAllThreads();
}
Destroy the audio I/O ("audioSystem" in your code) first. The audio I/O invokes your audio processing callback periodically, so it needs to be destroyed first, it will use deleted objects otherwise.
I'm having trouble displaying an image (PNG extracted with libpng) into an XCB window, it is always entirely empty/white. I'm pretty sure the PNG extraction is correct since I can perfectly re-write it into another file.
I've tried everything I found (explanations, guides, documentation) and I'm running out of ideas:
Creating an xcb_pixmap_t calling xcb_create_pixmap_from_bitmap_data() with the data taken from the PNG, then calling xcb_copy_area() into the EXPOSE part of the event loop.
Creating an xcb_image_t* calling xcb_image_create_from_bitmap_data() then trying to map it to the window with xcb_image_put(). I've even tried to display each pixel with xcb_image_put_pixel(), but without success.
Code sample:
xcb_pixmap_t pixmap = xcb_create_pixmap_from_bitmap_data(
connection, // xcb_connect(0, 0) (type: xcb_connection_t*)
window, // xcb_generate_id(connection) (type: xcb_window_t)
img.getData(), // uint8_t*
img.getWidth(), // 128
img.getHeight(), // 128
img.getBitDepth(), // 8
screen->black_pixel, // screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data (type: xcb_screen_t*)
screen->white_pixel,
nullptr);
// "img" is an instance of my own custom class, result of PNG reading
xcb_image_t* image = xcb_image_create_from_bitmap_data(
img.getData(),
img.getWidth(),
img.getHeight()); // image->data seems fine
xcb_image_put(connection,
window,
graphicsContext,
image, 0, 0, 0); // This does nothing
for (unsigned int i = 0; i < screen->height_in_pixels; ++i)
for (unsigned int j = 0; j < screen->width_in_pixels; ++j)
xcb_image_put_pixel(image, j, i, 0); // Displays nothing
[...]
// Into event loop
case XCB_EXPOSE: {
xcb_expose_event_t* exposeEvent = reinterpret_cast<xcb_expose_event_t*>(event);
xcb_copy_area(connection,
pixmap,
window,
graphicsContext,
exposeEvent->x, exposeEvent->y, // Top left x & y coordinates of the source's region to copy
exposeEvent->x, exposeEvent->y, // Top left x & y coordinates of the destination's region to copy to
exposeEvent->width,
exposeEvent->height);
xcb_flush(connection);
break;
}
From the examples I found I saw that it didn't need a colormap, but could that be the case? Could anyone tell me where I've gone wrong?
I threw together a simple xcb image viewer about 4 years ago, but just noticed this question, so apologies for the necromancy.
It uses xcb_image, stb_image and nanosvg, but compiles to a relatively small static binary (with a musl or uclibc toolchain)
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#define STBI_NO_HDR
#define STBI_NO_LINEAR
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define NANOSVG_IMPLEMENTATION
#include "nanosvg.h"
#define NANOSVGRAST_IMPLEMENTATION
#include "nanosvgrast.h"
int main(int argc, char **argv){
xcb_connection_t *c = xcb_connect(0, 0);
xcb_screen_t *s = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
int w, h, n,
depth = s->root_depth,
win_class = XCB_WINDOW_CLASS_INPUT_OUTPUT,
format = XCB_IMAGE_FORMAT_Z_PIXMAP;
xcb_colormap_t colormap = s->default_colormap;
xcb_drawable_t win = xcb_generate_id(c);
xcb_gcontext_t gc = xcb_generate_id(c);
xcb_pixmap_t pixmap = xcb_generate_id(c);
xcb_generic_event_t *ev;
xcb_image_t *image;
NSVGimage *shapes = NULL;
NSVGrasterizer *rast = NULL;
char *data = NULL;
unsigned *dp;
size_t i, len;
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
value_mask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS,
values[] = { s->black_pixel, value_mask };
if (argc<2) return -1;
if ((data = stbi_load(argv[1], &w, &h, &n, 4)))
;
else if ((shapes = nsvgParseFromFile(argv[1], "px", 96.0f))) {
w = (int)shapes->width;
h = (int)shapes->height;
rast = nsvgCreateRasterizer();
data = malloc(w*h*4);
nsvgRasterize(rast, shapes, 0,0,1, data, w, h, w*4);
}else return -1;
for(i=0,len=w*h,dp=(unsigned *)data;i<len;i++) //rgba to bgra
dp[i]=dp[i]&0xff00ff00|((dp[i]>>16)&0xFF)|((dp[i]<<16)&0xFF0000);
xcb_create_window(c,depth,win,s->root,0,0,w,h,1,win_class,s->root_visual,mask,values);
xcb_create_pixmap(c,depth,pixmap,win,w,h);
xcb_create_gc(c,gc,pixmap,0,NULL);
image = xcb_image_create_native(c,w,h,format,depth,data,w*h*4,data);
xcb_image_put(c, pixmap, gc, image, 0, 0, 0);
xcb_image_destroy(image);
xcb_map_window(c, win);
xcb_flush(c);
while ((ev = xcb_wait_for_event(c))) {
switch (ev->response_type & ~0x80){
case XCB_EXPOSE: {
xcb_expose_event_t *x = (xcb_expose_event_t *)ev;
xcb_copy_area(c,pixmap,win,gc,x->x,x->y,x->x,x->y,x->width,x->height);
xcb_flush(c);
}break;
case XCB_BUTTON_PRESS: goto end;
default: break;
}
}
end:
xcb_free_pixmap(c, pixmap);
xcb_disconnect(c);
return 0;
}
I want to take images from my IP camera. I work in visual studio 2012.
At first, I've used openCV to connect to it. Here is my code.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
int main()
{
cv::VideoCapture vcap;
const std::string videoStreamAddress = "rtsp://admin:admin#192.168.0.120/snl/live/1/1/stream1.cgi";
if (!vcap.open(videoStreamAddress))
{
printf("camera is null\n");
return -1;
}
else
{
cv::Mat image;
cv::namedWindow("Video", CV_WINDOW_AUTOSIZE);
while(1)
{
vcap >> image;
imshow("Video", image);
if(cv::waitKey(10) == 99 ) break;
}
}
cv::waitKey(1000);
return 0;
}
It shows the stream. But some of its images have distortion. I think it is because of decoding error. The error is this:
[h264 # 00decfe0] error while decoding MB 37 22, bytestream <td>
To solve this error I write another code inspired from http://answers.opencv.org/question/65932/how-to-stream-h264-video-with-rtsp-in-opencv-partially-answered/ . It uses libVLC to get the stream. here is my second code.
#include "opencv2/opencv.hpp"
#include "vlc/libvlc.h"
#include "vlc/libvlc_media.h"
#include "vlc/libvlc_media_player.h"
#include "ctime"
#include "Windows.h"
#include "string"
struct ctx
{
IplImage* image;
HANDLE mutex;
uchar* pixels;
};
void *lock(void *data, void**p_pixels)
{
struct ctx *ctx = (struct ctx*)data;
WaitForSingleObject(ctx->mutex, INFINITE);
*p_pixels = ctx->pixels;
return NULL;
}
void display(void *data, void *id){
(void) data;
assert(id == NULL);
}
void unlock(void *data, void *id, void *const *p_pixels){
struct ctx *ctx = (struct ctx*)data;
/* VLC just rendered the video, but we can also render stuff */
uchar *pixels = (uchar*)*p_pixels;
cvShowImage("image", ctx->image);
ReleaseMutex(ctx->mutex);
assert(id == NULL); /* picture identifier, not needed here */
}
int main()
{
// VLC pointers
libvlc_instance_t *vlcInstance;
libvlc_media_player_t *mp;
libvlc_media_t *media;
const char * const vlc_args[] = {
"-I", "dummy", // Don't use any interface
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // Log anything
"--verbose=2", // Be much more verbose then normal for debugging purpose
};
vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
media = libvlc_media_new_location(vlcInstance, "rtsp://admin:admin#192.168.21.120/snl/live/1/1/stream1.cgi");
mp = libvlc_media_player_new_from_media(media);
libvlc_media_release(media);
context->mutex = CreateMutex(NULL, FALSE, NULL);
context->image = new Mat(VIDEO_HEIGHT, VIDEO_WIDTH, CV_8UC3);
context->pixels = (unsigned char *)context->image->data;
// show blank image
imshow("test", *context->image);
libvlc_video_set_callbacks(mp, lock, unlock, display, context);
libvlc_video_set_format(mp, "RV24", VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_WIDTH * 24 / 8); // pitch = width * BitsPerPixel / 8
int ii = 0;
int key = 0;
while(key != 27)
{
ii++;
if (ii > 5)
{
libvlc_media_player_play(mp);
}
float fps = libvlc_media_player_get_fps(mp);
//printf("fps:%f\r\n",fps);
key = waitKey(100); // wait 100ms for Esc key
}
libvlc_media_player_stop(mp);
return 0;
}
But it has nearly the same error. Some pixels losts and images has distortion.
[h264 # 02a3b660] Frame num gap 6 4
[h264 # 02a42220] no picture oooo
How Can I fix this problem? The problem rooted from my code and the using libraries or my camera?
im working on some project like you,this error is because openCVcant deal with H264 , i suggest you use VLC library as mentioned in here,and cause you use VS2012 you can use VLCDotNetin your project.other options is FFmpeg,aforgethat are compatible with H264.
I want to play video file, that i obtained from IP-camera (H264-codec) using libVLC and OpenCV, so i took the code from this post, then created project in VS 2010, and put my mp4 file into project folder ("5.mp4"). When i started it - i got this errors:
main error: open of `5.mp4' failed
main error: Your input can't be opened
main error: VLC is unable to open the MRL '5.mp4'. Check the log for details.
Here's my code:
#include <vlc/vlc.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
using namespace cv;
using namespace std;
struct VideoDataStruct {
int param;
};
int done = 0;
libvlc_media_player_t *mp;
unsigned int videoBufferSize = 0;
uint8_t *videoBuffer = 0;
void cbVideoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size) {
// Locking
if (size > videoBufferSize || !videoBuffer)
{
printf("Reallocate raw video buffer\n");
free(videoBuffer);
videoBuffer = (uint8_t *) malloc(size);
videoBufferSize = size;
}
*pp_pixel_buffer = videoBuffer;
}
void cbVideoPostrender(void *p_video_data, uint8_t *p_pixel_buffer, int width, int height, int pixel_pitch, int size, int64_t pts) {
// Unlocking
//CloseHandle(hMutex);
}
static void handleEvent(const libvlc_event_t* pEvt, void* pUserData) {
libvlc_time_t time;
switch(pEvt->type)
{
case libvlc_MediaPlayerTimeChanged:
time = libvlc_media_player_get_time(mp);
printf("MediaPlayerTimeChanged %lld ms\n", (long long)time);
break;
case libvlc_MediaPlayerEndReached:
printf ("MediaPlayerEndReached\n");
done = 1;
break;
default:
printf("%s\n", libvlc_event_type_name(pEvt->type));
}
}
int main(int argc, char* argv[]) {
// VLC pointers
libvlc_instance_t *inst;
libvlc_media_t *m;
void *pUserData = 0;
VideoDataStruct dataStruct;
// VLC options
char smem_options[1000];
// RV24
sprintf(smem_options
, "#transcode{vcodec=RV24}:smem{"
"video-prerender-callback=%lld,"
"video-postrender-callback=%lld,"
"video-data=%lld,"
"no-time-sync},"
, (long long int)(intptr_t)(void*)&cbVideoPrerender
, (long long int)(intptr_t)(void*)&cbVideoPostrender
, (long long int)(intptr_t)(void*)&dataStruct
);
const char * const vlc_args[] = {
"-I", "dummy", // Don't use any interface
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // Log anything
"--verbose=1", // Be verbose
"--sout", smem_options // Stream to memory
};
// We launch VLC
inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
/* Create a new item */
m = libvlc_media_new_location(inst, "5.mp4");
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media (m);
libvlc_event_manager_t* eventManager = libvlc_media_player_event_manager(mp);
libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged, handleEvent, pUserData);
libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, handleEvent, pUserData);
libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged, handleEvent, pUserData);
libvlc_video_set_format(mp, "RV24", 1280, 720, 1280* 3 );
/* play the media_player */
libvlc_media_player_play (mp);
while(1)
{
if(videoBuffer) // Check for invalid input
{
// CV_8UC3 = 8 bits, 3 chanels
Mat img = Mat(Size(1280, 720), CV_8UC3, videoBuffer);
// cvtColor(img, img, CV_RGB2BGR);
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", img); // Show our image inside it.
}
}
libvlc_release (inst);
}
I guess, that is easy to fix, but i could't find any information at the Internet. I also tryied to put it into "C:\5.mp4", but i got the same errors. Thanks for any help.
EDIT:
Ok, so i fixed this issue, i need to put file:/// before "5.mp4", now my video is playing, but it looks like this:
EDIT02
Ok, with "*.avi" everything looks good, so i guess problem with this file - i recorded it frop IP-camera, using VLC, and saved it into *.mp4
Ok, so i found the problem, i made a mistake with video resolution, original resolution is 2560x1536, so when i put libvlc_video_set_format(mp,2560,1536,2560 *3); my picture looks fine, so after i pass it to OpenCV i could resize it.