summaryrefslogtreecommitdiff
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-04-19 20:46:37 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-04-19 21:23:52 +0200
commit2a976debc1de10c22c258583b543ab5b4bbe5974 (patch)
treea2b0a12017a42e8a37365ca84a6bf2a0179311e8 /ffmpeg.c
parent2ff935f4bb6173daf3361b2ac7b58c6e33994878 (diff)
parent2b98377935384ecd22c2cd26106b9e03a6c9f598 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: dv: Initialize encoder tables during encoder init. dv: Replace some magic numbers by the appropriate #define. FATE: pass the decoded output format and audio source file to enc_dec_pcm FATE: specify the input format when decoding in enc_dec_pcm() x86inc: support AVX abstraction for 2-operand instructions configure: detect PGI compiler and set suitable flags avconv: check for an incompatible changing channel layout avio: make AVIOContext.av_class pointer to const nutdec: add malloc check and fix const to non-const conversion warnings Conflicts: ffmpeg.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c99
1 files changed, 54 insertions, 45 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 9661869af3..3e77610288 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1381,6 +1381,58 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
}
}
+static void get_default_channel_layouts(OutputStream *ost, InputStream *ist)
+{
+ char layout_name[256];
+ AVCodecContext *enc = ost->st->codec;
+ AVCodecContext *dec = ist->st->codec;
+
+ if (dec->channel_layout &&
+ av_get_channel_layout_nb_channels(dec->channel_layout) != dec->channels) {
+ av_get_channel_layout_string(layout_name, sizeof(layout_name),
+ dec->channels, dec->channel_layout);
+ av_log(NULL, AV_LOG_ERROR, "New channel layout (%s) is invalid\n",
+ layout_name);
+ dec->channel_layout = 0;
+ }
+ if (!dec->channel_layout) {
+ if (enc->channel_layout && dec->channels == enc->channels) {
+ dec->channel_layout = enc->channel_layout;
+ } else {
+ dec->channel_layout = av_get_default_channel_layout(dec->channels);
+
+ if (!dec->channel_layout) {
+ av_log(NULL, AV_LOG_FATAL, "Unable to find default channel "
+ "layout for Input Stream #%d.%d\n", ist->file_index,
+ ist->st->index);
+ exit_program(1);
+ }
+ }
+ av_get_channel_layout_string(layout_name, sizeof(layout_name),
+ dec->channels, dec->channel_layout);
+ av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream "
+ "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
+ }
+ if (!enc->channel_layout) {
+ if (dec->channels == enc->channels) {
+ enc->channel_layout = dec->channel_layout;
+ return;
+ } else {
+ enc->channel_layout = av_get_default_channel_layout(enc->channels);
+ }
+ if (!enc->channel_layout) {
+ av_log(NULL, AV_LOG_FATAL, "Unable to find default channel layout "
+ "for Output Stream #%d.%d\n", ost->file_index,
+ ost->st->index);
+ exit_program(1);
+ }
+ av_get_channel_layout_string(layout_name, sizeof(layout_name),
+ enc->channels, enc->channel_layout);
+ av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Output Stream "
+ "#%d.%d : %s\n", ost->file_index, ost->st->index, layout_name);
+ }
+}
+
static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size)
{
int fill_char = 0x00;
@@ -1515,6 +1567,8 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
for(i=0; i<planes; i++)
buf[i]= decoded_frame->data[i];
+ get_default_channel_layouts(ost, ist);
+
if (alloc_audio_output_buf(dec, enc, decoded_frame->nb_samples) < 0) {
av_log(NULL, AV_LOG_FATAL, "Error allocating audio buffer\n");
exit_program(1);
@@ -2742,51 +2796,6 @@ static void print_sdp(void)
av_freep(&avc);
}
-static void get_default_channel_layouts(OutputStream *ost, InputStream *ist)
-{
- char layout_name[256];
- AVCodecContext *enc = ost->st->codec;
- AVCodecContext *dec = ist->st->codec;
-
- if (!dec->channel_layout) {
- if (enc->channel_layout && dec->channels == enc->channels) {
- dec->channel_layout = enc->channel_layout;
- } else {
- dec->channel_layout = av_get_default_channel_layout(dec->channels);
-
- if (!dec->channel_layout) {
- av_log(NULL, AV_LOG_FATAL, "Unable to find default channel "
- "layout for Input Stream #%d.%d\n", ist->file_index,
- ist->st->index);
- exit_program(1);
- }
- }
- av_get_channel_layout_string(layout_name, sizeof(layout_name),
- dec->channels, dec->channel_layout);
- av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream "
- "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
- }
- if (!enc->channel_layout) {
- if (dec->channels == enc->channels) {
- enc->channel_layout = dec->channel_layout;
- return;
- } else {
- enc->channel_layout = av_get_default_channel_layout(enc->channels);
- }
- if (!enc->channel_layout) {
- av_log(NULL, AV_LOG_FATAL, "Unable to find default channel layout "
- "for Output Stream #%d.%d\n", ost->file_index,
- ost->st->index);
- exit_program(1);
- }
- av_get_channel_layout_string(layout_name, sizeof(layout_name),
- enc->channels, enc->channel_layout);
- av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Output Stream "
- "#%d.%d : %s\n", ost->file_index, ost->st->index, layout_name);
- }
-}
-
-
static int init_input_stream(int ist_index, char *error, int error_len)
{
int i;