In a GUI I'm working on I intend to use VLC (axVLCplguin) to display camera feed. I want to test it with an offline video stored on my disc, however, each time I click on the button, which should start the video, I get a runtime error (caused on line VLC -> playlist -> add(path, NULL, NULL); ).
I assume, that the given MRL address - the first parameter of the method - is not in a correct format: file://C:/Users/User/Desktop/AMT.mp4
(viz.: https://wiki.videolan.org/Media_resource_locator/).
I've seen many tutorials, how to get a video feed in WinForms using the VLC plugin, but none of them had an included code in C++ (only in C#, where the simple absolute path to the video did the work).
void Grimr::MainForm::chbox_live_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
pbox_drawing->Visible = false;
if (chbox_area->Checked)
{
VLC->Visible = true;
VLC->AutoPlay = false;
String^ path = "C:\\Users\\User\\Desktop\\AMT.mp4";
VLC->playlist->add(path, NULL, NULL);
VLC->playlist->play();
}
}
Related
I am writing a C++ program using SDL 2 for the platform layer and opengl for graphics and rendering. I have a full working prototype with keyboard and mouse input. Now I am now trying to use SDL's game controller API to connect a gamepad (to replace or supplement keyboard controls). Unfortunately the controller does not seem to be recognized despite the fact that it works perfectly with other software. It's a Sony Dualshock 4 (for the Playstation 4 system). My system is Mac OS 10.9.5, and I am using SDL 2.0.5 with the official community controller database for SDL 2.0.5, which contains ps4 controller mappings:
030000004c050000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X,
4c05000000000000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X
I also added a new mapping using one of the official tools. That also loads successfully according to the relevant function call.
The following is my code, and it's about as close to a minimal example as I can get:
// in main
// window and graphics context initialization here
// initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0) {
fprintf(stderr, "%s\n", "SDL could not initialize");
return EXIT_FAILURE;
}
// load controller mappings, I tested this and 35 mappings load successfully, which is expected
SDL_GameControllerAddMappingsFromFile("./mapping/gamecontrollerdb_205.txt");
// the controller handle
SDL_GameController* controller = nullptr;
// max_joysticks is 1, which means that the device connects at least
int max_joysticks = SDL_NumJoysticks();
if (max_joysticks < 1) {
return EXIT_FAILURE;
}
// this returns, which means that the joystick exists, but it isn't recognized as a game controller.
if (!SDL_IsGameController(0)) {
return EXIT_FAILURE;
}
// I never get passed this.
controller = SDL_GameControllerOpen(0);
fprintf(stdout, "CONTROLLER: %s\n", SDL_GameControllerName(controller));
Has anyone encountered this problem? I've done some preliminary searching as I mentioned, but it seems that usually either the number of joysticks is 0, or everything is recognized.
Also, SDL_CONTROLLERDEVICEADDED isn't firing when I connect the controller.
The controller is connected via USB before I start the program. Also, this is one of the new controllers, and I'm not sure whether the mappings work with that new one. I assume so considering that there are two distinct entries.
Thank you.
EDIT:
I double checked and the PS4 controller works fine as a joystick, but it isn't recognized as a controller, which means that the mapping is incorrect or non-existent. This may be because my controller is "version 2" of the dualshock 4, and I'm not sure whether a 2.0.5-compatible mapping was added. hmmm
The controller was recognized as a joystick but not as a controller, meaning that none of the available mappings I could find (in 2.0.5 controller mapping format) corresponded with the controller. Updating from SDL 2.0.5 to 2.0.8 also updated available mappings it seems, and now the controller is recognized as a game controller.
Note: normally it is a terrible idea to upgrade tools mid-project, but in this case it was safe to do.
I am working on a Universal Windows Platform Application (UWP) in which I am using C++ as the main language. I want to read from two cameras at the same time. One camera belongs to the Kinect RGB camera and the other to the Kinect Depth camera. So far I've managed to read from just one using this piece of code:
void SDKTemplate::Scenario4_ReproVideo::Grabar_Click(Platform::Object^
sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
CameraCaptureUI^ dialog = ref new CameraCaptureUI();
dialog->VideoSettings->Format = CameraCaptureUIVideoFormat::Mp4;
Windows::Foundation::Collections::IPropertySet^ appSettings = ApplicationData::Current->LocalSettings->Values;
concurrency::task<StorageFile^>(dialog->CaptureFileAsync(CameraCaptureUIMode::Video)).then([this](StorageFile^ file) {
if (file != nullptr) {
concurrency::task<Streams::IRandomAccessStream^> (file->OpenAsync(FileAccessMode::Read)).then([this] (Streams::IRandomAccessStream^ stream){
CapturedVideo->SetSource(stream, "video/mp4");
logger->Text = "recording";
});
Windows::Foundation::Collections::IPropertySet^ appSettings = ApplicationData::Current->LocalSettings->Values;
appSettings->Insert("CapturedVideo", PropertyValue::CreateString(file->Path));
}
else {
logger->Text = "Something went wrong or was cancelled";
}
});
}
By doing this I can reliably record from one of the cameras. My problem is that I need to record from both cameras at the same time as I need the Depth and RGB to process the video.
I am new to concurrency, is there a way (the simpler the better) to achieve two recordings simultaneously?
In UWP app, we can capture photos and video using the MediaCapture class which provides functionality for capturing photos, audio, and videos from a capture device. See the topic Basic photo, video, and audio capture with MediaCapture.
We can initialize multiple MediaCapture instances then read frame by using MediaFrameReader Class. see the topic Discover and select camera capabilities with camera profiles and Process media frames with MediaFrameReader and also look into the official sample CameraFrames.
Besides, there is a similar thread about UWP multiple camera capture, you can also refer it:
Handle multiple camera capture UWP
I am trying to create a c++ windows form application in Visual Studio, which is communicating with an Arduino and controlling three LEDs with three trackBars. I managed to write the code that sends message the Arduino. But i would like to ask the Arduino about the state of the LED's when I start the program, to set the sliders at the right position.
My solutuion was to program the Arduino that if it gets the 'x1' command, it sends back the values of the LEDs (from 0-255) separated by commas. The code on the Arduino should be all right, because I used the same code to do the same thing in Qt Creator, and it worked perfectly there.
My test code works like if I click a button, it sends 'x1' command the Arduino, and in the SerialPort's DataReceived event I put the received value in a label.
There are two problems.
The first one is, even if I use Convert::ToString() or not, i get the ASCII code of the numbers and the commas. (eg.: for 0,0,0, I get on the screen: 484448444844)
The second one is that I don't always get the whole message. Sometimes the last 2-3 character is missing, and if I click the button again it shows up at the beginning of the new message. (I clear the label every time I click the button and the DataReceived event appends to it). I understand that sometimes some parts are delayed, but shouldn't theese parts trigger the DataReceived event when arrive, and show up at the end of the message?
How could I get rid of theese problems?
The code of the DataReceived event:
private: System::Void serialPort1_DataReceived(System::Object^ sender,
System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
//Try to read from serial
for (int i = 0; i < serialPort1->BytesToRead; i++)
{
lblTest->Text += Convert::ToString(serialPort1->ReadByte());
}
}
The code of the button:
private: System::Void btnTest_Click(System::Object^ sender,
System::EventArgs^ e) {
lblTest->Text = String::Empty;
serialPort1->Write("x1");
}
The Way I send message:
private: void sendSerialData(String^ data)
{
if (serialPort1->IsOpen)
{
serialPort1->Write(data);
lblMessage->Text = "Message sent to device: " + data;
}else {
lblMessage->Text = "Message transmission failed!";
}
}
And here is how i send these data from the Arduino to PC:
Serial.print(redVal);
Serial.print(',');
Serial.print(greenVal);
Serial.print(',');
Serial.print(blueVal);
Serial.print(',');
Serial.flush();
I would be very happy to find some tutorial about the use of SerialPort other than the MSDN website, because it is just listing the properties and the example code is not so easily understandable. And for some reason I cannot find too much for c++, only for c#, but I cannot switch to c# because of a later project.
Thanks in advance for any help.
I have a program that records video from a web camera. It shows the camera view in the form. When start button clicked it should start recording video and should be stopped after pressing stop button. Program compiles fine but no video is recorded. Can anyone say what is the wrong with it?
Here is my code.
{
camera = new QCamera(this);
viewFinder = new QCameraViewfinder(this);
camera->setViewfinder(viewFinder);
recorder = new QMediaRecorder(camera,this);
QBoxLayout *layout = new QVBoxLayout;
layout->addWidget(viewFinder);
ui->widget->setLayout(layout);
QVideoEncoderSettings settings = recorder->videoSettings();
settings.setResolution(640,480);
settings.setQuality(QMultimedia::VeryHighQuality);
settings.setFrameRate(30.0);
//settings.setCodec("video/mp4");
recorder->setVideoSettings(settings);
recorder->setContainerFormat("mp4");
camera->setCaptureMode(QCamera::CaptureVideo);
camera->start();
}
void usbrecorder::on_btn_Record_clicked()
{
usbrecorder::startRecording();
}
void usbrecorder::on_btn_Stop_clicked()
{
usbrecorder::stopRecording();
}
void usbrecorder::startRecording()
{
recorder->setOutputLocation(QUrl::fromLocalFile("C:\\Users\\Stranger\\Downloads\\Video\\vidoe_001.mp4"));
recorder->record();
}
void usbrecorder::stopRecording()
{
recorder->stop();
}
This is due to limitations on Windows.
As mentioned in Qt documentation here: https://doc.qt.io/qt-5/qtmultimedia-windows.html#limitations
Video recording is currently not supported. Additionally, the DirectShow plugin does not support any low-level video functionality such as monitoring video frames being played or recorded using QVideoProbe or related classes.
You need to specify an output location:
QMediaRecorder::setOutputLocation(const QUrl& location)
e.g.
setOutputLocation(QUrl("file:///home/user/vid.mp4"));
Try to print the state, status and error message:
qDebug()<<record.state();
qDebug()<<record.status();
qDebug()<<record.error();
and see what it prints. With those messages you can have a clear picture of your problem. Maybe QMediaRecorder cannot access your camera.
I want to create a simple video player with C++ and wxWidgets. I put wxMediaCtrl and wxFileDialog controls and created this code for button click event:
wxFileDialog * fopen = new wxFileDialog(this, wxT("Wybierz plik"), wxT(""), wxT(""), wxT("MP4 file (*.mp4)|*.mp4|AVI file (*.avi)|*.avi"));
if (fopen->ShowModal() == wxID_OK)
{
wxString fname = fopen->GetFilename();
media->Load(fname); // media is pointer to wxMediaCtrl object
media->Play();
}
delete fopen;
When I open file, it doesn't play. I have no idea what to do.
The documentation states:
For general operation, all you need to do is call Load() to load the file you want to render, catch the EVT_MEDIA_LOADED event, and then call Play() to show the video/audio of the media in that event.
So the problem looks to be that the file hasn't finished loading when you try to play it. You can also see the mediaplayer sample in the samples directory of your wxWidgets installation for more details.