70 opj_cparameters_t *parameters)
73 opj_image_cmptparm_t *cmptparm;
74 OPJ_COLOR_SPACE color_space;
94 color_space = CLRSPC_GRAY;
99 color_space = CLRSPC_SRGB;
117 color_space = CLRSPC_SYCC;
121 "The requested pixel format '%s' is not supported\n",
126 cmptparm =
av_mallocz(numcomps *
sizeof(*cmptparm));
132 for (i = 0; i < numcomps; i++) {
135 cmptparm[i].sgnd = 0;
136 cmptparm[i].dx = sub_dx[i];
137 cmptparm[i].dy = sub_dy[i];
138 cmptparm[i].w = avctx->
width / sub_dx[i];
139 cmptparm[i].h = avctx->
height / sub_dy[i];
142 img = opj_image_create(numcomps, cmptparm, color_space);
152 opj_set_default_encoder_parameters(&ctx->
enc_params);
198 const AVFrame *frame, opj_image_t *image)
202 int image_index, frame_index;
203 const int numcomps = image->numcomps;
205 for (compno = 0; compno < numcomps; ++compno) {
206 for (y = 0; y < avctx->
height; ++y) {
207 image_index = y * avctx->
width;
208 frame_index = y * frame->
linesize[0] + compno;
209 for (x = 0; x < avctx->
width; ++x) {
210 image->comps[compno].data[image_index++] =
211 frame->
data[0][frame_index];
212 frame_index += numcomps;
219 const AVFrame *frame, opj_image_t *image)
223 int image_index, frame_index;
224 const int numcomps = image->numcomps;
225 uint16_t *frame_ptr = (uint16_t*)frame->
data[0];
227 for (compno = 0; compno < numcomps; ++compno) {
228 for (y = 0; y < avctx->
height; ++y) {
229 image_index = y * avctx->
width;
230 frame_index = y * (frame->
linesize[0] / 2) + compno;
231 for (x = 0; x < avctx->
width; ++x) {
232 image->comps[compno].data[image_index++] =
233 frame_ptr[frame_index];
234 frame_index += numcomps;
241 const AVFrame *frame, opj_image_t *image)
246 int image_index, frame_index;
247 const int numcomps = image->numcomps;
249 for (compno = 0; compno < numcomps; ++compno) {
250 width = avctx->
width / image->comps[compno].dx;
251 height = avctx->
height / image->comps[compno].dy;
252 for (y = 0; y <
height; ++y) {
253 image_index = y *
width;
254 frame_index = y * frame->
linesize[compno];
255 for (x = 0; x <
width; ++x)
256 image->comps[compno].data[image_index++] =
257 frame->
data[compno][frame_index++];
269 int image_index, frame_index;
270 const int numcomps = image->numcomps;
273 for (compno = 0; compno < numcomps; ++compno) {
274 width = avctx->
width / image->comps[compno].dx;
275 height = avctx->
height / image->comps[compno].dy;
276 frame_ptr = (uint16_t*)frame->
data[compno];
278 image_index = y *
width;
279 frame_index = y * (frame->
linesize[compno] / 2);
280 for (x = 0; x <
width; ++x)
281 image->comps[compno].data[image_index++] =
282 frame_ptr[frame_index++];
288 const AVFrame *frame,
int *got_packet)
291 opj_cinfo_t *compress = ctx->
compress;
292 opj_image_t *image = ctx->
image;
336 "The frame's pixel format '%s' is not supported\n",
342 opj_setup_encoder(compress, &ctx->
enc_params, image);
343 stream = opj_cio_open((opj_common_ptr)compress,
NULL, 0);
349 if (!opj_encode(compress, stream, image,
NULL)) {
350 opj_cio_close(stream);
355 len = cio_tell(stream);
357 opj_cio_close(stream);
361 memcpy(pkt->
data, stream->buffer, len);
364 opj_cio_close(stream);
372 opj_destroy_compress(ctx->
compress);
373 opj_image_destroy(ctx->
image);
378 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
379 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
381 {
"format",
"Codec Format",
OFFSET(format),
AV_OPT_TYPE_INT, { .i64 = CODEC_JP2 }, CODEC_J2K, CODEC_JP2,
VE,
"format" },
388 {
"cinema_mode",
"Digital Cinema",
OFFSET(cinema_mode),
AV_OPT_TYPE_INT, { .i64 = OFF }, OFF, CINEMA4K_24,
VE,
"cinema_mode" },
393 {
"prog_order",
"Progression Order",
OFFSET(prog_order),
AV_OPT_TYPE_INT, { .i64 = LRCP }, LRCP, CPRL,
VE,
"prog_order" },
415 .
name =
"libopenjpeg",
435 .priv_class = &
class,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
packed RGB 8:8:8, 24bpp, RGBRGB...
AVFrame * coded_frame
the picture in the bitstream
#define AV_PIX_FMT_GRAY16
AVCodec ff_libopenjpeg_encoder
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV444P10
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV420P9
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
opj_cparameters_t enc_params
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static opj_image_t * libopenjpeg_create_image(AVCodecContext *avctx, opj_cparameters_t *parameters)
static void libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
#define AV_PIX_FMT_YUV420P10
static void warning_callback(const char *msg, void *data)
#define AV_PIX_FMT_YUV444P9
static int init(AVCodecParserContext *s)
uint16_t depth_minus1
number of bits in the component minus 1
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
uint8_t nb_components
The number of components each pixel has, (1-4)
int width
picture width / height.
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
static void libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV444P16
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
static void close(AVCodecParserContext *s)
static void libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
opj_event_mgr_t event_mgr
static void libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
#define AV_PIX_FMT_YUV422P16
static void info_callback(const char *msg, void *data)
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_PIX_FMT_YUV422P10
static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
#define AV_PIX_FMT_YUV422P9
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static const AVOption options[]
static void error_callback(const char *msg, void *data)
#define AV_PIX_FMT_YUV420P16
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
AVPixelFormat
Pixel format.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...