FFmpeg
Loading...
Searching...
No Matches
astcenc.c
Go to the documentation of this file.
1/*
2 * ASTC muxer (.astc container)
3 * Copyright (c) 2026 Jun Zhao
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * ASTC (Adaptive Scalable Texture Compression) muxer.
25 *
26 * The .astc container is a 16-byte header followed by the raw ASTC
27 * bitstream. The header is taken verbatim from the encoder's extradata
28 * (which it publishes in .astc form).
29 */
30
31#include "avformat.h"
32#include "avio.h"
33#include "mux.h"
34
35#define ASTC_HEADER_SIZE 16
36
40
42{
43 AVStream *st = s->streams[0];
44
46 av_log(s, AV_LOG_ERROR, ".astc muxer requires 16-byte extradata "
47 "(block size / dimensions) from the encoder.\n");
48 return AVERROR(EINVAL);
49 }
50
52 return 0;
53}
54
56{
57 ASTCMuxerContext *ctx = s->priv_data;
58
59 /* The container holds a single image; FF_OFMT_FLAG_MAX_ONE_OF_EACH only
60 * limits the number of streams, so packets must be rejected here. */
61 if (ctx->wrote_image) {
63 ".astc muxer supports a single image per file.\n");
64 return AVERROR(EINVAL);
65 }
66 ctx->wrote_image = 1;
67
68 avio_write(s->pb, pkt->data, pkt->size);
69 return 0;
70}
71
73 .p.name = "astc",
74 .p.long_name = NULL_IF_CONFIG_SMALL("ASTC (Adaptive Scalable Texture Compression)"),
75 .p.mime_type = "image/astc",
76 .p.extensions = "astc",
77 .p.audio_codec = AV_CODEC_ID_NONE,
78 .p.video_codec = AV_CODEC_ID_ASTC,
79 .p.subtitle_codec = AV_CODEC_ID_NONE,
80 .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH |
82 .priv_data_size = sizeof(ASTCMuxerContext),
85 .p.flags = AVFMT_NOTIMESTAMPS,
86};
const FFOutputFormat ff_astc_muxer
Definition astcenc.c:72
static AVFormatContext * ctx
static int astc_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition astcenc.c:55
static int astc_write_header(AVFormatContext *s)
Definition astcenc.c:41
Main libavformat public API header.
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:500
Buffered I/O operations.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
#define s(width, name)
Definition cbs_vp9.c:198
static AVPacket * pkt
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition ffmpeg_mux.c:205
static void write_header(FFV1Context *f)
Definition ffv1enc.c:384
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_ASTC
Definition codec_id.h:327
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define ASTC_HEADER_SIZE
Definition libastcdec.c:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
Definition mux.h:50
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
Definition mux.h:59
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
Format I/O context.
Definition avformat.h:1335
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
#define av_log(a,...)