CursorTask - VideoPlayer

Forum for software developers to discuss BCI2000 software development
elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

CursorTask - VideoPlayer

Post by elenamon » 09 Jun 2025, 11:15

Dear all,
I am currently working on the development of a custom pipeline using BCI2000. My goal is to provide video feedback to the user. At this stage, the video should be played as-is, although in the future I plan to implement dynamic control of playback speed. For this purpose, I have referred to a previous forum thread (viewtopic.php?t=3794). So I'm using the MyModifiedVideoPlayer class previously discussed.

Specifically, I am using the CursorTask module as a template, and I am attempting to play a video at standard speed during the feedback phase. However, I am encountering an issue: the video does not play, and no error messages are displayed.

Below, I have provided the relevant code related to video playback:

Code: Select all


MyCursorTask::MyCursorTask()
{
[...]
    mpVideoPlayer = new MyModifiedVideoPlayer(mrWindow, 1.0); // declared also in the header
    mSpeed = 1.0;
    mpVideoPlayer->SetSpeedup(mSpeed);
}


void MyCursorTask::OnInitialize(const SignalProperties& /*Input*/)
{
[...]

    mrWindow.Show();
    source_video = ".prog/video/myvideo.mp4";
    mpVideoPlayer->SetFile(source_video);
    AppLog.Screen << mpVideoPlayer->SetFile(source_video) << std::endl;
    mSpeed = 1.0;
    mpVideoPlayer->SetSpeedup(mSpeed);
}


void MyCursorTask::OnFeedbackEnd()
{
[...]
    mpVideoPlayer->Hide();
}


void MyCursorTask::DoFeedback(const GenericSignal& ControlSignal, bool& doProgress)
{
[...]
        mpVideoPlayer->Show();
        mSpeed = 1.0;
        mpVideoPlayer->SetSpeedup(mSpeed);
        mpVideoPlayer->Play();

}

Based on my observations, the application log (

Code: Select all

AppLog.Screen << mpVideoPlayer->SetFile(source_video) << std::endl;
) suggests that the video is not being loaded properly, as the corresponding log entry returns zero. Additionally, I would like to note that, unlike the original CursorTask, I have disabled the entire FeedbackScene that involves the cursor and target display.

Any assistance or suggestions you could provide would be greatly appreciated.

Thank you in advance for your support.

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 09 Jun 2025, 12:05

Hi,

I can offer two pieces of advice. First, the VideoPlayer::SetFile() method does not return an error string. Rather, it returns a reference to the VideoPlayer instance itself. To test for success, when loading a file, use VideoPlayer::IsOpen() and VideoPlayer::Error(). The latter gives you an error string if an error occurred.

Second, the file name you are using seems to have a typo in it. Between the initial dot, and the "prog" directory name, there should be a slash "/".

HTH

elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

Re: CursorTask - VideoPlayer

Post by elenamon » 10 Jun 2025, 11:18

Hi,
thank you very much for your suggestions. I have changed the path of the video as you suggested and tested using the methods you mentioned. According to the results the video is now correctly loaded but actually it still does not appear on the mrWindow (black screen). No errors occur when the application is compiled not even the applog reports anomalies. Do you have any other suggestion? Which other video player's attribute or method should I check?
Thanks in advance

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 10 Jun 2025, 11:37

With some video files, there might be playback issues. To check whether BCI2000 is able to play back your video, you may use the BCI2000MediaPlayer tool (bci2000/tools/BCI2000MediaPlayer/BCI2000MediaPlayer.exe). To run it with a certain media file, start it from the command line and enter the media file name after "BCI2000MediaPlayer.exe":

Code: Select all

BCI2000MediaPlayer ../../prog/video/myvideo.mp4

elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

Re: CursorTask - VideoPlayer

Post by elenamon » 11 Jun 2025, 04:48

Hi,
thank you again. I've just performed the test with the BCI200MediaPlayer as suggested and I've verified that the video is correctly open and playback.
So I really cannot figure it out what's wrong with my BCI2000 application module.
Is it possible to initialize and see a second window within the CursorTask application only to see the video? Could it be a useful test to try?
It is only a proposal, so you if you have any other different suggestions I would really appreciate to try them.
Thank you again in advance for the help

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 11 Jun 2025, 06:51

From your code, it seems that you are playing back during the feedback phase, but you may have removed the code that enters the feedback phase.
Apart from that, the DoFeedback() function is called repeatedly during feedback, and calling Show() and Play() repeatedly is probably not what you want.

