DeckLink output --enable-decklink

Website, builds, or other suggestions.
iotzo
Posts: 35
Joined: Thu Jan 24, 2013 4:49 pm

Re: DeckLink output --enable-decklink

Post by iotzo » Thu Nov 27, 2014 8:57 am

ramiro wrote:Could you please test this (untested) patch:

Code: Select all

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 9a9e44b..4e98c41 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -69,9 +69,11 @@ static char *dup_wchar_to_utf8(wchar_t *w)
 }
 #define DECKLINK_STR    OLECHAR *
 #define DECKLINK_STRDUP dup_wchar_to_utf8
+#define DECKLINK_FREE   SysFreeString
 #else
 #define DECKLINK_STR    const char *
 #define DECKLINK_STRDUP av_strdup
+#define DECKLINK_FREE   free
 #endif
 
 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
@@ -82,7 +84,7 @@ HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
         return hr;
     *displayName = DECKLINK_STRDUP(tmpDisplayName);
     /* free() is needed for a string returned by the DeckLink SDL. */
-    free((void *) tmpDisplayName);
+    DECKLINK_FREE((void *) tmpDisplayName);
     return hr;
 }
 
I just tested the patch, but now I'm getting compile time error:

Code: Select all

...
libavdevice/decklink_common.cpp: In function 'HRESULT ff_decklink_get_display_name(IDeckLink*, const char**)':
libavdevice/decklink_common.cpp:87:42: error: invalid conversion from 'void*' to 'BSTR {aka wchar_t*}' [-fpermissive]
     DECKLINK_FREE((void *) tmpDisplayName);
                                          ^
...
Compiler version:

Code: Select all

gcc -v
Using built-in specs.
COLLECT_GCC=D:\media-autobuild_suite-master\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=D:/media-autobuild_suite-master/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-4.9.2/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --with-gxx-include-dir=/mingw64/include/c++/4.9.2 --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-cloog-backend=isl --enable-version-specific-runtime-libs --disable-cloog-version-check --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-cloog=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=http://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 4.9.2 (Rev2, Built by MSYS2 project)

ramiro
Posts: 157
Joined: Tue May 10, 2011 12:56 am

Re: DeckLink output --enable-decklink

Post by ramiro » Thu Nov 27, 2014 11:12 pm

I hate C++ =)

Test this new patch:

Code: Select all

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 9a9e44b..6899bd2 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -69,9 +69,12 @@ static char *dup_wchar_to_utf8(wchar_t *w)
 }
 #define DECKLINK_STR    OLECHAR *
 #define DECKLINK_STRDUP dup_wchar_to_utf8
+#define DECKLINK_FREE(s) SysFreeString(s)
 #else
 #define DECKLINK_STR    const char *
 #define DECKLINK_STRDUP av_strdup
+/* free() is needed for a string returned by the DeckLink SDL. */
+#define DECKLINK_FREE(s) free((void *) s)
 #endif
 
 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
@@ -81,8 +84,7 @@ HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
     if (hr != S_OK)
         return hr;
     *displayName = DECKLINK_STRDUP(tmpDisplayName);
-    /* free() is needed for a string returned by the DeckLink SDL. */
-    free((void *) tmpDisplayName);
+    DECKLINK_FREE(tmpDisplayName);
     return hr;
 }
 

iotzo
Posts: 35
Joined: Thu Jan 24, 2013 4:49 pm

Re: DeckLink output --enable-decklink

Post by iotzo » Fri Nov 28, 2014 10:26 am

ramiro wrote:I hate C++ =)

Test this new patch:

Code: Select all

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 9a9e44b..6899bd2 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -69,9 +69,12 @@ static char *dup_wchar_to_utf8(wchar_t *w)
 }
 #define DECKLINK_STR    OLECHAR *
 #define DECKLINK_STRDUP dup_wchar_to_utf8
+#define DECKLINK_FREE(s) SysFreeString(s)
 #else
 #define DECKLINK_STR    const char *
 #define DECKLINK_STRDUP av_strdup
+/* free() is needed for a string returned by the DeckLink SDL. */
+#define DECKLINK_FREE(s) free((void *) s)
 #endif
 
 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
@@ -81,8 +84,7 @@ HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
     if (hr != S_OK)
         return hr;
     *displayName = DECKLINK_STRDUP(tmpDisplayName);
-    /* free() is needed for a string returned by the DeckLink SDL. */
-    free((void *) tmpDisplayName);
+    DECKLINK_FREE(tmpDisplayName);
     return hr;
 }
 
Almost there! :)
Now I got link time error:

Code: Select all

libavdevice/libavdevice.a(decklink_common.o):decklink_common.cpp:(.text+0x14c): undefined reference to `__imp_SysFreeString'
libavdevice/libavdevice.a(decklink_common.o):decklink_common.cpp:(.text+0x5b4): undefined reference to `__imp_SysFreeString'
, so I had to add -loleaut32 via --extra-libs configure option to get working binary.
Maybe we should take care of the configure script?

mark1st
Posts: 4
Joined: Wed Nov 12, 2014 6:32 pm

Re: DeckLink output --enable-decklink

Post by mark1st » Sat Nov 29, 2014 10:35 am

Well seems that something got wrong with latest ffmpeg builds from zeranoe (with decklink options enabled).
Running:
"ffmpeg -i test.avi -f decklink -list_devices 1 dummy" i've got with ffmepg git-2db2948 (2014-11-29)

COM initialization failed
[decklink @ 02e5b520] Could not create DeckLink iterator
dummy: Immediate exit request


while for ffmpeg-20140729-git (29-Jul-2014) i've got the expected messages:
[decklink @ 02e485e0] Blackmagic DeckLink devices:
[decklink @ 02e485e0] 'DeckLink SDI'


best regards,
mark

jbalvarado
Posts: 50
Joined: Thu Oct 03, 2013 3:47 pm

Re: DeckLink output --enable-decklink

Post by jbalvarado » Sun Nov 30, 2014 10:50 am

With msys2 I am able to build the decklink header also with widl and ffmpeg compiles to, without error, only some warnings. For what is the patch? Is there really necessary? At the moment I can not test my ffmpeg bin with decklink enabled.

iotzo
Posts: 35
Joined: Thu Jan 24, 2013 4:49 pm

Re: DeckLink output --enable-decklink

Post by iotzo » Sun Nov 30, 2014 8:54 pm

jbalvarado wrote:With msys2 I am able to build the decklink header also with widl and ffmpeg compiles to, without error, only some warnings. For what is the patch? Is there really necessary? At the moment I can not test my ffmpeg bin with decklink enabled.
The patch is for heap corruption run time error when you try to output via decklink:
Unhandled exception at 0x0000000076FA4102 (ntdll.dll) in ffmpeg_decklink_zeranoe.exe: 0xC0000374: A heap has been corrupted (parameters: 0x000000007701B4B0).
With this patch we can use ffmpeg windows build to output to decklink device.
There is no such problem with Linux build with decklink output support.

jbalvarado
Posts: 50
Joined: Thu Oct 03, 2013 3:47 pm

Re: DeckLink output --enable-decklink

Post by jbalvarado » Mon Dec 01, 2014 7:33 am

Thank you for explaining! Maybe we can send the patch to the ffmpeg tracker. But there is a other problem to in the current source code, ffmpeg v2.3.5 works, and after that not anymore: https://trac.ffmpeg.org/ticket/4144

iotzo
Posts: 35
Joined: Thu Jan 24, 2013 4:49 pm

Re: DeckLink output --enable-decklink

Post by iotzo » Mon Dec 01, 2014 10:19 am

jbalvarado wrote:Thank you for explaining! Maybe we can send the patch to the ffmpeg tracker. But there is a other problem to in the current source code, ffmpeg v2.3.5 works, and after that not anymore: https://trac.ffmpeg.org/ticket/4144
I saw the ticket and i can reproduce the error.
This is another part of the code when you are trying to get decklink device_list.
May I suggest this init code(taken from Decklink SDK examples):

Code: Select all

	HRESULT						result;
	// Initialize COM on this thread
	result = CoInitialize(NULL);
	if (FAILED(result))
	{
		fprintf(stderr, "Initialization of COM failed - result = %08x.\n", result);
		return NULL;
	}
	// Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
	result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&iter);
	if (FAILED(result))
	{
		fprintf(stderr, "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.\n");
		return NULL;
	}

, instead of the current init code:

Code: Select all

    if (CoInitialize(NULL) != S_OK) {
        av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n");
        return NULL;
    }

    if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL,
                         IID_IDeckLinkIterator, (void**) &iter) != S_OK) {
        av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n");
        return NULL;
    }

I just tested it with Ramiro's patch applied and I think it (re)solves "COM initialization failed" error when -list_devices is issued (ticket 4144).
If we combine the two modifications in one patch, we may get fully working build, I believe .

jbalvarado
Posts: 50
Joined: Thu Oct 03, 2013 3:47 pm

Re: DeckLink output --enable-decklink

Post by jbalvarado » Mon Dec 01, 2014 8:23 pm

Ok I have compile here a testversion:
https://www.dropbox.com/s/f9bnaz6xui0sh ... eg.7z?dl=0
Maybe somebody can test it in different ways? When it works I make a patch for it and post it to the ticker. I include both changes...

iotzo
Posts: 35
Joined: Thu Jan 24, 2013 4:49 pm

Re: DeckLink output --enable-decklink

Post by iotzo » Mon Dec 01, 2014 9:41 pm

jbalvarado wrote:Ok I have compile here a testversion:
https://www.dropbox.com/s/f9bnaz6xui0sh ... eg.7z?dl=0
Maybe somebody can test it in different ways? When it works I make a patch for it and post it to the ticker. I include both changes...
Both -list_devices and output to decklink are working now:)

Code: Select all

D:\>ffmpeg_decklink_jb -i test_dv.avi -f decklink -list_devices 1 dummy
ffmpeg version git-2014-12-01-51f2422 Copyright (c) 2000-2014 the FFmpeg developers
  built on Dec  1 2014 21:19:08 with gcc 4.9.2 (Rev2, Built by MSYS2 project)
  configuration: --arch=x86 --target-os=mingw32 --prefix=/local32 --bindir=/local32/bin-video --disable-debug --disable-shared --disable-doc --disable-w
32threads --enable-gpl --enable-version3 --enable-runtime-cpudetect --enable-avfilter --enable-avisynth --enable-libmp3lame --enable-libx264 --enable-de
cklink --extra-cflags=-I/build32/DeckLink_SDK_10.3.1/Win/include --extra-cflags=-DPTW32_STATIC_LIB --extra-libs='-lstdc++ -loleaut32'
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.101 / 56. 15.101
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, avi, from 'test_dv.avi':
  Metadata:
    encoder         : Lavf56.15.101
    timecode        : 00:00:00:00
  Duration: 00:00:55.20, start: 0.000000, bitrate: 30347 kb/s
    Stream #0:0: Video: dvvideo (dvsd / 0x64737664), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 28820 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 2 channels, s16, 1536 kb/s
[decklink @ 043ed820] Blackmagic DeckLink devices:
[decklink @ 043ed820]   'Intensity Pro'
Output #0, decklink, to 'dummy':
  Metadata:
    timecode        : 00:00:00:00
    encoder         : Lavf56.15.101
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.13.100 rawvideo
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc56.13.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (dvvideo (native) -> rawvideo (native))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Could not write header for output file #0 (incorrect codec parameters ?): Immediate exit requested

And some output test:

Code: Select all

D:\>ffmpeg_decklink_jb -i test_dv.avi -pix_fmt uyvy422 -f decklink "Intensity Pro"
ffmpeg version git-2014-12-01-51f2422 Copyright (c) 2000-2014 the FFmpeg developers
  built on Dec  1 2014 21:19:08 with gcc 4.9.2 (Rev2, Built by MSYS2 project)
  configuration: --arch=x86 --target-os=mingw32 --prefix=/local32 --bindir=/local32/bin-video --disable-debug --disable-shared --disable-doc --disable-w
32threads --enable-gpl --enable-version3 --enable-runtime-cpudetect --enable-avfilter --enable-avisynth --enable-libmp3lame --enable-libx264 --enable-de
cklink --extra-cflags=-I/build32/DeckLink_SDK_10.3.1/Win/include --extra-cflags=-DPTW32_STATIC_LIB --extra-libs='-lstdc++ -loleaut32'
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.101 / 56. 15.101
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, avi, from 'test_dv.avi':
  Metadata:
    encoder         : Lavf56.15.101
    timecode        : 00:00:00:00
  Duration: 00:00:55.20, start: 0.000000, bitrate: 30347 kb/s
    Stream #0:0: Video: dvvideo (dvsd / 0x64737664), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 28820 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 2 channels, s16, 1536 kb/s
[decklink @ 044dd7a0] Found Decklink mode 720 x 576 with rate 25.00(i)
Output #0, decklink, to 'Intensity Pro':
  Metadata:
    timecode        : 00:00:00:00
    encoder         : Lavf56.15.101
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 720x576 [SAR 64:45 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.13.100 rawvideo
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc56.13.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (dvvideo (native) -> rawvideo (native))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[decklink @ 044dd7a0] Encoder did not produce proper pts, making some up.
frame= 1105 fps= 25 q=0.0 Lsize=N/A time=00:00:44.20 bitrate=N/A

Post Reply
'