IWMWriter::BeginWriting method (wmsdkidl.h)
[The feature associated with this page, Windows Media Format 11 SDK, is a legacy feature. It has been superseded by Source Reader and Sink Writer. Source Reader and Sink Writer have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader and Sink Writer instead of Windows Media Format 11 SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
The BeginWriting method initializes the writing process.
Syntax
HRESULT BeginWriting();
Return value
The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.
Return code | Description |
---|---|
|
The method succeeded. |
|
There is not enough available memory. |
|
The method failed for an unspecified reason. |
|
An error occurred in the audio codec. |
|
The required audio codec is not available. |
|
A more recent content revocation list is needed. |
|
The output format is not valid. |
|
An error occurred in the video codec. |
|
The required video codec is not available. |
Remarks
The BeginWriting method must be called before any samples are written. This method does not actually start writing, but initializes the process. Between this call and the call to EndWriting there can be no configuration changes to the writer. The EndWriting method must be called to cleanly end the writing of the samples.
The following operations can be performed only before calling BeginWriting:
- Setting the profile with SetProfile
- Setting the output filename (if using IWMWriter::SetOutputFilename)
- Setting an attribute with IWMHeaderInfo::SetAttribute
- Marker operations (IWMHeaderInfo::GetMarkerCount, GetMarker, AddMarker, and RemoveMarker, although AddMarker is not implemented on the writer and the rest aren't useful if there are no markers)
- Calling IWMWriter::SetInputProps with a NULLIWMInputMediaProps parameter to indicate that the input stream will be written using WriteStreamSample.
- Header Script operations (IWMHeaderInfo::GetScriptCount, GetScript, AddScript, and RemoveScript)
- Codec info operations (IWMHeaderInfo2::GetCodecInfoCount and GetCodecInfo)
- IWMWriterPostView::SetPostViewProps
- IWMHeaderInfo::GetAttributeCount
- IWMHeaderInfo::GetAttributeByIndex
- IWMHeaderInfo::GetAttributeByName
- IWMWriterAdvanced2::SetInputSetting
Note: SetInputSetting can be called after BeginWriting for g_wszDeinterlaceMode, g_wszInitialPatternForInverseTelecine, g_wszInterlacedCoding, and g_wszJPEGCompressionQuality.
The following operations can be performed any time after a profile has been set:
- Any postview operations except for SetPostViewProps
- IWMWriter::SetInputProps except when passing in a NULLIWMInputMediaProps parameter.
- IWMWriter::GetInputProps
- IWMWriter::GetInputFormatCount
- IWMWriter::GetInputFormat
- Allocating samples with IWMWriter::AllocateSample
- Writing samples with IWMWriter::WriteSample and IWMWriterAdvanced::WriteStreamSample
- IWMWriter::EndWriting
- Adding and removing a sink with IWMWriterAdvanced::AddSink and IWMWriterAdvanced::RemoveSink
- IWMWriterAdvanced::SetLiveSource
- IWMWriterAdvanced::IsRealTime
- IWMWriterAdvanced::GetWriterTime (although it won't return meaningful values)
- IWMWriterAdvanced::GetStatistics
- IWMWriterAdvanced::SetSyncTolerance
- IWMWriterAdvanced::GetSyncTolerance
Examples
The following example code outlines how to set up a writer and send output both to a network sink and an archive file.
IWMWriter * pWriter = NULL;
IWMWriterAdvanced * pWriterAdvanced = NULL;
IWMWriterFileSink2 * pWriterFileSink = NULL;
IWMWriterNetworkSink2 * pWriterNetworkSink = NULL;
HRESULT hr = S_OK;
DWORD dwPort;
// Do everything in a dummy loop for easy error-handling.
do
{
// Create the basic objects.
hr = WMCreateWriter( &pWriter );
if( FAILED( hr ) )
{
break;
}
hr = WMCreateWriterFileSink( &pWriterFileSink );
if( FAILED( hr ) )
{
break;
}
hr = WMCreateWriterNetworkSink( &pWriterNetworkSink );
if( FAILED( hr ) )
{
break;
}
// Retrieve a pointer to an IWMWriterAdvanced interface and add the sinks.
hr = pWriter->QueryInterface( IID_IWMWriterAdvanced, (void **)&pWriterAdvanced );
if( FAILED( hr ) )
{
break;
}
hr = pWriterAdvanced->AddSink( pWriterFileSink );
if( FAILED( hr ) )
{
break;
}
hr = pWriterAdvanced->AddSink( pWriterNetworkSink );
if( FAILED( hr ) )
{
break;
}
hr = pWriterFileSink->Open( L"Archive file name" );
if( FAILED( hr ) )
{
break;
}
// Setting the port number to zero enables the SDK to select an
// appropriate port number.
dwPort = 0;
hr = pWriterNetworkSink->Open( &dwPort );
if( FAILED( hr ) )
{
break;
}
hr = pWriter->BeginWriting();
if( FAILED( hr ) )
{
break;
}
// Code to send data to the writer goes here (not shown).
// Close both sinks.
hr = pWriterFileSink->Close();
if( FAILED( hr ) )
{
break;
}
hr = pWriterNetworkSink->Close();
if( FAILED( hr ) )
{
break;
}
hr = pWriter-> EndWriting();
if( FAILED( hr ) )
{
break;
}
}
while( FALSE );
// Clean up.
if ( pWriter )
{
pWriter->Release();
}
if ( pWriterAdvanced )
{
pWriterAdvanced->Release();
}
if ( pWriterFileSink )
{
pWriterFileSink->Release();
}
if ( pWriterNetworkSink )
{
pWriterNetworkSink->Release();
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 2000 Professional [desktop apps only],Windows Media Format 7 SDK, or later versions of the SDK |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | wmsdkidl.h (include Wmsdk.h) |
Library | Wmvcore.lib; WMStubDRM.lib (if you use DRM) |