Commit 3ac23440 authored by Leo Izen's avatar Leo Izen Committed by Lynne

avformat/image2: add Jpeg XL as image2 format

This commit adds support to libavformat for muxing
and demuxing Jpeg XL images as image2 streams.
parent 5f0b4e9c
......@@ -439,6 +439,7 @@ Muxers/Demuxers:
ipmovie.c Mike Melanson
ircam* Paul B Mahol
iss.c Stefan Gehrer
jpegxl_probe.* Leo Izen
jvdec.c Peter Ross
kvag.c Zane van Iperen
libmodplug.c Clément Bœsch
......
......@@ -272,6 +272,7 @@ OBJS-$(CONFIG_IMAGE_GIF_PIPE_DEMUXER) += img2dec.o img2.o
OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER) += img2dec.o img2.o
OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER) += img2dec.o img2.o
OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER) += img2dec.o img2.o
OBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += img2dec.o img2.o jpegxl_probe.o
OBJS-$(CONFIG_IMAGE_PAM_PIPE_DEMUXER) += img2dec.o img2.o
OBJS-$(CONFIG_IMAGE_PBM_PIPE_DEMUXER) += img2dec.o img2.o
OBJS-$(CONFIG_IMAGE_PCX_PIPE_DEMUXER) += img2dec.o img2.o
......
......@@ -510,6 +510,7 @@ extern const AVInputFormat ff_image_gif_pipe_demuxer;
extern const AVInputFormat ff_image_j2k_pipe_demuxer;
extern const AVInputFormat ff_image_jpeg_pipe_demuxer;
extern const AVInputFormat ff_image_jpegls_pipe_demuxer;
extern const AVInputFormat ff_image_jpegxl_pipe_demuxer;
extern const AVInputFormat ff_image_pam_pipe_demuxer;
extern const AVInputFormat ff_image_pbm_pipe_demuxer;
extern const AVInputFormat ff_image_pcx_pipe_demuxer;
......
......@@ -88,6 +88,7 @@ const IdStrMap ff_img_tags[] = {
{ AV_CODEC_ID_GEM, "ximg" },
{ AV_CODEC_ID_GEM, "timg" },
{ AV_CODEC_ID_VBN, "vbn" },
{ AV_CODEC_ID_JPEGXL, "jxl" },
{ AV_CODEC_ID_NONE, NULL }
};
......
......@@ -36,6 +36,7 @@
#include "avio_internal.h"
#include "internal.h"
#include "img2.h"
#include "jpegxl_probe.h"
#include "libavcodec/mjpeg.h"
#include "libavcodec/vbn.h"
#include "libavcodec/xwd.h"
......@@ -837,6 +838,24 @@ static int jpegls_probe(const AVProbeData *p)
return 0;
}
static int jpegxl_probe(const AVProbeData *p)
{
const uint8_t *b = p->buf;
/* ISOBMFF-based container */
/* 0x4a584c20 == "JXL " */
if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE)
return AVPROBE_SCORE_EXTENSION + 1;
/* Raw codestreams all start with 0xff0a */
if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
return 0;
#if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size) >= 0)
return AVPROBE_SCORE_MAX - 2;
#endif
return 0;
}
static int pcx_probe(const AVProbeData *p)
{
const uint8_t *b = p->buf;
......@@ -1176,6 +1195,7 @@ IMAGEAUTO_DEMUXER(gif, GIF)
IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K)
IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG)
IMAGEAUTO_DEMUXER(jpegls, JPEGLS)
IMAGEAUTO_DEMUXER(jpegxl, JPEGXL)
IMAGEAUTO_DEMUXER(pam, PAM)
IMAGEAUTO_DEMUXER(pbm, PBM)
IMAGEAUTO_DEMUXER(pcx, PCX)
......
......@@ -263,9 +263,9 @@ static const AVClass img2mux_class = {
const AVOutputFormat ff_image2_muxer = {
.name = "image2",
.long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
.extensions = "bmp,dpx,exr,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,png,"
"ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,im24,"
"sunras,vbn,xbm,xface,pix,y",
.extensions = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,"
"png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
"im24,sunras,vbn,xbm,xface,pix,y",
.priv_data_size = sizeof(VideoMuxData),
.video_codec = AV_CODEC_ID_MJPEG,
.write_header = write_header,
......
This diff is collapsed.
/*
* Jpeg XL header verification
* Copyright (c) 2022 Leo Izen <leo.izen@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_JPEGXL_PROBE_H
#define AVFORMAT_JPEGXL_PROBE_H
#include <stdint.h>
#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff
#define FF_JPEGXL_CONTAINER_SIGNATURE_LE 0x204c584a0c000000
int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen);
#endif /* AVFORMAT_JPEGXL_PROBE_H */
......@@ -7839,6 +7839,7 @@ static int mov_probe(const AVProbeData *p)
if (tag == MKTAG('f','t','y','p') &&
( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ')
|| AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' ')
|| AV_RL32(p->buf + offset + 8) == MKTAG('j','x','l',' ')
)) {
score = FFMAX(score, 5);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment