title: Media Foundation Write Sample gives Access Violation while writing
body: <p><a href="https://docs.microsoft.com/en-us/windows/win32/medfound/tutorial--using-the-sink-writer-to-encode-video" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/win32/medfound/tutorial--using-the-sink-writer-to-encode-video</a>.</p>
  
  <p>I followed this Documentation and tried to create a video sample using a few  bitmapImages . However after the below line there is a Exception.</p>
  
  <p>The Bitmap Image is sent to the WriteFrame() function of format byte [] array format which is similar to VideosourceFrame but in DWORD format  in the tutorial. </p>
  
  <pre><code>pSinkWriter-&gt;WriteSample(streamIndex, spSample));
  </code></pre>
  
  <p>The Exception after this line is </p>
  
  <pre><code>     Exception thrown at 0x00007FFCE9A9DF33 (ntdll.dll) in Movie.exe: 0xC0000005: Access violation writing location 0x0000000000000024.
  </code></pre>
  
  <p>The run time values of the writer, sample, buffer : just before the Exception</p>
  
  <p><img src="https://i.stack.imgur.com/RZWon.png" alt="Media Buffer"></p>
  
  <p><img src="https://i.stack.imgur.com/thVFy.png" alt="Media sample"></p>
  
  <p><img src="https://i.stack.imgur.com/MY1zq.png" alt="Media SinkWriter">
  <a href="https://i.stack.imgur.com/WEH40.png" rel="nofollow noreferrer">callstack after the call to Writesample</a></p>
  
  <p>Any leads would be helpful.</p>