sipsorcery-org / SIPSorceryMedia.FFmpeg

GNU Lesser General Public License v2.1
34 stars 26 forks source link

Add FFmpegMicrophoneSource , Enhance FFmpegAudioDecoder and FFmpegVideoDecoder, #11

Closed ChristopheI closed 2 years ago

ChristopheI commented 2 years ago

In this PR:

FFmpegMicrophoneSource (new)

FFmpegAudioDecoder:

FFmpegVideoDecoder

Project FFmpegFileAndDevicesTest updated to test microphone

Scenario tested:

Since Audio and Video inputs are independent, it's possible to stream audio from a file or microphone and video from another (or same) file or a webcam.

Note: On Windows, to test microphone, the name of the device must be set like this: "audio=[DEVICE_NAME]"; Where DEVICE_NAME is a name listed by this command: ffmpeg -f dshow -list_devices true -i dummy

Example of output of this command:

DirectShow video devices (some may be both video and audio devices)
 "Integrated Camera"
    Alternative name "@device_pnp_\\?\usb#vid_30c9&pid_0014&mi_00#7&10a84933&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
 "HD Pro Webcam C920"
    Alternative name "@device_pnp_\\?\usb#vid_046d&pid_082d&mi_00#7&2f7f15f6&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
DirectShow audio devices
 "Microphone (HD Pro Webcam C920)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{A34B481B-520D-482D-B48C-3117D3659FD5}"
 "Microphone Array (Realtek(R) Audio)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{3B632CDA-D23D-4B1B-A8BE-1DDBBF5486D1}"
 "Microphone (Plantronics .Audio 478 USB)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{AE04B684-777A-45E2-A452-5

So in my case I can set "audio=Microphone (HD Pro Webcam C920)"

sipsorcery commented 2 years ago

@ChristopheI did you manage to get the FFmpegCameraSource to successfully initialise your webcam?

I get No such file or directory.

var ffmpegWebcam = new FFmpegCameraSource("video=HD Pro Webcam C920");

[NULL @ 000001d1cd212bc0] Opening 'video=HD Pro Webcam C920' for reading
[file @ 000001d1ab71ef40] Setting default whitelist 'file,crypto,data'
Unhandled exception. System.ApplicationException: No such file or directory

If it works for you then it's likely something in my set up. I can dig into it at some point.

ChristopheI commented 2 years ago

Both FFmpegCameraSource and FFmpegMicrophoneSource are working on my side in Win 10.

Firts, you must know the name of your devices using this command: (so you need "ffmpeg" excetubale file) ffmpeg -f dshow -list_devices true -i dummy

The ouput is like this on my computer:

DirectShow video devices (some may be both video and audio devices)
 "Integrated Camera"
    Alternative name "@device_pnp_\\?\usb#vid_30c9&pid_0014&mi_00#7&10a84933&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
 "HD Pro Webcam C920"
    Alternative name "@device_pnp_\\?\usb#vid_046d&pid_082d&mi_00#7&2f7f15f6&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
DirectShow audio devices
 "Microphone (HD Pro Webcam C920)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{A34B481B-520D-482D-B48C-3117D3659FD5}"
 "Microphone Array (Realtek(R) Audio)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{3B632CDA-D23D-4B1B-A8BE-1DDBBF5486D1}"
 "Microphone (Plantronics .Audio 478 USB)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{AE04B684-777A-45E2-A452-5

So for camera devices, I can use "video=Integrated Camera" OR "video=HD Pro Webcam C920"

And for microphone devices i can use "audio=Microphone (HD Pro Webcam C920)", "audio=Microphone Array (Realtek(R) Audio)" OR "audio=Microphone (Plantronics .Audio 478 USB)"

sipsorcery commented 2 years ago

Thanks for confirming.

I used the same ffmpeg command to get my list of webcams. Must be something else up with my config. I'll dig into it when I get a chance.

ChristopheI commented 2 years ago

@sipsorcery , Did you try using the new test project FFmpegFileAndDevicesTest ?

Use it with correct const values for:

Run this example then use the file webrtcmp4.html you have created in the WebRTCMp4Source example for the SIPsorcery repository .

sipsorcery commented 2 years ago

Sorry it took me so long to test this. Once I set my library path correctly I was able to get the new FFmpegCameraSource and FFmpegMicrophoneSource classes working with a WebRTC example.