0

I'm experiencing a problem with the Windows Media Foundation's decoder. I don't get why my code works when running as part of an executable lunched thru the UI of the OS, but doesn't work when executed from the context of a Windows Service. Basically the problem is in the creation of the decoder. It seams that the codec is not found.

I've configured the Windows Service to run with the same account as the one running the non-service executable - it is not working.

I've configured the Windows Service to run with the Local System account (allowing the service to interact with desktop) - it is not working.

Here's what I observe in mftrace when the decoder fails to create:

2332,1D90 12:30:05.27759 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @0285F8A0, MFT_FRIENDLY_NAME_Attribute=MPEG2VideoExtension;{3C0FBE52-D034-4115-995D-95B356B9855C}=1;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;{7347C815-79FC-4AD9-877D-ACDF5F46685E}=C:\Program Files\WindowsApps\Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe\x86\msmpeg2vdec_store.dll;MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 49 59 55 56 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;{957193AD-9029-4835-A2F2-3EC9AE9BB6C8}=Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe;{9D8B61A8-6BC8-4BFF-B31F-3A31060AFA3D}=Microsoft.MPEG2VideoExtension_8wekyb3d8bbwe;{BB49BC51-1810-4C3A-A9CF-D59C4E5B9622}={8103D590-5DC4-4825-A0D4-284395381C54};MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER;{DE106D30-42FB-4767-808D-0FCC6811B0B9}=MPEGDecoder.MFTMPEGDecoderTransform;{F9542F80-D069-4EFE-B30D-345536F76AAA}=0;{F9A1EF38-F61E-42E6-87B3-309438F9AC67}=0
2332,1D90 12:30:05.27768 CMFPlatExportDetours::MFTEnumEx @ Activate 01 @02861048, MFT_FRIENDLY_NAME_Attribute=Microsoft MPEG Video Decoder MFT;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={2D709E52-123F-49B5-9CBC-9AF5CDE28FB9};MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER
2332,1D90 12:30:05.27964 COle32ExportDetours::CoCreateInstance @ Created {0000034B-0000-0000-C000-000000000046}  () @01D825D8 - traced interfaces: 
2332,1D90 12:30:05.28801 COle32ExportDetours::CoCreateInstance @ Created {00000323-0000-0000-C000-000000000046} - ignored
2332,1D90 12:30:05.29134 COle32ExportDetours::CoCreateInstance @ Created {00000339-0000-0000-C000-000000000046}  () @01FD5610 - traced interfaces: 
2332,1D90 12:30:05.29494 COle32ExportDetours::CoCreateInstance @ Created {22F5B1DF-7D7A-4D21-97F8-C21AEFBA859C}  () @01DE59BC - traced interfaces: 
2332,1D90 12:30:05.29524 COle32ExportDetours::CoCreateInstance @ Created {0000034B-0000-0000-C000-000000000046}  () @01F48C48 - traced interfaces: 
2332,1D90 12:30:05.31066 COle32ExportDetours::CoCreateInstance @ Created {00000339-0000-0000-C000-000000000046}  () @01F47A60 - traced interfaces: 
**2332,1D90 12:30:05.31298 COle32ExportDetours::CoCreateInstance @ Failed to create {2D709E52-123F-49B5-9CBC-9AF5CDE28FB9} Microsoft MPEG Video Decoder MFT (C:\Windows\SysWOW64\msmpeg2vdec.dll) hr=0xC004F011 (null)**

And this is the mftrace output then the decoder is successfully created:

