Commit d7ee4402 authored by Anton Khirnov's avatar Anton Khirnov

ffmpeg: don't abuse a global for passing samplerate from input to output

It's broken with multiple files or audio streams.

This removes the default samplerate of 44100 for raw input, hence all
the FATE changes.
parent 88ff180a
...@@ -163,7 +163,7 @@ static char *vfilters = NULL; ...@@ -163,7 +163,7 @@ static char *vfilters = NULL;
#endif #endif
static int intra_only = 0; static int intra_only = 0;
static int audio_sample_rate = 44100; static int audio_sample_rate = 0;
static int64_t channel_layout = 0; static int64_t channel_layout = 0;
#define QSCALE_NONE -99999 #define QSCALE_NONE -99999
static float audio_qscale = QSCALE_NONE; static float audio_qscale = QSCALE_NONE;
...@@ -2170,6 +2170,13 @@ static int transcode(AVFormatContext **output_files, ...@@ -2170,6 +2170,13 @@ static int transcode(AVFormatContext **output_files,
if(!ost->fifo) if(!ost->fifo)
goto fail; goto fail;
ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE);
if (!codec->sample_rate) {
codec->sample_rate = icodec->sample_rate;
if (icodec->lowres)
codec->sample_rate >>= icodec->lowres;
}
choose_sample_rate(ost->st, codec->codec);
codec->time_base = (AVRational){1, codec->sample_rate};
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
icodec->request_channels = codec->channels; icodec->request_channels = codec->channels;
ist->decoding_needed = 1; ist->decoding_needed = 1;
...@@ -3268,15 +3275,9 @@ static int opt_input_file(const char *opt, const char *filename) ...@@ -3268,15 +3275,9 @@ static int opt_input_file(const char *opt, const char *filename)
set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]); set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
channel_layout = dec->channel_layout; channel_layout = dec->channel_layout;
audio_channels = dec->channels; audio_channels = dec->channels;
audio_sample_rate = dec->sample_rate;
audio_sample_fmt = dec->sample_fmt; audio_sample_fmt = dec->sample_fmt;
if(audio_disable) if(audio_disable)
st->discard= AVDISCARD_ALL; st->discard= AVDISCARD_ALL;
/* Note that av_find_stream_info can add more streams, and we
* currently have no chance of setting up lowres decoding
* early enough for them. */
if (dec->lowres)
audio_sample_rate >>= dec->lowres;
break; break;
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(video_codec_name); input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(video_codec_name);
...@@ -3338,6 +3339,7 @@ static int opt_input_file(const char *opt, const char *filename) ...@@ -3338,6 +3339,7 @@ static int opt_input_file(const char *opt, const char *filename)
input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams;
video_channel = 0; video_channel = 0;
audio_sample_rate = 0;
av_freep(&video_codec_name); av_freep(&video_codec_name);
av_freep(&audio_codec_name); av_freep(&audio_codec_name);
...@@ -3585,7 +3587,6 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) ...@@ -3585,7 +3587,6 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx)
if (audio_stream_copy) { if (audio_stream_copy) {
st->stream_copy = 1; st->stream_copy = 1;
audio_enc->channels = audio_channels; audio_enc->channels = audio_channels;
audio_enc->sample_rate = audio_sample_rate;
} else { } else {
audio_enc->codec_id = codec_id; audio_enc->codec_id = codec_id;
set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec); set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
...@@ -3596,14 +3597,13 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) ...@@ -3596,14 +3597,13 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx)
} }
audio_enc->channels = audio_channels; audio_enc->channels = audio_channels;
audio_enc->sample_fmt = audio_sample_fmt; audio_enc->sample_fmt = audio_sample_fmt;
audio_enc->sample_rate = audio_sample_rate; if (audio_sample_rate)
audio_enc->sample_rate = audio_sample_rate;
audio_enc->channel_layout = channel_layout; audio_enc->channel_layout = channel_layout;
if (av_get_channel_layout_nb_channels(channel_layout) != audio_channels) if (av_get_channel_layout_nb_channels(channel_layout) != audio_channels)
audio_enc->channel_layout = 0; audio_enc->channel_layout = 0;
choose_sample_fmt(st, codec); choose_sample_fmt(st, codec);
choose_sample_rate(st, codec);
} }
audio_enc->time_base= (AVRational){1, audio_sample_rate};
if (audio_language) { if (audio_language) {
av_dict_set(&st->metadata, "language", audio_language, 0); av_dict_set(&st->metadata, "language", audio_language, 0);
av_freep(&audio_language); av_freep(&audio_language);
...@@ -3889,6 +3889,8 @@ static void opt_output_file(const char *filename) ...@@ -3889,6 +3889,8 @@ static void opt_output_file(const char *filename)
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL); set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
audio_sample_rate = 0;
av_freep(&forced_key_frames); av_freep(&forced_key_frames);
uninit_opts(); uninit_opts();
init_opts(); init_opts();
......
...@@ -165,7 +165,7 @@ fate-wmapro-2ch: CMP = oneoff ...@@ -165,7 +165,7 @@ fate-wmapro-2ch: CMP = oneoff
fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm
FATE_TESTS += fate-ansi FATE_TESTS += fate-ansi
fate-ansi: CMD = framecrc -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24 fate-ansi: CMD = framecrc -ar 44100 -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24
FATE_TESTS += fate-wmv8-drm FATE_TESTS += fate-wmv8-drm
# discard last packet to avoid fails due to overread of VC-1 decoder # discard last packet to avoid fails due to overread of VC-1 decoder
......
...@@ -14,7 +14,7 @@ eval do_$test=y ...@@ -14,7 +14,7 @@ eval do_$test=y
do_lavf() do_lavf()
{ {
file=${outfile}lavf.$1 file=${outfile}lavf.$1
do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2 do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2
do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file $3 do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file $3
} }
...@@ -39,8 +39,8 @@ do_image_formats() ...@@ -39,8 +39,8 @@ do_image_formats()
do_audio_only() do_audio_only()
{ {
file=${outfile}lavf.$1 file=${outfile}lavf.$1
do_ffmpeg $file $DEC_OPTS $2 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3 do_ffmpeg $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3
do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file do_ffmpeg_crc $file $DEC_OPTS $4 -i $target_path/$file
} }
rm -f "$logfile" rm -f "$logfile"
...@@ -55,7 +55,7 @@ fi ...@@ -55,7 +55,7 @@ fi
if [ -n "$do_rm" ] ; then if [ -n "$do_rm" ] ; then
file=${outfile}lavf.rm file=${outfile}lavf.rm
do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed
# broken # broken
#do_ffmpeg_crc $file -i $target_path/$file #do_ffmpeg_crc $file -i $target_path/$file
fi fi
...@@ -181,11 +181,11 @@ do_audio_only wav ...@@ -181,11 +181,11 @@ do_audio_only wav
fi fi
if [ -n "$do_alaw" ] ; then if [ -n "$do_alaw" ] ; then
do_audio_only al do_audio_only al "" "" "-ar 44100"
fi fi
if [ -n "$do_mulaw" ] ; then if [ -n "$do_mulaw" ] ; then
do_audio_only ul do_audio_only ul "" "" "-ar 44100"
fi fi
if [ -n "$do_au" ] ; then if [ -n "$do_au" ] ; then
......
...@@ -114,7 +114,7 @@ do_video_encoding() ...@@ -114,7 +114,7 @@ do_video_encoding()
do_audio_encoding() do_audio_encoding()
{ {
file=${outfile}$1 file=${outfile}$1
do_ffmpeg $file $DEC_OPTS -ac 2 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2 do_ffmpeg $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2
} }
do_audio_decoding() do_audio_decoding()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment