自从我完成使用H.264和AAC编码器MFT将视频文件转换为MP4的程序已经过去几个月了。虽然它在Win7上运行良好,但是当我昨天在Win8上运行它(也在Win10 Build 10240上试过)时,我发现了一些与Win7上看到的不同的东西。
我的程序调用MFT-> ProcessInput()将帧发送到编码器,并在每个ProcessInput后调用ProcessOutput。
下面是我在Win7上转换文件时生成的日志。每次调用ProcessInput时,ProcessOutput都会返回一个帧。
Line 178: 00:00:24.562 MAIN encoding time = 0, duration = 420000
Line 180: 00:00:24.828 MAIN sample returned, sample time = 0
Line 185: 00:00:24.875 MAIN encoding time = 420000, duration = 420000
Line 187: 00:00:25.234 MAIN sample returned, sample time = 420000
Line 192: 00:00:25.359 MAIN encoding time = 840000, duration = 420000
Line 194: 00:00:25.469 MAIN sample returned, sample time = 840000
Line 199: 00:00:25.484 MAIN encoding time = 1260000, duration = 410000
Line 201: 00:00:25.562 MAIN sample returned, sample time = 1260000
Line 206: 00:00:25.578 MAIN encoding time = 1670000, duration = 420000
Line 208: 00:00:25.656 MAIN sample returned, sample time = 1670000
Line 213: 00:00:25.672 MAIN encoding time = 2090000, duration = 420000
Line 215: 00:00:25.781 MAIN sample returned, sample time = 2090000
Line 220: 00:00:25.859 MAIN encoding time = 2510000, duration = 420000
Line 222: 00:00:26.015 MAIN sample returned, sample time = 2510000
以下是我在Windows 8.1 64位和Windows 10上转换相同文件时看到的内容
Line 196: 00:00:21.187 MAIN encoding time = 0, duration = 420000
Line 200: 00:00:21.203 MAIN encoding time = 420000, duration = 420000
Line 204: 00:00:21.234 MAIN encoding time = 840000, duration = 420000
Line 208: 00:00:21.265 MAIN encoding time = 1260000, duration = 410000
Line 210: 00:00:21.281 MAIN sample returned, sample time = 420000
Line 215: 00:00:21.297 MAIN encoding time = 1670000, duration = 420000
Line 217: 00:00:21.312 MAIN sample returned, sample time = 1260000
Line 222: 00:00:21.343 MAIN encoding time = 2090000, duration = 420000
Line 224: 00:00:21.359 MAIN sample returned, sample time = 840000
Line 230: 00:00:21.375 MAIN encoding time = 2510000, duration = 420000
Line 232: 00:00:21.406 MAIN sample returned, sample time = 2090000
Line 237: 00:00:21.422 MAIN encoding time = 2930000, duration = 410000
Line 239: 00:00:21.437 MAIN sample returned, sample time = 1670000
Line 245: 00:00:21.468 MAIN encoding time = 3340000, duration = 420000
Line 247: 00:00:21.484 MAIN sample returned, sample time = 2930000
Line 252: 00:00:21.515 MAIN encoding time = 3760000, duration = 420000
Line 254: 00:00:21.515 MAIN sample returned, sample time = 2510000
在向编码器发送4帧之前,第一帧返回并不重要,对我来说重要的是返回帧的时间戳不是单调增加的。 (42,126,84,209 ...时间戳是通过调用IMFSample-> GetSampleTime()获得的。
之后我在Windows 10上运行了mftrace并获得了这个
MFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @08379F88, Time 0ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 42ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 84ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 126ms, Duration 41ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 167ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 209ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 42ms, Duration 42ms, Buffers 1, Size 24841B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=0 (0,0);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=0;MFSampleExtension_CleanPoint=1;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 251ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 126ms, Duration 42ms, Buffers 1, Size 1152B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=420000 (0,420000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=1;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 293ms, Duration 41ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 84ms, Duration 42ms, Buffers 1, Size 20B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=840000 (0,840000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=2;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
让我们只检查ProcessOutput
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 42ms, Duration 42ms, Buffers 1, Size 24841B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=0 (0,0);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=0;MFSampleExtension_CleanPoint=1;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 126ms, Duration 42ms, Buffers 1, Size 1152B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=420000 (0,420000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=1;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 84ms, Duration 42ms, Buffers 1, Size 20B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=840000 (0,840000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=2;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
我们可以看到返回的时间戳是42,126,84 ......
因为在我的程序中,复用器(复用编码的视频和音频数据并将其写入文件)需要单调增加时间戳,Win8 / 10上H.264编码器MFT的行为会破坏文件转换。
如果有人对整个mftrace日志感兴趣,我会把它放在https://dl.dropboxusercontent.com/u/89678527/mfrelease.log
感谢您的任何建议。