Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access file path on MacOS #61

Open
Hemesh-S opened this issue Jul 23, 2023 · 6 comments
Open

Cannot access file path on MacOS #61

Hemesh-S opened this issue Jul 23, 2023 · 6 comments

Comments

@Hemesh-S
Copy link

Hemesh-S commented Jul 23, 2023

Hi, a great library for use within MacOS and WebRTC.

I am trying to run the example project FFmpegFileAndDevicesTest.

It works fine when pointing to the external video source file, however, when I switch the source to use my Mac camera, it cannot get the path. It does get the list of cameras and selects the correct one with the correct name, but the path is returned as "0:"

Is there a way to resolve this?

I have installed all the relevant FFMPEG libraries and dependencies on my Mac, via homebrew.

Screenshot 2023-07-23 at 21 52 02

After which the application crashes when trying hitting the InitialiseDecoder() method in the FFmpegCameraSource class, specifically on the
if (ffmpeg.avformat_open_input(&pFormatContext, _sourceUrl, _inputFormat, &options) < 0) in the FFmpegVideoDecoder class.

@ha-ves
Copy link
Contributor

ha-ves commented Jul 26, 2023

Does the ffmpeg command access your webcam successfully?

Some helpful commands:

# List devices provided using AVFoundation in MacOS
ffmpeg -f avfoundation -list_devices true -i ""

# And then try to capture some video
ffmpeg -f avfoundation -i "0:" output.mp4

@Hemesh-S
Copy link
Author

Hemesh-S commented Jul 26, 2023

Hi thank you for your feedback, I have tried the suggested commands, and it does list the webcam under the video devices

image

However, when I try to run the capture video command I get the following error

image

It does request access to the camera though and I allow it.

I have then set the framerate in the command and it worked like below
ffmpeg -f avfoundation -framerate 30 -i "0:" output.mp4

When I tried to do the same in code in FFmpegCameraSource.cs it did not work

image

Can you advise further?

@ha-ves
Copy link
Contributor

ha-ves commented Jul 27, 2023

Hmm, can you enable the FFmpeg logger on AV_LOG_TRACE?

Some helpful code:

// Use Microsoft.Extensions.Logging package
ILoggerFactory logfactory = LoggerFactory.Create(config => {
    // Use Microsoft.Extensions.Logging.Console package
    config.AddSimpleConsole().SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
});

// Initialise FFmpeg librairies
FFmpegInit.Initialise(
    logLevel: FfmpegLogLevelEnum.AV_LOG_TRACE,
    appLogger: logfactory.CreateLogger("FFMPEG Log"));

@Hemesh-S
Copy link
Author

Hemesh-S commented Jul 27, 2023

Thank you for the suggestions, I have done so and this is how the log looks just after crashing once it hits if (ffmpeg.avformat_open_input(&pFormatContext, _sourceUrl, _inputFormat, &options) < 0) in FFmpegVideoDecoder

image

It only seems to be with a camera source though, screen and file do not have this issue.

@ha-ves
Copy link
Contributor

ha-ves commented Aug 1, 2023

Okay, it seems because of the default behavior of FFMPEG, seems it fails to get the correct supported mode.

If you can find a way to retrieve the "Supported Modes" of the device and then use the first one as the option "framerate", then it should be able to open the decoder context.

I don't have a MacOS ready, I can't test the suggested solution.

@ChristopheI
Copy link
Collaborator

Also to you give authorization to your app to have access to video devices ?
On Mac you have often trouble about security to access devices (audio and video)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants