1 /** MPEG video helper functions (MPEG 1, 2 and 4) 2 3 mkvmerge -- utility for splicing together matroska files 4 from component media subtypes 5 6 Distributed under the GPL v2 7 see the file COPYING for details 8 or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 9 10 \file 11 12 \author Written by Moritz Bunkus <moritz@bunkus.org>. 13 */ 14 15 #pragma once 16 17 #include "common/common_pch.h" 18 19 #include "common/math_fwd.h" 20 21 namespace mtx::mpeg1_2 { 22 23 // MPEG-1/-2 video start codes 24 constexpr auto PICTURE_START_CODE = 0x00000100u; 25 constexpr auto SLICE_START_CODE_LOWER = 0x00000101u; 26 constexpr auto SLICE_START_CODE_UPPER = 0x000001afu; 27 constexpr auto USER_DATA_START_CODE = 0x000001b2u; 28 constexpr auto SEQUENCE_HEADER_START_CODE = 0x000001b3u; 29 constexpr auto SEQUENCE_ERROR_START_CODE = 0x000001b4u; 30 constexpr auto EXT_START_CODE = 0x000001b5u; 31 constexpr auto SEQUENCE_END_CODE = 0x000001b7u; 32 constexpr auto GROUP_OF_PICTURES_START_CODE = 0x000001b8u; 33 constexpr auto MPEG_PROGRAM_END_CODE = 0x000001b9u; 34 constexpr auto PACKET_START_CODE = 0x000001bau; 35 constexpr auto SYSTEM_HEADER_START_CODE = 0x000001bbu; 36 constexpr auto PROGRAM_STREAM_MAP_START_CODE = 0x000001bcu; 37 38 // MPEG transport stream stram IDs 39 constexpr auto PROGRAM_STREAM_MAP = 0xbcu; 40 constexpr auto PRIVATE_STREAM_1 = 0xbdu; 41 constexpr auto PADDING_STREAM = 0xbeu; 42 constexpr auto PRIVATE_STREAM_2 = 0xbfu; 43 constexpr auto ECM_STREAM = 0xf0u; 44 constexpr auto EMM_STREAM = 0xf1u; 45 constexpr auto PROGRAM_STREAM_DIRECTORY = 0xffu; 46 constexpr auto DSMCC_STREAM = 0xf2u; 47 constexpr auto ITUTRECH222TYPEE_STREAM = 0xf8u; 48 49 // MPEG-1/-2 video frame rate indices 50 constexpr auto FPS_23_976 = 0x01u; // 24000/1001 51 constexpr auto FPS_24 = 0x02u; // 24 52 constexpr auto FPS_25 = 0x03u; // 25 53 constexpr auto FPS_29_97 = 0x04u; // 30000/1001 54 constexpr auto FPS_30 = 0x05u; // 30 55 constexpr auto FPS_50 = 0x06u; // 50 56 constexpr auto FPS_59_94 = 0x07u; // 60000/1001 57 constexpr auto FPS_60 = 0x08u; // 60 58 59 //MPEG-1/-2 video aspect ratio indices 60 constexpr auto AR_1_1 = 0x10u; // 1:1 61 constexpr auto AR_4_3 = 0x20u; // 4:3 62 constexpr auto AR_16_9 = 0x30u; // 16:9 63 constexpr auto AR_2_21 = 0x40u; // 2.21 64 65 constexpr auto FOURCC_MPEG1 = 0x10000001u; 66 constexpr auto FOURCC_MPEG2 = 0x10000002u; 67 68 int extract_fps_idx(const unsigned char *buffer, int buffer_size); 69 double get_fps(int idx); 70 std::optional<mtx_mp_rational_t> extract_aspect_ratio(const unsigned char *buffer, int buffer_size); 71 bool is_fourcc(uint32_t fourcc); 72 73 } 74