Using FFMPEG dshow to capture and write an avi file

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

smim123

  • Posts: 6
  • Joined: Thu Jun 07, 2018 6:34 pm
  • Real Name: Sirajum Mim

Using FFMPEG dshow to capture and write an avi file

PostThu Jul 19, 2018 2:49 pm

Hi,
I am using a decklink sdi 4K and would like to capture and write other than u sing the media express.

I came through few examples of ffmpeg dshow

https://trac.ffmpeg.org/wiki/DirectShow

and tried out some. I am able to capture video and save it. However, I am running into 2 issues:

1) I want to save it in AVI format but don’t seem to find the right codec for that and hence using rawvideo as the vcodec. with my command it seems like I am saving in avi but it’s really not.
2) I am only able to capture 1 min(max) video, after that frames start dropping.

Here is what I am running:

E:\folder> ffmpeg -f dshow -video_size 1920x1080 -rtbufsize 2096M -framerate 25 -i
video="Decklink Video Capture" -r 25 -threads 4 -vcodec rawvideo -b:v 850000000 -t 00:02:00
test39.avi



And this is what I get (I have made the important points bold):

ffmpeg version N-49235-gdd5689a-iotzo Copyright (c) 2000-2013 the FFmpeg developers
built on Jan 24 2013 16:06:46 with gcc 4.7.2 (GCC)
configuration: --enable-static --arch=x86_64 --target-os=mingw32 --cross-prefix=/var/zeranoe/sandbox/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --pkg-config=pkg-config --enable-gpl --enable-libx264 --enable-avisynth --enable-libxvid --enable-libmp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-fontconfig --enable-libass --enable-libutvideo --enable-libopus --disable-w32threads --enable-frei0r --enable-filter=frei0r --enable-libvo-aacenc --enable-bzlib --enable-libxavs --extra-cflags=-DPTW32_STATIC_LIB --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libbluray --enable-libvpx --extra-version=iotzo --enable-runtime-cpudetect
libavutil 52. 15.102 / 52. 15.102
libavcodec 54. 90.100 / 54. 90.100
libavformat 54. 61.104 / 54. 61.104
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 33.100 / 3. 33.100
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[dshow @ 0000000004245980] Estimating duration from bitrate, this may be inaccurate
Input #0, dshow, from 'video=Decklink Video Capture':
Duration: N/A, start: 0.138020, bitrate: N/A
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, 25 tbr, 10000k tbn, 25 tbc
File 'test39.avi' already exists. Overwrite ? [y/N] y
Output #0, avi, to 'test39.avi':
Metadata:
ISFT : Lavf54.61.104
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, q=2-31, 850000 kb/s, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> rawvideo)
Press [q] to stop, [?] for help
real-time buffer 62% full! frame dropped! time=00:01:12.96 bitrate=829444.3kbits/s
frame= 1846 fps= 22 q=0.0 Lsize= 7476339kB time=00:01:13.84 bitrate=829444.3kbits/s
video:7476300kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.000520%


I want to get 2 mins of video without dropping any frames and would like to save in AVI format. Can anyone help me and point what I am doing wrong?

Thanks.
Offline

Ian Morrish

  • Posts: 287
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 1:43 am

The native Decklink WDM capture method may be more reliable.

There is a version of FFMPEG compiled with Decklink native support (not included by default) which I have at home so will try it tonight and let you know if it works.
Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com
Offline

Ian Morrish

  • Posts: 287
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 8:03 am

I think this is what you want for raw. (I have changed the name of my device using Desktop Video Settings as I have a few different devices in my PC)
F:\Tools\FFMGEP with Decklink support\ffmpeg-3.2-win64-static\bin>ffmpeg -f decklink -t 00:05:00 -i "4K Ian Morrish@5" -pix_fmt yuv420p -vcodec mpegts -c copy testing5.avi

The number after the @ is based on info here https://ianmorrish.wordpress.com/2017/1 ... ink-cards/

5 minutes = 28Gb. Boy is that quality noticeable, never captured this level before, playing back with VLC.
Only 0, 1 or 2 dropped frames at the very beginning of the capture each time I tested (probably disk delay in starting up).

Input #0, decklink, from '4K Ian Morrish@5':
Duration: N/A, start: 0.000000, bitrate: 830976 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream #0:1: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, 829440 kb/s, 25 tbr, 1000k tbn, 1000k tbc
Output #0, avi, to 'testing6.avi':
Metadata:
ISFT : Lavf57.56.100
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, q=2-31, 829440 kb/s, 25 tbr, 600 tbn, 1000k tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, 1536 kb/s
Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com
Offline

