Mercurial > mplayer.hg
annotate libmpcodecs/ae_lavc.c @ 31714:140bde72c97f
Add some "const" to avoid incompatible pointer type warnings
author | reimar |
---|---|
date | Sat, 24 Jul 2010 11:33:28 +0000 |
parents | ef92321146a1 |
children | f957f330aa6d |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29673
diff
changeset
|
18 |
15234 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <inttypes.h> | |
15238 | 22 #include <unistd.h> |
15234 | 23 #include <string.h> |
15240 | 24 #include <sys/types.h> |
26203 | 25 #include "config.h" |
15234 | 26 #include "m_option.h" |
17012 | 27 #include "mp_msg.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
28 #include "libmpdemux/aviheader.h" |
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
29 #include "libmpdemux/ms_hdr.h" |
22600
3c2b4a866c6a
Add explicit location for headers from the stream/ directory.
diego
parents:
22316
diff
changeset
|
30 #include "stream/stream.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
31 #include "libmpdemux/muxer.h" |
15234 | 32 #include "ae_lavc.h" |
33 #include "help_mp.h" | |
31589
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
34 #include "av_opts.h" |
17012 | 35 #include "libaf/af_format.h" |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
36 #include "libaf/reorder_ch.h" |
15234 | 37 #include "libavcodec/avcodec.h" |
28132 | 38 #include "libavutil/intreadwrite.h" |
15234 | 39 |
40 static AVCodec *lavc_acodec; | |
41 static AVCodecContext *lavc_actx; | |
42 extern char *lavc_param_acodec; | |
43 extern int lavc_param_abitrate; | |
44 extern int lavc_param_atag; | |
17842 | 45 extern int lavc_param_audio_global_header; |
31589
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
46 extern char *lavc_param_audio_avopt; |
25962 | 47 extern int avcodec_initialized; |
15234 | 48 static int compressed_frame_size = 0; |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26203
diff
changeset
|
49 #ifdef CONFIG_LIBAVFORMAT |
21820
cd705f30bb31
Include libavformat/riff.h when building with static libavformat and
reimar
parents:
21773
diff
changeset
|
50 #include "libavformat/avformat.h" |
21966
d9494ca70ca7
Simplify by using av_codec_get_id and include riff.h only in demux_lavf.c
reimar
parents:
21963
diff
changeset
|
51 extern const struct AVCodecTag *mp_wav_taglists[]; |
17096 | 52 #endif |
15234 | 53 |
54 static int bind_lavc(audio_encoder_t *encoder, muxer_stream_t *mux_a) | |
55 { | |
56 mux_a->wf = malloc(sizeof(WAVEFORMATEX)+lavc_actx->extradata_size+256); | |
57 mux_a->wf->wFormatTag = lavc_param_atag; | |
58 mux_a->wf->nChannels = lavc_actx->channels; | |
59 mux_a->wf->nSamplesPerSec = lavc_actx->sample_rate; | |
60 mux_a->wf->nAvgBytesPerSec = (lavc_actx->bit_rate / 8); | |
19360
d4d72e5eea07
pass average bitrate from encoder to (lavf) muxer
michael
parents:
17855
diff
changeset
|
61 mux_a->avg_rate= lavc_actx->bit_rate; |
15234 | 62 mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec; |
63 if(lavc_actx->block_align) | |
64 mux_a->h.dwSampleSize = mux_a->h.dwScale = lavc_actx->block_align; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
65 else |
15234 | 66 { |
67 mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * lavc_actx->frame_size)/ mux_a->wf->nSamplesPerSec; /* for cbr */ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
68 |
15234 | 69 if ((mux_a->wf->nAvgBytesPerSec * |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
70 lavc_actx->frame_size) % mux_a->wf->nSamplesPerSec) |
15234 | 71 { |
72 mux_a->h.dwScale = lavc_actx->frame_size; | |
73 mux_a->h.dwRate = lavc_actx->sample_rate; | |
74 mux_a->h.dwSampleSize = 0; // Blocksize not constant | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
75 } |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
76 else |
21773
03bc990498fc
the avi spec does not allow random samplesize whoever wrote this should be shot
michael
parents:
21771
diff
changeset
|
77 mux_a->h.dwSampleSize = 0; |
15234 | 78 } |
21773
03bc990498fc
the avi spec does not allow random samplesize whoever wrote this should be shot
michael
parents:
21771
diff
changeset
|
79 if(mux_a->h.dwSampleSize) |
03bc990498fc
the avi spec does not allow random samplesize whoever wrote this should be shot
michael
parents:
21771
diff
changeset
|
80 mux_a->wf->nBlockAlign = mux_a->h.dwSampleSize; |
03bc990498fc
the avi spec does not allow random samplesize whoever wrote this should be shot
michael
parents:
21771
diff
changeset
|
81 else |
03bc990498fc
the avi spec does not allow random samplesize whoever wrote this should be shot
michael
parents:
21771
diff
changeset
|
82 mux_a->wf->nBlockAlign = 1; |
15234 | 83 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000; |
84 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign; | |
85 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
86 switch(lavc_param_atag) |
15234 | 87 { |
88 case 0x11: /* imaadpcm */ | |
89 mux_a->wf->wBitsPerSample = 4; | |
90 mux_a->wf->cbSize = 2; | |
28132 | 91 AV_WL16(mux_a->wf+1, lavc_actx->frame_size); |
15234 | 92 break; |
93 case 0x55: /* mp3 */ | |
94 mux_a->wf->cbSize = 12; | |
95 mux_a->wf->wBitsPerSample = 0; /* does not apply */ | |
96 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1; | |
97 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2; | |
98 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign; | |
99 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1; | |
100 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0; | |
101 break; | |
102 default: | |
103 mux_a->wf->wBitsPerSample = 0; /* Unknown */ | |
104 if (lavc_actx->extradata && (lavc_actx->extradata_size > 0)) | |
105 { | |
15501
7cdc07507650
wrong memcpy of extradata; 10l to whomever wrote that broken code
nicodvb
parents:
15244
diff
changeset
|
106 memcpy(mux_a->wf+1, lavc_actx->extradata, lavc_actx->extradata_size); |
15234 | 107 mux_a->wf->cbSize = lavc_actx->extradata_size; |
108 } | |
109 else | |
110 mux_a->wf->cbSize = 0; | |
111 break; | |
112 } | |
113 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
114 // Fix allocation |
15234 | 115 mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
116 |
15234 | 117 encoder->input_format = AF_FORMAT_S16_NE; |
118 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize; | |
119 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
120 |
15234 | 121 return 1; |
122 } | |
123 | |
124 static int encode_lavc(audio_encoder_t *encoder, uint8_t *dest, void *src, int size, int max_size) | |
125 { | |
126 int n; | |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
127 if ((encoder->params.channels == 6 || encoder->params.channels == 5) && |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
128 (!strcmp(lavc_acodec->name,"ac3") || |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
129 !strcmp(lavc_acodec->name,"libfaac"))) { |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
130 int isac3 = !strcmp(lavc_acodec->name,"ac3"); |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
131 reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, |
29491
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
132 isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
133 : AF_CHANNEL_LAYOUT_AAC_DEFAULT, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
134 encoder->params.channels, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
135 size / 2, 2); |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24359
diff
changeset
|
136 } |
15234 | 137 n = avcodec_encode_audio(lavc_actx, dest, size, src); |
17855
4b1930c9345c
do not randomly chop up packets, this isnt allowed in almost no container
michael
parents:
17842
diff
changeset
|
138 compressed_frame_size = n; |
15234 | 139 return n; |
140 } | |
141 | |
142 | |
143 static int close_lavc(audio_encoder_t *encoder) | |
144 { | |
145 compressed_frame_size = 0; | |
146 return 1; | |
147 } | |
148 | |
149 static int get_frame_size(audio_encoder_t *encoder) | |
150 { | |
17855
4b1930c9345c
do not randomly chop up packets, this isnt allowed in almost no container
michael
parents:
17842
diff
changeset
|
151 int sz = compressed_frame_size; |
4b1930c9345c
do not randomly chop up packets, this isnt allowed in almost no container
michael
parents:
17842
diff
changeset
|
152 compressed_frame_size = 0; |
4b1930c9345c
do not randomly chop up packets, this isnt allowed in almost no container
michael
parents:
17842
diff
changeset
|
153 return sz; |
15234 | 154 } |
155 | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26203
diff
changeset
|
156 #ifndef CONFIG_LIBAVFORMAT |
15244
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
157 static uint32_t lavc_find_atag(char *codec) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
158 { |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
159 if(codec == NULL) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
160 return 0; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
161 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
162 if(! strcasecmp(codec, "mp2")) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
163 return 0x50; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
164 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
165 if(! strcasecmp(codec, "mp3")) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
166 return 0x55; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
167 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
168 if(! strcasecmp(codec, "ac3")) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
169 return 0x2000; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
170 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
171 if(! strcasecmp(codec, "adpcm_ima_wav")) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
172 return 0x11; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
173 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
174 if(! strncasecmp(codec, "bonk", 4)) |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
175 return 0x2048; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
176 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
177 return 0; |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
178 } |
24359 | 179 #endif |
15244
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
180 |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
181 |
15234 | 182 int mpae_init_lavc(audio_encoder_t *encoder) |
183 { | |
184 encoder->params.samples_per_frame = encoder->params.sample_rate; | |
185 encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
186 |
15234 | 187 if(!lavc_param_acodec) |
188 { | |
189 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_NoLavcAudioCodecName); | |
190 return 0; | |
191 } | |
192 | |
25962 | 193 if(!avcodec_initialized){ |
15234 | 194 avcodec_init(); |
195 avcodec_register_all(); | |
25962 | 196 avcodec_initialized=1; |
15234 | 197 } |
198 | |
199 lavc_acodec = avcodec_find_encoder_by_name(lavc_param_acodec); | |
200 if (!lavc_acodec) | |
201 { | |
202 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LavcAudioCodecNotFound, lavc_param_acodec); | |
203 return 0; | |
204 } | |
205 if(lavc_param_atag == 0) | |
206 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26203
diff
changeset
|
207 #ifdef CONFIG_LIBAVFORMAT |
21966
d9494ca70ca7
Simplify by using av_codec_get_id and include riff.h only in demux_lavf.c
reimar
parents:
21963
diff
changeset
|
208 lavc_param_atag = av_codec_get_tag(mp_wav_taglists, lavc_acodec->id); |
15244
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
209 #else |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
210 lavc_param_atag = lavc_find_atag(lavc_param_acodec); |
a8a8a4d69a1c
restore old lavc_find_atag to be used when compiling mplayer without libavformat
nicodvb
parents:
15240
diff
changeset
|
211 #endif |
15234 | 212 if(!lavc_param_atag) |
213 { | |
214 mp_msg(MSGT_MENCODER, MSGL_FATAL, "Couldn't find wav tag for specified codec, exit\n"); | |
215 return 0; | |
216 } | |
217 } | |
218 | |
219 lavc_actx = avcodec_alloc_context(); | |
220 if(lavc_actx == NULL) | |
221 { | |
222 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_CouldntAllocateLavcContext); | |
223 return 0; | |
224 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
225 |
29673
a3cc38ad5878
Set codec_type and codec_id in codec context for lavc encoders.
reimar
parents:
29491
diff
changeset
|
226 lavc_actx->codec_type = CODEC_TYPE_AUDIO; |
a3cc38ad5878
Set codec_type and codec_id in codec context for lavc encoders.
reimar
parents:
29491
diff
changeset
|
227 lavc_actx->codec_id = lavc_acodec->id; |
15234 | 228 // put sample parameters |
229 lavc_actx->channels = encoder->params.channels; | |
230 lavc_actx->sample_rate = encoder->params.sample_rate; | |
28660
0812215421d7
Set time_base to 1/samplerate, like FFmpeg does, instead of leaving it at the
diego
parents:
28132
diff
changeset
|
231 lavc_actx->time_base.num = 1; |
0812215421d7
Set time_base to 1/samplerate, like FFmpeg does, instead of leaving it at the
diego
parents:
28132
diff
changeset
|
232 lavc_actx->time_base.den = encoder->params.sample_rate; |
23957
74eb6825d332
allow to specify the audio bitrate in bits (some codecs need that ...)
michael
parents:
23121
diff
changeset
|
233 if(lavc_param_abitrate<1000) |
74eb6825d332
allow to specify the audio bitrate in bits (some codecs need that ...)
michael
parents:
23121
diff
changeset
|
234 lavc_actx->bit_rate = encoder->params.bitrate = lavc_param_abitrate * 1000; |
74eb6825d332
allow to specify the audio bitrate in bits (some codecs need that ...)
michael
parents:
23121
diff
changeset
|
235 else |
74eb6825d332
allow to specify the audio bitrate in bits (some codecs need that ...)
michael
parents:
23121
diff
changeset
|
236 lavc_actx->bit_rate = encoder->params.bitrate = lavc_param_abitrate; |
31589
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
237 if(lavc_param_audio_avopt){ |
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
238 if(parse_avopts(lavc_actx, lavc_param_audio_avopt) < 0){ |
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
239 mp_msg(MSGT_MENCODER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavc_param_audio_avopt); |
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
240 return 0; |
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
241 } |
ef92321146a1
Make it possible to set all options for lavc audio encoder.
reimar
parents:
30633
diff
changeset
|
242 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28928
diff
changeset
|
243 |
15234 | 244 |
245 /* | |
246 * Special case for adpcm_ima_wav. | |
22316
f3d7a1b58a82
cosmetics: Fix some common typos, appropiate --> appropRiate,
diego
parents:
21966
diff
changeset
|
247 * The bitrate is only dependent on samplerate. |
15234 | 248 * We have to known frame_size and block_align in advance, |
249 * so I just copied the code from libavcodec/adpcm.c | |
250 * | |
251 * However, ms adpcm_ima_wav uses a block_align of 2048, | |
252 * lavc defaults to 1024 | |
253 */ | |
254 if(lavc_param_atag == 0x11) { | |
255 int blkalign = 2048; | |
256 int framesize = (blkalign - 4 * lavc_actx->channels) * 8 / (4 * lavc_actx->channels) + 1; | |
257 lavc_actx->bit_rate = lavc_actx->sample_rate*8*blkalign/framesize; | |
258 } | |
17842 | 259 if((lavc_param_audio_global_header&1) |
260 /*|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))*/){ | |
261 lavc_actx->flags |= CODEC_FLAG_GLOBAL_HEADER; | |
262 } | |
263 if(lavc_param_audio_global_header&2){ | |
264 lavc_actx->flags2 |= CODEC_FLAG2_LOCAL_HEADER; | |
265 } | |
15234 | 266 |
267 if(avcodec_open(lavc_actx, lavc_acodec) < 0) | |
268 { | |
269 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_CouldntOpenCodec, lavc_param_acodec, lavc_param_abitrate); | |
270 return 0; | |
271 } | |
272 | |
273 if(lavc_param_atag == 0x11) { | |
274 lavc_actx->block_align = 2048; | |
275 lavc_actx->frame_size = (lavc_actx->block_align - 4 * lavc_actx->channels) * 8 / (4 * lavc_actx->channels) + 1; | |
276 } | |
277 | |
278 encoder->decode_buffer_size = lavc_actx->frame_size * 2 * encoder->params.channels; | |
28928
f2b3f28982b8
Avoid ridiculously small decode_buffer_size (e.g. 4 with acodec=pcm_s16le)
reimar
parents:
28660
diff
changeset
|
279 while (encoder->decode_buffer_size < 1024) encoder->decode_buffer_size *= 2; |
15234 | 280 encoder->bind = bind_lavc; |
281 encoder->get_frame_size = get_frame_size; | |
282 encoder->encode = encode_lavc; | |
283 encoder->close = close_lavc; | |
284 | |
285 return 1; | |
286 } |