14724,5784 13:40:53.00531 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @0371A2C8, MFT_FRIENDLY_NAME_Attribute=MPEG2VideoExtension;{3C0FBE52-D034-4115-995D-95B356B9855C}=1;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;{7347C815-79FC-4AD9-877D-ACDF5F46685E}=C:\Program Files\WindowsApps\Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe\x86\msmpeg2vdec_store.dll;MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 49 59 55 56 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;{957193AD-9029-4835-A2F2-3EC9AE9BB6C8}=Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe;{9D8B61A8-6BC8-4BFF-B31F-3A31060AFA3D}=Microsoft.MPEG2VideoExtension_8wekyb3d8bbwe;{BB49BC51-1810-4C3A-A9CF-D59C4E5B9622}={5A73C951-DE09-4E99-89B9-CE0671C2B3A6};MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER;{DE106D30-42FB-4767-808D-0FCC6811B0B9}=MPEGDecoder.MFTMPEGDecoderTransform;{F9542F80-D069-4EFE-B30D-345536F76AAA}=0;{F9A1EF38-F61E-42E6-87B3-309438F9AC67}=0
14724,5784 13:40:53.00541 CMFPlatExportDetours::MFTEnumEx @ Activate 01 @03715648, MFT_FRIENDLY_NAME_Attribute=Microsoft MPEG Video Decoder MFT;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={2D709E52-123F-49B5-9CBC-9AF5CDE28FB9};MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER
14724,5784 13:40:53.05267 COle32ExportDetours::CoCreateInstance @ Created {0000034B-0000-0000-C000-000000000046}  () @03080608 - traced interfaces: 
14724,5784 13:40:53.06348 COle32ExportDetours::CoCreateInstance @ Created {00000323-0000-0000-C000-000000000046} - ignored
14724,5784 13:40:53.06760 COle32ExportDetours::CoCreateInstance @ Created {00000339-0000-0000-C000-000000000046}  () @03037CB0 - traced interfaces: 
14724,5784 13:40:53.07307 COle32ExportDetours::CoCreateInstance @ Created {22F5B1DF-7D7A-4D21-97F8-C21AEFBA859C}  () @02E7716C - traced interfaces: 
14724,5784 13:40:53.07353 COle32ExportDetours::CoCreateInstance @ Created {0000034B-0000-0000-C000-000000000046}  () @03080B30 - traced interfaces: 
**14724,5784 13:40:53.09256 CMFActivateDetours::ActivateObject @0371A2C8 New MFT @03086DEC**
14724,5784 13:40:53.09270 CMFTransformDetours::Attach @03086DEC Rate control @03086DD4
14724,5784 13:40:53.09272 CMFActivateDetours::GetGUID @0371A2C8 attribute not found guidKey = MFT_TRANSFORM_CLSID_Attribute
14724,5784 13:40:53.09275 CMFAttributesDetours::GetUINT32 @00FFE438 attribute not found guidKey = {FB5D2347-4DD8-4509-AED0-DB5FA9AA93F4}
14724,5784 13:40:53.09278 CMFTopologyNodeDetours::GetGUID @03718870 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
14724,5784 13:40:53.09278 CMFTransformDetours::Attach @03086DEC Rate control @03086DD4
14724,5784 13:40:53.09287 CMFAttributesDetours::GetUINT32 @0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09288 CMFAttributesDetours::GetStringLength @0371B6F0 attribute not found guidKey = MFT_ENUM_HARDWARE_URL_Attribute
14724,5784 13:40:53.09296 CMFTopologyDetours::GetUINT32 @036F9A18 attribute not found guidKey = MF_TOPOLOGY_DXVA_MODE
14724,5784 13:40:53.09300 CMFAttributesDetours::GetUINT32 @0371B6F0 attribute not found guidKey = GUID_NULL
14724,5784 13:40:53.09310 CMFAttributesDetours::GetUINT32 @0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09310 CMFAttributesDetours::GetUINT32 @0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09311 CMFAttributesDetours::GetStringLength @0371B6F0 attribute not found guidKey = MFT_ENUM_HARDWARE_URL_Attribute
14724,5784 13:40:53.09312 CMFTopologyDetours::GetUINT32 @036F9A18 attribute not found guidKey = {E48E1D3B-859A-40EC-928E-A5889EF0B458}
14724,5784 13:40:53.09312 CMFAttributesDetours::GetUINT32 @0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09312 CMFTopologyNodeDetours::GetUINT32 @03718870 attribute not found guidKey = MF_TOPONODE_LOCKED
14724,5784 13:40:53.09320 CMFTransformDetours::SetInputType @03086DEC Succeeded MT: MF_MT_FRAME_SIZE=3092376453696 (720,576);MF_MT_AVG_BITRATE=9700400;MF_MT_COMPRESSED=1;MF_MT_MPEG_SEQUENCE_HEADER=00 00 01 b3 2d 02 40 23 17 ae e3 80 00 00 01 b5 14 8a 00 01 00 00 ;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_DEFAULT_STRIDE=0;MF_MT_AM_FORMAT_TYPE=FORMAT_MPEG2Video;MF_MT_AVG_BIT_ERROR_RATE=0;MF_MT_MPEG2_LEVEL=2;MF_MT_MPEG2_PROFILE=2;MF_MT_FIXED_SIZE_SAMPLES=1;{C380465D-2271-428C-9B83-ECEA3B4A85C1}=0;MF_MT_FRAME_RATE=107374182401 (25,1);MF_MT_PIXEL_ASPECT_RATIO=68719476751 (16,15);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_SAMPLE_SIZE=1;MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MEDIASUBTYPE_MPEG2_VIDEO

