locked
Subtitles? How to add text to mp4 RRS feed

  • Question

  • Hello,

    Is it possible to add subtitles to a video, using media foundation? I know it is possible to include subtitles into a mp4 file, but I can't find anything about it regarding media foundation.

    The final goal is to provide information about specific frames. So when generating a mp4 using a sinkwriter, is is possible to add text to each sample (and visually display it when watching the mp4)?

    Any help would be welcome.

    Tuesday, December 12, 2017 3:58 PM

All replies

  • Thanks for the response. I've tried creating a new IMFMediaType and setting major/sub type as suggested but without further parameters. When adding the stream to the sinkwriter the following error returns: The Media format is recognized but not supported. I guess this means it is not implemented. I'm currently on win 10 pro.

    	CHECK_HR( MFCreateMediaType( &pMediaTypeSubtitle ) );
    	CHECK_HR( pMediaTypeSubtitle->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Subtitle ) );
    	CHECK_HR( pMediaTypeSubtitle->SetGUID( MF_MT_SUBTYPE, MFSubtitleFormat_TTML ) );
    	CHECK_HR( pSinkWriter->AddStream( pMediaTypeSubtitle, &streamIndexSubtitles ) );

    My hopes are now focused on the IMFTimedTextTrack, although it seems it is only supported since win 10 which is not prefered...


    Wednesday, December 13, 2017 10:36 AM
  • My current version is 1709, build 16299.125 which was released just two days ago, 12 dec.

    If I open mfapi.h, I see MFMediaType_Subtitle is defined there.

    Thursday, December 14, 2017 9:49 AM
  • When/if you are using stock Media Foundation MPEG-4 File Sink, you are bound by its capabilities. And.. there is no mention of subtitles there so no you cannot add text to MP4 with stock Media Foundation. 

    Okay you still have an option to blend H.264 Annex D compatible SEI NAL unit data with 608/708 captions, which Windows TV & Movies player recognizes as well as a few other players. But I don't think it works out for you and I just mention this for completeness...

    You will need to use non Media Foundation tools to add text or just generate an .SRT standalone file expecting that player could pick it up.


    http://alax.info/blog/tag/directshow

    Thursday, December 14, 2017 11:29 AM
  • What about importing subtitles from a file? Does MediaFoundation support it?
    Tuesday, March 3, 2020 12:06 PM