[FFmpeg-devel] [PATCH] avformat/aea: Add aea muxer

asivery asivery at protonmail.com
Sat Mar 9 19:20:49 EET 2024


Thank you both for the suggestions. I've updated the code as requested, and I apologize for the AV_LOG_WARNING instead of AV_LOG_ERROR - it was an oversight on my part.
I have also added the stream codec check, and it did get triggered when I tried to feed it audio that was not ATRAC1, so it seems it is required.
Regarding titles being truncated - that was my intention. However I've now added a warning if it was going to happen.
As for the block count in the header - none of the modern software which uses AEA reads that field, but for the older software, it will now be truncated to UINT32_MAX if needed.
Is there anything else that needs changes?

- asivery

On Saturday, March 9th, 2024 at 1:06 PM, Andreas Rheinhardt <andreas.rheinhardt at outlook.com> wrote:

> asivery via ffmpeg-devel:
> 
> > +#include "libavutil/intreadwrite.h"
> > +#include "libavutil/avstring.h"
> 
> 
> These two headers seem unused.
> 
> > +#include "avformat.h"
> > +#include "avio_internal.h"
> > +#include "rawenc.h"
> > +#include "mux.h"
> > +
> > +static int aea_write_header(AVFormatContext *s)
> > +{
> > + const AVDictionaryEntry title_entry;
> > + int title_length = 0;
> > + char title_contents;
> 
> 
> const please. Also we put the * to the variable (because "char* foo,
> bar" still only declares one pointer to char). Furthermore, the scope
> for this should be the block below.
> 
> > + AVStream st;
> > +
> > + if (s->nb_streams > 1) {
> > + av_log(s, AV_LOG_WARNING, "Got more than one stream to encode. This is not supported.\n");
> > + return AVERROR(EINVAL);
> > + }
> > +
> > + st = s->streams[0];
> > + if (st->codecpar->ch_layout.nb_channels != 1 && st->codecpar->ch_layout.nb_channels != 2) {
> > + av_log(s, AV_LOG_ERROR, "Invalid amount of channels to mux (%d).\n", st->codecpar->ch_layout.nb_channels);
> > + return AVERROR(EINVAL);
> > + }
> > +
> > + if (st->codecpar->sample_rate != 44100) {
> > + av_log(s, AV_LOG_ERROR, "Invalid sample rate (%d) AEA only supports 44.1kHz.\n", st->codecpar->sample_rate);
> > + return AVERROR(EINVAL);
> > + }
> > +
> > + / Write magic /
> > + avio_wl32(s->pb, 2048);
> > +
> > + / Write AEA title */
> > + title_entry = av_dict_get(st->metadata, "title", NULL, 0);
> > + if (title_entry) {
> > + title_contents = title_entry->value;
> > + title_length = strlen(title_contents);
> 
> 
> Possible truncation here.
> 
> > + title_length = FFMIN(256, title_length);
> > + avio_write(s->pb, title_contents, title_length);
> > + }
> > +
> > + ffio_fill(s->pb, 0, 256 - title_length);
> > +
> > + /* Write number of frames (zero at header-writing time, will seek later), number of channels /
> > + avio_wl32(s->pb, 0);
> > + avio_w8(s->pb, st->codecpar->ch_layout.nb_channels);
> > + avio_w8(s->pb, 0);
> > +
> > + / Pad the header to 2048 bytes */
> > + ffio_fill(s->pb, 0, 1782);
> > +
> > + return 0;
> > +}
> > +
> > +static int aea_write_trailer(struct AVFormatContext *s)
> > +{
> > + AVIOContext *pb = s->pb;
> > + AVStream st = s->streams[0];
> > + if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
> > + / Seek to rewrite the block count. */
> > + avio_seek(pb, 260, SEEK_SET);
> > + avio_wl32(pb, st->nb_frames * st->codecpar->ch_layout.nb_channels);
> 
> 
> I don't see anything guaranteeing that the result fits into 32 bits.
> 
> > + } else {
> > + av_log(s, AV_LOG_WARNING, "unable to rewrite AEA header.\n");
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +const FFOutputFormat ff_aea_muxer = {
> > + .p.name = "aea",
> > + .p.long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
> > + .p.extensions = "aea",
> > + .p.audio_codec = AV_CODEC_ID_ATRAC1,
> > +
> > + .write_header = aea_write_header,
> > + .write_packet = ff_raw_write_packet,
> > + .write_trailer = aea_write_trailer,
> > +};
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avformat-aea-Add-aea-muxer.patch
Type: text/x-patch
Size: 6904 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240309/91ebd97b/attachment.bin>


More information about the ffmpeg-devel mailing list