From: 9mmilly via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: 9mmilly <9mmilly@0x3f4f3e.org>
Subject: [FFmpeg-devel] [PATCH] libavformat/rot: added rot pcm header support
Date: Fri, 23 Jan 2026 13:35:29 +0100
Message-ID: <20260123123529.6896-1-9mmilly@0x3f4f3e.org> (raw)
implemented rot muxer and demuxer
---
configure | 2 +
libavformat/Makefile | 2 +
libavformat/allformats.c | 2 +
libavformat/rot.c | 230 +++++++++++++++++++++++++++++++++++++++
4 files changed, 236 insertions(+)
create mode 100644 libavformat/rot.c
diff --git a/configure b/configure
index 01edfacacc..360cb38431 100755
--- a/configure
+++ b/configure
@@ -3875,6 +3875,8 @@ ogg_demuxer_select="dirac_parse"
ogv_muxer_select="ogg_muxer"
opus_muxer_select="ogg_muxer"
psp_muxer_select="mov_muxer"
+rot_demuxer_select="pcm"
+rot_muxer_select=""
rtp_demuxer_select="sdp_demuxer"
rtp_muxer_select="iso_writer"
rtp_mpegts_muxer_select="mpegts_muxer rtp_muxer"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 5fd3f7252a..c7fbaa1c33 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -521,6 +521,8 @@ OBJS-$(CONFIG_RM_DEMUXER) += rmdec.o rm.o rmsipr.o
OBJS-$(CONFIG_RM_MUXER) += rmenc.o rm.o
OBJS-$(CONFIG_ROQ_DEMUXER) += idroqdec.o
OBJS-$(CONFIG_ROQ_MUXER) += idroqenc.o rawenc.o
+OBJS-$(CONFIG_ROT_DEMUXER) += rot.o pcm.o
+OBJS-$(CONFIG_ROT_MUXER) += rot.o
OBJS-$(CONFIG_RSD_DEMUXER) += rsd.o
OBJS-$(CONFIG_RPL_DEMUXER) += rpl.o
OBJS-$(CONFIG_RSO_DEMUXER) += rsodec.o rso.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6ec361fb7b..e730f88568 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -407,6 +407,8 @@ extern const FFInputFormat ff_rm_demuxer;
extern const FFOutputFormat ff_rm_muxer;
extern const FFInputFormat ff_roq_demuxer;
extern const FFOutputFormat ff_roq_muxer;
+extern const FFInputFormat ff_rot_demuxer;
+extern const FFOutputFormat ff_rot_muxer;
extern const FFInputFormat ff_rpl_demuxer;
extern const FFInputFormat ff_rsd_demuxer;
extern const FFInputFormat ff_rso_demuxer;
diff --git a/libavformat/rot.c b/libavformat/rot.c
new file mode 100644
index 0000000000..520f038f8b
--- /dev/null
+++ b/libavformat/rot.c
@@ -0,0 +1,230 @@
+/*
+* Copyright (c) 2014 9mmilly
+*
+* This file is part of FFmpeg.
+*
+* Permission to use, copy, modify, and/or distribute this software for any
+* purpose with or without fee is hereby granted, provided that the above
+* copyright notice and this permission notice appear in all copies.
+*
+* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#include <stdint.h>
+#include <string.h>
+
+#include "avformat.h"
+#include "demux.h"
+#include "internal.h"
+#include "libavcodec/codec_id.h"
+#include "mux.h"
+#include "pcm.h"
+#include "rawenc.h"
+
+#define ROT_IDENTIFIER "frot"
+
+typedef enum {
+ ROT_FORMAT_S8,
+ ROT_FORMAT_S16,
+ ROT_FORMAT_S24,
+ ROT_FORMAT_S32,
+ ROT_FORMAT_FLOAT,
+ ROT_FORMAT_DOUBLE
+} rot_format;
+
+/* demuxer */
+
+static int rot_probe(const AVProbeData *probe) {
+ if (probe->buf_size <= 32)
+ return 0;
+
+ if (probe->buf_size >= 36) {
+ if (memcmp(probe->buf, ROT_IDENTIFIER, 4) == 0)
+ return AVPROBE_SCORE_MAX;
+ }
+ return 0;
+}
+
+static int rot_read_header(AVFormatContext *context) {
+ uint8_t header_buffer[8];
+
+ if (avio_read(context->pb, header_buffer, sizeof(header_buffer)) != 8)
+ return AVERROR_INVALIDDATA;
+
+ uint16_t sample_rate;
+ memcpy(&sample_rate, (header_buffer + 4), 2);
+
+ uint8_t channels;
+ memcpy(&channels, (header_buffer + 6), 1);
+
+ uint8_t format;
+ memcpy(&format, (header_buffer + 7), 1);
+
+ if (sample_rate <= 0 || channels <= 0)
+ return AVERROR_INVALIDDATA;
+
+ AVStream *stream = avformat_new_stream(context, NULL);
+ if (!stream) {
+ av_log(stream, AV_LOG_ERROR, "invalid audio parameters\n");
+ return AVERROR(ENOMEM);
+ }
+
+ stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ stream->codecpar->ch_layout.nb_channels = channels;
+ stream->codecpar->sample_rate = sample_rate;
+
+ switch (format) {
+ case ROT_FORMAT_S8:
+ stream->codecpar->codec_id = AV_CODEC_ID_PCM_S8;
+ stream->codecpar->bits_per_coded_sample = 8;
+ stream->codecpar->block_align = 8 * channels / 8;
+ stream->codecpar->bit_rate = (int64_t)sample_rate * channels * 8;
+ break;
+
+ case ROT_FORMAT_S16:
+ stream->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+ stream->codecpar->bits_per_coded_sample = 16;
+ stream->codecpar->block_align = 16 * channels / 8;
+ stream->codecpar->bit_rate = (int64_t)sample_rate * channels * 16;
+ break;
+
+ case ROT_FORMAT_S24:
+ stream->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
+ stream->codecpar->bits_per_coded_sample = 24;
+ stream->codecpar->block_align = 24 * channels / 8;
+ stream->codecpar->bit_rate = (int64_t)sample_rate * channels * 24;
+ break;
+
+ case ROT_FORMAT_S32:
+ stream->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
+ stream->codecpar->bits_per_coded_sample = 32;
+ stream->codecpar->block_align = 32 * channels / 8;
+ stream->codecpar->bit_rate = (int64_t)sample_rate * channels * 32;
+ break;
+
+ case ROT_FORMAT_FLOAT:
+ stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
+ stream->codecpar->bits_per_coded_sample = 32;
+ stream->codecpar->block_align = 32 * channels / 8;
+ stream->codecpar->bit_rate = (int64_t)sample_rate * channels * 32;
+ break;
+
+ case ROT_FORMAT_DOUBLE:
+ stream->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
+ stream->codecpar->bits_per_coded_sample = 64;
+ stream->codecpar->block_align = 64 * channels / 8;
+ stream->codecpar->bit_rate = (int64_t)sample_rate * channels * 64;
+ break;
+
+ default:
+ return AVERROR_INVALIDDATA;
+ }
+ avpriv_set_pts_info(stream, 64, 1, sample_rate);
+
+ return 0;
+}
+
+const FFInputFormat ff_rot_demuxer = {
+ .p.name = "rot",
+ .p.long_name = NULL_IF_CONFIG_SMALL("rot pcm header"),
+ .priv_data_size = 0,
+ .p.extensions = "rot",
+ .read_probe = rot_probe,
+ .read_header = rot_read_header,
+ .read_packet = ff_pcm_read_packet};
+
+/* muxer */
+
+static int rot_write_header(AVFormatContext *context) {
+
+ const FFOutputFormat *ofmt = ffofmt(context->oformat);
+ av_log(context, AV_LOG_INFO, "flags_internal: 0x%x\n",
+ ofmt->flags_internal);
+
+ if (context->nb_streams <= 0)
+ return AVERROR(EINVAL);
+
+ AVStream *stream = context->streams[0];
+ if (stream == NULL)
+ return AVERROR(EINVAL);
+
+ uint8_t header_buffer[8];
+ uint16_t sample_rate = stream->codecpar->sample_rate;
+ uint8_t channels = stream->codecpar->ch_layout.nb_channels;
+
+ if (sample_rate <= 0 || channels <= 0)
+ return AVERROR(EINVAL);
+
+ uint8_t format;
+ switch (stream->codecpar->codec_id) {
+ case AV_CODEC_ID_PCM_S8:
+ format = ROT_FORMAT_S8;
+ break;
+
+ case AV_CODEC_ID_PCM_S16LE:
+ format = ROT_FORMAT_S16;
+ break;
+
+ case AV_CODEC_ID_PCM_S24LE:
+ format = ROT_FORMAT_S24;
+ break;
+
+ case AV_CODEC_ID_PCM_S32LE:
+ format = ROT_FORMAT_S32;
+ break;
+
+ case AV_CODEC_ID_PCM_F32LE:
+ format = ROT_FORMAT_FLOAT;
+ break;
+
+ case AV_CODEC_ID_PCM_F64LE:
+ format = ROT_FORMAT_DOUBLE;
+ break;
+ default:
+ return AVERROR(EINVAL);
+ }
+
+ memcpy(header_buffer, ROT_IDENTIFIER, 4);
+ memcpy(header_buffer + 4, &sample_rate, 2);
+ memcpy(header_buffer + 6, &channels, 1);
+ memcpy(header_buffer + 7, &format, 1);
+
+ avio_write(context->pb, header_buffer, sizeof(header_buffer));
+ return 0;
+}
+
+static int rot_write_packet(AVFormatContext *context, AVPacket *packet) {
+ avio_write(context->pb, packet->data, packet->size);
+ return 0;
+}
+
+static int rot_query_codec(enum AVCodecID codec_id, int std_compliance) {
+ switch (codec_id) {
+ case AV_CODEC_ID_PCM_S8:
+ case AV_CODEC_ID_PCM_S16LE:
+ case AV_CODEC_ID_PCM_S24LE:
+ case AV_CODEC_ID_PCM_S32LE:
+ case AV_CODEC_ID_PCM_F32LE:
+ case AV_CODEC_ID_PCM_F64LE:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+const FFOutputFormat ff_rot_muxer = {
+ .p.name = "rot",
+ .p.long_name = NULL_IF_CONFIG_SMALL("rot pcm header"),
+ .priv_data_size = 0,
+ .p.extensions = "rot",
+ .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
+ .query_codec = rot_query_codec,
+ .write_header = rot_write_header,
+ .write_packet = rot_write_packet,
+};
--
2.51.2
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next reply other threads:[~2026-01-23 12:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 12:35 9mmilly via ffmpeg-devel [this message]
2026-01-24 10:11 ` [FFmpeg-devel] " Rémi Denis-Courmont via ffmpeg-devel
2026-01-25 14:02 ` Michael Niedermayer via ffmpeg-devel
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=20260123123529.6896-1-9mmilly@0x3f4f3e.org \
--to=ffmpeg-devel@ffmpeg.org \
--cc=9mmilly@0x3f4f3e.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