dshow webcam and microphone capture

For the developers that use FFmpeg in Windows software.
fuwaneko
Posts: 6
Joined: Sat Aug 06, 2011 11:37 am

dshow webcam and microphone capture

Post by fuwaneko » Sat Aug 06, 2011 11:47 am

So I'm able to enumerate devices, build AVInputFormat, open device, etc. The problem is that produced video is messed. It plays at extreme speed, and audio is basically just noise. That's what I do:
1. Get muxing example from ffmpeg source
2. Adapt it so frame and audio data are passed from webcam and microphone, I use av_decode_video2, av_decode_audio here, because some web cameras produce encoded streams
3. Encoding part untouched: same as in muxing example

I do not calculate any pts/dts/whatever stuff, because I don't know the right way to do it. I tried to play with these values, but the result is horrible always. I tried 90kHz discretization, etc.

I tried two webcams: one on my laptop, other is FalseCamera (plays any video file and pretends to be webcam). They both have strange stream->time_base of 1/10000000 (yes, 10 million).

I don't know what to do. ffmpeg is poorly documented, it's almost impossible to use it in some project, and google-sensei shows only stupid results with “how do i use ffmpeg.exe”.

If anyone can help me understand how to use ffmpeg api, I would really appreciate it. Thanks in advance.

fuwaneko
Posts: 6
Joined: Sat Aug 06, 2011 11:37 am

Re: dshow webcam and microphone capture

Post by fuwaneko » Mon Aug 08, 2011 6:31 am

Looks like I solved the problem with video. I set output video stream start_time to 0 (it corresponds to pts calculation, so it's correct value), and video is okay. Now I'm going to add audio stream to see how it goes.

rogerdpack
Posts: 1872
Joined: Fri Aug 05, 2011 9:56 pm

Re: dshow webcam and microphone capture

Post by rogerdpack » Thu Sep 01, 2011 2:28 pm

could you post your microphone capture example sometime?

fuwaneko
Posts: 6
Joined: Sat Aug 06, 2011 11:37 am

Re: dshow webcam and microphone capture

Post by fuwaneko » Thu Sep 01, 2011 3:15 pm

No problem, will post here soon.

casioo
Posts: 2
Joined: Fri Aug 24, 2012 4:15 pm

Re: dshow webcam and microphone capture

Post by casioo » Fri Aug 24, 2012 4:18 pm

Sorry for bringing this up again, but i'm looking for ffmpeg microphone capture examples.
Could you show me yours? Or where can i find another example?

rogerdpack
Posts: 1872
Joined: Fri Aug 05, 2011 9:56 pm

Re: dshow webcam and microphone capture

Post by rogerdpack » Sun Aug 26, 2012 3:45 am

in general it's like
$ ffmpeg -f dshow -i audio="sound card name here"
if that's what you're looking for.

casioo
Posts: 2
Joined: Fri Aug 24, 2012 4:15 pm

Re: dshow webcam and microphone capture

Post by casioo » Sun Aug 26, 2012 8:15 am

Hey rogerdpack,

maybe this is the wrong section, but i am more looking for c/c++ examples for visual studio. I want to use ffmpeg with a little gui. But i havent found a way to record from microfone. Any idea where to find help?

thanks in advance

fuwaneko
Posts: 6
Joined: Sat Aug 06, 2011 11:37 am

Re: dshow webcam and microphone capture

Post by fuwaneko » Mon Aug 27, 2012 3:00 am

I don't know if this helps. But here is my old source file. It features:
- DShow capture from webcam and microphone
- encoding via VFW dll
- basic usage of ffmpeg api.

Sorry it's poorly commented, but general idea should be clear. Also features multithreaded encoding with boost.thread. If you have any questions I'd be glad to help, it's really hard to find anything good on ffmpeg api.
Attachments
avcap.zip
(7.02 KiB) Downloaded 403 times

rogerdpack
Posts: 1872
Joined: Fri Aug 05, 2011 9:56 pm

Re: dshow webcam and microphone capture

Post by rogerdpack » Mon Aug 27, 2012 3:52 pm

you multi thread encode libav using your own threads?

fuwaneko
Posts: 6
Joined: Sat Aug 06, 2011 11:37 am

Re: dshow webcam and microphone capture

Post by fuwaneko » Mon Aug 27, 2012 4:55 pm

rogerdpack wrote:you multi thread encode libav using your own threads?
They are not mine :) Boost. Why?

Post Reply