title: Apply MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE to IMFSinkWriter
body: <p>Currently I'm creating WMV file with Windows Media Foundation SDK using the method (Transcode API) in following article: <a href="https://docs.microsoft.com/en-us/windows/desktop/medfound/tutorial--using-the-sink-writer-to-encode-video" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/medfound/tutorial--using-the-sink-writer-to-encode-video</a></p>
  
  <p>What I noticed is if I don't set MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE, output WMV file may be corrupted (show up as terrible artifacts during playback) when coded WMV file over the specified bitrate.</p>
  
  <p>According to following article, the flag needs to set to IMFASFContentInfo:
  <a href="https://docs.microsoft.com/en-us/windows/desktop/medfound/mfpkey-asfmediasink-autoadjust-bitrate-property" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/medfound/mfpkey-asfmediasink-autoadjust-bitrate-property</a></p>
  
  <p>So I tried following way:</p>
  
  <pre>
      IMFSinkWriter* pSinkWriter = NULL;
  
      //initialize sink writer with MFCreateSinkWriterFromURL
      ...
  
      IMFASFContentInfo* pContentInfo = NULL;
  
      pSinkWriter->GetServiceForStream((DWORD)MF_SINK_WRITER_MEDIASINK, GUID_NULL, __uuidof(IMFASFContentInfo), (LPVOID*)&pContentInfo);
  
      IPropertyStore* pPropStore = NULL;
      pContentInfo->GetEncodingConfigurationPropertyStore(0, &pPropStore);
  
      PROPVARIANT var;
      PropVariantInit(&var);
      var.vt = VT_BOOL;
      var.boolVal = VARIANT_TRUE;
  
      pPropStore->SetValue(MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE, var);
      PropVariantClear(&var);
  
      //Add Video stream and BeginWriting, then start passing samples
      ...
  
  </pre>
  
  <p>But, the settings does not seem to be applied to muxer, and I still see obvious artifacts of corrupted stream.</p>
  
  <p>What I guess is since MFCreateSinkWriterFromURL will create MediaSink and underlying IMFASFMultiplexer internally, however MFASF_MULTIPLEXER_AUTOADJUST_BITRATE needs to be set during creating IMFASFMultiplexer, so settings the flag after SinkWriter is created is too late.</p>
  
  <p>If I don't use Transcode API, and create IMFASFWriter by myself, I think I can set MFASF_MULTIPLEXER_AUTOADJUST_BITRATE during creating IMFASFWriter manually but since I already have a working code besides settings this flag by using Transcode API, if possible I want to keep current way.</p>
  
  <p>If anybody has any clue/solution/workaround, please let me know.</p>