FFmpeg
Loading...
Searching...
No Matches
wvenc.c
Go to the documentation of this file.
1/*
2 * WavPack muxer
3 * Copyright (c) 2013 Konstantin Shishkov <kostya.shishkov@gmail.com>
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
24
25#include "apetag.h"
26#include "avformat.h"
27#include "mux.h"
28#include "wv.h"
29
33
35{
36 WvMuxContext *s = ctx->priv_data;
38 int ret;
39
40 if (pkt->size < WV_HEADER_SIZE ||
41 (ret = ff_wv_parse_header(&header, pkt->data)) < 0) {
42 av_log(ctx, AV_LOG_ERROR, "Invalid WavPack packet.\n");
43 return AVERROR(EINVAL);
44 }
45 s->samples += header.samples;
46
47 avio_write(ctx->pb, pkt->data, pkt->size);
48
49 return 0;
50}
51
53{
54 WvMuxContext *s = ctx->priv_data;
55
56 /* update total number of samples in the first block */
57 if ((ctx->pb->seekable & AVIO_SEEKABLE_NORMAL) && s->samples &&
58 s->samples < UINT32_MAX) {
59 int64_t pos = avio_tell(ctx->pb);
60 avio_seek(ctx->pb, 12, SEEK_SET);
61 avio_wl32(ctx->pb, s->samples);
62 avio_seek(ctx->pb, pos, SEEK_SET);
63 }
64
66 return 0;
67}
68
70 .p.name = "wv",
71 .p.long_name = NULL_IF_CONFIG_SMALL("raw WavPack"),
72 .p.mime_type = "audio/x-wavpack",
73 .p.extensions = "wv",
74 .priv_data_size = sizeof(WvMuxContext),
75 .p.audio_codec = AV_CODEC_ID_WAVPACK,
76 .p.video_codec = AV_CODEC_ID_NONE,
77 .p.subtitle_codec = AV_CODEC_ID_NONE,
78 .write_packet = wv_write_packet,
79 .write_trailer = wv_write_trailer,
80 .p.flags = AVFMT_NOTIMESTAMPS,
81 .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH |
83};
const FFOutputFormat ff_wv_muxer
Definition wvenc.c:69
int ff_ape_write_tag(AVFormatContext *s)
Write an APE tag into a file.
Definition apetag.c:178
Main libavformat public API header.
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition avio.h:41
void avio_wl32(AVIOContext *s, unsigned int val)
Definition aviobuf.c:360
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_WAVPACK
Definition codec_id.h:478
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#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
static const uint8_t header[24]
Definition sdr2.c:68
unsigned int pos
Definition spdifenc.c:431
Format I/O context.
Definition avformat.h:1333
This structure stores compressed data.
Definition packet.h:580
Definition wv.h:34
int64_t samples
Definition wvenc.c:31
#define av_log(a,...)
static AVFormatContext * ctx
Definition movenc.c:49
#define WV_HEADER_SIZE
Definition wavpack.h:33
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
Definition wv.c:30
static int wv_write_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition wvenc.c:34
static av_cold int wv_write_trailer(AVFormatContext *ctx)
Definition wvenc.c:52