[FFmpeg-cvslog] avcodec/extract_extradata: zero initalize the padding bytes in all allocated buffers
ffmpeg | branch: release/3.4 | James Almer | Fri Mar 9 13:00:55 2018 -0300| [c289f4b6c9390d5b2b6388b0d82d40af62ea7ce2] | committer: James Almer avcodec/extract_extradata: zero initalize the padding bytes in all allocated buffers Reviewed-by: Derek Buitenhuis Signed-off-by: James Almer (cherry picked from commit d168e78effd170377ec57f67bca05c9f0de91bca) > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c289f4b6c9390d5b2b6388b0d82d40af62ea7ce2 --- libavcodec/extract_extradata_bsf.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index d40907a675..fbfd12aeef 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -114,6 +114,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, ret = AVERROR(ENOMEM); goto fail; } +memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); *data = extradata; *size = extradata_size; @@ -137,6 +138,8 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, pkt->buf = filtered_buf; pkt->data = filtered_buf->data; pkt->size = filtered_data - filtered_buf->data; + +memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE); } } @@ -169,6 +172,7 @@ static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, return AVERROR(ENOMEM); memcpy(*data, pkt->data, extradata_size); +memset(*data + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); *size = extradata_size; if (s->remove) { @@ -199,6 +203,7 @@ static int extract_extradata_mpeg12(AVBSFContext *ctx, AVPacket *pkt, return AVERROR(ENOMEM); memcpy(*data, pkt->data, *size); +memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE); if (s->remove) { pkt->data += *size; @@ -228,6 +233,7 @@ static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt, return AVERROR(ENOMEM); memcpy(*data, pkt->data, *size); +memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE); if (s->remove) { pkt->data += *size; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] vc2enc: replace quantization LUT with a smaller division LUT
ffmpeg | branch: master | Rostislav Pehlivanov | Tue Feb 27 23:12:33 2018 +| [ea6973a5733ce1a6b6359357fd5c1722c2774dce] | committer: Rostislav Pehlivanov vc2enc: replace quantization LUT with a smaller division LUT This commit replaces the huge and impractical LUT which converted coeffs and a quantizer to bits to encode and instead uses a standard multiplication and a shift to replace the division and then codes the values using the regular golomb coding functions. Signed-off-by: Rostislav Pehlivanov > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ea6973a5733ce1a6b6359357fd5c1722c2774dce --- libavcodec/vc2enc.c | 118 ++-- 1 file changed, 31 insertions(+), 87 deletions(-) diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c index b7adcd3d36..2e480ba8d0 100644 --- a/libavcodec/vc2enc.c +++ b/libavcodec/vc2enc.c @@ -29,10 +29,6 @@ #include "vc2enc_dwt.h" #include "diractab.h" -/* Total range is -COEF_LUT_TAB to +COEFF_LUT_TAB, but total tab size is half - * (COEF_LUT_TAB*DIRAC_MAX_QUANT_INDEX), as the sign is appended during encoding */ -#define COEF_LUT_TAB 2048 - /* The limited size resolution of each slice forces us to do this */ #define SSIZE_ROUND(b) (FFALIGN((b), s->size_scaler) + 4 + s->prefix_bytes) @@ -152,9 +148,8 @@ typedef struct VC2EncContext { uint8_t quant[MAX_DWT_LEVELS][4]; int custom_quant_matrix; -/* Coefficient LUT */ -uint32_t *coef_lut_val; -uint8_t *coef_lut_len; +/* Division LUT */ +uint32_t qmagic_lut[116][2]; int num_x; /* #slices horizontally */ int num_y; /* #slices vertically */ @@ -229,37 +224,6 @@ static av_always_inline int count_vc2_ue_uint(uint32_t val) return ff_log2(topbit)*2 + 1; } -static av_always_inline void get_vc2_ue_uint(int val, uint8_t *nbits, - uint32_t *eval) -{ -int i; -int pbits = 0, bits = 0, topbit = 1, maxval = 1; - -if (!val++) { -*nbits = 1; -*eval = 1; -return; -} - -while (val > maxval) { -topbit <<= 1; -maxval <<= 1; -maxval |= 1; -} - -bits = ff_log2(topbit); - -for (i = 0; i < bits; i++) { -topbit >>= 1; -pbits <<= 2; -if (val & topbit) -pbits |= 0x1; -} - -*nbits = bits*2 + 1; -*eval = (pbits << 1) | 1; -} - /* VC-2 10.4 - parse_info() */ static void encode_parse_info(VC2EncContext *s, enum DiracParseCodes pcode) { @@ -557,7 +521,7 @@ static void encode_picture_start(VC2EncContext *s) encode_wavelet_transform(s); } -#define QUANT(c, qf) (((c) << 2)/(qf)) +#define QUANT(c, mul, add, shift) (((mul) * (c) + (add)) >> (shift)) /* VC-2 13.5.5.2 - slice_band() */ static void encode_subband(VC2EncContext *s, PutBitContext *pb, int sx, int sy, @@ -570,24 +534,17 @@ static void encode_subband(VC2EncContext *s, PutBitContext *pb, int sx, int sy, const int top= b->height * (sy+0) / s->num_y; const int bottom = b->height * (sy+1) / s->num_y; -const int qfactor = ff_dirac_qscale_tab[quant]; -const uint8_t *len_lut = &s->coef_lut_len[quant*COEF_LUT_TAB]; -const uint32_t *val_lut = &s->coef_lut_val[quant*COEF_LUT_TAB]; - dwtcoef *coeff = b->buf + top * b->stride; +const uint64_t q_m = ((uint64_t)(s->qmagic_lut[quant][0])) << 2; +const uint64_t q_a = s->qmagic_lut[quant][1]; +const int q_s = av_log2(ff_dirac_qscale_tab[quant]) + 32; for (y = top; y < bottom; y++) { for (x = left; x < right; x++) { -const int neg = coeff[x] < 0; -uint32_t c_abs = FFABS(coeff[x]); -if (c_abs < COEF_LUT_TAB) { -put_bits(pb, len_lut[c_abs], val_lut[c_abs] | neg); -} else { -c_abs = QUANT(c_abs, qfactor); -put_vc2_ue_uint(pb, c_abs); -if (c_abs) -put_bits(pb, 1, neg); -} +uint32_t c_abs = QUANT(FFABS(coeff[x]), q_m, q_a, q_s); +put_vc2_ue_uint(pb, c_abs); +if (c_abs) +put_bits(pb, 1, coeff[x] < 0); } coeff += b->stride; } @@ -619,8 +576,9 @@ static int count_hq_slice(SliceArgs *slice, int quant_idx) SubBand *b = &s->plane[p].band[level][orientation]; const int q_idx = quants[level][orientation]; -const uint8_t *len_lut = &s->coef_lut_len[q_idx*COEF_LUT_TAB]; -const int qfactor = ff_dirac_qscale_tab[q_idx]; +const uint64_t q_m = ((uint64_t)s->qmagic_lut[q_idx][0]) << 2; +const uint64_t q_a = s->qmagic_lut[q_idx][1]; +const int q_s = av_log2(ff_dirac_qscale_tab[q_idx]) + 32; const int left = b->width * slice->x/ s->num_x; const int right = b->width *(slice->x+1) / s->num_x; @@ -631,14 +589,9 @@ static int count_hq_slice(SliceArgs *sl
[FFmpeg-cvslog] lavf/mov.c: Use the correct offset to shift timestamp when seeking.
ffmpeg | branch: master | Sasi Inguva | Fri Mar 9 13:30:21 2018 -0800| [43205df645bc10bc780c646ca0d652b574535f06] | committer: Michael Niedermayer lavf/mov.c: Use the correct offset to shift timestamp when seeking. Fixes seek for files with empty edits and files with negative ctts (dts_shift > 0). Added fate samples and tests. Signed-off-by: Sasi Inguva Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=43205df645bc10bc780c646ca0d652b574535f06 --- libavformat/isom.h | 1 + libavformat/mov.c| 27 --- tests/fate/seek.mak | 6 ++ tests/ref/seek/empty-edit-mp4| 134 +++ tests/ref/seek/test-iibbibb-mp4 | 122 tests/ref/seek/test-iibbibb-neg-ctts-mp4 | 122 6 files changed, 401 insertions(+), 11 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 65676fb0f5..4da34142f0 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -168,6 +168,7 @@ typedef struct MOVStreamContext { int *keyframes; int time_scale; int64_t time_offset; ///< time offset of the edit list entries +int64_t min_corrected_pts; ///< minimum Composition time shown by the edits excluding empty edits. int current_sample; int64_t current_index; MOVIndexRange* index_ranges; diff --git a/libavformat/mov.c b/libavformat/mov.c index 39c2179dcd..51228f5df2 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3378,7 +3378,6 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) int64_t edit_list_start_ctts_sample = 0; int64_t curr_cts; int64_t curr_ctts = 0; -int64_t min_corrected_pts = -1; int64_t empty_edits_sum_duration = 0; int64_t edit_list_index = 0; int64_t index; @@ -3419,6 +3418,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) msc->ctts_sample = 0; msc->ctts_allocated_size = 0; +// Reinitialize min_corrected_pts so that it can be computed again. +msc->min_corrected_pts = -1; + // If the dts_shift is positive (in case of negative ctts values in mov), // then negate the DTS by dts_shift if (msc->dts_shift > 0) { @@ -3563,10 +3565,10 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } } } else { -if (min_corrected_pts < 0) { -min_corrected_pts = edit_list_dts_counter + curr_ctts + msc->dts_shift; +if (msc->min_corrected_pts < 0) { +msc->min_corrected_pts = edit_list_dts_counter + curr_ctts + msc->dts_shift; } else { -min_corrected_pts = FFMIN(min_corrected_pts, edit_list_dts_counter + curr_ctts + msc->dts_shift); +msc->min_corrected_pts = FFMIN(msc->min_corrected_pts, edit_list_dts_counter + curr_ctts + msc->dts_shift); } if (edit_list_start_encountered == 0) { edit_list_start_encountered = 1; @@ -3625,16 +3627,16 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } } } -// If there are empty edits, then min_corrected_pts might be positive intentionally. So we subtract the -// sum duration of emtpy edits here. -min_corrected_pts -= empty_edits_sum_duration; +// If there are empty edits, then msc->min_corrected_pts might be positive +// intentionally. So we subtract the sum duration of emtpy edits here. +msc->min_corrected_pts -= empty_edits_sum_duration; // If the minimum pts turns out to be greater than zero after fixing the index, then we subtract the // dts by that amount to make the first pts zero. -if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && min_corrected_pts > 0) { -av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", min_corrected_pts); +if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && msc->min_corrected_pts > 0) { +av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts); for (i = 0; i < st->nb_index_entries; ++i) { -st->index_entries[i].timestamp -= min_corrected_pts; +st->index_entries[i].timestamp -= msc->min_corrected_pts; } } @@ -3697,6 +3699,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) if (empty_duration) empty_duration = av_rescale(empty_duration, sc->time_scale, mov->time_scale); sc->time_offset = start_time - empty_duration; +sc->min_corrected_pts = start_time; if (!mov->advanced_editlist) current_dts = -sc->time_offset; } @@ -7158,7 +7161,9 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int sample, time_sam
[FFmpeg-cvslog] avcodec/ffv1: support of more pix_fmt
ffmpeg | branch: master | Jérôme Martinez | Wed Mar 7 11:19:03 2018 +0100| [b6fc09cdb4c4e5e4974ca35159f459174b9a9be5] | committer: Michael Niedermayer avcodec/ffv1: support of more pix_fmt Without direct support of such pix_fmt, content is padded to 16-bit and it is not possible to know that the source file was with a smaller bit depth so framemd5 is different Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b6fc09cdb4c4e5e4974ca35159f459174b9a9be5 --- libavcodec/ffv1dec.c | 14 +- libavcodec/ffv1enc.c | 13 - 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 3d2ee2569f..b4a183c5b7 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -591,7 +591,10 @@ static int read_header(FFV1Context *f) if (!f->transparency && !f->chroma_planes) { if (f->avctx->bits_per_raw_sample <= 8) f->avctx->pix_fmt = AV_PIX_FMT_GRAY8; -else if (f->avctx->bits_per_raw_sample == 10) { +else if (f->avctx->bits_per_raw_sample == 9) { +f->packed_at_lsb = 1; +f->avctx->pix_fmt = AV_PIX_FMT_GRAY9; +} else if (f->avctx->bits_per_raw_sample == 10) { f->packed_at_lsb = 1; f->avctx->pix_fmt = AV_PIX_FMT_GRAY10; } else if (f->avctx->bits_per_raw_sample == 12) { @@ -642,6 +645,7 @@ static int read_header(FFV1Context *f) f->packed_at_lsb = 1; switch(16 * f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P10; break; +case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P10; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P10; break; } @@ -656,9 +660,17 @@ static int read_header(FFV1Context *f) f->packed_at_lsb = 1; switch(16 * f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P12; break; +case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P12; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P12; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P12; break; } +} else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) { +f->packed_at_lsb = 1; +switch(16 * f->chroma_h_shift + f->chroma_v_shift) { +case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P14; break; +case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P14; break; +case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P14; break; +} } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){ f->packed_at_lsb = 1; switch(16 * f->chroma_h_shift + f->chroma_v_shift) { diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 2e999b0986..dd4d7429f5 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -558,6 +558,7 @@ FF_ENABLE_DEPRECATION_WARNINGS s->plane_count = 3; switch(avctx->pix_fmt) { +case AV_PIX_FMT_GRAY9: case AV_PIX_FMT_YUV444P9: case AV_PIX_FMT_YUV422P9: case AV_PIX_FMT_YUV420P9: @@ -568,6 +569,7 @@ FF_ENABLE_DEPRECATION_WARNINGS s->bits_per_raw_sample = 9; case AV_PIX_FMT_GRAY10: case AV_PIX_FMT_YUV444P10: +case AV_PIX_FMT_YUV440P10: case AV_PIX_FMT_YUV420P10: case AV_PIX_FMT_YUV422P10: case AV_PIX_FMT_YUVA444P10: @@ -577,11 +579,17 @@ FF_ENABLE_DEPRECATION_WARNINGS s->bits_per_raw_sample = 10; case AV_PIX_FMT_GRAY12: case AV_PIX_FMT_YUV444P12: +case AV_PIX_FMT_YUV440P12: case AV_PIX_FMT_YUV420P12: case AV_PIX_FMT_YUV422P12: -s->packed_at_lsb = 1; if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) s->bits_per_raw_sample = 12; +case AV_PIX_FMT_YUV444P14: +case AV_PIX_FMT_YUV420P14: +case AV_PIX_FMT_YUV422P14: +if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) +s->bits_per_raw_sample = 14; +s->packed_at_lsb = 1; case AV_PIX_FMT_GRAY16: case AV_PIX_FMT_YUV444P16: case AV_PIX_FMT_YUV422P16: @@ -1330,6 +1338,9 @@ AVCodec ff_ffv1_encoder = { AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GBRP16, AV_PIX_FMT_RGB48, AV_PIX_FMT_GBRAP16, AV_PIX_FMT_RGBA64, +AV_PIX_FMT_GRAY9, +AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14, +AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV440P12, AV_PIX_FMT_NONE }, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avcodec/extract_extradata: don't allocate more space than needed when removing NALUs in h264/hevc
ffmpeg | branch: master | James Almer | Fri Mar 9 14:31:30 2018 -0300| [2536bd863246218631ab27144d8a3be45036445a] | committer: James Almer avcodec/extract_extradata: don't allocate more space than needed when removing NALUs in h264/hevc Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2536bd863246218631ab27144d8a3be45036445a --- libavcodec/extract_extradata_bsf.c | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index fbfd12aeef..4e2d601742 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -62,7 +62,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, ExtractExtradataContext *s = ctx->priv_data; H2645Packet h2645_pkt = { 0 }; -int extradata_size = 0; +int extradata_size = 0, filtered_size = 0; const int *extradata_nal_types; int nb_extradata_nal_types; int i, has_sps = 0, has_vps = 0, ret = 0; @@ -90,6 +90,8 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, } else { if (nal->type == H264_NAL_SPS) has_sps = 1; } +} else if (s->remove) { +filtered_size += nal->raw_size + 3; } } @@ -100,11 +102,13 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, uint8_t *extradata, *filtered_data; if (s->remove) { -filtered_buf = av_buffer_alloc(pkt->size + AV_INPUT_BUFFER_PADDING_SIZE); +filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!filtered_buf) { ret = AVERROR(ENOMEM); goto fail; } +memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + filtered_data = filtered_buf->data; } @@ -137,9 +141,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, av_buffer_unref(&pkt->buf); pkt->buf = filtered_buf; pkt->data = filtered_buf->data; -pkt->size = filtered_data - filtered_buf->data; - -memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE); +pkt->size = filtered_size; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog