|
XenevaOS
|
#include <stdio.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <assert.h>

Go to the source code of this file.
Classes | |
| struct | MP4E_track_t |
| struct | MP4D_track_t |
| struct | MP4D_demux_tag |
| struct | MP4D_sample_to_chunk_t_tag |
| struct | h264_sps_id_patcher_t |
| struct | mp4_h26x_writer_tag |
Typedefs | |
| typedef uint64_t | boxsize_t |
| typedef boxsize_t | MP4D_file_offset_t |
| typedef struct MP4E_mux_tag | MP4E_mux_t |
| typedef struct MP4D_sample_to_chunk_t_tag | MP4D_sample_to_chunk_t |
| typedef struct MP4D_demux_tag | MP4D_demux_t |
| typedef struct mp4_h26x_writer_tag | mp4_h26x_writer_t |
Enumerations | |
| enum | track_media_kind_t { e_audio , e_video , e_private } |
Functions | |
| int | mp4_h26x_write_init (mp4_h26x_writer_t *h, MP4E_mux_t *mux, int width, int height, int is_hevc) |
| void | mp4_h26x_write_close (mp4_h26x_writer_t *h) |
| int | mp4_h26x_write_nal (mp4_h26x_writer_t *h, const unsigned char *nal, int length, unsigned timeStamp90kHz_next) |
| int | MP4D_open (MP4D_demux_t *mp4, int(*read_callback)(int64_t offset, void *buffer, size_t size, void *token), void *token, int64_t file_size) |
| MP4D_file_offset_t | MP4D_frame_offset (const MP4D_demux_t *mp4, unsigned int ntrack, unsigned int nsample, unsigned int *frame_bytes, unsigned *timestamp, unsigned *duration) |
| void | MP4D_close (MP4D_demux_t *mp4) |
| const void * | MP4D_read_sps (const MP4D_demux_t *mp4, unsigned int ntrack, int nsps, int *sps_bytes) |
| const void * | MP4D_read_pps (const MP4D_demux_t *mp4, unsigned int ntrack, int npps, int *pps_bytes) |
| MP4E_mux_t * | MP4E_open (int sequential_mode_flag, int enable_fragmentation, void *token, int(*write_callback)(int64_t offset, const void *buffer, size_t size, void *token)) |
| int | MP4E_add_track (MP4E_mux_t *mux, const MP4E_track_t *track_data) |
| int | MP4E_put_sample (MP4E_mux_t *mux, int track_num, const void *data, int data_bytes, int duration, int kind) |
| int | MP4E_close (MP4E_mux_t *mux) |
| int | MP4E_set_dsi (MP4E_mux_t *mux, int track_id, const void *dsi, int bytes) |
| int | MP4E_set_vps (MP4E_mux_t *mux, int track_id, const void *vps, int bytes) |
| int | MP4E_set_sps (MP4E_mux_t *mux, int track_id, const void *sps, int bytes) |
| int | MP4E_set_pps (MP4E_mux_t *mux, int track_id, const void *pps, int bytes) |
| int | MP4E_set_text_comment (MP4E_mux_t *mux, const char *comment) |
| #define FIX_BAD_ANDROID_META_BOX 1 |
| #define HEVC_NAL_BLA_W_LP 16 |
| #define HEVC_NAL_CRA_NUT 21 |
| #define HEVC_NAL_PPS 34 |
| #define HEVC_NAL_SPS 33 |
| #define HEVC_NAL_VPS 32 |
| #define MAX_CHUNKS_DEPTH 64 |
| #define MINIMP4_ALLOW_64BIT 1 |
| #define MINIMP4_MAX_PPS 256 |
| #define MINIMP4_MAX_SPS 32 |
| #define MINIMP4_MIN | ( | x, | |
| y | |||
| ) | ((x) < (y) ? (x) : (y)) |
| #define MINIMP4_TRANSCODE_SPS_ID 1 |
| #define MP4_OBJECT_TYPE_AUDIO_ISO_IEC_13818_7_LC_PROFILE 0x67 |
| #define MP4_OBJECT_TYPE_AUDIO_ISO_IEC_13818_7_MAIN_PROFILE 0x66 |
| #define MP4_OBJECT_TYPE_AUDIO_ISO_IEC_13818_7_SSR_PROFILE 0x68 |
| #define MP4_OBJECT_TYPE_AUDIO_ISO_IEC_14496_3 0x40 |
| #define MP4_OBJECT_TYPE_AVC 0x21 |
| #define MP4_OBJECT_TYPE_HEVC 0x23 |
| #define MP4_OBJECT_TYPE_USER_PRIVATE 0xC0 |
| #define MP4D_AVC_SUPPORTED 1 |
| #define MP4D_HANDLER_TYPE_SOUN 0x736F756E |
| #define MP4D_HANDLER_TYPE_VIDE 0x76696465 |
| #define MP4D_HEVC_SUPPORTED 1 |
| #define MP4D_INFO_SUPPORTED 1 |
| #define MP4D_PRINT_INFO_SUPPORTED 0 |
| #define MP4D_TFDT_SUPPORT 0 |
| #define MP4D_TIMESTAMPS_SUPPORTED 1 |
| #define MP4D_TRACE_SUPPORTED 0 |
| #define MP4D_TRACE_TIMESTAMPS 1 |
| #define MP4E_HANDLER_TYPE_GESM 0x6765736D |
| #define MP4E_SAMPLE_CONTINUATION 2 |
| #define MP4E_SAMPLE_DEFAULT 0 |
| #define MP4E_SAMPLE_RANDOM_ACCESS 1 |
| #define MP4E_STATUS_BAD_ARGUMENTS -1 |
| #define MP4E_STATUS_FILE_WRITE_ERROR -3 |
| #define MP4E_STATUS_NO_MEMORY -2 |
| #define MP4E_STATUS_OK 0 |
| #define MP4E_STATUS_ONLY_ONE_DSI_ALLOWED -4 |
| typedef struct mp4_h26x_writer_tag mp4_h26x_writer_t |
| typedef struct MP4D_demux_tag MP4D_demux_t |
| typedef boxsize_t MP4D_file_offset_t |
| typedef struct MP4D_sample_to_chunk_t_tag MP4D_sample_to_chunk_t |
| typedef struct MP4E_mux_tag MP4E_mux_t |
| enum track_media_kind_t |
| void mp4_h26x_write_close | ( | mp4_h26x_writer_t * | h | ) |
| int mp4_h26x_write_init | ( | mp4_h26x_writer_t * | h, |
| MP4E_mux_t * | mux, | ||
| int | width, | ||
| int | height, | ||
| int | is_hevc | ||
| ) |
| int mp4_h26x_write_nal | ( | mp4_h26x_writer_t * | h, |
| const unsigned char * | nal, | ||
| int | length, | ||
| unsigned | timeStamp90kHz_next | ||
| ) |
| void MP4D_close | ( | MP4D_demux_t * | mp4 | ) |
De-allocated memory
| MP4D_file_offset_t MP4D_frame_offset | ( | const MP4D_demux_t * | mp4, |
| unsigned int | ntrack, | ||
| unsigned int | nsample, | ||
| unsigned int * | frame_bytes, | ||
| unsigned * | timestamp, | ||
| unsigned * | duration | ||
| ) |
Return position and size for given sample from given track. The 'sample' is a MP4 term for 'frame'
frame_bytes [OUT] - return coded frame size in bytes timestamp [OUT] - return frame timestamp (in mp4->timescale units) duration [OUT] - return frame duration (in mp4->timescale units)
function return offset for the frame
| int MP4D_open | ( | MP4D_demux_t * | mp4, |
| int(*)(int64_t offset, void *buffer, size_t size, void *token) | read_callback, | ||
| void * | token, | ||
| int64_t | file_size | ||
| ) |
Parse given input stream as MP4 file. Allocate and store data indexes. return 1 on success, 0 on failure The MP4 indexes may be stored at the end of stream, so this function may parse all stream. It is guaranteed that function will read/seek sequentially, and will never jump back.
| const void * MP4D_read_pps | ( | const MP4D_demux_t * | mp4, |
| unsigned int | ntrack, | ||
| int | npps, | ||
| int * | pps_bytes | ||
| ) |
| const void * MP4D_read_sps | ( | const MP4D_demux_t * | mp4, |
| unsigned int | ntrack, | ||
| int | nsps, | ||
| int * | sps_bytes | ||
| ) |
Helper functions to parse mp4.track[ntrack].dsi for H.264 SPS/PPS Return pointer to internal mp4 memory, it must not be free()-ed
Example: process all SPS in MP4 file: while (sps = MP4D_read_sps(mp4, num_of_avc_track, sps_count, &sps_bytes)) { process(sps, sps_bytes); sps_count++; }
| int MP4E_add_track | ( | MP4E_mux_t * | mux, |
| const MP4E_track_t * | track_data | ||
| ) |
Add new track The track_data parameter does not referred by the multiplexer after function return, and may be allocated in short-time memory. The dsi member of track_data parameter is mandatory.
return ID of added track, or error code MP4E_STATUS_*
| int MP4E_close | ( | MP4E_mux_t * | mux | ) |
Finalize MP4 file, de-allocated memory, and closes MP4 multiplexer. The close operation takes a time and disk space, since it writes MP4 file indexes. Please note that this function does not closes file handle, which was passed to open function.
return error code MP4E_STATUS_*
| MP4E_mux_t * MP4E_open | ( | int | sequential_mode_flag, |
| int | enable_fragmentation, | ||
| void * | token, | ||
| int(*)(int64_t offset, const void *buffer, size_t size, void *token) | write_callback | ||
| ) |
Allocates and initialize mp4 multiplexor Given file handler is transparent to the MP4 library, and used only as argument for given fwrite_callback() function. By appropriate definition of callback function application may use any other file output API (for example C++ streams, or Win32 file functions)
return multiplexor handle on success; NULL on failure
| int MP4E_put_sample | ( | MP4E_mux_t * | mux, |
| int | track_num, | ||
| const void * | data, | ||
| int | data_bytes, | ||
| int | duration, | ||
| int | kind | ||
| ) |
Add new sample to specified track The tracks numbered starting with 0, according to order of MP4E_add_track() calls 'kind' is one of MP4E_SAMPLE_... defines
return error code MP4E_STATUS_*
Example: MP4E_put_sample(mux, 0, data, data_bytes, duration, MP4E_SAMPLE_DEFAULT);
| int MP4E_set_dsi | ( | MP4E_mux_t * | mux, |
| int | track_id, | ||
| const void * | dsi, | ||
| int | bytes | ||
| ) |
Set Decoder Specific Info (DSI) Can be used for audio and private tracks. MUST be used for AAC track. Only one DSI can be set. It is an error to set DSI again
return error code MP4E_STATUS_*
| int MP4E_set_pps | ( | MP4E_mux_t * | mux, |
| int | track_id, | ||
| const void * | pps, | ||
| int | bytes | ||
| ) |
Set PPS data. MUST be used for AVC (H.264) track. Up to 256 different PPS can be used in one track.
return error code MP4E_STATUS_*
| int MP4E_set_sps | ( | MP4E_mux_t * | mux, |
| int | track_id, | ||
| const void * | sps, | ||
| int | bytes | ||
| ) |
Set SPS data. MUST be used for AVC (H.264) track. Up to 32 different SPS can be used in one track.
return error code MP4E_STATUS_*
| int MP4E_set_text_comment | ( | MP4E_mux_t * | mux, |
| const char * | comment | ||
| ) |
Set or replace ASCII test comment for the file. Set comment to NULL to remove comment.
return error code MP4E_STATUS_*
| int MP4E_set_vps | ( | MP4E_mux_t * | mux, |
| int | track_id, | ||
| const void * | vps, | ||
| int | bytes | ||
| ) |
Set VPS data. MUST be used for HEVC (H.265) track.
return error code MP4E_STATUS_*