Any help would be appreciated as I'm already stuck on this.

AnTo
  • 1
  • 2
  • It's not surprising it doesn't work. Local System is a very special account, not a logged-on account, seen as a computer etc.. (https://learn.microsoft.com/en-us/windows/win32/services/localsystem-account) You should try to use a normal user account (in service configuration, or impersonate in code). – Simon Mourier Jan 20 '23 at 13:19
  • What I'm trying to say is that it's not because of the user the service is running as. I've tried with the Network Service, Local System users and also with a local user which is part of the administrators group. The same code works when executed in UI application with the same local user. – AnTo Jan 20 '23 at 13:32
  • Is it H.265 decoding? – Roman R. Jan 20 '23 at 13:41
  • OK. it's probably applicable to MPEG-2 too. Perhaps it's the same problem as [in this question](https://stackoverflow.com/q/61963327/868014): the decoders are installed as Windows Store add-ons and are exposed to apps through a very specific shim layer. The decoder might not be available to this account because of COM security, which would be a rather hard challenge to fix. – Roman R. Jan 20 '23 at 13:47
  • I would say that you would want to instantiate this decoder explicitly from your service app. and if it does not work then look for this narrow problem first: whether you can impersonate or specify real user account. – Roman R. Jan 20 '23 at 13:48
  • It's MPEG2 decoding. Yes, I have installed the MPEG-2 Video Extension from the Windows Store. I'm aware that everything installed from the Windows Store is user-specific. That's why my first try was to run the service with the same user account as the one on which the decoder runs with no issues. – AnTo Jan 20 '23 at 14:00
  • So I guess the problem I'm having is a different one. – AnTo Jan 20 '23 at 14:06
  • I thought a bit more about this, and it's probably not exactly COM security, but rather absence of package identity in desktop app. In interactive scenario it is not a problem and access to Windows Store packaged codec is granted, but in service it does not happen and so your switching service user name does not help either. – Roman R. Jan 22 '23 at 09:18
  • Hmmm … isn’t it a bit weird that the same behavior is experienced in Windows 10 1607 where (is far as I understood) this codec is part of the Windows installation and no download from the store is required? – AnTo Jan 22 '23 at 13:16
  • I think your going back to 1607 might be insufficient: [OS: Windows 10 version 15063.0 or higher](https://apps.microsoft.com/store/detail/mpeg2-video-extension/9N95Q1ZZPMH4?hl=en-us&gl=us) suggests that it's good enough, but it still can be already packaged ass AppModel extension there. – Roman R. Jan 22 '23 at 13:24
  • That is, essential part is where the codec (COM server) is still in windows\system32 where it was in good old times, or it's moved to `C:\Program Files\WindowsApps\...` – Roman R. Jan 22 '23 at 13:33
  • Do you have a reproducible sample so we can test? – Simon Mourier Jan 22 '23 at 14:59
  • @SimonMourier the reproducer is fairly simple: https://gist.github.com/roman380/797362e76412c070fcc73e1a1a6b9ed2 when in service context MFTEnum finds no codec – Roman R. Jan 22 '23 at 15:27
  • I've put that in a service https://gist.github.com/smourier/b2c5c4b030b203ec1e754ca3ce753df0 If I use local system, I do get 0, but if I use my usual account, I get 1 (Windows 10 x64 latest), so I don't reproduce. – Simon Mourier Jan 22 '23 at 16:38
  • All right, so I’m not doing something stupid. I wonder how come no one else is complaining about this behavior. Isn’t this scenario supposed to be supported? – AnTo Jan 22 '23 at 18:35
  • Microsoft lost contact with general developer audience many years ago, on this set of technologies in particular, so problems like this have no solution for years. You are supposed to reach their support and discuss the problem directly, or you can also try their own QA forum where people forward questions to respective teams. – Roman R. Jan 22 '23 at 18:50

0 Answers0