What goes under the hood in the determination of a video file resolution (eg. .mts or .mp4 files)?











up vote
-1
down vote

favorite












I'd like to know how the resolution of a movie file is determined at the lowest level. Given such a file as input, how do command line tools lime mediainfo, ffprobe etc. determine its resolution? Is it calculated on the fly, or is it already written in the metadata of the movie file itself? If the latter, and if the metadata does not exist, is it possible to calculate the resolution from the file itself?



We can focus on .mts and .mp4 files in the answer.










share|improve this question






















  • I would suppose it is included in the headers of said format.
    – Vivick
    Nov 12 at 7:00















up vote
-1
down vote

favorite












I'd like to know how the resolution of a movie file is determined at the lowest level. Given such a file as input, how do command line tools lime mediainfo, ffprobe etc. determine its resolution? Is it calculated on the fly, or is it already written in the metadata of the movie file itself? If the latter, and if the metadata does not exist, is it possible to calculate the resolution from the file itself?



We can focus on .mts and .mp4 files in the answer.










share|improve this question






















  • I would suppose it is included in the headers of said format.
    – Vivick
    Nov 12 at 7:00













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'd like to know how the resolution of a movie file is determined at the lowest level. Given such a file as input, how do command line tools lime mediainfo, ffprobe etc. determine its resolution? Is it calculated on the fly, or is it already written in the metadata of the movie file itself? If the latter, and if the metadata does not exist, is it possible to calculate the resolution from the file itself?



We can focus on .mts and .mp4 files in the answer.










share|improve this question













I'd like to know how the resolution of a movie file is determined at the lowest level. Given such a file as input, how do command line tools lime mediainfo, ffprobe etc. determine its resolution? Is it calculated on the fly, or is it already written in the metadata of the movie file itself? If the latter, and if the metadata does not exist, is it possible to calculate the resolution from the file itself?



We can focus on .mts and .mp4 files in the answer.







video mp4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 6:50









forgodsakehold

654




654












  • I would suppose it is included in the headers of said format.
    – Vivick
    Nov 12 at 7:00


















  • I would suppose it is included in the headers of said format.
    – Vivick
    Nov 12 at 7:00
















I would suppose it is included in the headers of said format.
– Vivick
Nov 12 at 7:00




I would suppose it is included in the headers of said format.
– Vivick
Nov 12 at 7:00












1 Answer
1






active

oldest

votes

















up vote
0
down vote













A good source to look at for this type of info is the QuickTime Format specification as MP4 is largely the same as this, and the QuickTime document is nicely put together.



You can see there that the width and height in pixels of a track is included in a header 'atom' at the start of each track:



enter image description here



See here for more info: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-32963



The same information is available, albeit without the same diagrams, in the ISO 14496-1 Media Format specification, which is the standardised version and basis of mp4:



aligned(8) class TrackHeaderBox
extends FullBox(‘tkhd’, version, flags){
if (version==1) {
unsigned int(64) creation_time;
unsigned int(64) modification_time;
unsigned int(32) track_ID;
const unsigned int(32) reserved = 0;
unsigned int(64) duration;
} else { // version==0
unsigned int(32) creation_time;
unsigned int(32) modification_time;
unsigned int(32) track_ID;
const unsigned int(32) reserved = 0;
unsigned int(32) duration;
}
const unsigned int(32)[2] reserved = 0;
template int(16) layer = 0;
template int(16) alternate_group = 0;
template int(16) volume = {if track_is_audio 0x0100 else 0};
const unsigned int(16) reserved = 0;
template int(32)[9] matrix=
{ 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
// unity matrix
unsigned int(32) width;
unsigned int(32) height;


You can access that spec here (requires a click to accept license): https://standards.iso.org/ittf/PubliclyAvailableStandards/c068960_ISO_IEC_14496-12_2015.zip






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',
    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%2f53257131%2fwhat-goes-under-the-hood-in-the-determination-of-a-video-file-resolution-eg-m%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








    up vote
    0
    down vote













    A good source to look at for this type of info is the QuickTime Format specification as MP4 is largely the same as this, and the QuickTime document is nicely put together.



    You can see there that the width and height in pixels of a track is included in a header 'atom' at the start of each track:



    enter image description here



    See here for more info: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-32963



    The same information is available, albeit without the same diagrams, in the ISO 14496-1 Media Format specification, which is the standardised version and basis of mp4:



    aligned(8) class TrackHeaderBox
    extends FullBox(‘tkhd’, version, flags){
    if (version==1) {
    unsigned int(64) creation_time;
    unsigned int(64) modification_time;
    unsigned int(32) track_ID;
    const unsigned int(32) reserved = 0;
    unsigned int(64) duration;
    } else { // version==0
    unsigned int(32) creation_time;
    unsigned int(32) modification_time;
    unsigned int(32) track_ID;
    const unsigned int(32) reserved = 0;
    unsigned int(32) duration;
    }
    const unsigned int(32)[2] reserved = 0;
    template int(16) layer = 0;
    template int(16) alternate_group = 0;
    template int(16) volume = {if track_is_audio 0x0100 else 0};
    const unsigned int(16) reserved = 0;
    template int(32)[9] matrix=
    { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
    // unity matrix
    unsigned int(32) width;
    unsigned int(32) height;


    You can access that spec here (requires a click to accept license): https://standards.iso.org/ittf/PubliclyAvailableStandards/c068960_ISO_IEC_14496-12_2015.zip






    share|improve this answer

























      up vote
      0
      down vote













      A good source to look at for this type of info is the QuickTime Format specification as MP4 is largely the same as this, and the QuickTime document is nicely put together.



      You can see there that the width and height in pixels of a track is included in a header 'atom' at the start of each track:



      enter image description here



      See here for more info: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-32963



      The same information is available, albeit without the same diagrams, in the ISO 14496-1 Media Format specification, which is the standardised version and basis of mp4:



      aligned(8) class TrackHeaderBox
      extends FullBox(‘tkhd’, version, flags){
      if (version==1) {
      unsigned int(64) creation_time;
      unsigned int(64) modification_time;
      unsigned int(32) track_ID;
      const unsigned int(32) reserved = 0;
      unsigned int(64) duration;
      } else { // version==0
      unsigned int(32) creation_time;
      unsigned int(32) modification_time;
      unsigned int(32) track_ID;
      const unsigned int(32) reserved = 0;
      unsigned int(32) duration;
      }
      const unsigned int(32)[2] reserved = 0;
      template int(16) layer = 0;
      template int(16) alternate_group = 0;
      template int(16) volume = {if track_is_audio 0x0100 else 0};
      const unsigned int(16) reserved = 0;
      template int(32)[9] matrix=
      { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
      // unity matrix
      unsigned int(32) width;
      unsigned int(32) height;


      You can access that spec here (requires a click to accept license): https://standards.iso.org/ittf/PubliclyAvailableStandards/c068960_ISO_IEC_14496-12_2015.zip






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        A good source to look at for this type of info is the QuickTime Format specification as MP4 is largely the same as this, and the QuickTime document is nicely put together.



        You can see there that the width and height in pixels of a track is included in a header 'atom' at the start of each track:



        enter image description here



        See here for more info: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-32963



        The same information is available, albeit without the same diagrams, in the ISO 14496-1 Media Format specification, which is the standardised version and basis of mp4:



        aligned(8) class TrackHeaderBox
        extends FullBox(‘tkhd’, version, flags){
        if (version==1) {
        unsigned int(64) creation_time;
        unsigned int(64) modification_time;
        unsigned int(32) track_ID;
        const unsigned int(32) reserved = 0;
        unsigned int(64) duration;
        } else { // version==0
        unsigned int(32) creation_time;
        unsigned int(32) modification_time;
        unsigned int(32) track_ID;
        const unsigned int(32) reserved = 0;
        unsigned int(32) duration;
        }
        const unsigned int(32)[2] reserved = 0;
        template int(16) layer = 0;
        template int(16) alternate_group = 0;
        template int(16) volume = {if track_is_audio 0x0100 else 0};
        const unsigned int(16) reserved = 0;
        template int(32)[9] matrix=
        { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
        // unity matrix
        unsigned int(32) width;
        unsigned int(32) height;


        You can access that spec here (requires a click to accept license): https://standards.iso.org/ittf/PubliclyAvailableStandards/c068960_ISO_IEC_14496-12_2015.zip






        share|improve this answer












        A good source to look at for this type of info is the QuickTime Format specification as MP4 is largely the same as this, and the QuickTime document is nicely put together.



        You can see there that the width and height in pixels of a track is included in a header 'atom' at the start of each track:



        enter image description here



        See here for more info: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-32963



        The same information is available, albeit without the same diagrams, in the ISO 14496-1 Media Format specification, which is the standardised version and basis of mp4:



        aligned(8) class TrackHeaderBox
        extends FullBox(‘tkhd’, version, flags){
        if (version==1) {
        unsigned int(64) creation_time;
        unsigned int(64) modification_time;
        unsigned int(32) track_ID;
        const unsigned int(32) reserved = 0;
        unsigned int(64) duration;
        } else { // version==0
        unsigned int(32) creation_time;
        unsigned int(32) modification_time;
        unsigned int(32) track_ID;
        const unsigned int(32) reserved = 0;
        unsigned int(32) duration;
        }
        const unsigned int(32)[2] reserved = 0;
        template int(16) layer = 0;
        template int(16) alternate_group = 0;
        template int(16) volume = {if track_is_audio 0x0100 else 0};
        const unsigned int(16) reserved = 0;
        template int(32)[9] matrix=
        { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
        // unity matrix
        unsigned int(32) width;
        unsigned int(32) height;


        You can access that spec here (requires a click to accept license): https://standards.iso.org/ittf/PubliclyAvailableStandards/c068960_ISO_IEC_14496-12_2015.zip







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 11:56









        Mick

        11.9k12460




        11.9k12460






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53257131%2fwhat-goes-under-the-hood-in-the-determination-of-a-video-file-resolution-eg-m%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

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python