sipsorcery-org / SIPSorceryMedia.FFmpeg

GNU Lesser General Public License v2.1
31 stars 24 forks source link

Cannot access file path on MacOS #61

Open Hemesh-S opened 11 months ago

Hemesh-S commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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)