From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 3/6] Add CRYO APC muxer
Date: Tue, 26 Dec 2023 23:30:49 +0100
Message-ID: <20231226223049.GU6420@pb2> (raw)
In-Reply-To: <b8e9700eb46a47361586caea2c04b74da3461c37.camel@haerdin.se>
[-- Attachment #1.1: Type: text/plain, Size: 4074 bytes --]
Hi
On Tue, Dec 26, 2023 at 04:52:47PM +0100, Tomas Härdin wrote:
>
[...]
> +
> +static int apc_write_header(AVFormatContext *s)
> +{
> + AVIOContext *pb = s->pb;
> + AVCodecParameters *par;
> + AVStream *st;
> +
> + if (s->nb_streams != 1) {
> + av_log(s, AV_LOG_ERROR, "Must have exactly one stream\n");
> + return AVERROR(EINVAL);
> + }
> +
> + st = s->streams[0];
> + par = st->codecpar;
> +
> + if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels > 2) {
> + av_log(s, AV_LOG_ERROR, "Must be mono or stereo\n");
> + return AVERROR(EINVAL);
> + }
> +
> + if (par->extradata_size != 0 && par->extradata_size != 8) {
> + av_log(s, AV_LOG_ERROR,
> + "Must have exactly 0 or 8 bytes of extradata, got %i\n",
> + par->extradata_size);
> + return AVERROR(EINVAL);
> + }
> +
> + ffio_wfourcc(pb, "CRYO");
> + ffio_wfourcc(pb, "_APC");
> + ffio_wfourcc(pb, "1.20");
> + avio_wl32(pb, 0); // number or samples
please add to the comment "updated in apc_write_trailer()"
> + avio_wl32(pb, par->sample_rate);
> +
> + // write extradata if we have it (remuxing)
> + // else write dummy values and wait for AV_PKT_DATA_NEW_EXTRADATA (encoding)
> + if (par->extradata_size) {
> + avio_write(pb, par->extradata, par->extradata_size);
> + } else {
> + avio_wl64(pb, 0);
> + }
> +
> + avio_wl32(pb, par->ch_layout.nb_channels - 1);
> + avpriv_set_pts_info(st, 64, 1, par->sample_rate);
> + return 0;
> +}
> +
> +static int apc_write_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + size_t extradata_size = 0;
> + const uint8_t *extradata = av_packet_get_side_data(
> + pkt, AV_PKT_DATA_NEW_EXTRADATA, &extradata_size);
> +
> + if (extradata_size == 8) {
> + // we got predictors from encoder
> + // try to seek back end write them
> + int64_t pos = avio_tell(s->pb), err;
> + if ((err = avio_seek(s->pb, 20, SEEK_SET)) >= 0) {
> + avio_write(s->pb, extradata, extradata_size);
> + avio_seek(s->pb, pos, SEEK_SET);
> + } else {
> + av_log(s, AV_LOG_ERROR, "Got predictors from encoder but couldn't seek back to write them\n");
> + // fail since we should always be able to do this within the avio cache
> + // unless the encoder gave us predictors way too late for some reason
> + return err;
> + }
> + }
I think the encoder should buffer data or use 2 passes
if it needs future data. seeking back in the muxer is a bit odd.
if it becomes available always in teh first packet then maybe the
whole header could be written in the first packet
I would suggest, you add APC support to nut.
Thats a good test to ensure the packet and extradata is set at the right time
for a generic muxer
> +
> + avio_write(s->pb, pkt->data, pkt->size);
> + return 0;
> +}
> +
> +static int apc_write_trailer(AVFormatContext *s)
> +{
> + int64_t file_size = avio_tell(s->pb);
> +
> + // write length, if we're able to seek back
> + if (avio_seek(s->pb, 12, SEEK_SET) >= 0) {
> + if (file_size - APC_HEADER_SIZE >
> + UINT32_MAX * s->streams[0]->codecpar->ch_layout.nb_channels / 2) {
> + av_log(s, AV_LOG_ERROR, "File too large\n");
> + return AVERROR(EINVAL);
> + }
> +
> + avio_wl32(s->pb, (file_size - APC_HEADER_SIZE) *
> + 2 / s->streams[0]->codecpar->ch_layout.nb_channels);
I think something like this is slightly cleaner:
int64_t number_of_samples = (file_size - APC_HEADER_SIZE) *
2 / s->streams[0]->codecpar->ch_layout.nb_channels;
if (number_of_samples > UINT32_MAX)
...
[...]
thx
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Avoid a single point of failure, be that a person or equipment.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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:[~2023-12-26 22:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-26 15:51 [FFmpeg-devel] [PATCH 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
2023-12-26 15:52 ` [FFmpeg-devel] [PATCH 2/6] apc: Read duration from file Tomas Härdin
2023-12-26 15:52 ` [FFmpeg-devel] [PATCH 3/6] Add CRYO APC muxer Tomas Härdin
2023-12-26 22:30 ` Michael Niedermayer [this message]
2023-12-28 10:31 ` Tomas Härdin
2023-12-29 17:33 ` Michael Niedermayer
2023-12-30 17:01 ` Tomas Härdin
2023-12-31 21:36 ` Michael Niedermayer
2023-12-28 17:23 ` Tomas Härdin
2023-12-28 17:29 ` Tomas Härdin
2023-12-26 15:53 ` [FFmpeg-devel] [PATCH 4/6] Un-mark IMA APC as intra-only Tomas Härdin
2023-12-26 15:53 ` [FFmpeg-devel] [PATCH 5/6] Add ADPCM IMA CRYO APC encoder Tomas Härdin
2023-12-26 15:53 ` [FFmpeg-devel] [PATCH 6/6] Add myself as APC maintainer Tomas Härdin
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=20231226223049.GU6420@pb2 \
--to=michael@niedermayer.cc \
--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