2

This question is about using Window Media API to output a 4K WMV video (although theoretically WMV doesn't support output to 4K)

After IWMWriter->BeginWriting() is called on both 32bit and 64bit Win10 (on both systems BeginWriting() returns S_OK), program takes about 450MB memory.

After that I start to use IWMWriter->AllocateSample() to allocate sample buffer and write it to sink using IWMWriter->WriteSample().

On 64bit Win10, conversion can finish gracefully but on 32bit Win10, WriteSample() fails with "out of memory" error after several frames are written.

The only difference I can see on 2 systems is: before calling BeginWriting(), 64Win10 takes 110 MB memory so after BeginWriting() is called, 110+450 is used. On 32bit Win10, 150 MB is used before BeginWriting() so after that 150+450 is used.

The peak working set of the failed conversion is only 761MB, anyone know why in this case WriteSample() returns out of memory. Is there any workaround for this?

== Update: =============================================

The source video contains both video and audio, in the failed case the program writes both video and audio and failed to write video.

If I take audio track out of the file so it only contains video, then conversion can finish gracefully. The peak working set is 716MB.

rhbc73
  • 739
  • 9
  • 24

1 Answers1

0

It's about video encoder's memory requirements: at this resolution the application does not fit standard 2 GB of address space of a 32-bit application. You might want to link with /LARGEADDRESSAWARE to bypass out of memory condition.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thanks for your suggestion Roman. But large address aware is already enabled. The same sample program also runs correctly on a 32 bit Win7 system. – rhbc73 Aug 15 '16 at 01:17
  • Your code "as is" causes access violation in `BeginWriting` call on my system in both 32 and 64 bit versions. However before setting /LARGEADDRESSAWARE 32 bit version indeed went into out-of-memory condition. So I still think it's the problem for 32 bits and high resolution. Win 7 encoder might be less greedy in memory requirements and work straight away. – Roman R. Aug 15 '16 at 05:18
  • Thanks Roman. This problem is somewhat solved. As I said I got an "out of memory" when BeginWriting is called. That's because I didn't memset media type correctly. memset(p, size, value) was written to memset(p, value, size) when setting input properties. – rhbc73 Aug 16 '16 at 06:53
  • With memset correctly written, on my 32 bit Win10 machine, after BeginWriting() is called, about 450MB was taken by the program. Another mistake I've made is, the memory consumption after BeginWriting() is called on 64bit Win10 is also 450MB. So the behavior on 32bit and 64bit systems are consistent. – rhbc73 Aug 16 '16 at 06:57