From: lance.lmwang@gmail.com
To: ffmpeg-devel@ffmpeg.org
Cc: Limin Wang <lance.lmwang@gmail.com>
Subject: [FFmpeg-devel] [PATCH v2 1/3] avformat: add bitpacked demuxer
Date: Thu, 23 Dec 2021 07:03:02 +0800
Message-ID: <1640214184-12529-1-git-send-email-lance.lmwang@gmail.com> (raw)
In-Reply-To: <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com>
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".
next prev parent reply other threads:[~2021-12-22 23:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com>
2021-12-21 13:13 ` [FFmpeg-devel] [PATCH] " lance.lmwang
2021-12-21 13:20 ` Andreas Rheinhardt
2021-12-21 13:34 ` lance.lmwang
2021-12-22 13:38 ` Andreas Rheinhardt
2021-12-22 14:01 ` lance.lmwang
2021-12-22 23:03 ` lance.lmwang [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1640214184-12529-1-git-send-email-lance.lmwang@gmail.com \
--to=lance.lmwang@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git