70 opj_cparameters_t *parameters)
73 opj_image_cmptparm_t *cmptparm;
74 OPJ_COLOR_SPACE color_space;
94 color_space = CLRSPC_GRAY;
100 color_space = CLRSPC_SRGB;
118 color_space = CLRSPC_SYCC;
122 "The requested pixel format '%s' is not supported\n",
127 cmptparm =
av_mallocz(numcomps *
sizeof(*cmptparm));
133 for (i = 0; i < numcomps; i++) {
136 cmptparm[i].sgnd = 0;
137 cmptparm[i].dx = sub_dx[i];
138 cmptparm[i].dy = sub_dy[i];
139 cmptparm[i].w = avctx->
width / sub_dx[i];
140 cmptparm[i].h = avctx->
height / sub_dy[i];
143 img = opj_image_create(numcomps, cmptparm, color_space);
153 opj_set_default_encoder_parameters(&ctx->
enc_params);
199 const AVFrame *frame, opj_image_t *image)
203 int image_index, frame_index;
204 const int numcomps = image->numcomps;
206 for (compno = 0; compno < numcomps; ++compno)
207 for (y = 0; y < avctx->
height; ++y) {
208 image_index = y * avctx->
width;
209 frame_index = y * frame->
linesize[0] + compno;
210 for (x = 0; x < avctx->
width; ++x) {
211 image->comps[compno].data[image_index++] =
212 frame->
data[0][frame_index];
213 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;
240 const AVFrame *frame, opj_image_t *image)
245 int image_index, frame_index;
246 const int numcomps = image->numcomps;
248 for (compno = 0; compno < numcomps; ++compno) {
249 width = avctx->
width / image->comps[compno].dx;
250 height = avctx->
height / image->comps[compno].dy;
251 for (y = 0; y <
height; ++y) {
252 image_index = y *
width;
253 frame_index = y * frame->
linesize[compno];
254 for (x = 0; x <
width; ++x)
255 image->comps[compno].data[image_index++] =
256 frame->
data[compno][frame_index++];
268 int image_index, frame_index;
269 const int numcomps = image->numcomps;
272 for (compno = 0; compno < numcomps; ++compno) {
273 width = avctx->
width / image->comps[compno].dx;
274 height = avctx->
height / image->comps[compno].dy;
275 frame_ptr = (uint16_t *)frame->
data[compno];
277 image_index = y *
width;
278 frame_index = y * (frame->
linesize[compno] / 2);
279 for (x = 0; x <
width; ++x)
280 image->comps[compno].data[image_index++] =
281 frame_ptr[frame_index++];
287 const AVFrame *frame,
int *got_packet)
290 opj_cinfo_t *compress = ctx->
compress;
291 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",
436 .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)
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
AVFrame * coded_frame
the picture in the bitstream
#define AV_PIX_FMT_RGBA64
AVCodec ff_libopenjpeg_encoder
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
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)
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)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static void libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
static void warning_callback(const char *msg, void *data)
#define AV_PIX_FMT_YUV444P16
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint16_t depth_minus1
Number of bits in the component minus 1.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
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)
#define AV_PIX_FMT_YUV422P9
uint8_t nb_components
The number of components each pixel has, (1-4)
#define AV_PIX_FMT_GRAY16
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)
#define AV_PIX_FMT_YUV444P9
static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV420P16
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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)
#define AV_PIX_FMT_YUV420P10
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_YUV420P9
static void info_callback(const char *msg, void *data)
int global_quality
Global quality for codecs which cannot change it per frame.
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static av_cold int init(AVCodecParserContext *s)
static const AVOption options[]
static void error_callback(const char *msg, void *data)
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 ...
#define AV_PIX_FMT_YUV422P16