avconv: use stream copy by default when possible.

This commit is contained in:
Anton Khirnov 2011-08-13 08:37:13 +02:00
parent a3f2f766af
commit 4f4f33844a
5 changed files with 47 additions and 37 deletions

View File

@ -2829,10 +2829,7 @@ static AVCodec *choose_codec(AVFormatContext *s, AVStream *st, enum AVMediaType
}
if (!codec_name) {
if (s->oformat) {
st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, type);
return avcodec_find_encoder(st->codec->codec_id);
}
return NULL;
} else if (!strcmp(codec_name, "copy"))
st->stream_copy = 1;
else {
@ -3075,7 +3072,7 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
}
}
static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType type)
static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType type, int source_idx)
{
OutputStream *ost;
AVStream *st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
@ -3102,6 +3099,18 @@ static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType typ
ost->st = st;
st->codec->codec_type = type;
ost->enc = choose_codec(oc, st, type, codec_names);
if (!ost->enc) {
/* no codec specified, try copy if possible or fallback to format default */
if (source_idx >= 0 && avformat_query_codec(oc->oformat, input_streams[source_idx].st->codec->codec_id,
FF_COMPLIANCE_NORMAL) == 1) {
st->codec->codec_id = input_streams[source_idx].st->codec->codec_id;
st->stream_copy = 1;
} else {
st->codec->codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, type);
ost->enc = avcodec_find_encoder(st->codec->codec_id);
}
}
if (ost->enc) {
ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
}
@ -3113,13 +3122,13 @@ static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType typ
return ost;
}
static OutputStream *new_video_stream(AVFormatContext *oc)
static OutputStream *new_video_stream(AVFormatContext *oc, int source_idx)
{
AVStream *st;
OutputStream *ost;
AVCodecContext *video_enc;
ost = new_output_stream(oc, AVMEDIA_TYPE_VIDEO);
ost = new_output_stream(oc, AVMEDIA_TYPE_VIDEO, source_idx);
st = ost->st;
if (!st->stream_copy) {
ost->frame_aspect_ratio = frame_aspect_ratio;
@ -3228,13 +3237,13 @@ static OutputStream *new_video_stream(AVFormatContext *oc)
return ost;
}
static OutputStream *new_audio_stream(AVFormatContext *oc)
static OutputStream *new_audio_stream(AVFormatContext *oc, int source_idx)
{
AVStream *st;
OutputStream *ost;
AVCodecContext *audio_enc;
ost = new_output_stream(oc, AVMEDIA_TYPE_AUDIO);
ost = new_output_stream(oc, AVMEDIA_TYPE_AUDIO, source_idx);
st = ost->st;
ost->bitstream_filters = audio_bitstream_filters;
@ -3274,13 +3283,13 @@ static OutputStream *new_audio_stream(AVFormatContext *oc)
return ost;
}
static OutputStream *new_data_stream(AVFormatContext *oc)
static OutputStream *new_data_stream(AVFormatContext *oc, int source_idx)
{
AVStream *st;
OutputStream *ost;
AVCodecContext *data_enc;
ost = new_output_stream(oc, AVMEDIA_TYPE_DATA);
ost = new_output_stream(oc, AVMEDIA_TYPE_DATA, source_idx);
st = ost->st;
data_enc = st->codec;
if (!st->stream_copy) {
@ -3299,13 +3308,13 @@ static OutputStream *new_data_stream(AVFormatContext *oc)
return ost;
}
static OutputStream *new_subtitle_stream(AVFormatContext *oc)
static OutputStream *new_subtitle_stream(AVFormatContext *oc, int source_idx)
{
AVStream *st;
OutputStream *ost;
AVCodecContext *subtitle_enc;
ost = new_output_stream(oc, AVMEDIA_TYPE_SUBTITLE);
ost = new_output_stream(oc, AVMEDIA_TYPE_SUBTITLE, source_idx);
st = ost->st;
subtitle_enc = st->codec;
@ -3407,7 +3416,7 @@ static int read_avserver_streams(AVFormatContext *s, const char *filename)
AVCodec *codec;
codec = avcodec_find_encoder(ic->streams[i]->codec->codec_id);
ost = new_output_stream(s, codec->type);
ost = new_output_stream(s, codec->type, -1);
st = ost->st;
// FIXME: a more elegant solution is needed
@ -3474,7 +3483,7 @@ static void opt_output_file(const char *filename)
/* pick the "best" stream of each type */
#define NEW_STREAM(type, index)\
if (index >= 0) {\
ost = new_ ## type ## _stream(oc);\
ost = new_ ## type ## _stream(oc, index);\
ost->source_index = index;\
ost->sync_ist = &input_streams[index];\
input_streams[index].discard = 0;\
@ -3520,23 +3529,24 @@ static void opt_output_file(const char *filename)
} else {
for (i = 0; i < nb_stream_maps; i++) {
StreamMap *map = &stream_maps[i];
int source_idx = input_files[map->file_index].ist_index + map->stream_index;
if (map->disabled)
continue;
ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
ist = &input_streams[source_idx];
switch (ist->st->codec->codec_type) {
case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(oc); break;
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(oc); break;
case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(oc); break;
case AVMEDIA_TYPE_DATA: ost = new_data_stream(oc); break;
case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(oc, source_idx); break;
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(oc, source_idx); break;
case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(oc, source_idx); break;
case AVMEDIA_TYPE_DATA: ost = new_data_stream(oc, source_idx); break;
default:
av_log(NULL, AV_LOG_ERROR, "Cannot map stream #%d.%d - unsupported type.\n",
map->file_index, map->stream_index);
exit_program(1);
}
ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
ost->source_index = source_idx;
ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
map->sync_stream_index];
ist->discard = 0;

View File

@ -320,12 +320,12 @@ fi
if [ -n "$do_wmav1" ] ; then
do_audio_encoding wmav1.asf "-acodec wmav1"
do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav -acodec pcm_s16le
$tiny_psnr $pcm_dst $pcm_ref 2 8192
fi
if [ -n "$do_wmav2" ] ; then
do_audio_encoding wmav2.asf "-acodec wmav2"
do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav -acodec pcm_s16le
$tiny_psnr $pcm_dst $pcm_ref 2 8192
fi

View File

@ -189,7 +189,7 @@ fate-msvideo1-8bit: CMD = framecrc -i $(SAMPLES)/cram/skating.avi -t 1 -pix_fmt
FATE_TESTS += fate-mszh
fate-mszh: CMD = framecrc -i $(SAMPLES)/lcl/mszh-1frame.avi
FATE_TESTS += fate-mtv
fate-mtv: CMD = framecrc -i $(SAMPLES)/mtv/comedian_auto-partial.mtv -acodec copy -pix_fmt rgb24
fate-mtv: CMD = framecrc -i $(SAMPLES)/mtv/comedian_auto-partial.mtv -vcodec rawvideo -acodec copy -pix_fmt rgb24
FATE_TESTS += fate-mxf-demux
fate-mxf-demux: CMD = framecrc -i $(SAMPLES)/mxf/C0023S01.mxf -acodec copy -vcodec copy
FATE_TESTS += fate-nc-demux
@ -197,7 +197,7 @@ fate-nc-demux: CMD = framecrc -i $(SAMPLES)/nc-camera/nc-sample-partial -vcodec
FATE_TESTS += fate-nsv-demux
fate-nsv-demux: CMD = framecrc -i $(SAMPLES)/nsv/witchblade-51kbps.nsv -t 6 -vcodec copy -acodec copy
FATE_TESTS += fate-nuv
fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv
fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv -acodec pcm_s16le
FATE_TESTS += fate-oma-demux
fate-oma-demux: CMD = crc -i $(SAMPLES)/oma/01-Untitled-partial.oma -acodec copy
FATE_TESTS += fate-pcm_dvd

View File

@ -44,7 +44,7 @@ do_audio_only()
}
if [ -n "$do_avi" ] ; then
do_lavf avi
do_lavf avi "-acodec mp2"
fi
if [ -n "$do_asf" ] ; then
@ -63,11 +63,11 @@ do_lavf mpg
fi
if [ -n "$do_mxf" ] ; then
do_lavf mxf "-ar 48000 -bf 2 -timecode_frame_start 264363"
do_lavf mxf "-acodec pcm_s16le -ar 48000 -bf 2 -timecode_frame_start 264363"
fi
if [ -n "$do_mxf_d10" ]; then
do_lavf mxf_d10 "-ar 48000 -ac 2 -r 25 -s 720x576 -vf pad=720:608:0:32 -vcodec mpeg2video -intra -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -top 1 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10"
do_lavf mxf_d10 "-acodec pcm_s16le -ar 48000 -ac 2 -r 25 -s 720x576 -vf pad=720:608:0:32 -vcodec mpeg2video -intra -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -top 1 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10"
fi
if [ -n "$do_ts" ] ; then
@ -91,11 +91,11 @@ do_lavf mov "-acodec pcm_alaw"
fi
if [ -n "$do_dv_fmt" ] ; then
do_lavf dv "-ar 48000 -r 25 -s pal -ac 2"
do_lavf dv "-acodec pcm_s16le -ar 48000 -r 25 -s pal -ac 2"
fi
if [ -n "$do_gxf" ] ; then
do_lavf gxf "-ar 48000 -r 25 -s pal -ac 1"
do_lavf gxf "-acodec pcm_s16le -ar 48000 -r 25 -s pal -ac 1"
fi
if [ -n "$do_nut" ] ; then
@ -103,7 +103,7 @@ do_lavf nut "-acodec mp2"
fi
if [ -n "$do_mkv" ] ; then
do_lavf mkv
do_lavf mkv "-acodec mp2"
fi
@ -198,11 +198,11 @@ do_audio_only mmf
fi
if [ -n "$do_aiff" ] ; then
do_audio_only aif
do_audio_only aif "" "-acodec pcm_s16be"
fi
if [ -n "$do_voc" ] ; then
do_audio_only voc
do_audio_only voc "" "-acodec pcm_u8"
fi
if [ -n "$do_voc_s16" ] ; then
@ -228,8 +228,8 @@ conversions="yuv420p yuv422p yuv444p yuyv422 yuv410p yuv411p yuvj420p \
for pix_fmt in $conversions ; do
file=${outfile}${pix_fmt}.yuv
run_avconv $DEC_OPTS -r 1 -t 1 -f image2 -vcodec pgmyuv -i $raw_src \
$ENC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst
$ENC_OPTS -f rawvideo -vcodec rawvideo -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst
do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \
$ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
$ENC_OPTS -f rawvideo -vcodec rawvideo -s 352x288 -pix_fmt yuv444p
done
fi

View File

@ -95,7 +95,7 @@ do_avconv_crc()
do_video_decoding()
{
do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2
do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo -vcodec rawvideo $ENC_OPTS -vsync 0 $2
}
do_video_encoding()
@ -112,5 +112,5 @@ do_audio_encoding()
do_audio_decoding()
{
do_avconv $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav
do_avconv $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav -acodec pcm_s16le
}