My suggestion is to create an OnStartRun() function if it doesn't exist, and move the content of DoFeedback() there.

elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

Re: CursorTask - VideoPlayer

Post by elenamon » 11 Jun 2025, 06:53

Sorry for the second reply, I want to add that in the DoFeedback section I've tested if the video is open and if it is playing, and it reported that is open and is playing during the feedback, but actually I'm not able to see it.

Code: Select all

    if (mpVideoPlayer->IsPlaying()) {
        AppLog.Screen << "playing" << std::endl;
    }
    if (mpVideoPlayer->IsOpen()) {
        AppLog.Screen << "Open" << std::endl;
    }
So the problem seems to be related to where the video is open and played, why I'm not able to see it.
Hope that this can help in the final resolution of my problem
Thanks again

PS. I've just seen your last answer. Thank you, I'll try your last suggestion and I'll reply back. Thanks

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 11 Jun 2025, 08:56

BTW, I just noticed that you didn't set a rectangle for your video. You probably want to see it in native resolution, so use

Code: Select all

GUI::Rect rect = { 0.5, 0.5, 0.5, 0.5 };
mpVideoPlayer->SetObjectRect(rect);
mpVideoPlayer->SetScalingMode(GUI::GraphObject::AdjustBoth);
in the constructor.

elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

Re: CursorTask - VideoPlayer

Post by elenamon » 11 Jun 2025, 10:24

Thank you again for the new suggestions.

Trying to move the contenet of DoFeedback() to OnStartRun() nothing changed: in the Applog is reported that the video is open and played but it is not visible in the mrWindow.

I've add the definition of the rect as suggested and in the system Log appear the following errors before starting the session:

Code: Select all

resource deadlock would occur: resource deadlock would occur.
2025-06-11T16:16:15.429 - Application error, MyCursorTask::Initialize: Unhandled exception of type std::system_error:
resource deadlock would occur: resource deadlock would occur
Terminating MyCursor module.
2025-06-11T16:16:16.439 - Application error:
Lost connection to Application.
Any other suggestions?
Thanks a million for the support

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 11 Jun 2025, 10:39

I'd suggest to remove

Code: Select all

mrWindow.Show();
from OnInitialize().

elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

Re: CursorTask - VideoPlayer

Post by elenamon » 11 Jun 2025, 11:26

Unfortunately removing the suggested line nothing changes and the error on the System Log is still the same.
As the problem seems to be in OnInitialize(), I transcript here all the code about that section (not only the lines ralted to the VideoPlayer), hoping tha this can help in finding the solution.

Code: Select all

void MyCursorTask::OnInitialize(const SignalProperties& /*Input*/)
{
    float feedbackDuration = Parameter("FeedbackDuration").InSampleBlocks();
    mMaxFeedbackDuration = static_cast<int>(Parameter("MaxFeedbackDuration").InSampleBlocks());
    mrWindow.Show();
    source_video = "./video/myvideo.mp4";
    mpVideoPlayer->SetFile(source_video);

    AppLog.Screen << "video loaded - " << source_video << std::endl;
    AppLog.Screen << mpVideoPlayer->Error() << std::endl;
    if (mpVideoPlayer->IsOpen()) {
        AppLog.Screen << "open" << std::endl;
    }
    mpVideoPlayer->Hide();
    mSpeed = 1;
    mpVideoPlayer->SetSpeedup(mSpeed);
}

Thanks for the help

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 11 Jun 2025, 11:36

There is nothing suspicious in your OnInitialize() function.

How do you obtain the mrWindow reference in the constructor of your task?

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 11 Jun 2025, 11:59

I reproduced the issue on my machine, so I will be able to help you more efficiently. I will come back to you once I identified the source of the issue.

elenamon
Posts: 12
Joined: 09 Jun 2025, 09:04

Re: CursorTask - VideoPlayer

Post by elenamon » 11 Jun 2025, 12:08

The mrWindow is defined in the header file in this way:

Code: Select all

ApplicationWindow& mrWindow;
and in the .cpp file is initialized as

Code: Select all

mrWindow(Window())
Thanks a million to have riproduced my issue. I'll wait for yuor precious reply.

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: CursorTask - VideoPlayer

Post by mellinger » 11 Jun 2025, 16:57

There were two independent issues, one that caused the error message, and one that caused the black screen.
I fixed both of them, and the example code now works on my machine.

Please do an SVN update on your side and let me know if the issues persist for you.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests