diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-01-16 01:17:26 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-01-19 12:02:36 +0100 |
commit | b177fca06b98f5ca2a2a9f178b49256b32e243e7 (patch) | |
tree | 19f16009259efcd7d4740d7ecb0393a12b1b50d4 /libavformat/avc.h | |
parent | f9b8b89b75fa0afa06ed6be1579b80cd73086c33 (diff) |
avformat/avc: Add functions to split access unit into list of NALUs
This will allow to avoid the temporary buffer and memcpys
when repacketing annex B to mp4-style H.264/H.265 without
searching twice for start codes.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/avc.h')
-rw-r--r-- | libavformat/avc.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libavformat/avc.h b/libavformat/avc.h index 9792b77913..aced285c7a 100644 --- a/libavformat/avc.h +++ b/libavformat/avc.h @@ -25,6 +25,35 @@ #include <stdint.h> #include "avio.h" +typedef struct NALU { + int offset; + uint32_t size; +} NALU; + +typedef struct NALUList { + NALU *nalus; + unsigned nalus_array_size; + unsigned nb_nalus; ///< valid entries in nalus +} NALUList; + +/* This function will parse the given annex B buffer and create + * a NALUList from it. This list can be passed to ff_nal_units_write_list() + * to write the access unit reformatted to mp4. + * + * @param list A NALUList. The list->nalus and list->nalus_array_size + * must be valid when calling this function and may be updated. + * nb_nalus is set by this function on success. + * @param buf buffer containing annex B H.264 or H.265. Must be padded. + * @param size size of buf, excluding padding. + * @return < 0 on error, the size of the mp4-style packet on success. + */ +int ff_nal_units_create_list(NALUList *list, const uint8_t *buf, int size); + +/* Writes a NALUList to the specified AVIOContext. The list must originate + * from ff_nal_units_create_list() with the same buf. */ +void ff_nal_units_write_list(const NALUList *list, AVIOContext *pb, + const uint8_t *buf); + int ff_avc_parse_nal_units(AVIOContext *s, const uint8_t *buf, int size); int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); |