about fmp4 encoding , how to fill the mdat box wit H264 frame?












0















I used C language to encode H264 frames (just have I/P frame) into fmp4 files. When I fill the mdat box, I don't know how to fill the frame data.

Is (I/P)frame data filled directly?

Do the first 4 bytes need to be filled with frame length?



I tried to use FFMPG to encode fmp4 file, and found that the data in mdat box was completely different from the original I/P frame data.

Is it coded again?

Can I directly fill the data of I/P frame into mdat box?










share|improve this question

























  • please add your code which you tried till now.

    – raju_eww
    Jan 1 at 4:22











  • The code is messy and inconvenient to display, just tell me the way of thinking, and then I will debug, thank you very much!

    – YuanDa.Yu
    Jan 1 at 8:21











  • Create a Minimal, Complete, and Verifiable example please. If you follow the concept, it will not be messy anymore. Also if you do, helping you will be easier. Describing code is often laden with the misconceptions which cause it to malfunction. Making an MCVE provices a second layer of communication which usually helps spotting the root fo the problem.

    – Yunnosch
    Jan 1 at 12:29











  • The answer is too complex for Q/A format unless you are a little more specific. The layout of the mdat is described in the moov (or moof) you can’t address one without addressing the other.

    – szatmary
    Jan 1 at 20:13
















0















I used C language to encode H264 frames (just have I/P frame) into fmp4 files. When I fill the mdat box, I don't know how to fill the frame data.

Is (I/P)frame data filled directly?

Do the first 4 bytes need to be filled with frame length?



I tried to use FFMPG to encode fmp4 file, and found that the data in mdat box was completely different from the original I/P frame data.

Is it coded again?

Can I directly fill the data of I/P frame into mdat box?










share|improve this question

























  • please add your code which you tried till now.

    – raju_eww
    Jan 1 at 4:22











  • The code is messy and inconvenient to display, just tell me the way of thinking, and then I will debug, thank you very much!

    – YuanDa.Yu
    Jan 1 at 8:21











  • Create a Minimal, Complete, and Verifiable example please. If you follow the concept, it will not be messy anymore. Also if you do, helping you will be easier. Describing code is often laden with the misconceptions which cause it to malfunction. Making an MCVE provices a second layer of communication which usually helps spotting the root fo the problem.

    – Yunnosch
    Jan 1 at 12:29











  • The answer is too complex for Q/A format unless you are a little more specific. The layout of the mdat is described in the moov (or moof) you can’t address one without addressing the other.

    – szatmary
    Jan 1 at 20:13














0












0








0








I used C language to encode H264 frames (just have I/P frame) into fmp4 files. When I fill the mdat box, I don't know how to fill the frame data.

Is (I/P)frame data filled directly?

Do the first 4 bytes need to be filled with frame length?



I tried to use FFMPG to encode fmp4 file, and found that the data in mdat box was completely different from the original I/P frame data.

Is it coded again?

Can I directly fill the data of I/P frame into mdat box?










share|improve this question
















I used C language to encode H264 frames (just have I/P frame) into fmp4 files. When I fill the mdat box, I don't know how to fill the frame data.

Is (I/P)frame data filled directly?

Do the first 4 bytes need to be filled with frame length?



I tried to use FFMPG to encode fmp4 file, and found that the data in mdat box was completely different from the original I/P frame data.

Is it coded again?

Can I directly fill the data of I/P frame into mdat box?







c mp4 h.264 fmp4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 12:27









Yunnosch

11.3k52033




11.3k52033










asked Jan 1 at 3:59









YuanDa.YuYuanDa.Yu

355




355













  • please add your code which you tried till now.

    – raju_eww
    Jan 1 at 4:22











  • The code is messy and inconvenient to display, just tell me the way of thinking, and then I will debug, thank you very much!

    – YuanDa.Yu
    Jan 1 at 8:21











  • Create a Minimal, Complete, and Verifiable example please. If you follow the concept, it will not be messy anymore. Also if you do, helping you will be easier. Describing code is often laden with the misconceptions which cause it to malfunction. Making an MCVE provices a second layer of communication which usually helps spotting the root fo the problem.

    – Yunnosch
    Jan 1 at 12:29











  • The answer is too complex for Q/A format unless you are a little more specific. The layout of the mdat is described in the moov (or moof) you can’t address one without addressing the other.

    – szatmary
    Jan 1 at 20:13



















  • please add your code which you tried till now.

    – raju_eww
    Jan 1 at 4:22











  • The code is messy and inconvenient to display, just tell me the way of thinking, and then I will debug, thank you very much!

    – YuanDa.Yu
    Jan 1 at 8:21











  • Create a Minimal, Complete, and Verifiable example please. If you follow the concept, it will not be messy anymore. Also if you do, helping you will be easier. Describing code is often laden with the misconceptions which cause it to malfunction. Making an MCVE provices a second layer of communication which usually helps spotting the root fo the problem.

    – Yunnosch
    Jan 1 at 12:29











  • The answer is too complex for Q/A format unless you are a little more specific. The layout of the mdat is described in the moov (or moof) you can’t address one without addressing the other.

    – szatmary
    Jan 1 at 20:13

















please add your code which you tried till now.

– raju_eww
Jan 1 at 4:22





please add your code which you tried till now.

– raju_eww
Jan 1 at 4:22













The code is messy and inconvenient to display, just tell me the way of thinking, and then I will debug, thank you very much!

– YuanDa.Yu
Jan 1 at 8:21





The code is messy and inconvenient to display, just tell me the way of thinking, and then I will debug, thank you very much!

– YuanDa.Yu
Jan 1 at 8:21













