| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 37 | typedef struct ASTCMuxerContext { | ||
| 38 | int wrote_image; | ||
| 39 | } ASTCMuxerContext; | ||
| 40 | |||
| 41 | ✗ | static int astc_write_header(AVFormatContext *s) | |
| 42 | { | ||
| 43 | ✗ | AVStream *st = s->streams[0]; | |
| 44 | |||
| 45 | ✗ | if (st->codecpar->extradata_size < ASTC_HEADER_SIZE) { | |
| 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 | |||
| 51 | ✗ | avio_write(s->pb, st->codecpar->extradata, ASTC_HEADER_SIZE); | |
| 52 | ✗ | return 0; | |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | static int astc_write_packet(AVFormatContext *s, AVPacket *pkt) | |
| 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) { | |
| 62 | ✗ | av_log(s, AV_LOG_ERROR, | |
| 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 | |||
| 72 | const FFOutputFormat ff_astc_muxer = { | ||
| 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 | | ||
| 81 | FF_OFMT_FLAG_ONLY_DEFAULT_CODECS, | ||
| 82 | .priv_data_size = sizeof(ASTCMuxerContext), | ||
| 83 | .write_header = astc_write_header, | ||
| 84 | .write_packet = astc_write_packet, | ||
| 85 | .p.flags = AVFMT_NOTIMESTAMPS, | ||
| 86 | }; | ||
| 87 |