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
32
37
47
51
53 {
55 twolame_close(&
s->glopts);
56 return 0;
57 }
58
60 {
63
66
67 s->glopts = twolame_init();
70
71 twolame_set_verbosity(
s->glopts,
s->verbosity);
72 twolame_set_mode(
s->glopts,
s->mode);
73 twolame_set_psymodel(
s->glopts,
s->psymodel);
74 twolame_set_energy_levels(
s->glopts,
s->energy);
75 twolame_set_error_protection(
s->glopts,
s->error_protection);
76 twolame_set_copyright(
s->glopts,
s->copyright);
77 twolame_set_original(
s->glopts,
s->original);
78
80 twolame_set_in_samplerate(
s->glopts, avctx->
sample_rate);
81 twolame_set_out_samplerate(
s->glopts, avctx->
sample_rate);
82
86 else
88 }
89
91 twolame_set_VBR(
s->glopts, TRUE);
92 twolame_set_VBR_level(
s->glopts,
95 "VBR in MP2 is a hack, use another codec that supports it.\n");
96 } else {
97 twolame_set_bitrate(
s->glopts, avctx->
bit_rate / 1000);
98 }
99
100 ret = twolame_init_params(
s->glopts);
104 }
105
106 return 0;
107 }
108
111 {
114
117
121 ret = twolame_encode_buffer_float32_interleaved(
s->glopts,
126 break;
128 ret = twolame_encode_buffer_float32(
s->glopts,
133 break;
135 ret = twolame_encode_buffer_interleaved(
s->glopts,
139 break;
141 ret = twolame_encode_buffer(
s->glopts,
146 break;
147 default:
149 "Unsupported sample format %d.\n", avctx->
sample_fmt);
151 }
152 } else {
153 ret = twolame_encode_flush(
s->glopts, avpkt->
data, avpkt->
size);
154 }
155
156 if (!
ret)
// no bytes written
157 return 0;
158 if (
ret < 0)
// twolame error
160
165 } else {
166 avpkt->
pts =
s->next_pts;
167 }
168 // this is for setting pts for flushed packet(s).
171
173 *got_packet_ptr = 1;
174 return 0;
175 }
176
177 #define OFFSET(x) offsetof(TWOLAMEContext, x)
178 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
180 {
"mode",
"Mpeg Mode",
OFFSET(
mode),
AV_OPT_TYPE_INT, { .i64 = TWOLAME_AUTO_MODE }, TWOLAME_AUTO_MODE, TWOLAME_MONO,
AE, .unit =
"mode"},
188 {
"error_protection",
"enable CRC error protection",
OFFSET(error_protection),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
AE},
191 {
"verbosity",
"set library optput level (0-10)",
OFFSET(verbosity),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 10,
AE},
193 };
194
200 };
201
203 { "b", "0" },
205 };
206
208 16000, 22050, 24000, 32000, 44100, 48000, 0
209 };
210
212 .
p.
name =
"libtwolame",
230 },
234 { 0 },
235 },
237 .p.wrapper_name = "libtwolame",
238 };