diff options
author | Martin Storsjö <martin@martin.st> | 2012-03-22 15:25:58 +0400 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2012-03-25 00:53:18 +0400 |
commit | d5ed5e7d0c1fa46de348db0de4c82b0f621db3d4 (patch) | |
tree | c76a1a445e3f43dd6948515e31cd361f559e0ad6 /libavformat/avc.c | |
parent | 2ee01fbded0a6b35b55d125dfd5807219837cf30 (diff) |
avc: Add a function for converting mp4 style extradata to annex b
Make movenc use this function instead of the current custom
conversion function.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/avc.c')
-rw-r--r-- | libavformat/avc.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libavformat/avc.c b/libavformat/avc.c index b0c511e7b5..2fd5ac807b 100644 --- a/libavformat/avc.c +++ b/libavformat/avc.c @@ -160,3 +160,34 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) } return 0; } + +int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size) +{ + uint16_t sps_size, pps_size; + uint8_t *out; + int out_size; + + *buf = NULL; + if (*size >= 4 && (AV_RB32(in) == 0x00000001 || AV_RB24(in) == 0x000001)) + return 0; + if (*size < 11 || in[0] != 1) + return AVERROR_INVALIDDATA; + + sps_size = AV_RB16(&in[6]); + if (11 + sps_size > *size) + return AVERROR_INVALIDDATA; + pps_size = AV_RB16(&in[9 + sps_size]); + if (11 + sps_size + pps_size > *size) + return AVERROR_INVALIDDATA; + out_size = 8 + sps_size + pps_size; + out = av_mallocz(out_size); + if (!out) + return AVERROR(ENOMEM); + AV_WB32(&out[0], 0x00000001); + memcpy(out + 4, &in[8], sps_size); + AV_WB32(&out[4 + sps_size], 0x00000001); + memcpy(out + 8 + sps_size, &in[11 + sps_size], pps_size); + *buf = out; + *size = out_size; + return 0; +} |