1 /*
2 * Interface to libtwolame for mp2 encoding
3 * Copyright (c) 2012 Paul B Mahol
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 * Interface to libtwolame for mp2 encoding.
25 */
26
27 #include <twolame.h>
28
31
35
45
49
51 {
54 return 0;
55 }
56
58 {
61
64
65 s->
glopts = twolame_init();
68
76
80
83
86 twolame_set_VBR_level(s->
glopts,
89 "VBR in MP2 is a hack, use another codec that supports it.\n");
90 } else {
92 }
93
94 ret = twolame_init_params(s->
glopts);
95 if (ret) {
98 }
99
100 return 0;
101 }
102
105 {
108
111
112 if (frame) {
115 ret = twolame_encode_buffer_float32_interleaved(s->
glopts,
116 (
const float *)frame->
data[0],
120 break;
122 ret = twolame_encode_buffer_float32(s->
glopts,
123 (
const float *)frame->
data[0],
124 (
const float *)frame->
data[1],
127 break;
129 ret = twolame_encode_buffer_interleaved(s->
glopts,
130 (
const short int *)frame->
data[0],
133 break;
135 ret = twolame_encode_buffer(s->
glopts,
136 (
const short int *)frame->
data[0],
137 (
const short int *)frame->
data[1],
140 break;
141 default:
143 "Unsupported sample format %d.\n", avctx->
sample_fmt);
145 }
146 } else {
148 }
149
150 if (!ret) // no bytes written
151 return 0;
152 if (ret < 0) // twolame error
154
155 if (frame) {
159 } else {
161 }
162 // this is for setting pts for flushed packet(s).
165
167 *got_packet_ptr = 1;
168 return 0;
169 }
170
171 #define OFFSET(x) offsetof(TWOLAMEContext, x)
172 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
182 {
"error_protection",
"enable CRC error protection",
OFFSET(error_protection),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
AE},
185 {
"verbosity",
"set library optput level (0-10)",
OFFSET(verbosity),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 10,
AE},
187 };
188
194 };
195
197 { "b", "0" },
199 };
200
202 16000, 22050, 24000, 32000, 44100, 48000, 0
203 };
204
206 .
name =
"libtwolame",
216 .priv_class = &twolame_class,
223 },
224 .channel_layouts = (const uint64_t[]) {
227 0 },
229 };