3 * Copyright (c) 2012 Paul B Mahol
5 * This file is part of FFmpeg.
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.
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.
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
24 #include "avio_internal.h"
32 static int write_header(AVFormatContext *s)
34 WVMuxContext *wc = s->priv_data;
35 AVCodecContext *codec = s->streams[0]->codec;
37 if (s->nb_streams > 1) {
38 av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
39 return AVERROR(EINVAL);
41 if (codec->codec_id != AV_CODEC_ID_WAVPACK) {
42 av_log(s, AV_LOG_ERROR, "unsupported codec\n");
43 return AVERROR(EINVAL);
45 if (codec->extradata_size > 0) {
46 av_log_missing_feature(s, "remuxing from matroska container", 0);
47 return AVERROR_PATCHWELCOME;
49 wc->off = codec->channels > 2 ? 4 : 0;
50 avpriv_set_pts_info(s->streams[0], 64, 1, codec->sample_rate);
55 static int write_packet(AVFormatContext *s, AVPacket *pkt)
57 WVMuxContext *wc = s->priv_data;
58 AVIOContext *pb = s->pb;
60 wc->duration += pkt->duration;
61 ffio_wfourcc(pb, "wvpk");
62 avio_wl32(pb, pkt->size + 12 + wc->off);
67 avio_wl32(pb, pkt->pts);
68 avio_write(s->pb, pkt->data, pkt->size);
74 static int write_trailer(AVFormatContext *s)
76 WVMuxContext *wc = s->priv_data;
77 AVIOContext *pb = s->pb;
82 avio_seek(pb, 12, SEEK_SET);
83 avio_wl32(pb, wc->duration);
90 AVOutputFormat ff_wv_muxer = {
92 .long_name = NULL_IF_CONFIG_SMALL("WavPack"),
93 .priv_data_size = sizeof(WVMuxContext),
95 .audio_codec = AV_CODEC_ID_WAVPACK,
96 .video_codec = AV_CODEC_ID_NONE,
97 .write_header = write_header,
98 .write_packet = write_packet,
99 .write_trailer = write_trailer,