* Re: [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer
[not found] <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com>
@ 2021-12-21 13:13 ` lance.lmwang
2021-12-21 13:20 ` Andreas Rheinhardt
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 1/3] " lance.lmwang
2 siblings, 0 replies; 8+ messages in thread
From: lance.lmwang @ 2021-12-21 13:13 UTC (permalink / raw)
To: ffmpeg-devel
On Tue, Dec 14, 2021 at 10:35:13PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
>
> Allows user can playback bitpacked pixel format directly:
> ffplay -video_size 1280x720 test.bitpacked
> ffplay -f bitpacked -video_size 1280x720 -pixel_format uyvy422 test.yuv
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavformat/Makefile | 1 +
> libavformat/allformats.c | 1 +
> libavformat/bitpackeddec.c | 136 +++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 138 insertions(+)
> create mode 100644 libavformat/bitpackeddec.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 2b5caf9..90b7333 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -138,6 +138,7 @@ OBJS-$(CONFIG_BINKA_DEMUXER) += binka.o
> OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
> OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
> OBJS-$(CONFIG_BIT_MUXER) += bit.o
> +OBJS-$(CONFIG_BITPACKED_DEMUXER) += bitpackeddec.o
> OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o
> OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o
> OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 1054ac9..a100639 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -96,6 +96,7 @@ extern const AVInputFormat ff_bink_demuxer;
> extern const AVInputFormat ff_binka_demuxer;
> extern const AVInputFormat ff_bit_demuxer;
> extern const AVOutputFormat ff_bit_muxer;
> +extern const AVInputFormat ff_bitpacked_demuxer;
> extern const AVInputFormat ff_bmv_demuxer;
> extern const AVInputFormat ff_bfstm_demuxer;
> extern const AVInputFormat ff_brstm_demuxer;
> diff --git a/libavformat/bitpackeddec.c b/libavformat/bitpackeddec.c
> new file mode 100644
> index 0000000..ba404ad
> --- /dev/null
> +++ b/libavformat/bitpackeddec.c
> @@ -0,0 +1,136 @@
> +/*
> + * Raw bitpacked video demuxer
> + * Copyright (c) 2021 Limin Wang
> + *
> + * 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
> + */
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/parseutils.h"
> +#include "libavutil/pixdesc.h"
> +#include "libavutil/opt.h"
> +#include "internal.h"
> +#include "avformat.h"
> +
> +typedef struct BitPackedDemuxerContext {
> + const AVClass *class; /**< Class for private options. */
> + int width, height; /**< Integers describing video size, set by a private option. */
> + char *pixel_format; /**< Set by a private option. */
> + AVRational framerate; /**< AVRational describing framerate, set by a private option. */
> +} BitPackedDemuxerContext;
> +
> +static int bitpacked_read_header(AVFormatContext *ctx)
> +{
> + BitPackedDemuxerContext *s = ctx->priv_data;
> + AVStream *st;
> + enum AVPixelFormat pix_fmt;
> + unsigned int pgroup; /* size of the pixel group in bytes */
> + unsigned int xinc;
> + const AVPixFmtDescriptor *desc;
> + int tag;
> + int ret;
> +
> + st = avformat_new_stream(ctx, NULL);
> + if (!st)
> + return AVERROR(ENOMEM);
> +
> + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> + st->codecpar->codec_id = ctx->iformat->raw_codec_id;
> +
> + if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
> + av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
> + return AVERROR(EINVAL);
> + }
> + desc = av_pix_fmt_desc_get(pix_fmt);
> +
> + ret = av_image_check_size(s->width, s->height, 0, ctx);
> + if (ret < 0)
> + return ret;
> +
> + st->codecpar->width = s->width;
> + st->codecpar->height = s->height;
> + st->codecpar->format = pix_fmt;
> + st->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
> +
> + if (pix_fmt == AV_PIX_FMT_YUV422P10) {
> + tag = MKTAG('U', 'Y', 'V', 'Y');
> + pgroup = 5;
> + xinc = 2;
> + } else if (pix_fmt == AV_PIX_FMT_UYVY422) {
> + tag = MKTAG('U', 'Y', 'V', 'Y');
> + pgroup = 4;
> + xinc = 2;
> + pix_fmt = AV_PIX_FMT_UYVY422;
> + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
> + } else {
> + av_log(ctx, AV_LOG_ERROR, "unsupported the pixel format: %s yet.\n",
> + s->pixel_format);
> + return AVERROR(EINVAL);
> + }
> + st->codecpar->format = pix_fmt;
> + st->codecpar->codec_tag = tag;
> +
> + avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
> + ctx->packet_size = s->width * s->height * pgroup / xinc;
> + st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
> + (AVRational){8,1}, st->time_base);
> +
> + return 0;
> +}
> +
> +static int bitpacked_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + int ret;
> +
> + ret = av_get_packet(s->pb, pkt, s->packet_size);
> + pkt->pts = pkt->dts = pkt->pos / s->packet_size;
> +
> + pkt->stream_index = 0;
> + if (ret < 0)
> + return ret;
> + return 0;
> +}
> +
> +#define OFFSET(x) offsetof(BitPackedDemuxerContext, x)
> +#define DEC AV_OPT_FLAG_DECODING_PARAM
> +static const AVOption bitpacked_options[] = {
> + { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
> + { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv422p10"}, 0, 0, DEC },
> + { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
> + { NULL },
> +};
> +
> +static const AVClass bitpacked_demuxer_class = {
> + .class_name = "bitpacked demuxer",
> + .item_name = av_default_item_name,
> + .option = bitpacked_options,
> + .version = LIBAVUTIL_VERSION_INT,
> +};
> +
> +#if CONFIG_BITPACKED_DEMUXER
> +const AVInputFormat ff_bitpacked_demuxer = {
> + .name = "bitpacked",
> + .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
> + .priv_data_size = sizeof(BitPackedDemuxerContext),
> + .read_header = bitpacked_read_header,
> + .read_packet = bitpacked_read_packet,
> + .flags = AVFMT_GENERIC_INDEX,
> + .extensions = "bitpacked",
> + .raw_codec_id = AV_CODEC_ID_BITPACKED,
> + .priv_class = &bitpacked_demuxer_class,
> +};
> +#endif // CONFIG_BITPACKED_DEMUXER
ping for review. will bump minor version if it's ready to push.
> --
> 1.8.3.1
>
--
Thanks,
Limin Wang
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer
[not found] <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com>
2021-12-21 13:13 ` [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer lance.lmwang
@ 2021-12-21 13:20 ` Andreas Rheinhardt
2021-12-21 13:34 ` lance.lmwang
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 1/3] " lance.lmwang
2 siblings, 1 reply; 8+ messages in thread
From: Andreas Rheinhardt @ 2021-12-21 13:20 UTC (permalink / raw)
To: ffmpeg-devel
lance.lmwang@gmail.com:
> From: Limin Wang <lance.lmwang@gmail.com>
>
> Allows user can playback bitpacked pixel format directly:
> ffplay -video_size 1280x720 test.bitpacked
> ffplay -f bitpacked -video_size 1280x720 -pixel_format uyvy422 test.yuv
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavformat/Makefile | 1 +
> libavformat/allformats.c | 1 +
> libavformat/bitpackeddec.c | 136 +++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 138 insertions(+)
> create mode 100644 libavformat/bitpackeddec.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 2b5caf9..90b7333 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -138,6 +138,7 @@ OBJS-$(CONFIG_BINKA_DEMUXER) += binka.o
> OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
> OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
> OBJS-$(CONFIG_BIT_MUXER) += bit.o
> +OBJS-$(CONFIG_BITPACKED_DEMUXER) += bitpackeddec.o
> OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o
> OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o
> OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 1054ac9..a100639 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -96,6 +96,7 @@ extern const AVInputFormat ff_bink_demuxer;
> extern const AVInputFormat ff_binka_demuxer;
> extern const AVInputFormat ff_bit_demuxer;
> extern const AVOutputFormat ff_bit_muxer;
> +extern const AVInputFormat ff_bitpacked_demuxer;
> extern const AVInputFormat ff_bmv_demuxer;
> extern const AVInputFormat ff_bfstm_demuxer;
> extern const AVInputFormat ff_brstm_demuxer;
> diff --git a/libavformat/bitpackeddec.c b/libavformat/bitpackeddec.c
> new file mode 100644
> index 0000000..ba404ad
> --- /dev/null
> +++ b/libavformat/bitpackeddec.c
> @@ -0,0 +1,136 @@
> +/*
> + * Raw bitpacked video demuxer
> + * Copyright (c) 2021 Limin Wang
> + *
> + * 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
> + */
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/parseutils.h"
> +#include "libavutil/pixdesc.h"
> +#include "libavutil/opt.h"
> +#include "internal.h"
> +#include "avformat.h"
> +
> +typedef struct BitPackedDemuxerContext {
> + const AVClass *class; /**< Class for private options. */
> + int width, height; /**< Integers describing video size, set by a private option. */
> + char *pixel_format; /**< Set by a private option. */
> + AVRational framerate; /**< AVRational describing framerate, set by a private option. */
> +} BitPackedDemuxerContext;
> +
> +static int bitpacked_read_header(AVFormatContext *ctx)
> +{
> + BitPackedDemuxerContext *s = ctx->priv_data;
> + AVStream *st;
> + enum AVPixelFormat pix_fmt;
> + unsigned int pgroup; /* size of the pixel group in bytes */
> + unsigned int xinc;
> + const AVPixFmtDescriptor *desc;
> + int tag;
> + int ret;
> +
> + st = avformat_new_stream(ctx, NULL);
> + if (!st)
> + return AVERROR(ENOMEM);
> +
> + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> + st->codecpar->codec_id = ctx->iformat->raw_codec_id;
Seems like you copied this code from somewhere. Where did you copy it from?
> +
> + if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
> + av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
> + return AVERROR(EINVAL);
> + }
> + desc = av_pix_fmt_desc_get(pix_fmt);
> +
> + ret = av_image_check_size(s->width, s->height, 0, ctx);
> + if (ret < 0)
> + return ret;
> +
> + st->codecpar->width = s->width;
> + st->codecpar->height = s->height;
> + st->codecpar->format = pix_fmt;
> + st->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
> +
> + if (pix_fmt == AV_PIX_FMT_YUV422P10) {
> + tag = MKTAG('U', 'Y', 'V', 'Y');
> + pgroup = 5;
> + xinc = 2;
> + } else if (pix_fmt == AV_PIX_FMT_UYVY422) {
> + tag = MKTAG('U', 'Y', 'V', 'Y');
> + pgroup = 4;
> + xinc = 2;
> + pix_fmt = AV_PIX_FMT_UYVY422;
> + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
> + } else {
> + av_log(ctx, AV_LOG_ERROR, "unsupported the pixel format: %s yet.\n",
> + s->pixel_format);
> + return AVERROR(EINVAL);
> + }
> + st->codecpar->format = pix_fmt;
> + st->codecpar->codec_tag = tag;
> +
> + avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
> + ctx->packet_size = s->width * s->height * pgroup / xinc;
> + st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
> + (AVRational){8,1}, st->time_base);
> +
> + return 0;
> +}
> +
> +static int bitpacked_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + int ret;
> +
> + ret = av_get_packet(s->pb, pkt, s->packet_size);
> + pkt->pts = pkt->dts = pkt->pos / s->packet_size;
> +
> + pkt->stream_index = 0;
> + if (ret < 0)
> + return ret;
> + return 0;
> +}
> +
> +#define OFFSET(x) offsetof(BitPackedDemuxerContext, x)
> +#define DEC AV_OPT_FLAG_DECODING_PARAM
> +static const AVOption bitpacked_options[] = {
> + { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
> + { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv422p10"}, 0, 0, DEC },
> + { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
> + { NULL },
> +};
> +
> +static const AVClass bitpacked_demuxer_class = {
> + .class_name = "bitpacked demuxer",
> + .item_name = av_default_item_name,
> + .option = bitpacked_options,
> + .version = LIBAVUTIL_VERSION_INT,
> +};
> +
> +#if CONFIG_BITPACKED_DEMUXER
> +const AVInputFormat ff_bitpacked_demuxer = {
> + .name = "bitpacked",
> + .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
> + .priv_data_size = sizeof(BitPackedDemuxerContext),
> + .read_header = bitpacked_read_header,
> + .read_packet = bitpacked_read_packet,
> + .flags = AVFMT_GENERIC_INDEX,
> + .extensions = "bitpacked",
> + .raw_codec_id = AV_CODEC_ID_BITPACKED,
> + .priv_class = &bitpacked_demuxer_class,
> +};
> +#endif // CONFIG_BITPACKED_DEMUXER
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer
2021-12-21 13:20 ` Andreas Rheinhardt
@ 2021-12-21 13:34 ` lance.lmwang
2021-12-22 13:38 ` Andreas Rheinhardt
0 siblings, 1 reply; 8+ messages in thread
From: lance.lmwang @ 2021-12-21 13:34 UTC (permalink / raw)
To: ffmpeg-devel
On Tue, Dec 21, 2021 at 02:20:31PM +0100, Andreas Rheinhardt wrote:
> lance.lmwang@gmail.com:
> > From: Limin Wang <lance.lmwang@gmail.com>
> >
> > Allows user can playback bitpacked pixel format directly:
> > ffplay -video_size 1280x720 test.bitpacked
> > ffplay -f bitpacked -video_size 1280x720 -pixel_format uyvy422 test.yuv
> >
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> > libavformat/Makefile | 1 +
> > libavformat/allformats.c | 1 +
> > libavformat/bitpackeddec.c | 136 +++++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 138 insertions(+)
> > create mode 100644 libavformat/bitpackeddec.c
> >
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index 2b5caf9..90b7333 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -138,6 +138,7 @@ OBJS-$(CONFIG_BINKA_DEMUXER) += binka.o
> > OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
> > OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
> > OBJS-$(CONFIG_BIT_MUXER) += bit.o
> > +OBJS-$(CONFIG_BITPACKED_DEMUXER) += bitpackeddec.o
> > OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o
> > OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o
> > OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index 1054ac9..a100639 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -96,6 +96,7 @@ extern const AVInputFormat ff_bink_demuxer;
> > extern const AVInputFormat ff_binka_demuxer;
> > extern const AVInputFormat ff_bit_demuxer;
> > extern const AVOutputFormat ff_bit_muxer;
> > +extern const AVInputFormat ff_bitpacked_demuxer;
> > extern const AVInputFormat ff_bmv_demuxer;
> > extern const AVInputFormat ff_bfstm_demuxer;
> > extern const AVInputFormat ff_brstm_demuxer;
> > diff --git a/libavformat/bitpackeddec.c b/libavformat/bitpackeddec.c
> > new file mode 100644
> > index 0000000..ba404ad
> > --- /dev/null
> > +++ b/libavformat/bitpackeddec.c
> > @@ -0,0 +1,136 @@
> > +/*
> > + * Raw bitpacked video demuxer
> > + * Copyright (c) 2021 Limin Wang
> > + *
> > + * 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
> > + */
> > +
> > +#include "libavutil/imgutils.h"
> > +#include "libavutil/parseutils.h"
> > +#include "libavutil/pixdesc.h"
> > +#include "libavutil/opt.h"
> > +#include "internal.h"
> > +#include "avformat.h"
> > +
> > +typedef struct BitPackedDemuxerContext {
> > + const AVClass *class; /**< Class for private options. */
> > + int width, height; /**< Integers describing video size, set by a private option. */
> > + char *pixel_format; /**< Set by a private option. */
> > + AVRational framerate; /**< AVRational describing framerate, set by a private option. */
> > +} BitPackedDemuxerContext;
> > +
> > +static int bitpacked_read_header(AVFormatContext *ctx)
> > +{
> > + BitPackedDemuxerContext *s = ctx->priv_data;
> > + AVStream *st;
> > + enum AVPixelFormat pix_fmt;
> > + unsigned int pgroup; /* size of the pixel group in bytes */
> > + unsigned int xinc;
> > + const AVPixFmtDescriptor *desc;
> > + int tag;
> > + int ret;
> > +
> > + st = avformat_new_stream(ctx, NULL);
> > + if (!st)
> > + return AVERROR(ENOMEM);
> > +
> > + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> > + st->codecpar->codec_id = ctx->iformat->raw_codec_id;
>
> Seems like you copied this code from somewhere. Where did you copy it from?
Yes, this part is coming from v210 demuxer I think.
>
> > +
> > + if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
> > + av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
> > + return AVERROR(EINVAL);
> > + }
> > + desc = av_pix_fmt_desc_get(pix_fmt);
> > +
> > + ret = av_image_check_size(s->width, s->height, 0, ctx);
> > + if (ret < 0)
> > + return ret;
> > +
> > + st->codecpar->width = s->width;
> > + st->codecpar->height = s->height;
> > + st->codecpar->format = pix_fmt;
> > + st->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
> > +
> > + if (pix_fmt == AV_PIX_FMT_YUV422P10) {
> > + tag = MKTAG('U', 'Y', 'V', 'Y');
> > + pgroup = 5;
> > + xinc = 2;
> > + } else if (pix_fmt == AV_PIX_FMT_UYVY422) {
> > + tag = MKTAG('U', 'Y', 'V', 'Y');
> > + pgroup = 4;
> > + xinc = 2;
> > + pix_fmt = AV_PIX_FMT_UYVY422;
> > + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
> > + } else {
> > + av_log(ctx, AV_LOG_ERROR, "unsupported the pixel format: %s yet.\n",
> > + s->pixel_format);
> > + return AVERROR(EINVAL);
> > + }
> > + st->codecpar->format = pix_fmt;
> > + st->codecpar->codec_tag = tag;
> > +
> > + avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
> > + ctx->packet_size = s->width * s->height * pgroup / xinc;
> > + st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
> > + (AVRational){8,1}, st->time_base);
> > +
> > + return 0;
> > +}
> > +
> > +static int bitpacked_read_packet(AVFormatContext *s, AVPacket *pkt)
> > +{
> > + int ret;
> > +
> > + ret = av_get_packet(s->pb, pkt, s->packet_size);
> > + pkt->pts = pkt->dts = pkt->pos / s->packet_size;
> > +
> > + pkt->stream_index = 0;
> > + if (ret < 0)
> > + return ret;
> > + return 0;
> > +}
> > +
> > +#define OFFSET(x) offsetof(BitPackedDemuxerContext, x)
> > +#define DEC AV_OPT_FLAG_DECODING_PARAM
> > +static const AVOption bitpacked_options[] = {
> > + { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
> > + { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv422p10"}, 0, 0, DEC },
> > + { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
> > + { NULL },
> > +};
> > +
> > +static const AVClass bitpacked_demuxer_class = {
> > + .class_name = "bitpacked demuxer",
> > + .item_name = av_default_item_name,
> > + .option = bitpacked_options,
> > + .version = LIBAVUTIL_VERSION_INT,
> > +};
> > +
> > +#if CONFIG_BITPACKED_DEMUXER
> > +const AVInputFormat ff_bitpacked_demuxer = {
> > + .name = "bitpacked",
> > + .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
> > + .priv_data_size = sizeof(BitPackedDemuxerContext),
> > + .read_header = bitpacked_read_header,
> > + .read_packet = bitpacked_read_packet,
> > + .flags = AVFMT_GENERIC_INDEX,
> > + .extensions = "bitpacked",
> > + .raw_codec_id = AV_CODEC_ID_BITPACKED,
> > + .priv_class = &bitpacked_demuxer_class,
> > +};
> > +#endif // CONFIG_BITPACKED_DEMUXER
> >
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
--
Thanks,
Limin Wang
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer
2021-12-21 13:34 ` lance.lmwang
@ 2021-12-22 13:38 ` Andreas Rheinhardt
2021-12-22 14:01 ` lance.lmwang
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 13:38 UTC (permalink / raw)
To: ffmpeg-devel
lance.lmwang@gmail.com:
> On Tue, Dec 21, 2021 at 02:20:31PM +0100, Andreas Rheinhardt wrote:
>> lance.lmwang@gmail.com:
>>> From: Limin Wang <lance.lmwang@gmail.com>
>>>
>>> Allows user can playback bitpacked pixel format directly:
>>> ffplay -video_size 1280x720 test.bitpacked
>>> ffplay -f bitpacked -video_size 1280x720 -pixel_format uyvy422 test.yuv
>>>
>>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>>> ---
>>> libavformat/Makefile | 1 +
>>> libavformat/allformats.c | 1 +
>>> libavformat/bitpackeddec.c | 136 +++++++++++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 138 insertions(+)
>>> create mode 100644 libavformat/bitpackeddec.c
>>>
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index 2b5caf9..90b7333 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -138,6 +138,7 @@ OBJS-$(CONFIG_BINKA_DEMUXER) += binka.o
>>> OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
>>> OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
>>> OBJS-$(CONFIG_BIT_MUXER) += bit.o
>>> +OBJS-$(CONFIG_BITPACKED_DEMUXER) += bitpackeddec.o
>>> OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o
>>> OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o
>>> OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o
>>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>>> index 1054ac9..a100639 100644
>>> --- a/libavformat/allformats.c
>>> +++ b/libavformat/allformats.c
>>> @@ -96,6 +96,7 @@ extern const AVInputFormat ff_bink_demuxer;
>>> extern const AVInputFormat ff_binka_demuxer;
>>> extern const AVInputFormat ff_bit_demuxer;
>>> extern const AVOutputFormat ff_bit_muxer;
>>> +extern const AVInputFormat ff_bitpacked_demuxer;
>>> extern const AVInputFormat ff_bmv_demuxer;
>>> extern const AVInputFormat ff_bfstm_demuxer;
>>> extern const AVInputFormat ff_brstm_demuxer;
>>> diff --git a/libavformat/bitpackeddec.c b/libavformat/bitpackeddec.c
>>> new file mode 100644
>>> index 0000000..ba404ad
>>> --- /dev/null
>>> +++ b/libavformat/bitpackeddec.c
>>> @@ -0,0 +1,136 @@
>>> +/*
>>> + * Raw bitpacked video demuxer
>>> + * Copyright (c) 2021 Limin Wang
>>> + *
>>> + * 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
>>> + */
>>> +
>>> +#include "libavutil/imgutils.h"
>>> +#include "libavutil/parseutils.h"
>>> +#include "libavutil/pixdesc.h"
>>> +#include "libavutil/opt.h"
>>> +#include "internal.h"
>>> +#include "avformat.h"
>>> +
>>> +typedef struct BitPackedDemuxerContext {
>>> + const AVClass *class; /**< Class for private options. */
>>> + int width, height; /**< Integers describing video size, set by a private option. */
>>> + char *pixel_format; /**< Set by a private option. */
>>> + AVRational framerate; /**< AVRational describing framerate, set by a private option. */
>>> +} BitPackedDemuxerContext;
>>> +
>>> +static int bitpacked_read_header(AVFormatContext *ctx)
>>> +{
>>> + BitPackedDemuxerContext *s = ctx->priv_data;
>>> + AVStream *st;
>>> + enum AVPixelFormat pix_fmt;
>>> + unsigned int pgroup; /* size of the pixel group in bytes */
>>> + unsigned int xinc;
>>> + const AVPixFmtDescriptor *desc;
>>> + int tag;
>>> + int ret;
>>> +
>>> + st = avformat_new_stream(ctx, NULL);
>>> + if (!st)
>>> + return AVERROR(ENOMEM);
>>> +
>>> + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
>>> + st->codecpar->codec_id = ctx->iformat->raw_codec_id;
>>
>> Seems like you copied this code from somewhere. Where did you copy it from?
>
> Yes, this part is coming from v210 demuxer I think.
>
The original source seems to be rawvideodec; it has exactly the same
options, exactly the same private struct, exactly the same read_packet
function and its read_header function is quite similar. You should reuse
the common code.
>>
>>> +
>>> + if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
>>> + av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
>>> + return AVERROR(EINVAL);
>>> + }
>>> + desc = av_pix_fmt_desc_get(pix_fmt);
>>> +
>>> + ret = av_image_check_size(s->width, s->height, 0, ctx);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + st->codecpar->width = s->width;
>>> + st->codecpar->height = s->height;
>>> + st->codecpar->format = pix_fmt;
>>> + st->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
>>> +
>>> + if (pix_fmt == AV_PIX_FMT_YUV422P10) {
>>> + tag = MKTAG('U', 'Y', 'V', 'Y');
>>> + pgroup = 5;
>>> + xinc = 2;
>>> + } else if (pix_fmt == AV_PIX_FMT_UYVY422) {
>>> + tag = MKTAG('U', 'Y', 'V', 'Y');
>>> + pgroup = 4;
>>> + xinc = 2;
>>> + pix_fmt = AV_PIX_FMT_UYVY422;
>>> + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
>>> + } else {
>>> + av_log(ctx, AV_LOG_ERROR, "unsupported the pixel format: %s yet.\n",
>>> + s->pixel_format);
>>> + return AVERROR(EINVAL);
>>> + }
>>> + st->codecpar->format = pix_fmt;
>>> + st->codecpar->codec_tag = tag;
>>> +
>>> + avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
>>> + ctx->packet_size = s->width * s->height * pgroup / xinc;
>>> + st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
>>> + (AVRational){8,1}, st->time_base);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int bitpacked_read_packet(AVFormatContext *s, AVPacket *pkt)
>>> +{
>>> + int ret;
>>> +
>>> + ret = av_get_packet(s->pb, pkt, s->packet_size);
>>> + pkt->pts = pkt->dts = pkt->pos / s->packet_size;
>>> +
>>> + pkt->stream_index = 0;
>>> + if (ret < 0)
>>> + return ret;
>>> + return 0;
>>> +}
>>> +
>>> +#define OFFSET(x) offsetof(BitPackedDemuxerContext, x)
>>> +#define DEC AV_OPT_FLAG_DECODING_PARAM
>>> +static const AVOption bitpacked_options[] = {
>>> + { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
>>> + { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv422p10"}, 0, 0, DEC },
>>> + { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
>>> + { NULL },
>>> +};
>>> +
>>> +static const AVClass bitpacked_demuxer_class = {
>>> + .class_name = "bitpacked demuxer",
>>> + .item_name = av_default_item_name,
>>> + .option = bitpacked_options,
>>> + .version = LIBAVUTIL_VERSION_INT,
>>> +};
>>> +
>>> +#if CONFIG_BITPACKED_DEMUXER
>>> +const AVInputFormat ff_bitpacked_demuxer = {
>>> + .name = "bitpacked",
>>> + .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
>>> + .priv_data_size = sizeof(BitPackedDemuxerContext),
>>> + .read_header = bitpacked_read_header,
>>> + .read_packet = bitpacked_read_packet,
>>> + .flags = AVFMT_GENERIC_INDEX,
>>> + .extensions = "bitpacked",
>>> + .raw_codec_id = AV_CODEC_ID_BITPACKED,
>>> + .priv_class = &bitpacked_demuxer_class,
>>> +};
>>> +#endif // CONFIG_BITPACKED_DEMUXER
>>>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer
2021-12-22 13:38 ` Andreas Rheinhardt
@ 2021-12-22 14:01 ` lance.lmwang
0 siblings, 0 replies; 8+ messages in thread
From: lance.lmwang @ 2021-12-22 14:01 UTC (permalink / raw)
To: ffmpeg-devel
On Wed, Dec 22, 2021 at 02:38:13PM +0100, Andreas Rheinhardt wrote:
> lance.lmwang@gmail.com:
> > On Tue, Dec 21, 2021 at 02:20:31PM +0100, Andreas Rheinhardt wrote:
> >> lance.lmwang@gmail.com:
> >>> From: Limin Wang <lance.lmwang@gmail.com>
> >>>
> >>> Allows user can playback bitpacked pixel format directly:
> >>> ffplay -video_size 1280x720 test.bitpacked
> >>> ffplay -f bitpacked -video_size 1280x720 -pixel_format uyvy422 test.yuv
> >>>
> >>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> >>> ---
> >>> libavformat/Makefile | 1 +
> >>> libavformat/allformats.c | 1 +
> >>> libavformat/bitpackeddec.c | 136 +++++++++++++++++++++++++++++++++++++++++++++
> >>> 3 files changed, 138 insertions(+)
> >>> create mode 100644 libavformat/bitpackeddec.c
> >>>
> >>> diff --git a/libavformat/Makefile b/libavformat/Makefile
> >>> index 2b5caf9..90b7333 100644
> >>> --- a/libavformat/Makefile
> >>> +++ b/libavformat/Makefile
> >>> @@ -138,6 +138,7 @@ OBJS-$(CONFIG_BINKA_DEMUXER) += binka.o
> >>> OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
> >>> OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
> >>> OBJS-$(CONFIG_BIT_MUXER) += bit.o
> >>> +OBJS-$(CONFIG_BITPACKED_DEMUXER) += bitpackeddec.o
> >>> OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o
> >>> OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o
> >>> OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o
> >>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> >>> index 1054ac9..a100639 100644
> >>> --- a/libavformat/allformats.c
> >>> +++ b/libavformat/allformats.c
> >>> @@ -96,6 +96,7 @@ extern const AVInputFormat ff_bink_demuxer;
> >>> extern const AVInputFormat ff_binka_demuxer;
> >>> extern const AVInputFormat ff_bit_demuxer;
> >>> extern const AVOutputFormat ff_bit_muxer;
> >>> +extern const AVInputFormat ff_bitpacked_demuxer;
> >>> extern const AVInputFormat ff_bmv_demuxer;
> >>> extern const AVInputFormat ff_bfstm_demuxer;
> >>> extern const AVInputFormat ff_brstm_demuxer;
> >>> diff --git a/libavformat/bitpackeddec.c b/libavformat/bitpackeddec.c
> >>> new file mode 100644
> >>> index 0000000..ba404ad
> >>> --- /dev/null
> >>> +++ b/libavformat/bitpackeddec.c
> >>> @@ -0,0 +1,136 @@
> >>> +/*
> >>> + * Raw bitpacked video demuxer
> >>> + * Copyright (c) 2021 Limin Wang
> >>> + *
> >>> + * 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
> >>> + */
> >>> +
> >>> +#include "libavutil/imgutils.h"
> >>> +#include "libavutil/parseutils.h"
> >>> +#include "libavutil/pixdesc.h"
> >>> +#include "libavutil/opt.h"
> >>> +#include "internal.h"
> >>> +#include "avformat.h"
> >>> +
> >>> +typedef struct BitPackedDemuxerContext {
> >>> + const AVClass *class; /**< Class for private options. */
> >>> + int width, height; /**< Integers describing video size, set by a private option. */
> >>> + char *pixel_format; /**< Set by a private option. */
> >>> + AVRational framerate; /**< AVRational describing framerate, set by a private option. */
> >>> +} BitPackedDemuxerContext;
> >>> +
> >>> +static int bitpacked_read_header(AVFormatContext *ctx)
> >>> +{
> >>> + BitPackedDemuxerContext *s = ctx->priv_data;
> >>> + AVStream *st;
> >>> + enum AVPixelFormat pix_fmt;
> >>> + unsigned int pgroup; /* size of the pixel group in bytes */
> >>> + unsigned int xinc;
> >>> + const AVPixFmtDescriptor *desc;
> >>> + int tag;
> >>> + int ret;
> >>> +
> >>> + st = avformat_new_stream(ctx, NULL);
> >>> + if (!st)
> >>> + return AVERROR(ENOMEM);
> >>> +
> >>> + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> >>> + st->codecpar->codec_id = ctx->iformat->raw_codec_id;
> >>
> >> Seems like you copied this code from somewhere. Where did you copy it from?
> >
> > Yes, this part is coming from v210 demuxer I think.
> >
>
> The original source seems to be rawvideodec; it has exactly the same
> options, exactly the same private struct, exactly the same read_packet
> function and its read_header function is quite similar. You should reuse
> the common code.
OK, I'll try to add it to rawvideodec.c and reuse the common code.
>
> >>
> >>> +
> >>> + if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
> >>> + av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
> >>> + return AVERROR(EINVAL);
> >>> + }
> >>> + desc = av_pix_fmt_desc_get(pix_fmt);
> >>> +
> >>> + ret = av_image_check_size(s->width, s->height, 0, ctx);
> >>> + if (ret < 0)
> >>> + return ret;
> >>> +
> >>> + st->codecpar->width = s->width;
> >>> + st->codecpar->height = s->height;
> >>> + st->codecpar->format = pix_fmt;
> >>> + st->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
> >>> +
> >>> + if (pix_fmt == AV_PIX_FMT_YUV422P10) {
> >>> + tag = MKTAG('U', 'Y', 'V', 'Y');
> >>> + pgroup = 5;
> >>> + xinc = 2;
> >>> + } else if (pix_fmt == AV_PIX_FMT_UYVY422) {
> >>> + tag = MKTAG('U', 'Y', 'V', 'Y');
> >>> + pgroup = 4;
> >>> + xinc = 2;
> >>> + pix_fmt = AV_PIX_FMT_UYVY422;
> >>> + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
> >>> + } else {
> >>> + av_log(ctx, AV_LOG_ERROR, "unsupported the pixel format: %s yet.\n",
> >>> + s->pixel_format);
> >>> + return AVERROR(EINVAL);
> >>> + }
> >>> + st->codecpar->format = pix_fmt;
> >>> + st->codecpar->codec_tag = tag;
> >>> +
> >>> + avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
> >>> + ctx->packet_size = s->width * s->height * pgroup / xinc;
> >>> + st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
> >>> + (AVRational){8,1}, st->time_base);
> >>> +
> >>> + return 0;
> >>> +}
> >>> +
> >>> +static int bitpacked_read_packet(AVFormatContext *s, AVPacket *pkt)
> >>> +{
> >>> + int ret;
> >>> +
> >>> + ret = av_get_packet(s->pb, pkt, s->packet_size);
> >>> + pkt->pts = pkt->dts = pkt->pos / s->packet_size;
> >>> +
> >>> + pkt->stream_index = 0;
> >>> + if (ret < 0)
> >>> + return ret;
> >>> + return 0;
> >>> +}
> >>> +
> >>> +#define OFFSET(x) offsetof(BitPackedDemuxerContext, x)
> >>> +#define DEC AV_OPT_FLAG_DECODING_PARAM
> >>> +static const AVOption bitpacked_options[] = {
> >>> + { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
> >>> + { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv422p10"}, 0, 0, DEC },
> >>> + { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
> >>> + { NULL },
> >>> +};
> >>> +
> >>> +static const AVClass bitpacked_demuxer_class = {
> >>> + .class_name = "bitpacked demuxer",
> >>> + .item_name = av_default_item_name,
> >>> + .option = bitpacked_options,
> >>> + .version = LIBAVUTIL_VERSION_INT,
> >>> +};
> >>> +
> >>> +#if CONFIG_BITPACKED_DEMUXER
> >>> +const AVInputFormat ff_bitpacked_demuxer = {
> >>> + .name = "bitpacked",
> >>> + .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
> >>> + .priv_data_size = sizeof(BitPackedDemuxerContext),
> >>> + .read_header = bitpacked_read_header,
> >>> + .read_packet = bitpacked_read_packet,
> >>> + .flags = AVFMT_GENERIC_INDEX,
> >>> + .extensions = "bitpacked",
> >>> + .raw_codec_id = AV_CODEC_ID_BITPACKED,
> >>> + .priv_class = &bitpacked_demuxer_class,
> >>> +};
> >>> +#endif // CONFIG_BITPACKED_DEMUXER
> >>>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
--
Thanks,
Limin Wang
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 1/3] avformat: add bitpacked demuxer
[not found] <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com>
2021-12-21 13:13 ` [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer lance.lmwang
2021-12-21 13:20 ` Andreas Rheinhardt
@ 2021-12-22 23:03 ` lance.lmwang
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 2/3] avformat: reuse the common code for v210/v210x lance.lmwang
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 3/3] avformat: remove unused v210.c lance.lmwang
2 siblings, 2 replies; 8+ messages in thread
From: lance.lmwang @ 2021-12-22 23:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Limin Wang
From: Limin Wang <lance.lmwang@gmail.com>
Allows user can playback bitpacked pixel format directly:
ffplay -video_size 1280x720 -pixel_format yuv422p10 test.bitpacked
ffplay -f bitpacked -video_size 1280x720 -pixel_format uyvy422 test.yuv
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/rawvideodec.c | 56 ++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2b5caf9..65fb789 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -138,6 +138,7 @@ OBJS-$(CONFIG_BINKA_DEMUXER) += binka.o
OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
OBJS-$(CONFIG_BIT_MUXER) += bit.o
+OBJS-$(CONFIG_BITPACKED_DEMUXER) += rawvideodec.o
OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o
OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o
OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1054ac9..a100639 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -96,6 +96,7 @@ extern const AVInputFormat ff_bink_demuxer;
extern const AVInputFormat ff_binka_demuxer;
extern const AVInputFormat ff_bit_demuxer;
extern const AVOutputFormat ff_bit_muxer;
+extern const AVInputFormat ff_bitpacked_demuxer;
extern const AVInputFormat ff_bmv_demuxer;
extern const AVInputFormat ff_bfstm_demuxer;
extern const AVInputFormat ff_brstm_demuxer;
diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c
index 5049a29..a2ce423 100644
--- a/libavformat/rawvideodec.c
+++ b/libavformat/rawvideodec.c
@@ -59,10 +59,39 @@ static int rawvideo_read_header(AVFormatContext *ctx)
st->codecpar->width = s->width;
st->codecpar->height = s->height;
+
+ if (ctx->iformat->raw_codec_id == AV_CODEC_ID_BITPACKED) {
+ unsigned int pgroup; /* size of the pixel group in bytes */
+ unsigned int xinc;
+ const AVPixFmtDescriptor *desc;
+ int tag;
+
+ desc = av_pix_fmt_desc_get(pix_fmt);
+ st->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
+ if (pix_fmt == AV_PIX_FMT_YUV422P10) {
+ tag = MKTAG('U', 'Y', 'V', 'Y');
+ pgroup = 5;
+ xinc = 2;
+ } else if (pix_fmt == AV_PIX_FMT_UYVY422) {
+ tag = MKTAG('U', 'Y', 'V', 'Y');
+ pgroup = 4;
+ xinc = 2;
+ pix_fmt = AV_PIX_FMT_UYVY422;
+ st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "unsupported format: %s for bitpacked.\n",
+ s->pixel_format);
+ return AVERROR(EINVAL);
+ }
+ st->codecpar->codec_tag = tag;
+ packet_size = s->width * s->height * pgroup / xinc;
+ } else {
+ packet_size = av_image_get_buffer_size(pix_fmt, s->width, s->height, 1);
+ if (packet_size < 0)
+ return packet_size;
+ }
+
st->codecpar->format = pix_fmt;
- packet_size = av_image_get_buffer_size(st->codecpar->format, s->width, s->height, 1);
- if (packet_size < 0)
- return packet_size;
ctx->packet_size = packet_size;
st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
(AVRational){8,1}, st->time_base);
@@ -111,3 +140,24 @@ const AVInputFormat ff_rawvideo_demuxer = {
.raw_codec_id = AV_CODEC_ID_RAWVIDEO,
.priv_class = &rawvideo_demuxer_class,
};
+
+static const AVClass bitpacked_demuxer_class = {
+ .class_name = "bitpacked demuxer",
+ .item_name = av_default_item_name,
+ .option = rawvideo_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+#if CONFIG_BITPACKED_DEMUXER
+const AVInputFormat ff_bitpacked_demuxer = {
+ .name = "bitpacked",
+ .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
+ .priv_data_size = sizeof(RawVideoDemuxerContext),
+ .read_header = rawvideo_read_header,
+ .read_packet = rawvideo_read_packet,
+ .flags = AVFMT_GENERIC_INDEX,
+ .extensions = "bitpacked",
+ .raw_codec_id = AV_CODEC_ID_BITPACKED,
+ .priv_class = &bitpacked_demuxer_class,
+};
+#endif // CONFIG_BITPACKED_DEMUXER
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/3] avformat: reuse the common code for v210/v210x
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 1/3] " lance.lmwang
@ 2021-12-22 23:03 ` lance.lmwang
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 3/3] avformat: remove unused v210.c lance.lmwang
1 sibling, 0 replies; 8+ messages in thread
From: lance.lmwang @ 2021-12-22 23:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Limin Wang
From: Limin Wang <lance.lmwang@gmail.com>
As suggested by Andreas Rheinhardt, most code of v210 demuxer is common code
which is duplicated from rawvideodec, so it's better to move v210/v210x
demuxer code to rawvideodec.c and reuse the common code.
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
libavformat/Makefile | 4 ++--
libavformat/rawvideodec.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 65fb789..14b66e4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -559,8 +559,8 @@ OBJS-$(CONFIG_TTY_DEMUXER) += tty.o sauce.o
OBJS-$(CONFIG_TY_DEMUXER) += ty.o
OBJS-$(CONFIG_TXD_DEMUXER) += txd.o
OBJS-$(CONFIG_UNCODEDFRAMECRC_MUXER) += uncodedframecrcenc.o framehash.o
-OBJS-$(CONFIG_V210_DEMUXER) += v210.o
-OBJS-$(CONFIG_V210X_DEMUXER) += v210.o
+OBJS-$(CONFIG_V210_DEMUXER) += rawvideodec.o
+OBJS-$(CONFIG_V210X_DEMUXER) += rawvideodec.o
OBJS-$(CONFIG_VAG_DEMUXER) += vag.o
OBJS-$(CONFIG_VC1_DEMUXER) += rawdec.o vc1dec.o
OBJS-$(CONFIG_VC1_MUXER) += rawenc.o
diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c
index a2ce423..6ff87a8 100644
--- a/libavformat/rawvideodec.c
+++ b/libavformat/rawvideodec.c
@@ -33,6 +33,8 @@ typedef struct RawVideoDemuxerContext {
AVRational framerate; /**< AVRational describing framerate, set by a private option. */
} RawVideoDemuxerContext;
+// v210 frame width is padded to multiples of 48
+#define GET_PACKET_SIZE(w, h) (((w + 47) / 48) * 48 * h * 8 / 3)
static int rawvideo_read_header(AVFormatContext *ctx)
{
@@ -85,6 +87,12 @@ static int rawvideo_read_header(AVFormatContext *ctx)
}
st->codecpar->codec_tag = tag;
packet_size = s->width * s->height * pgroup / xinc;
+ } else if ((ctx->iformat->raw_codec_id == AV_CODEC_ID_V210) ||
+ (ctx->iformat->raw_codec_id == AV_CODEC_ID_V210X)) {
+ pix_fmt = ctx->iformat->raw_codec_id == AV_CODEC_ID_V210 ?
+ AV_PIX_FMT_YUV422P10 : AV_PIX_FMT_YUV422P16;
+
+ packet_size = GET_PACKET_SIZE(s->width, s->height);
} else {
packet_size = av_image_get_buffer_size(pix_fmt, s->width, s->height, 1);
if (packet_size < 0)
@@ -161,3 +169,38 @@ const AVInputFormat ff_bitpacked_demuxer = {
.priv_class = &bitpacked_demuxer_class,
};
#endif // CONFIG_BITPACKED_DEMUXER
+
+static const AVClass v210_demuxer_class = {
+ .class_name = "v210(x) demuxer",
+ .item_name = av_default_item_name,
+ .option = rawvideo_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+#if CONFIG_V210_DEMUXER
+const AVInputFormat ff_v210_demuxer = {
+ .name = "v210",
+ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
+ .priv_data_size = sizeof(RawVideoDemuxerContext),
+ .read_header = rawvideo_read_header,
+ .read_packet = rawvideo_read_packet,
+ .flags = AVFMT_GENERIC_INDEX,
+ .extensions = "v210",
+ .raw_codec_id = AV_CODEC_ID_V210,
+ .priv_class = &v210_demuxer_class,
+};
+#endif // CONFIG_V210_DEMUXER
+
+#if CONFIG_V210X_DEMUXER
+const AVInputFormat ff_v210x_demuxer = {
+ .name = "v210x",
+ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
+ .priv_data_size = sizeof(RawVideoDemuxerContext),
+ .read_header = rawvideo_read_header,
+ .read_packet = rawvideo_read_packet,
+ .flags = AVFMT_GENERIC_INDEX,
+ .extensions = "yuv10",
+ .raw_codec_id = AV_CODEC_ID_V210X,
+ .priv_class = &v210_demuxer_class,
+};
+#endif // CONFIG_V210X_DEMUXER
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/3] avformat: remove unused v210.c
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 1/3] " lance.lmwang
2021-12-22 23:03 ` [FFmpeg-devel] [PATCH v2 2/3] avformat: reuse the common code for v210/v210x lance.lmwang
@ 2021-12-22 23:03 ` lance.lmwang
1 sibling, 0 replies; 8+ messages in thread
From: lance.lmwang @ 2021-12-22 23:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Limin Wang
From: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
libavformat/v210.c | 123 -----------------------------------------------------
1 file changed, 123 deletions(-)
delete mode 100644 libavformat/v210.c
diff --git a/libavformat/v210.c b/libavformat/v210.c
deleted file mode 100644
index 24f71d4..0000000
--- a/libavformat/v210.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Raw v210 video demuxer
- * Copyright (c) 2015 Tiancheng "Timothy" Gu
- *
- * 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
- */
-
-#include "libavutil/imgutils.h"
-#include "libavutil/parseutils.h"
-#include "libavutil/pixdesc.h"
-#include "libavutil/opt.h"
-#include "internal.h"
-#include "avformat.h"
-
-typedef struct V210DemuxerContext {
- const AVClass *class; /**< Class for private options. */
- int width, height; /**< Integers describing video size, set by a private option. */
- AVRational framerate; /**< AVRational describing framerate, set by a private option. */
-} V210DemuxerContext;
-
-// v210 frame width is padded to multiples of 48
-#define GET_PACKET_SIZE(w, h) (((w + 47) / 48) * 48 * h * 8 / 3)
-
-static int v210_read_header(AVFormatContext *ctx)
-{
- V210DemuxerContext *s = ctx->priv_data;
- AVStream *st;
- int ret;
-
- st = avformat_new_stream(ctx, NULL);
- if (!st)
- return AVERROR(ENOMEM);
-
- st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
-
- st->codecpar->codec_id = ctx->iformat->raw_codec_id;
-
- avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
-
- ret = av_image_check_size(s->width, s->height, 0, ctx);
- if (ret < 0)
- return ret;
- st->codecpar->width = s->width;
- st->codecpar->height = s->height;
- st->codecpar->format = ctx->iformat->raw_codec_id == AV_CODEC_ID_V210 ?
- AV_PIX_FMT_YUV422P10 : AV_PIX_FMT_YUV422P16;
- ctx->packet_size = GET_PACKET_SIZE(s->width, s->height);
- st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
- (AVRational){8,1}, st->time_base);
-
- return 0;
-}
-
-
-static int v210_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int ret;
-
- ret = av_get_packet(s->pb, pkt, s->packet_size);
- pkt->pts = pkt->dts = pkt->pos / s->packet_size;
-
- pkt->stream_index = 0;
- if (ret < 0)
- return ret;
- return 0;
-}
-
-#define OFFSET(x) offsetof(V210DemuxerContext, x)
-#define DEC AV_OPT_FLAG_DECODING_PARAM
-static const AVOption v210_options[] = {
- { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
- { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
- { NULL },
-};
-
-static const AVClass v210_demuxer_class = {
- .class_name = "v210(x) demuxer",
- .item_name = av_default_item_name,
- .option = v210_options,
- .version = LIBAVUTIL_VERSION_INT,
-};
-
-#if CONFIG_V210_DEMUXER
-const AVInputFormat ff_v210_demuxer = {
- .name = "v210",
- .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
- .priv_data_size = sizeof(V210DemuxerContext),
- .read_header = v210_read_header,
- .read_packet = v210_read_packet,
- .flags = AVFMT_GENERIC_INDEX,
- .extensions = "v210",
- .raw_codec_id = AV_CODEC_ID_V210,
- .priv_class = &v210_demuxer_class,
-};
-#endif // CONFIG_V210_DEMUXER
-
-#if CONFIG_V210X_DEMUXER
-const AVInputFormat ff_v210x_demuxer = {
- .name = "v210x",
- .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
- .priv_data_size = sizeof(V210DemuxerContext),
- .read_header = v210_read_header,
- .read_packet = v210_read_packet,
- .flags = AVFMT_GENERIC_INDEX,
- .extensions = "yuv10",
- .raw_codec_id = AV_CODEC_ID_V210X,
- .priv_class = &v210_demuxer_class,
-};
-#endif // CONFIG_V210X_DEMUXER
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread