Skip to main content

 none
Transcode asf file with MJPG codec to mp4/avi RRS feed

  • Question

  • I've been trying to transcode an asf video clip with MJPG codec to mp4 or avi.

    I'm getting an error saying "The operation failed because no samples were processed by the sink".

    I tried the sample code from  Win7Samples/multimedia/mediafoundation/Transcode and MFCopy. Both failed with the same error

    I've set the output video sub type as MFVideoFormat_H264 and the container as MFTranscodeContainerType_ASF.

    Could anyone please point me in the right direction on how to convert an asf file with mjpg codec info to mp4/avi?

    

    Thursday, November 7, 2019 8:34 AM

All replies

  • Hi ShyamalaAzhagarasan,

    I'm getting an error saying "The operation failed because no samples were processed by the sink"

    It sounds like the hardware isn't sending data to be recorded.  Are you sure your hardware is working correctly?

    Can you locate the error on that line of code?

    Best regards,

    Strive


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 8, 2019 7:52 AM
  • Hi Strive,

    I'm opening as asf creating a IMFMediaSource using CreateObjectFromURL, code is from (//github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/multimedia/mediafoundation/Transcode).

    This works fine when the asf contains H264 video stream, but when the codec is MJPG it fails. The error is thrown during finalize.

    Regards,

    Shyamala

    Monday, November 11, 2019 4:56 AM
  • Hi Shyamala,

    The error is thrown during finalize.

    Which API threw the error?

    I have tried Transcode sample,  but I can't reproduce your error.

    What I changed:

       if (SUCCEEDED(hr))
        {
    //        hr = pVideoAttrs->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_WMV3);
    	  hr = pVideoAttrs->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
        }
    	const WCHAR* sInputFile = L"example.asf";  // Audio source file name
    	const WCHAR* sOutputFile = L"123.mp4";  // Output file name

    If there's anything else need to change, please let me know.

    Best regards,

    Strive


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, November 12, 2019 10:20 AM
  • Hi Strive,

    I don't get the error for H264, I've a camera which streams in MJPG format. I've exported a clip from that to an asf file. 

    When I try to transcode this asf file to an mp4, the session gets ended and session close also succeeds.

        case MESessionEnded:
                hr = m_pSession->Close();
                if (SUCCEEDED(hr))
                {
                    wprintf_s(L"Finished encoding.\n");
                }
                break;

    After this 

                    

        while (meType != MESessionClosed)
        {
            hr = m_pSession->GetEvent(0, &pEvent);

            if (FAILED(hr)) { break; }

            // Get the event type.
            hr = pEvent->GetType(&meType);

            if (FAILED(hr)) { break; }

            hr = pEvent->GetStatus(&hrStatus);

            if (FAILED(hr)) { break; }

            if (FAILED(hrStatus))
            {
                wprintf_s(L"Failed. 0x%X error condition triggered this event.\n", hrStatus); //error occurs here
                hr = hrStatus;
                break;
            }

    Regards,

    Shyamala

    Thursday, November 14, 2019 9:44 AM
  • Hi Shyamala,

    Yes, I can reproduce your issue.  This works fine when the asf contains H264 video stream, and it failed when the codec is MJPG.

    So would you mind sharing the following detailed information to narrow down this issue?

    • When change hr = pVideoAttrs->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264) to hr = pVideoAttrs->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_MJPG), trancode asf file will fail, right?
    • Please check the return value of m_pTopology which locate in the hr = MFCreateTranscodeTopology( m_pSource, sURL, m_pProfile, &m_pTopology ). Beacuse when transform asf file to mp4 file, the code will fail and m_pTopology will return NULL. 
    • In addition, please help check the value of hr which also locate in hr = MFCreateTranscodeTopology( m_pSource, sURL, m_pProfile, &m_pTopology )
    HRESULT CTranscoder::EncodeToFile(const WCHAR *sURL)
    {
        assert (m_pSession);
        assert (m_pSource);
        assert (m_pProfile);
        
        if (!sURL)
        {
            return E_INVALIDARG;
        }
    
        HRESULT hr = S_OK;
    
        //Here failed , please check the value of hr and m_pTopology
        hr = MFCreateTranscodeTopology( m_pSource, sURL, m_pProfile, &m_pTopology );
    	
        // Set the topology on the media session.
        if (SUCCEEDED(hr))
        {
            hr = m_pSession->SetTopology(0, m_pTopology);
        }
        
        //Get media session events. This will start the encoding session.
        if (SUCCEEDED(hr))
        {
            hr = Transcode();
        }
    
        return hr;
    }

    Best regards,

    Strive


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Friday, November 15, 2019 8:35 AM
  • Hi Strive,

    When I set the Video sub type to MJPG, I get the error "No suitable transform is found". It's failing at the MFCreateTranscodeTopology. 

    If I try to set the sub type to H264, then I get the error Ma "The operation failed because no samples were processed by the sink". 

    Regards,

    Shyamala

    Tuesday, November 19, 2019 7:03 AM
  • Hi Shyamala,

    Thank you for your prompt reply.

    I will discuss this issue with relevant engineers. Once there is a conclusion, I will update the answer in the first time.

    Best regards,

    Strive


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 19, 2019 9:59 AM
  • Hi Shyamala,

    The Transcode sample code provided by Microsoft is not interned to convert asf file to mp4/avi.

    Would minding sharing a sample video and the code snippet if you have changed the code sample?

    Regards & Fei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, December 4, 2019 8:15 AM
  • If you still haven’t found a solution for your problem, you could consider trying the LEADTOOLS Multimedia SDK. (Disclaimer: I am an employee of the vendor of this library).

    The following code can convert Motion JPEG ASF to AVI without re-compressing the video:
    private void AsfToAvi(string inputASF, string outputAVI)
    {
       ConvertCtrl converter = new ConvertCtrl();
       converter.SourceFile = inputASF;
       converter.TargetFormat = TargetFormatType.AVI;
       converter.TargetFile = outputAVI;
       converter.StartConvert();
       while (converter.State != ConvertState.Stopped)
       {
          Console.WriteLine("Converting ...");
          Application.DoEvents();
       }
       MessageBox.Show("done");
    }
    

    Other output formats are supported, such as MP4, with slight changes to the code.

    If you would like to try this, there’s a free evaluation edition, which includes free email and chat support on this page.

    3 hours 38 minutes ago