From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A894F40568 for ; Tue, 21 Dec 2021 13:14:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5B3AB68AEF7; Tue, 21 Dec 2021 15:14:02 +0200 (EET) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 096C168807F for ; Tue, 21 Dec 2021 15:13:57 +0200 (EET) Received: by mail-pj1-f41.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso2558939pji.0 for ; Tue, 21 Dec 2021 05:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=MAAXIqmpKtxqt8tFQOYQ0t5SbhDaCE+HtGtlMuBJmfc=; b=BIp5oSZXNHGA9thNiI60030uAXOkoV6EwUhhEJpq2Wfwx4MLXnEGblsjzfBaJp4Rwh BdK0MUJmZ5FMfm6M5ZHs93owapp2AeLb5gk0875i0ttTg+wwfiqb+5IyvM3RJPrG4R1o VU2n/QPDS8OOieKYJFHU0+J4uTCzWlYWrC4hQ9yroEr5SnBK9/Pp6aieTrvRXom+Vcjd QMQ9YiRT3K5uWkKdrwy4q/qIBHnmi7PsmpRO5Zabe/Ih1zkJN8b+XdsblbhKhhc2yjPn bZSJ3fKLJGHi35/eQDiELKYzl3IfQoCJVqMKUcHZJRif+Xkf2QrUtzuh6c1V4Sqw6nHX i1Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to; bh=MAAXIqmpKtxqt8tFQOYQ0t5SbhDaCE+HtGtlMuBJmfc=; b=OsnVYVUnJSgHOMxZt76c0dbCik8rE4Z1cVi+mGrXtLGosZJcHfnxOCYcwwpWAt5MpQ zuV2VW4NXO884LQVszewudqenc4LZacxdmjl7txT5nK9i+ttWpMe93ep8LztLPwCQRq1 mfjnPr3a2F4nS3LDQVKrm3v8Gc1+AT2YMitX3q7moCiJsFw5w6jo2jkxojDjldGV82zx D+mZOYay9+bsyqrUu+D9QWCA4BiOWxfw2N3hHKxK0L+C9laYfjYbag2knRi22EitUVyz zQVdAc1sIFVi2ZdVBbzkEUqSF2OjCBBHZpRaFGLI6KMeL/bozUnDl6XNayku6Z1QUohi mhBg== X-Gm-Message-State: AOAM532n+vm87zGgkSDPrmMF7rALqeupE8Zpyc2kVJwJQ9toEyIYqUc+ 2vyYAcVKibOLYOvk74evwZ2VuPM11lY= X-Google-Smtp-Source: ABdhPJyICKjD8HzSqyHAa/DSI4KYD9Qc+1Yc3mc6lkCG3V7h9P1i6x7QmxAe9UOfkQHY3ssmoitRoA== X-Received: by 2002:a17:90b:3903:: with SMTP id ob3mr3938648pjb.178.1640092435105; Tue, 21 Dec 2021 05:13:55 -0800 (PST) Received: from gmail.com ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id l16sm18749799pfu.115.2021.12.21.05.13.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Dec 2021 05:13:54 -0800 (PST) Date: Tue, 21 Dec 2021 21:13:51 +0800 From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Message-ID: <20211221131351.GA26741@gmail.com> Mail-Followup-To: ffmpeg-devel@ffmpeg.org References: <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1639492513-12002-1-git-send-email-lance.lmwang@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH] avformat: add bitpacked demuxer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, Dec 14, 2021 at 10:35:13PM +0800, lance.lmwang@gmail.com wrote: > From: Limin Wang > > 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 > --- > 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".