Create a Minimal, Complete, and Verifiable example please. If you follow the concept, it will not be messy anymore. Also if you do, helping you will be easier. Describing code is often laden with the misconceptions which cause it to malfunction. Making an MCVE provices a second layer of communication which usually helps spotting the root fo the problem.

– Yunnosch
Jan 1 at 12:29





Create a Minimal, Complete, and Verifiable example please. If you follow the concept, it will not be messy anymore. Also if you do, helping you will be easier. Describing code is often laden with the misconceptions which cause it to malfunction. Making an MCVE provices a second layer of communication which usually helps spotting the root fo the problem.

– Yunnosch
Jan 1 at 12:29













The answer is too complex for Q/A format unless you are a little more specific. The layout of the mdat is described in the moov (or moof) you can’t address one without addressing the other.

– szatmary
Jan 1 at 20:13





The answer is too complex for Q/A format unless you are a little more specific. The layout of the mdat is described in the moov (or moof) you can’t address one without addressing the other.

– szatmary
Jan 1 at 20:13












1 Answer
1






active

oldest

votes


















0














H.264 can be in different stream formats. One is called "Annex B" the other one is MP4.
In "Annex B" your NAL units are prefix with start codes 00 00 00 01 or 00 00 01.
In MP4 your NAL units are prefixed with the size in bytes.



I assume your encoder emits "Annex B".




  1. Remove the start code (00) 00 00 01


  2. Prefix your NAL units with the size (typically 4 bytes)


  3. Filter out AUD/SPS/PPS NAL units from your stream


  4. Write you converted NAL units into the MDAT box


  5. Create an AVC Configuration Box ('avcC') based on your SPS, PPS and the length size


  6. Store your avcC box in moov->trak->mdia->minf->stbl->avc1->avcC


  7. While you are writing your samples into mdat - keep track of sizes, offsets and frame types to create the correct stts, stss, stsc, stsz and stco boxes.







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992918%2fabout-fmp4-encoding-how-to-fill-the-mdat-box-wit-h264-frame%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    H.264 can be in different stream formats. One is called "Annex B" the other one is MP4.
    In "Annex B" your NAL units are prefix with start codes 00 00 00 01 or 00 00 01.
    In MP4 your NAL units are prefixed with the size in bytes.



    I assume your encoder emits "Annex B".




    1. Remove the start code (00) 00 00 01


    2. Prefix your NAL units with the size (typically 4 bytes)


    3. Filter out AUD/SPS/PPS NAL units from your stream


    4. Write you converted NAL units into the MDAT box


    5. Create an AVC Configuration Box ('avcC') based on your SPS, PPS and the length size


    6. Store your avcC box in moov->trak->mdia->minf->stbl->avc1->avcC


    7. While you are writing your samples into mdat - keep track of sizes, offsets and frame types to create the correct stts, stss, stsc, stsz and stco boxes.







    share|improve this answer




























      0














      H.264 can be in different stream formats. One is called "Annex B" the other one is MP4.
      In "Annex B" your NAL units are prefix with start codes 00 00 00 01 or 00 00 01.
      In MP4 your NAL units are prefixed with the size in bytes.



      I assume your encoder emits "Annex B".




      1. Remove the start code (00) 00 00 01


      2. Prefix your NAL units with the size (typically 4 bytes)


      3. Filter out AUD/SPS/PPS NAL units from your stream


      4. Write you converted NAL units into the MDAT box


      5. Create an AVC Configuration Box ('avcC') based on your SPS, PPS and the length size


      6. Store your avcC box in moov->trak->mdia->minf->stbl->avc1->avcC


      7. While you are writing your samples into mdat - keep track of sizes, offsets and frame types to create the correct stts, stss, stsc, stsz and stco boxes.







      share|improve this answer


























        0












        0








        0







        H.264 can be in different stream formats. One is called "Annex B" the other one is MP4.
        In "Annex B" your NAL units are prefix with start codes 00 00 00 01 or 00 00 01.
        In MP4 your NAL units are prefixed with the size in bytes.



        I assume your encoder emits "Annex B".




        1. Remove the start code (00) 00 00 01


        2. Prefix your NAL units with the size (typically 4 bytes)


        3. Filter out AUD/SPS/PPS NAL units from your stream


        4. Write you converted NAL units into the MDAT box


        5. Create an AVC Configuration Box ('avcC') based on your SPS, PPS and the length size


        6. Store your avcC box in moov->trak->mdia->minf->stbl->avc1->avcC


        7. While you are writing your samples into mdat - keep track of sizes, offsets and frame types to create the correct stts, stss, stsc, stsz and stco boxes.







        share|improve this answer













        H.264 can be in different stream formats. One is called "Annex B" the other one is MP4.
        In "Annex B" your NAL units are prefix with start codes 00 00 00 01 or 00 00 01.
        In MP4 your NAL units are prefixed with the size in bytes.



        I assume your encoder emits "Annex B".




        1. Remove the start code (00) 00 00 01


        2. Prefix your NAL units with the size (typically 4 bytes)


        3. Filter out AUD/SPS/PPS NAL units from your stream


        4. Write you converted NAL units into the MDAT box


        5. Create an AVC Configuration Box ('avcC') based on your SPS, PPS and the length size


        6. Store your avcC box in moov->trak->mdia->minf->stbl->avc1->avcC


        7. While you are writing your samples into mdat - keep track of sizes, offsets and frame types to create the correct stts, stss, stsc, stsz and stco boxes.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 22:31









        Markus SchumannMarkus Schumann

        4,38811416




        4,38811416
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992918%2fabout-fmp4-encoding-how-to-fill-the-mdat-box-wit-h264-frame%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas