FFmpeg
Loading...
Searching...
No Matches
opus.c
Go to the documentation of this file.
1/*
2 * Ogg Opus muxer mapping
3 * Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at free dot fr>
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
23#include "libavcodec/opus/tab.h"
25#include "libavutil/mem.h"
28
29#define OPUS_HEADER_SIZE 19
30
32 OGGStreamContext *oggstream, int bitexact,
33 AVDictionary **m, AVChapter **chapters,
34 unsigned int nb_chapters)
35{
36 uint8_t *p;
37
40
41 /* first packet: Opus header */
42 p = av_mallocz(par->extradata_size);
43 if (!p)
44 return AVERROR(ENOMEM);
45 oggstream->header[0] = p;
46 oggstream->header_len[0] = par->extradata_size;
48
49 /* second packet: VorbisComment */
50 p = ff_ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0, chapters, nb_chapters);
51 if (!p)
52 return AVERROR(ENOMEM);
53 oggstream->header[1] = p;
54 bytestream_put_buffer(&p, "OpusTags", 8);
55
56 return 0;
57}
58
60{
61 OGGStreamContext *oggstream = st->priv_data;
62 int err;
63
65 err = opus_build_headers(st->codecpar, oggstream,
66 s->flags & AVFMT_FLAG_BITEXACT,
67 &st->metadata, s->chapters, s->nb_chapters);
68 if (err) {
69 av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
70 return err;
71 }
72
73 /* The pre-skip of the link's OpusHead, in the 48 kHz time base. */
74 oggstream->packet_granule_offset = AV_RL16(oggstream->header[0] + 10);
75 return 0;
76}
77
79 .codec_id = AV_CODEC_ID_OPUS,
80 .new_links = 1,
81 .init = opus_init,
82};
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:865
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition avformat.h:1570
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition bytestream.h:372
#define s(width, name)
Definition cbs_vp9.c:198
@ AV_CODEC_ID_OPUS
Definition codec_id.h:519
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define AV_RL16(p)
Memory handling functions.
#define OPUS_HEADER_SIZE
Definition opus.c:29
static int opus_build_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m, AVChapter **chapters, unsigned int nb_chapters)
Definition opus.c:31
static int opus_init(AVFormatContext *s, AVStream *st)
Definition opus.c:59
uint8_t * ff_ogg_write_vorbiscomment(int64_t offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit, AVChapter **chapters, unsigned int nb_chapters)
Allocate a comment header packet holding a VorbisComment.
Definition muxer.c:257
const OGGMuxerMapping ff_ogg_opus_muxer_mapping
Definition opus.c:78
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
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:1401
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
AVDictionary * metadata
Definition avformat.h:848
void * priv_data
Definition avformat.h:793
Codec mapping of the muxer: the parts of the Ogg encapsulation that depend on the codec.
Definition muxer.h:71
uint8_t * header[3]
Definition muxer.h:47
int packet_granule_offset
added to the end timestamp of a packet without packet_granule
Definition muxer.h:58
int header_len[3]
Definition muxer.h:48
#define OPUS_TIMESTAMP_RATE
The clock of Opus: packet lengths, pre-skip and trimming count samples at 48 kHz whatever the sample ...
Definition tab.h:35
#define av_mallocz(s)
#define av_log(a,...)