locked
Add "title" frame to a mp4 video RRS feed

  • Question

  • So, I am trying to add a "static" frame to represent title to a mp4 video.

    Basically I am using MFCopy style method.

    This is my method:

    1. I created a static 24 bit BMP file. It just has a text. The dimensions of the image is same as the dimension of the mp4 file.

    2. Next, in my code, I extracted the image data from the BMP file.

    3. Converted the RGB 24 data to YUY2 using Intel IPP.

    4. Using IMFTransform, I converted YUY2 sample to H264 sample.

    5. Now, I created reader for the input mp4 file and created a writer with same properties. Basically, like MFCopy.

    6. Next, I wrote the title image H264 sample. Basically for 2 seconds. Just write the same sample (The idea is to show the static title at the beginning of the video for a few seconds).

    7. Next, read from the input mp4 file and write to the new mp4 file (with the timestamp of timestamp + 2 seconds)

    Now, the output mp4 file does show the duration as input duration + 2, but I don't see any title for the first 2 seconds. Basically, the output file is the input file, no difference.

    I am just wondering where I went wrong? Any pointers?

    Friday, February 15, 2013 10:49 AM

Answers

  • OK. I got it. Basically creating a separate "title" file and merge worked!
    • Marked as answer by Kadambi Wednesday, February 27, 2013 2:10 PM
    Wednesday, February 27, 2013 2:09 PM

All replies

  • I thought about this problem.

    In this situation, does Decode re-encode option works best?

    So, original mp4 file -> Decode audio and video data:

    1. Take RGB32 data and encode and add to new mp4 file,

    2. Take decoded data from original mp4 file and add to new mp4 file.

    Friday, February 15, 2013 3:52 PM
  • OK, the decode re-encode seems to be the right approach.

    One minor change was to get YUY2 data as opposed to RGB32.

    The bug now is that the audio starts immediately and is not displaced as I'd like it to be. 

    So, when the title slide is shown, the audio plays and is not displaced.

    Tuesday, February 19, 2013 7:17 AM
  • Splicing in new content with an already encoded H264 stream is always tricky.  You have to make sure that the SPS (sequence parameter set) and PPS (picture parameter set) and other sequence header values do not change at all for the two seconds of title frames.  Decoding and re-encoding is a lot easier and more reliable, though it does come with a quality loss.

    To displace the audio, you would need to follow a similar process to the one that you did for video.  Create audio samples filled with silence (filled with 0x80 for 8-bit PCM or 0 otherwise) for the first two seconds, and then modify the audio timestamps of the real stream to be +2 seconds.

    Thursday, February 21, 2013 11:56 PM
  • Matt

    Thanks for replying.

    I was going to post exactly the same based on my findings.

    I created "null audio" (value of 0 for PCM data) buffers and filled the mp4 file.

    Decoding and re-encoding is reliable and yes it does come with quality loss. At the same time it takes too long (obviously) Hence, I am actually going to try a third approach!

    With "title" frame and "null audio", I created a 4 second mp4 file. Now I will try to merge the two mp4 files without decode and re-encode. Sort of like mfcopy in general. Take data from title video file and dump it to a new file. Take data from my video and dump it to a new file with timestamps to be +4 seconds.

    I will post my findings. 

    Friday, February 22, 2013 5:33 AM
  • OK. I got it. Basically creating a separate "title" file and merge worked!
    • Marked as answer by Kadambi Wednesday, February 27, 2013 2:10 PM
    Wednesday, February 27, 2013 2:09 PM