locked
How to encode video from the captured video to ismv by providing publishpoint using ssfsdk api and intel sdk ? RRS feed

  • Question

  • Hello,

    I am using Media Foundation transform tool for Capturing video from camera. 
    HRESULT ConfigureVideoEncoding(IMFCaptureSource *pSource, IMFCaptureRecordSink *pRecord, REFGUID guidEncodingType)
    {
        IMFMediaType *pMediaType = NULL;
        IMFMediaType *pMediaType2 = NULL;
        GUID guidSubType = GUID_NULL;
    
        // Configure the video format for the recording sink.
        HRESULT hr = pSource->GetCurrentDeviceMediaType((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_RECORD , &pMediaType);
       
        hr = CloneVideoMediaType(pMediaType, guidEncodingType, &pMediaType2);
       
        hr = pMediaType->GetGUID(MF_MT_SUBTYPE, &guidSubType);
       
        if(guidSubType == MFVideoFormat_H264_ES || guidSubType == MFVideoFormat_H264 || guidSubType == MFVideoFormat_YUY2)
        {
            //When the webcam supports H264_ES or H264, we just bypass the stream. The output from Capture engine shall be the same as
    		//the native type supported by the webcam
    		hr = pMediaType2->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_YUY2);
        }
        else
        {    
            UINT32 uiEncodingBitrate;
            hr = GetEncodingBitrate(pMediaType2, &uiEncodingBitrate);
       
            hr = pMediaType2->SetUINT32(MF_MT_AVG_BITRATE, uiEncodingBitrate);
        }
      
        // Connect the video stream to the recording sink.
        DWORD dwSinkStreamIndex;
        hr = pRecord->AddStream((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_RECORD, pMediaType2, NULL, &dwSinkStreamIndex);
    done:
        SafeRelease(&pMediaType);
        SafeRelease(&pMediaType2);
        return hr;
    }
    
    HRESULT ConfigureAudioEncoding(IMFCaptureSource *pSource, IMFCaptureRecordSink *pRecord, REFGUID guidEncodingType)
    {
        IMFCollection *pAvailableTypes = NULL;
        IMFMediaType *pMediaType = NULL;
        IMFAttributes *pAttributes = NULL;
    
        // Configure the audio format for the recording sink.
    
        HRESULT hr = MFCreateAttributes(&pAttributes, 1);
       
        // Enumerate low latency media types
        hr = pAttributes->SetUINT32(MF_LOW_LATENCY, TRUE);
           // Get a list of encoded output formats that are supported by the encoder.
        hr = MFTranscodeGetAudioOutputAvailableTypes(guidEncodingType, MFT_ENUM_FLAG_ALL | MFT_ENUM_FLAG_SORTANDFILTER,
            pAttributes, &pAvailableTypes);
       
    
        // Pick the first format from the list.
    
        hr = GetCollectionObject(pAvailableTypes, 0, &pMediaType); 
     
        // Connect the audio stream to the recording sink.
        DWORD dwSinkStreamIndex;
        hr = pRecord->AddStream((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_AUDIO, pMediaType, NULL, &dwSinkStreamIndex);
        if(hr == MF_E_INVALIDSTREAMNUMBER)
        {
            //If an audio device is not present, allow video only recording
            hr = S_OK;
        }
    done:
        return hr;
    }
    I want to create a DXD11 pipeline for getting streams from the recorded video to send it to ssfsdk api method ( Smooth Streaming Format SDK)
    hr = SSFMuxAddStream(hSSFMux, &streamInfo, &pCtx->dwStreamIndex);
    And later using
    hr = SSFMuxProcessOutput( pCtx->hSSFMux, pCtx->dwStreamIndex, &outputBuffer ); 
    we will get chunks (streams) in output buffer.
    I wanted to write these streams to publishpoint ( http://<server>/<pubpoint>/Streams(<identifier>) ) for live streaming.

    I have found below code for this.
      fResult = WinHttpSendRequest(
                        hHttpRequest,
                        szAdditionalHeaders,
                        ARRAYSIZE(szAdditionalHeaders)-1,
                        WINHTTP_NO_REQUEST_DATA,
                        0,
                        0,
                        NULL
                        );
        if( !fResult )
        {
            hr = HRESULT_FROM_WIN32( GetLastError() );
            goto done;
        }
    
    And here’s an example of a function for posting HTTP chunks (assuming WinHTTP is operating in “synchronous” mode):
    
         HRESULT WriteToSmoothStreamOutput(
            __in HINTERNET hHttpRequest,
            __in_ecount(cbData) LPCVOID pbData,
            __in ULONG cbData )
        {
            HRESULT hr = S_OK;
            BOOL fResult = FALSE;
            DWORD cbWritten;
    
            char szHttpChunkHeaderA[32];
            char szHttpChunkFooterA[] = "\r\n";
    
            //
            // Send the HTTP Chunk Transfer Encoding chunk-start mark
            // Observe the use of UTF-8 strings.
            //
    
            hr = StringCchPrintfA(
                    szHttpChunkHeaderA,
                    ARRAYSIZE(szHttpChunkHeaderA),
                    "%X\r\n",
                    cbData );
        
            fResult = WinHttpWriteData(
                            hHttpRequest,
                            szHttpChunkHeaderA,
                            (DWORD)( strlen(szHttpChunkHeaderA) * sizeof(char) ),
                            &cbWritten
                            );
        
            // Send the actual chunk data
            //
    
            if( cbData > 0 )
            {
                fResult = WinHttpWriteData(
                                hHttpRequest,
                                pbData,
                                cbData,
                                &cbWritten
                                );
              
            }
    
            //
            // Send the HTTP Chunk Transfer Encoding chunk-end mark
            //
    
            fResult = WinHttpWriteData(
                            hHttpRequest,
                            szHttpChunkFooterA,
                            (DWORD)( strlen(szHttpChunkFooterA) * sizeof(char) ),
                            &cbWritten
                            );
           
        done:
             return( hr );
        }  
    But WinHttp is unable to connect and write streams to publishpoint for live streaming.

    Please suggest for the above requirement.


    Tuesday, October 21, 2014 9:53 AM