This options is only used by huffyuv, ffvhuv, jpegls, mjpeg, mpegvideoenc, png, utvideo. It is a very codec-specific options, so deprecate the global variant. Set proper limits to the maximum allowed values, and update utvideoenc tests to use the new option name. Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>tags/n3.0
| @@ -1678,15 +1678,15 @@ typedef struct AVCodecContext { | |||||
| * - decoding: Set by user (or 0). | * - decoding: Set by user (or 0). | ||||
| */ | */ | ||||
| int slice_count; | int slice_count; | ||||
| /** | |||||
| * prediction method (needed for huffyuv) | |||||
| * - encoding: Set by user. | |||||
| * - decoding: unused | |||||
| */ | |||||
| #if FF_API_PRIVATE_OPT | |||||
| /** @deprecated use encoder private options instead */ | |||||
| attribute_deprecated | |||||
| int prediction_method; | int prediction_method; | ||||
| #define FF_PRED_LEFT 0 | #define FF_PRED_LEFT 0 | ||||
| #define FF_PRED_PLANE 1 | #define FF_PRED_PLANE 1 | ||||
| #define FF_PRED_MEDIAN 2 | #define FF_PRED_MEDIAN 2 | ||||
| #endif | |||||
| /** | /** | ||||
| * slice offsets in the frame in bytes | * slice offsets in the frame in bytes | ||||
| @@ -193,7 +193,12 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||||
| } | } | ||||
| avctx->bits_per_coded_sample = s->bitstream_bpp; | avctx->bits_per_coded_sample = s->bitstream_bpp; | ||||
| s->decorrelate = s->bitstream_bpp >= 24; | s->decorrelate = s->bitstream_bpp >= 24; | ||||
| s->predictor = avctx->prediction_method; | |||||
| #if FF_API_PRIVATE_OPT | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | |||||
| if (avctx->prediction_method) | |||||
| s->predictor = avctx->prediction_method; | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | |||||
| #endif | |||||
| s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0; | s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0; | ||||
| if (s->context) { | if (s->context) { | ||||
| if (s->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) { | if (s->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) { | ||||
| @@ -698,12 +703,34 @@ static av_cold int encode_end(AVCodecContext *avctx) | |||||
| #define OFFSET(x) offsetof(HYuvContext, x) | #define OFFSET(x) offsetof(HYuvContext, x) | ||||
| #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | ||||
| #define HUFF_CLASS(variant) \ | |||||
| static const AVClass variant ## _class = { \ | |||||
| .class_name = # variant, \ | |||||
| .item_name = av_default_item_name, \ | |||||
| .option = variant ## _options, \ | |||||
| .version = LIBAVUTIL_VERSION_INT, \ | |||||
| } | |||||
| #define FF_HUFFYUV_COMMON_OPTS \ | |||||
| { "pred", "Prediction method", OFFSET(predictor), AV_OPT_TYPE_INT, { .i64 = LEFT }, LEFT, MEDIAN, VE, "pred" }, \ | |||||
| { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT }, INT_MIN, INT_MAX, VE, "pred" }, \ | |||||
| { "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PLANE }, INT_MIN, INT_MAX, VE, "pred" }, \ | |||||
| { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MEDIAN }, INT_MIN, INT_MAX, VE, "pred" } | |||||
| static const AVOption huffyuv_options[] = { | |||||
| FF_HUFFYUV_COMMON_OPTS, | |||||
| { NULL}, | |||||
| }; | |||||
| HUFF_CLASS(huffyuv); | |||||
| AVCodec ff_huffyuv_encoder = { | AVCodec ff_huffyuv_encoder = { | ||||
| .name = "huffyuv", | .name = "huffyuv", | ||||
| .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), | .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), | ||||
| .type = AVMEDIA_TYPE_VIDEO, | .type = AVMEDIA_TYPE_VIDEO, | ||||
| .id = AV_CODEC_ID_HUFFYUV, | .id = AV_CODEC_ID_HUFFYUV, | ||||
| .priv_data_size = sizeof(HYuvContext), | .priv_data_size = sizeof(HYuvContext), | ||||
| .priv_class = &huffyuv_class, | |||||
| .init = encode_init, | .init = encode_init, | ||||
| .encode2 = encode_frame, | .encode2 = encode_frame, | ||||
| .close = encode_end, | .close = encode_end, | ||||
| @@ -717,16 +744,12 @@ AVCodec ff_huffyuv_encoder = { | |||||
| #if CONFIG_FFVHUFF_ENCODER | #if CONFIG_FFVHUFF_ENCODER | ||||
| static const AVOption ffhuffyuv_options[] = { | static const AVOption ffhuffyuv_options[] = { | ||||
| FF_HUFFYUV_COMMON_OPTS, | |||||
| { "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, | { "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, | ||||
| { NULL } | { NULL } | ||||
| }; | }; | ||||
| static const AVClass ffhuffyuv_class = { | |||||
| .class_name = "ffhuffyuv encoder", | |||||
| .item_name = av_default_item_name, | |||||
| .option = ffhuffyuv_options, | |||||
| .version = LIBAVUTIL_VERSION_INT, | |||||
| }; | |||||
| HUFF_CLASS(ffhuffyuv); | |||||
| AVCodec ff_ffvhuff_encoder = { | AVCodec ff_ffvhuff_encoder = { | ||||
| .name = "ffvhuff", | .name = "ffvhuff", | ||||
| @@ -34,6 +34,12 @@ | |||||
| #include "mjpegenc.h" | #include "mjpegenc.h" | ||||
| #include "jpegls.h" | #include "jpegls.h" | ||||
| typedef struct JPEGLSContext { | |||||
| AVClass *class; | |||||
| int pred; | |||||
| } JPEGLSContext; | |||||
| /** | /** | ||||
| * Encode error from regular symbol | * Encode error from regular symbol | ||||
| */ | */ | ||||
| @@ -249,8 +255,8 @@ static void ls_store_lse(JLSState *state, PutBitContext *pb) | |||||
| static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, | static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, | ||||
| const AVFrame *pict, int *got_packet) | const AVFrame *pict, int *got_packet) | ||||
| { | { | ||||
| JPEGLSContext *ctx = avctx->priv_data; | |||||
| const AVFrame *const p = pict; | const AVFrame *const p = pict; | ||||
| const int near = avctx->prediction_method; | |||||
| PutBitContext pb, pb2; | PutBitContext pb, pb2; | ||||
| GetBitContext gb; | GetBitContext gb; | ||||
| uint8_t *buf2 = NULL; | uint8_t *buf2 = NULL; | ||||
| @@ -261,6 +267,13 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, | |||||
| int i, size, ret; | int i, size, ret; | ||||
| int comps; | int comps; | ||||
| #if FF_API_PRIVATE_OPT | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | |||||
| if (avctx->prediction_method) | |||||
| ctx->pred = avctx->prediction_method; | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | |||||
| #endif | |||||
| if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 || | if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 || | ||||
| avctx->pix_fmt == AV_PIX_FMT_GRAY16) | avctx->pix_fmt == AV_PIX_FMT_GRAY16) | ||||
| comps = 1; | comps = 1; | ||||
| @@ -301,7 +314,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, | |||||
| put_bits(&pb, 8, i); // component ID | put_bits(&pb, 8, i); // component ID | ||||
| put_bits(&pb, 8, 0); // mapping index: none | put_bits(&pb, 8, 0); // mapping index: none | ||||
| } | } | ||||
| put_bits(&pb, 8, near); | |||||
| put_bits(&pb, 8, ctx->pred); | |||||
| put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line | put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line | ||||
| put_bits(&pb, 8, 0); // point transform: none | put_bits(&pb, 8, 0); // point transform: none | ||||
| @@ -310,7 +323,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, | |||||
| goto memfail; | goto memfail; | ||||
| /* initialize JPEG-LS state from JPEG parameters */ | /* initialize JPEG-LS state from JPEG parameters */ | ||||
| state->near = near; | |||||
| state->near = ctx->pred; | |||||
| state->bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8; | state->bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8; | ||||
| ff_jpegls_reset_coding_parameters(state, 0); | ff_jpegls_reset_coding_parameters(state, 0); | ||||
| ff_jpegls_init_state(state); | ff_jpegls_init_state(state); | ||||
| @@ -433,11 +446,31 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| #define OFFSET(x) offsetof(JPEGLSContext, x) | |||||
| #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||||
| static const AVOption options[] = { | |||||
| { "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, VE, "pred" }, | |||||
| { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { NULL}, | |||||
| }; | |||||
| static const AVClass jpegls_class = { | |||||
| .class_name = "jpegls", | |||||
| .item_name = av_default_item_name, | |||||
| .option = options, | |||||
| .version = LIBAVUTIL_VERSION_INT, | |||||
| }; | |||||
| AVCodec ff_jpegls_encoder = { | AVCodec ff_jpegls_encoder = { | ||||
| .name = "jpegls", | .name = "jpegls", | ||||
| .long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"), | .long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"), | ||||
| .type = AVMEDIA_TYPE_VIDEO, | .type = AVMEDIA_TYPE_VIDEO, | ||||
| .id = AV_CODEC_ID_JPEGLS, | .id = AV_CODEC_ID_JPEGLS, | ||||
| .priv_data_size = sizeof(JPEGLSContext), | |||||
| .priv_class = &jpegls_class, | |||||
| .init = encode_init_ls, | .init = encode_init_ls, | ||||
| .encode2 = encode_picture_ls, | .encode2 = encode_picture_ls, | ||||
| .pix_fmts = (const enum AVPixelFormat[]) { | .pix_fmts = (const enum AVPixelFormat[]) { | ||||
| @@ -43,6 +43,7 @@ | |||||
| #include "mjpegenc.h" | #include "mjpegenc.h" | ||||
| typedef struct LJpegEncContext { | typedef struct LJpegEncContext { | ||||
| AVClass *class; | |||||
| IDCTDSPContext idsp; | IDCTDSPContext idsp; | ||||
| ScanTable scantable; | ScanTable scantable; | ||||
| uint16_t matrix[64]; | uint16_t matrix[64]; | ||||
| @@ -56,6 +57,7 @@ typedef struct LJpegEncContext { | |||||
| uint8_t huff_size_dc_chrominance[12]; | uint8_t huff_size_dc_chrominance[12]; | ||||
| uint16_t (*scratch)[4]; | uint16_t (*scratch)[4]; | ||||
| int pred; | |||||
| } LJpegEncContext; | } LJpegEncContext; | ||||
| static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb, | static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb, | ||||
| @@ -66,15 +68,21 @@ static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb, | |||||
| const int height = frame->height; | const int height = frame->height; | ||||
| const int linesize = frame->linesize[0]; | const int linesize = frame->linesize[0]; | ||||
| uint16_t (*buffer)[4] = s->scratch; | uint16_t (*buffer)[4] = s->scratch; | ||||
| const int predictor = avctx->prediction_method+1; | |||||
| int left[3], top[3], topleft[3]; | int left[3], top[3], topleft[3]; | ||||
| int x, y, i; | int x, y, i; | ||||
| #if FF_API_PRIVATE_OPT | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | |||||
| if (avctx->prediction_method) | |||||
| s->pred = avctx->prediction_method + 1; | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | |||||
| #endif | |||||
| for (i = 0; i < 3; i++) | for (i = 0; i < 3; i++) | ||||
| buffer[0][i] = 1 << (9 - 1); | buffer[0][i] = 1 << (9 - 1); | ||||
| for (y = 0; y < height; y++) { | for (y = 0; y < height; y++) { | ||||
| const int modified_predictor = y ? predictor : 1; | |||||
| const int modified_predictor = y ? s->pred : 1; | |||||
| uint8_t *ptr = frame->data[0] + (linesize * y); | uint8_t *ptr = frame->data[0] + (linesize * y); | ||||
| if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < width * 3 * 3) { | if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < width * 3 * 3) { | ||||
| @@ -181,12 +189,18 @@ static inline void ljpeg_encode_yuv_mb(LJpegEncContext *s, PutBitContext *pb, | |||||
| static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb, | static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb, | ||||
| const AVFrame *frame) | const AVFrame *frame) | ||||
| { | { | ||||
| const int predictor = avctx->prediction_method + 1; | |||||
| LJpegEncContext *s = avctx->priv_data; | LJpegEncContext *s = avctx->priv_data; | ||||
| const int mb_width = (avctx->width + s->hsample[0] - 1) / s->hsample[0]; | const int mb_width = (avctx->width + s->hsample[0] - 1) / s->hsample[0]; | ||||
| const int mb_height = (avctx->height + s->vsample[0] - 1) / s->vsample[0]; | const int mb_height = (avctx->height + s->vsample[0] - 1) / s->vsample[0]; | ||||
| int mb_x, mb_y; | int mb_x, mb_y; | ||||
| #if FF_API_PRIVATE_OPT | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | |||||
| if (avctx->prediction_method) | |||||
| s->pred = avctx->prediction_method + 1; | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | |||||
| #endif | |||||
| for (mb_y = 0; mb_y < mb_height; mb_y++) { | for (mb_y = 0; mb_y < mb_height; mb_y++) { | ||||
| if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < | if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < | ||||
| mb_width * 4 * 3 * s->hsample[0] * s->vsample[0]) { | mb_width * 4 * 3 * s->hsample[0] * s->vsample[0]) { | ||||
| @@ -195,7 +209,7 @@ static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb, | |||||
| } | } | ||||
| for (mb_x = 0; mb_x < mb_width; mb_x++) | for (mb_x = 0; mb_x < mb_width; mb_x++) | ||||
| ljpeg_encode_yuv_mb(s, pb, frame, predictor, mb_x, mb_y); | |||||
| ljpeg_encode_yuv_mb(s, pb, frame, s->pred, mb_x, mb_y); | |||||
| } | } | ||||
| return 0; | return 0; | ||||
| @@ -227,7 +241,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, | |||||
| init_put_bits(&pb, pkt->data, pkt->size); | init_put_bits(&pb, pkt->data, pkt->size); | ||||
| ff_mjpeg_encode_picture_header(avctx, &pb, &s->scantable, | ff_mjpeg_encode_picture_header(avctx, &pb, &s->scantable, | ||||
| s->matrix); | |||||
| s->pred, s->matrix); | |||||
| header_bits = put_bits_count(&pb); | header_bits = put_bits_count(&pb); | ||||
| @@ -316,12 +330,31 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| #define OFFSET(x) offsetof(LJpegEncContext, x) | |||||
| #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||||
| static const AVOption options[] = { | |||||
| { "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" }, | |||||
| { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { NULL}, | |||||
| }; | |||||
| static const AVClass ljpeg_class = { | |||||
| .class_name = "ljpeg", | |||||
| .item_name = av_default_item_name, | |||||
| .option = options, | |||||
| .version = LIBAVUTIL_VERSION_INT, | |||||
| }; | |||||
| AVCodec ff_ljpeg_encoder = { | AVCodec ff_ljpeg_encoder = { | ||||
| .name = "ljpeg", | .name = "ljpeg", | ||||
| .long_name = NULL_IF_CONFIG_SMALL("Lossless JPEG"), | .long_name = NULL_IF_CONFIG_SMALL("Lossless JPEG"), | ||||
| .type = AVMEDIA_TYPE_VIDEO, | .type = AVMEDIA_TYPE_VIDEO, | ||||
| .id = AV_CODEC_ID_LJPEG, | .id = AV_CODEC_ID_LJPEG, | ||||
| .priv_data_size = sizeof(LJpegEncContext), | .priv_data_size = sizeof(LJpegEncContext), | ||||
| .priv_class = &ljpeg_class, | |||||
| .init = ljpeg_encode_init, | .init = ljpeg_encode_init, | ||||
| .encode2 = ljpeg_encode_frame, | .encode2 = ljpeg_encode_frame, | ||||
| .close = ljpeg_encode_close, | .close = ljpeg_encode_close, | ||||
| @@ -154,12 +154,31 @@ void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[8][64]) | |||||
| s->i_tex_bits += get_bits_diff(s); | s->i_tex_bits += get_bits_diff(s); | ||||
| } | } | ||||
| #define OFFSET(x) offsetof(MpegEncContext, x) | |||||
| #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||||
| static const AVOption options[] = { | |||||
| { "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" }, | |||||
| { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { NULL}, | |||||
| }; | |||||
| static const AVClass mjpeg_class = { | |||||
| .class_name = "mjpeg", | |||||
| .item_name = av_default_item_name, | |||||
| .option = options, | |||||
| .version = LIBAVUTIL_VERSION_INT, | |||||
| }; | |||||
| AVCodec ff_mjpeg_encoder = { | AVCodec ff_mjpeg_encoder = { | ||||
| .name = "mjpeg", | .name = "mjpeg", | ||||
| .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), | .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), | ||||
| .type = AVMEDIA_TYPE_VIDEO, | .type = AVMEDIA_TYPE_VIDEO, | ||||
| .id = AV_CODEC_ID_MJPEG, | .id = AV_CODEC_ID_MJPEG, | ||||
| .priv_data_size = sizeof(MpegEncContext), | .priv_data_size = sizeof(MpegEncContext), | ||||
| .priv_class = &mjpeg_class, | |||||
| .init = ff_mpv_encode_init, | .init = ff_mpv_encode_init, | ||||
| .encode2 = ff_mpv_encode_picture, | .encode2 = ff_mpv_encode_picture, | ||||
| .close = ff_mpv_encode_end, | .close = ff_mpv_encode_end, | ||||
| @@ -134,7 +134,7 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p) | |||||
| } | } | ||||
| void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, | void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, | ||||
| ScanTable *intra_scantable, | |||||
| ScanTable *intra_scantable, int pred, | |||||
| uint16_t intra_matrix[64]) | uint16_t intra_matrix[64]) | ||||
| { | { | ||||
| int chroma_h_shift, chroma_v_shift; | int chroma_h_shift, chroma_v_shift; | ||||
| @@ -217,7 +217,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, | |||||
| put_bits(pb, 4, 1); /* DC huffman table index */ | put_bits(pb, 4, 1); /* DC huffman table index */ | ||||
| put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */ | put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */ | ||||
| put_bits(pb, 8, lossless ? avctx->prediction_method + 1 : 0); /* Ss (not used) */ | |||||
| put_bits(pb, 8, lossless ? pred : 0); /* Ss (not used) */ | |||||
| switch (avctx->codec_id) { | switch (avctx->codec_id) { | ||||
| case AV_CODEC_ID_MJPEG: put_bits(pb, 8, 63); break; /* Se (not used) */ | case AV_CODEC_ID_MJPEG: put_bits(pb, 8, 63); break; /* Se (not used) */ | ||||
| @@ -28,7 +28,7 @@ | |||||
| #include "put_bits.h" | #include "put_bits.h" | ||||
| void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, | void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, | ||||
| ScanTable *intra_scantable, | |||||
| ScanTable *intra_scantable, int pred, | |||||
| uint16_t intra_matrix[64]); | uint16_t intra_matrix[64]); | ||||
| void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits); | void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits); | ||||
| void ff_mjpeg_encode_stuffing(PutBitContext *pbc); | void ff_mjpeg_encode_stuffing(PutBitContext *pbc); | ||||
| @@ -405,6 +405,7 @@ typedef struct MpegEncContext { | |||||
| /* MJPEG specific */ | /* MJPEG specific */ | ||||
| struct MJpegContext *mjpeg_ctx; | struct MJpegContext *mjpeg_ctx; | ||||
| int pred; | |||||
| /* MSMPEG4 specific */ | /* MSMPEG4 specific */ | ||||
| int mv_table_index; | int mv_table_index; | ||||
| @@ -921,6 +921,9 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | FF_DISABLE_DEPRECATION_WARNINGS | ||||
| if (avctx->brd_scale) | if (avctx->brd_scale) | ||||
| s->brd_scale = avctx->brd_scale; | s->brd_scale = avctx->brd_scale; | ||||
| if (avctx->prediction_method) | |||||
| s->pred = avctx->prediction_method + 1; | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | FF_ENABLE_DEPRECATION_WARNINGS | ||||
| #endif | #endif | ||||
| @@ -3583,7 +3586,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) | |||||
| case FMT_MJPEG: | case FMT_MJPEG: | ||||
| if (CONFIG_MJPEG_ENCODER) | if (CONFIG_MJPEG_ENCODER) | ||||
| ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable, | ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable, | ||||
| s->intra_matrix); | |||||
| s->pred, s->intra_matrix); | |||||
| break; | break; | ||||
| case FMT_H261: | case FMT_H261: | ||||
| if (CONFIG_H261_ENCODER) | if (CONFIG_H261_ENCODER) | ||||
| @@ -236,10 +236,12 @@ static const AVOption avcodec_options[] = { | |||||
| {"guess_mvs", "iterative motion vector (MV) search (slow)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_EC_GUESS_MVS }, INT_MIN, INT_MAX, V|D, "ec"}, | {"guess_mvs", "iterative motion vector (MV) search (slow)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_EC_GUESS_MVS }, INT_MIN, INT_MAX, V|D, "ec"}, | ||||
| {"deblock", "use strong deblock filter for damaged MBs", 0, AV_OPT_TYPE_CONST, {.i64 = FF_EC_DEBLOCK }, INT_MIN, INT_MAX, V|D, "ec"}, | {"deblock", "use strong deblock filter for damaged MBs", 0, AV_OPT_TYPE_CONST, {.i64 = FF_EC_DEBLOCK }, INT_MIN, INT_MAX, V|D, "ec"}, | ||||
| {"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, | {"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, | ||||
| #if FF_API_PRIVATE_OPT | |||||
| {"pred", "prediction method", OFFSET(prediction_method), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E, "pred"}, | {"pred", "prediction method", OFFSET(prediction_method), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E, "pred"}, | ||||
| {"left", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PRED_LEFT }, INT_MIN, INT_MAX, V|E, "pred"}, | {"left", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PRED_LEFT }, INT_MIN, INT_MAX, V|E, "pred"}, | ||||
| {"plane", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PRED_PLANE }, INT_MIN, INT_MAX, V|E, "pred"}, | {"plane", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PRED_PLANE }, INT_MIN, INT_MAX, V|E, "pred"}, | ||||
| {"median", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PRED_MEDIAN }, INT_MIN, INT_MAX, V|E, "pred"}, | {"median", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PRED_MEDIAN }, INT_MIN, INT_MAX, V|E, "pred"}, | ||||
| #endif | |||||
| {"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, V|E}, | {"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, V|E}, | ||||
| {"debug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.i64 = DEFAULT }, 0, INT_MAX, V|A|S|E|D, "debug"}, | {"debug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.i64 = DEFAULT }, 0, INT_MAX, V|A|S|E|D, "debug"}, | ||||
| {"pict", "picture info", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_PICT_INFO }, INT_MIN, INT_MAX, V|D, "debug"}, | {"pict", "picture info", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_PICT_INFO }, INT_MIN, INT_MAX, V|D, "debug"}, | ||||
| @@ -19,6 +19,7 @@ | |||||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
| */ | */ | ||||
| #include "libavutil/opt.h" | |||||
| #include "libavutil/stereo3d.h" | #include "libavutil/stereo3d.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| @@ -35,6 +36,7 @@ | |||||
| #define IOBUF_SIZE 4096 | #define IOBUF_SIZE 4096 | ||||
| typedef struct PNGEncContext { | typedef struct PNGEncContext { | ||||
| AVClass *class; | |||||
| HuffYUVEncDSPContext hdsp; | HuffYUVEncDSPContext hdsp; | ||||
| uint8_t *bytestream; | uint8_t *bytestream; | ||||
| @@ -486,21 +488,48 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||||
| ff_huffyuvencdsp_init(&s->hdsp); | ff_huffyuvencdsp_init(&s->hdsp); | ||||
| s->filter_type = av_clip(avctx->prediction_method, | |||||
| PNG_FILTER_VALUE_NONE, | |||||
| PNG_FILTER_VALUE_MIXED); | |||||
| #if FF_API_PRIVATE_OPT | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | |||||
| if (avctx->prediction_method) | |||||
| s->filter_type = av_clip(avctx->prediction_method, | |||||
| PNG_FILTER_VALUE_NONE, | |||||
| PNG_FILTER_VALUE_MIXED); | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | |||||
| #endif | |||||
| if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK) | if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK) | ||||
| s->filter_type = PNG_FILTER_VALUE_NONE; | s->filter_type = PNG_FILTER_VALUE_NONE; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| #define OFFSET(x) offsetof(PNGEncContext, x) | |||||
| #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||||
| static const AVOption options[] = { | |||||
| { "pred", "Prediction method", OFFSET(filter_type), AV_OPT_TYPE_INT, { .i64 = PNG_FILTER_VALUE_NONE }, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED, VE, "pred" }, | |||||
| { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_NONE }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "sub", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_SUB }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "up", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_UP }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "avg", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_AVG }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "paeth", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_PAETH }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "mixed", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_MIXED }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { NULL}, | |||||
| }; | |||||
| static const AVClass png_class = { | |||||
| .class_name = "png", | |||||
| .item_name = av_default_item_name, | |||||
| .option = options, | |||||
| .version = LIBAVUTIL_VERSION_INT, | |||||
| }; | |||||
| AVCodec ff_png_encoder = { | AVCodec ff_png_encoder = { | ||||
| .name = "png", | .name = "png", | ||||
| .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"), | .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"), | ||||
| .type = AVMEDIA_TYPE_VIDEO, | .type = AVMEDIA_TYPE_VIDEO, | ||||
| .id = AV_CODEC_ID_PNG, | .id = AV_CODEC_ID_PNG, | ||||
| .priv_data_size = sizeof(PNGEncContext), | .priv_data_size = sizeof(PNGEncContext), | ||||
| .priv_class = &png_class, | |||||
| .init = png_enc_init, | .init = png_enc_init, | ||||
| .encode2 = encode_frame, | .encode2 = encode_frame, | ||||
| .pix_fmts = (const enum AVPixelFormat[]) { | .pix_fmts = (const enum AVPixelFormat[]) { | ||||
| @@ -26,9 +26,11 @@ | |||||
| #include "utvideo.h" | #include "utvideo.h" | ||||
| #if FF_API_PRIVATE_OPT | |||||
| const int ff_ut_pred_order[5] = { | const int ff_ut_pred_order[5] = { | ||||
| PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT | PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT | ||||
| }; | }; | ||||
| #endif | |||||
| const int ff_ut_rgb_order[4] = { 1, 2, 0, 3 }; // G, B, R, A | const int ff_ut_rgb_order[4] = { 1, 2, 0, 3 }; // G, B, R, A | ||||
| @@ -26,6 +26,8 @@ | |||||
| #include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
| #include "libavutil/intreadwrite.h" | #include "libavutil/intreadwrite.h" | ||||
| #include "libavutil/opt.h" | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "bswapdsp.h" | #include "bswapdsp.h" | ||||
| @@ -111,6 +113,8 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) | |||||
| ff_bswapdsp_init(&c->bdsp); | ff_bswapdsp_init(&c->bdsp); | ||||
| ff_huffyuvencdsp_init(&c->hdsp); | ff_huffyuvencdsp_init(&c->hdsp); | ||||
| #if FF_API_PRIVATE_OPT | |||||
| FF_DISABLE_DEPRECATION_WARNINGS | |||||
| /* Check the prediction method, and error out if unsupported */ | /* Check the prediction method, and error out if unsupported */ | ||||
| if (avctx->prediction_method < 0 || avctx->prediction_method > 4) { | if (avctx->prediction_method < 0 || avctx->prediction_method > 4) { | ||||
| av_log(avctx, AV_LOG_WARNING, | av_log(avctx, AV_LOG_WARNING, | ||||
| @@ -126,7 +130,10 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) | |||||
| } | } | ||||
| /* Convert from libavcodec prediction type to Ut Video's */ | /* Convert from libavcodec prediction type to Ut Video's */ | ||||
| c->frame_pred = ff_ut_pred_order[avctx->prediction_method]; | |||||
| if (avctx->prediction_method) | |||||
| c->frame_pred = ff_ut_pred_order[avctx->prediction_method]; | |||||
| FF_ENABLE_DEPRECATION_WARNINGS | |||||
| #endif | |||||
| if (c->frame_pred == PRED_GRADIENT) { | if (c->frame_pred == PRED_GRADIENT) { | ||||
| av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n"); | av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n"); | ||||
| @@ -631,12 +638,32 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| #define OFFSET(x) offsetof(UtvideoContext, x) | |||||
| #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||||
| static const AVOption options[] = { | |||||
| { "pred", "Prediction method", OFFSET(frame_pred), AV_OPT_TYPE_INT, { .i64 = PRED_LEFT }, PRED_NONE, PRED_MEDIAN, VE, "pred" }, | |||||
| { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_NONE }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_LEFT }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "gradient", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_GRADIENT }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_MEDIAN }, INT_MIN, INT_MAX, VE, "pred" }, | |||||
| { NULL}, | |||||
| }; | |||||
| static const AVClass utvideo_class = { | |||||
| .class_name = "utvideo", | |||||
| .item_name = av_default_item_name, | |||||
| .option = options, | |||||
| .version = LIBAVUTIL_VERSION_INT, | |||||
| }; | |||||
| AVCodec ff_utvideo_encoder = { | AVCodec ff_utvideo_encoder = { | ||||
| .name = "utvideo", | .name = "utvideo", | ||||
| .long_name = NULL_IF_CONFIG_SMALL("Ut Video"), | .long_name = NULL_IF_CONFIG_SMALL("Ut Video"), | ||||
| .type = AVMEDIA_TYPE_VIDEO, | .type = AVMEDIA_TYPE_VIDEO, | ||||
| .id = AV_CODEC_ID_UTVIDEO, | .id = AV_CODEC_ID_UTVIDEO, | ||||
| .priv_data_size = sizeof(UtvideoContext), | .priv_data_size = sizeof(UtvideoContext), | ||||
| .priv_class = &utvideo_class, | |||||
| .init = utvideo_encode_init, | .init = utvideo_encode_init, | ||||
| .encode2 = utvideo_encode_frame, | .encode2 = utvideo_encode_frame, | ||||
| .close = utvideo_encode_close, | .close = utvideo_encode_close, | ||||
| @@ -37,7 +37,7 @@ FATE_UTVIDEOENC += fate-utvideoenc_rgba_median | |||||
| fate-utvideoenc_rgba_median: OPTS = -pix_fmt rgba -pred median | fate-utvideoenc_rgba_median: OPTS = -pix_fmt rgba -pred median | ||||
| FATE_UTVIDEOENC += fate-utvideoenc_rgba_none | FATE_UTVIDEOENC += fate-utvideoenc_rgba_none | ||||
| fate-utvideoenc_rgba_none: OPTS = -pix_fmt rgba -pred 3 | |||||
| fate-utvideoenc_rgba_none: OPTS = -pix_fmt rgba -pred none | |||||
| FATE_UTVIDEOENC += fate-utvideoenc_rgb_left | FATE_UTVIDEOENC += fate-utvideoenc_rgb_left | ||||
| fate-utvideoenc_rgb_left: OPTS = -pix_fmt rgb24 -pred left | fate-utvideoenc_rgb_left: OPTS = -pix_fmt rgb24 -pred left | ||||
| @@ -46,7 +46,7 @@ FATE_UTVIDEOENC += fate-utvideoenc_rgb_median | |||||
| fate-utvideoenc_rgb_median: OPTS = -pix_fmt rgb24 -pred median | fate-utvideoenc_rgb_median: OPTS = -pix_fmt rgb24 -pred median | ||||
| FATE_UTVIDEOENC += fate-utvideoenc_rgb_none | FATE_UTVIDEOENC += fate-utvideoenc_rgb_none | ||||
| fate-utvideoenc_rgb_none: OPTS = -pix_fmt rgb24 -pred 3 | |||||
| fate-utvideoenc_rgb_none: OPTS = -pix_fmt rgb24 -pred none | |||||
| FATE_UTVIDEOENC += fate-utvideoenc_yuv420_left | FATE_UTVIDEOENC += fate-utvideoenc_yuv420_left | ||||
| fate-utvideoenc_yuv420_left: OPTS = -pix_fmt yuv420p -pred left | fate-utvideoenc_yuv420_left: OPTS = -pix_fmt yuv420p -pred left | ||||
| @@ -55,7 +55,7 @@ FATE_UTVIDEOENC += fate-utvideoenc_yuv420_median | |||||
| fate-utvideoenc_yuv420_median: OPTS = -pix_fmt yuv420p -pred median | fate-utvideoenc_yuv420_median: OPTS = -pix_fmt yuv420p -pred median | ||||
| FATE_UTVIDEOENC += fate-utvideoenc_yuv420_none | FATE_UTVIDEOENC += fate-utvideoenc_yuv420_none | ||||
| fate-utvideoenc_yuv420_none: OPTS = -pix_fmt yuv420p -pred 3 | |||||
| fate-utvideoenc_yuv420_none: OPTS = -pix_fmt yuv420p -pred none | |||||
| FATE_UTVIDEOENC += fate-utvideoenc_yuv422_left | FATE_UTVIDEOENC += fate-utvideoenc_yuv422_left | ||||
| fate-utvideoenc_yuv422_left: OPTS = -pix_fmt yuv422p -pred left | fate-utvideoenc_yuv422_left: OPTS = -pix_fmt yuv422p -pred left | ||||
| @@ -64,7 +64,7 @@ FATE_UTVIDEOENC += fate-utvideoenc_yuv422_median | |||||
| fate-utvideoenc_yuv422_median: OPTS = -pix_fmt yuv422p -pred median | fate-utvideoenc_yuv422_median: OPTS = -pix_fmt yuv422p -pred median | ||||
| FATE_UTVIDEOENC += fate-utvideoenc_yuv422_none | FATE_UTVIDEOENC += fate-utvideoenc_yuv422_none | ||||
| fate-utvideoenc_yuv422_none: OPTS = -pix_fmt yuv422p -pred 3 | |||||
| fate-utvideoenc_yuv422_none: OPTS = -pix_fmt yuv422p -pred none | |||||
| $(FATE_UTVIDEOENC): $(VREF) | $(FATE_UTVIDEOENC): $(VREF) | ||||