{"id":1553,"date":"2015-10-10T21:25:14","date_gmt":"2015-10-10T19:25:14","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1553"},"modified":"2015-10-10T21:25:14","modified_gmt":"2015-10-10T19:25:14","slug":"reference-signal-source-for-directshow","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1553","title":{"rendered":"Reference signal source for DirectShow"},"content":{"rendered":"<div>\n<p>Every so often there are tasks that need certain reference video or video\/audio footage with specific properties: resolution, frame rate, frame accuracy with content identifying specific frame, motion in view, amount of motion which is &#8220;hard&#8221; for processing with encoder tuned for natural video, specific video and audio synchronization.<\/p>\n<p>There is of course some content available, and sometimes<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.youtube.com\/user\/bipbopbipbop\" target=\"_blank\">it&#8217;s really nice<\/a>:<\/p>\n<p><a href=\"https:\/\/www.youtube.com\/user\/bipbopbipbop\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1554 size-large\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image01-800x463.png\" alt=\"Bipbopbipbop video on Youtube\" width=\"625\" height=\"362\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image01-800x463.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image01-320x185.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image01-624x361.png 624w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image01.png 829w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>However once in a while you need 59.94 fps and not 60, and another time you&#8217;d go with 50 so that millisecond time is well-aligned and every second has equal number of frames, then next time you need specific aspect ratio override and then you&#8217;d prefer longer clip to a short one.<\/p>\n<p>I converted one of my sources for reference signal into DirectShow filters, which might be used to produce infinite signal, or otherwise they might be used to generate a file of specific format with specific properties.<\/p>\n<p>The filters are<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><em>Reference Video Source<\/em><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>and<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><em>Reference Audio Source<\/em>, regular filters registered in a separate category (not virtual video\/audio source devices &#8211; yet?), available for instantiation programmatically or in GraphStudioNext\/GraphEdit.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1555\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image02-800x567.png\" alt=\"DirectShowReferenceSource filters in GraphStudio\" width=\"625\" height=\"443\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image02-800x567.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image02-320x227.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image02-624x442.png 624w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image02.png 892w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>The filters are in both 32- and 64-bit versions, with hardcoded properties (yet?): 1280&#215;720@50 32-bit RGB for video and 16-bit PCM mono at 48 kHz for audio. Programmatically, however, the filters can be tuned flexibly using<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd319788\" target=\"_blank\"><code>IAMStreamConfig::Format<\/code><\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>call:<\/p>\n<ul>\n<li>Video:\n<ul>\n<li>Any resolution<\/li>\n<li>32-bit RGB, top-to-bottom only (the filter internally uses Direct2D\/WIC to generate the images)<\/li>\n<li>Any positive frame rate<\/li>\n<li>Aspect ratio can be overridden using<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd407326\" target=\"_blank\"><code>VIDEOINFOHEADER2<\/code><\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>format, e.g. to force SD video to be 4:3<\/li>\n<\/ul>\n<\/li>\n<li>Audio:\n<ul>\n<li>Any sample rate<\/li>\n<li>16-bit PCM or 32-bit IEEE floating point format<\/li>\n<li>Mono<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Video filter generates image sequence with properties burnt in, with frame number, 100ns time, time with frame number within second, and a circle with a sector filled to reflect current sub-second time. There is Uh\/Oh text inside the circle at sharp second times and the background color is in continuous transition between colors.<\/p>\n<p>Audio filter beeps every second during the first 100 ms of a second, with a tone different for every fifth and every tenth second.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1556\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image03-692x600.png\" alt=\"DirectShowReferenceSource fitlers running in GraphStudio\" width=\"625\" height=\"542\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image03-692x600.png 692w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image03-320x278.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image03-624x541.png 624w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Image03.png 768w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>Both filters support<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd319789\" target=\"_blank\"><code>IAMStreamControl<\/code><\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>interface, and<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd319792\" target=\"_blank\"><code>IAMStreamControl::StopAt<\/code><\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>method in particular, which allows to limit signal duration and be used for time accurate file creation.<\/p>\n<p>This comes with a<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/Generate\" target=\"_blank\">sample project<\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>that demonstrates ASF file generation for specific properties and duration. Output file generated by the sample is<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/_Bin\/Output.asf\" target=\"_blank\">Output.asf<\/a>.<\/p>\n<p>ASF file format and<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd390985\" target=\"_blank\">WM ASF Writer<\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>are chosen for code brevity and to reference stock multiplexer. This has a downside that multiplexer re-scales video to profile&#8217;s resolution and frame rate, of course. Those interested in generation of their own content would use something like their favorite H.264 and AAC encoders with MP4 or MKV multiplexer perhaps. And a nicer output would look like <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/_Bin\/Output.mp4\" target=\"_blank\">Output.mp4<\/a><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>then.<\/p>\n<p>A good thing about publishing these filters is that while preparing test project, I hit a<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/github.com\/roman380\/gdcl.co.uk-mpeg4\/issues\/2\" target=\"_blank\">thread safety bug in GDCL MP4 multiplexer<\/a>, which is presumably present in all\/most version of the mp4mux.dll out there: if filter graph is stopped at the time of video streaming, before reaching end-of-stream on video leg (which is often the case because upstream connection would be H.264 encoder having internal queue of frames draining then on worker threads processing stop request), multiplexer might generate a memory access violation trying to use<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><code>NULL<\/code><span class=\"Apple-converted-space\">\u00c2\u00a0<\/span>track object, which is already gone.<\/p>\n<h3>Download links<\/h3>\n<ul>\n<li>Binaries:\n<ul>\n<li>32-bit:<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/_Bin\/DirectShowReferenceSource-Win32.dll\" target=\"_blank\"><code>DirectShowReferenceSource-Win32.dll<\/code><\/a><\/li>\n<li>64-bit:<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/_Bin\/DirectShowReferenceSource-x64.dll\" target=\"_blank\"><code>DirectShowReferenceSource-x64.dll<\/code><\/a><\/li>\n<li>Sample project<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><code>Generate<\/code>:<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/Generate\/\" target=\"_blank\">SVN<\/a>,<span class=\"Apple-converted-space\">\u00c2\u00a0<\/span><a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/Generate\" target=\"_blank\">Trac<\/a><\/li>\n<li>License: This software is free to use<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every so often there are tasks that need certain reference video or video\/audio footage with specific properties: resolution, frame rate, frame accuracy with content identifying specific frame, motion in view, amount of motion which is &#8220;hard&#8221; for processing with encoder tuned for natural video, specific video and audio synchronization. There is of course some content&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1553\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[485,78,119,493,486],"class_list":["post-1553","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-audio","tag-directshow","tag-filter","tag-reference","tag-video"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1553"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1553\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}