Search code examples
ffmpegvideo-capturedirectshowvideo-encoding

Issue capturing video within device specs from a USB Grabber with ffmpeg & directshow


I am using a USB Grabber (this one: http://www.logilink.com/Suche/vg0001a) to capture some old VHS footage. I am using ffmpeg with directshow to do so. The device properties are as follows:

[dshow @ 000001d57618a300] DirectShow video device options (from video devices)
[dshow @ 000001d57618a300]  Pin "Capture" (alternative pin name "0")
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=160x120 fps=5 max s=160x120 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=176x144 fps=5 max s=176x144 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=320x240 fps=5 max s=320x240 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=352x288 fps=5 max s=352x288 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=720x480 fps=5 max s=720x480 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuyv422  min s=720x576 fps=5 max s=720x576 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuv420p  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuv420p  min s=160x120 fps=5 max s=160x120 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuv420p  min s=176x144 fps=5 max s=176x144 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuv420p  min s=320x240 fps=5 max s=320x240 fps=30
[dshow @ 000001d57618a300]   pixel_format=yuv420p  min s=352x288 fps=5 max s=352x288 fps=30
[dshow @ 000001d57618a300] Crossbar Switching Information for USB2.0 Grabber:
[dshow @ 000001d57618a300]   Crossbar Output pin 0: "Video Decoder" related output pin: 1 current input pin: 0 compatible input pins: 0 1
[dshow @ 000001d57618a300]   Crossbar Output pin 1: "Audio Decoder" related output pin: 0 current input pin: 4 compatible input pins: 3 4
[dshow @ 000001d57618a300]   Crossbar Input pin 0 - "Video Composite" related input pin: 4
[dshow @ 000001d57618a300]   Crossbar Input pin 1 - "S-Video" related input pin: 4
[dshow @ 000001d57618a300]   Crossbar Input pin 2 - "Video Tuner" related input pin: 3
[dshow @ 000001d57618a300]   Crossbar Input pin 3 - "Audio Tuner" related input pin: 2
[dshow @ 000001d57618a300]   Crossbar Input pin 4 - "Audio Line" related input pin: 0

I ran some tests and can capture and re-encode on the fly just fine at a variety of resolutions at both yuv420p and yuyv422 with the following command:

ffmpeg -f dshow -pixel_format yuyv422 -video_size 720x480 -framerate 25 -i video="USB2.0 Grabber":audio="Digital Audio Interface (USB Audio Interface)" -c:v libx264 -crf 18 -aspect 4:3 -vf "yadif=1" -pix_fmt yuv420p -c:a aac -b:a 392k capture.mp4

However, when I set -pixel_format yuyv422 -video_size 720x576 -framerate 25 which is within specs of the device, the process fails with a Too many packets buffered for output stream 0:1.. I tried increasing the buffer size with -rtbufsize and while the process starts, the video is never captured and the frame count is stuck at zero while converting - audio is captured fine.

I thought it was the encoding not being able to keep up, but streaming the video or capturing the raw video feed with -vcodec copy I encounter the same issues.

Using VLC to play from a capture device plays the audio only when using 720x576 as the size, while lower resolutions play fine, which make me think the issue is either with the device or me leaving out some specific directshow option.

Any ideas?


Solution

  • I managed to solve this by setting the directshow video format to a PAL option (by default it's set to NTSC). I could do this from another application that leveraged directshow capture, or directly from ffmpeg using the -show_video_device_dialog true dshow option, which causes a GUI to appear before the conversion process. Only had to do this once because the setting is sticky. Afterwards, video at 720x576 was captured fine.