smim123

  • Posts: 6
  • Joined: Thu Jun 07, 2018 6:34 pm
  • Real Name: Sirajum Mim

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 1:21 pm

Ian Morrish wrote:I think this is what you want for raw. (I have changed the name of my device using Desktop Video Settings as I have a few different devices in my PC)
F:\Tools\FFMGEP with Decklink support\ffmpeg-3.2-win64-static\bin>ffmpeg -f decklink -t 00:05:00 -i "4K Ian Morrish@5" -pix_fmt yuv420p -vcodec mpegts -c copy testing5.avi

The number after the @ is based on info here https://ianmorrish.wordpress.com/2017/1 ... ink-cards/

5 minutes = 28Gb. Boy is that quality noticeable, never captured this level before, playing back with VLC.
Only 0, 1 or 2 dropped frames at the very beginning of the capture each time I tested (probably disk delay in starting up).

Input #0, decklink, from '4K Ian Morrish@5':
Duration: N/A, start: 0.000000, bitrate: 830976 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream #0:1: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, 829440 kb/s, 25 tbr, 1000k tbn, 1000k tbc
Output #0, avi, to 'testing6.avi':
Metadata:
ISFT : Lavf57.56.100
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, q=2-31, 829440 kb/s, 25 tbr, 600 tbn, 1000k tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, 1536 kb/s


Hi Ian,

Thanks for your response. I tried to use the decklink command first:

ffmpeg -f decklink -list_devices 1 -i dummy
from this website
https://www.ffmpeg.org/ffmpeg-devices.html#Examples-1. But I always end up getting
Unknown input format: 'decklink'.

As ffmpeg -f decklink isn't working for me hence I chose to do ffmpeg - f dshow. Any idea how to fix this?

I am now able to get 2 mins of good quality video without frames dropped. I was before saving to a drive where the read/write speed was not fast enough to keep up with the video, I changed my drive and now it works.

I read that solution here:
https://www.blackmagicdesign.com/ca/dev ... d-playback

However, now occasionally when I try to capture it I keep getting multiple dropped frames. So I just exit and enter the command again. I assume it may get better if I could use decklink instead of dshow.

Thanks
Offline

Ian Morrish

  • Posts: 287
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 6:36 pm

Try this version. It has decklink support. https://1drv.ms/u/s!ApGpqMMpRLhikJx4U33e7mQNIzyiVQ


Sent from my SM-G950F using Tapatalk
Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com
Offline

smim123

  • Posts: 6
  • Joined: Thu Jun 07, 2018 6:34 pm
  • Real Name: Sirajum Mim

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 7:01 pm

Ian,

Thanks. I tried that one and now when I do a query to list the devices for decklink it shows me that a Decklink Device is available but when i try to capture it using this device it says no such device or address.


C:\WINDOWS\system32>ffmpeg -f decklink -list_devices 1 -i dummy
ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.100 / 57. 64.100
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
[decklink @ 0000000002ff68a0] Blackmagic DeckLink devices:
[decklink @ 0000000002ff68a0] 'DeckLink SDI 4K'
dummy: Immediate exit requested

C:\WINDOWS\system32>ffmpeg -f decklink -video_size 1920x1080 -rtbufsize 2096M -framerate 25 -i video="DeckLink SDI 4K" -r 25 -threads 4 -vcodec rawvideo -crf 0 -preset ultrafast -b:v 850000000 -t 00:00:15 D:\Mim\videos\test_ffmpeg.avi
ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.100 / 57. 64.100
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
video=DeckLink SDI 4K: No such device or address

Any idea?
Offline

Ian Morrish

  • Posts: 287
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 7:24 pm

The parameters are different for decklink source.
try this
ffmpeg -f decklink -t 00:05:00 -i "DeckLink SDI 4K@5" -pix_fmt yuv420p -vcodec mpegts -c copy testing5.avi
Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com
Offline

smim123

  • Posts: 6
  • Joined: Thu Jun 07, 2018 6:34 pm
  • Real Name: Sirajum Mim

Re: Using FFMPEG dshow to capture and write an avi file

PostWed Jul 25, 2018 9:03 pm

Ian,

this seems to work and save the video but it doesn't display the video. It only shows this when played(see attachment).

Thanks,
Mim
Attachments
Capture.PNG
capture
Capture.PNG (12.08 KiB) Viewed 639 times
Offline

Ian Morrish

  • Posts: 287
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: Using FFMPEG dshow to capture and write an avi file

PostThu Jul 26, 2018 7:21 am

I see that when the input signal is not detected. Have you confirmed with Media Express that signal matches the Video Project settings of 1080p25 (this is what the @5 relates to).
Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 1 guest