From d8b999e2d0736751bb25edc3aa0651cdbf3cbf41 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Mon, 15 Aug 2011 18:14:12 -0700 Subject: [PATCH 01/11] mpegts: log into an AVFormatContext rather than MpegTSContext. MpegTSContext's AVClass member can be NULL. --- libavformat/mpegts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index f22edec81a..fa5bd4c5a1 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -628,7 +628,7 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt) if(pes->total_size != MAX_PES_PAYLOAD && pes->pes_header_size + pes->data_index != pes->total_size + 6) { - av_log(pes->ts, AV_LOG_WARNING, "PES packet size mismatch\n"); + av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n"); pes->flags |= AV_PKT_FLAG_CORRUPT; } memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); @@ -1293,7 +1293,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) tss->last_cc = cc; if (!cc_ok) { - av_log(ts, AV_LOG_WARNING, "Continuity Check Failed\n"); + av_log(ts->stream, AV_LOG_WARNING, "Continuity Check Failed\n"); if(tss->type == MPEGTS_PES) { PESContext *pc = tss->u.pes_filter.opaque; pc->flags |= AV_PKT_FLAG_CORRUPT; From f1f298cd32b18bb910ff045df327ccb139628db7 Mon Sep 17 00:00:00 2001 From: Diogo Franco Date: Tue, 16 Aug 2011 09:43:23 +0000 Subject: [PATCH 02/11] Do not write ID3v1 tags by default ID3v1 are legacy tags with several limitations; furthermore avconv/ffmpeg writes the tags in UTF-8 which probably has near-0 software support. Add a -write_id3v1 option to be able to turn it on; disabled by default. Signed-off-by: Anton Khirnov --- libavformat/mp3enc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index e702e3b502..3704e49320 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -135,6 +135,7 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2 typedef struct MP3Context { const AVClass *class; int id3v2_version; + int write_id3v1; int64_t nb_frames_offset; } MP3Context; @@ -144,7 +145,7 @@ static int mp3_write_trailer(struct AVFormatContext *s) MP3Context *mp3 = s->priv_data; /* write the id3v1 tag */ - if (id3v1_create_tag(s, buf) > 0) { + if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) { avio_write(s->pb, buf, ID3v1_TAG_SIZE); } @@ -178,6 +179,8 @@ AVOutputFormat ff_mp2_muxer = { static const AVOption options[] = { { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.", offsetof(MP3Context, id3v2_version), FF_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM}, + { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.", + offsetof(MP3Context, write_id3v1), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, { NULL }, }; From 5759cce70db528c4feef48e480747e690a500b48 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 16 Aug 2011 11:32:57 +0200 Subject: [PATCH 03/11] avconv: don't segfault on 0 input files. --- avconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index 7be68043e5..24f6cd6221 100644 --- a/avconv.c +++ b/avconv.c @@ -3656,7 +3656,7 @@ static void opt_output_file(const char *filename) } /* copy global metadata by default */ - if (metadata_global_autocopy) + if (metadata_global_autocopy && nb_input_files) av_dict_copy(&oc->metadata, input_files[0].ctx->metadata, AV_DICT_DONT_OVERWRITE); if (metadata_streams_autocopy) From 7f5bf4fbaf1f2142547321a16358f9871fabdcc6 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 8 Jun 2011 14:32:07 +0000 Subject: [PATCH 04/11] flvenc: use int64_t to store offsets Metadata currently is written only at the start of the file in normal cases, when transcoding from a rtmp source metadata could be written later and the offset recorded can exceed 32bit. Signed-off-by: Anton Khirnov --- libavformat/flvenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 36f7e1f46c..f3017d7563 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -179,7 +179,7 @@ static int flv_write_header(AVFormatContext *s) AVCodecContext *audio_enc = NULL, *video_enc = NULL; int i; double framerate = 0.0; - int metadata_size_pos, data_size; + int64_t metadata_size_pos, data_size; AVDictionaryEntry *tag = NULL; for(i=0; inb_streams; i++){ From bca06e77e1b07f1dab04c3b9fef6fdcb62b4a401 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 11 Aug 2011 17:45:50 +0200 Subject: [PATCH 05/11] lavc: add avcodec_get_type() for mapping codec_id -> type. --- doc/APIchanges | 3 +++ libavcodec/avcodec.h | 8 ++++++++ libavcodec/utils.c | 14 ++++++++++++++ libavcodec/version.h | 4 ++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index ac95d168eb..64d15710c2 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-08-xx - xxxxxxx - lavc 53.8.0 + Add avcodec_get_type(). + 2011-08-06 - 2f63440 - lavf 53.4.0 Add error_recognition to AVFormatContext. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5bc1878fd0..0859e0efde 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -210,6 +210,7 @@ enum CodecID { CODEC_ID_DFA, /* various PCM "codecs" */ + CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs CODEC_ID_PCM_S16LE= 0x10000, CODEC_ID_PCM_S16BE, CODEC_ID_PCM_U16LE, @@ -340,6 +341,7 @@ enum CodecID { CODEC_ID_QDMC, /* subtitle codecs */ + CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. CODEC_ID_DVD_SUBTITLE= 0x17000, CODEC_ID_DVB_SUBTITLE, CODEC_ID_TEXT, ///< raw UTF-8 text @@ -351,6 +353,7 @@ enum CodecID { CODEC_ID_SRT, /* other specific kind of codecs (generally used for attachments) */ + CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs. CODEC_ID_TTF= 0x18000, CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it @@ -4273,4 +4276,9 @@ enum AVLockOp { */ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)); +/** + * Get the type of the given codec. + */ +enum AVMediaType avcodec_get_type(enum CodecID codec_id); + #endif /* AVCODEC_AVCODEC_H */ diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0abab9a83d..166fbec607 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1301,3 +1301,17 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count) return ff_thread_init(s); } #endif + +enum AVMediaType avcodec_get_type(enum CodecID codec_id) +{ + if (codec_id <= CODEC_ID_NONE) + return AVMEDIA_TYPE_UNKNOWN; + else if (codec_id < CODEC_ID_FIRST_AUDIO) + return AVMEDIA_TYPE_VIDEO; + else if (codec_id < CODEC_ID_FIRST_SUBTITLE) + return AVMEDIA_TYPE_AUDIO; + else if (codec_id < CODEC_ID_FIRST_UNKNOWN) + return AVMEDIA_TYPE_SUBTITLE; + + return AVMEDIA_TYPE_UNKNOWN; +} diff --git a/libavcodec/version.h b/libavcodec/version.h index 7eb5ce0424..24a33d7e69 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,8 +21,8 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 7 -#define LIBAVCODEC_VERSION_MICRO 1 +#define LIBAVCODEC_VERSION_MINOR 8 +#define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ From 48f9e457ea0143e14b04f7ae9cc5358904f9475a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 11 Aug 2011 20:34:45 +0200 Subject: [PATCH 06/11] lavf: add avformat_query_codec(). It allows to check if a given codec can be written into a container. --- doc/APIchanges | 3 +++ libavformat/avformat.h | 18 ++++++++++++++++++ libavformat/utils.c | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/doc/APIchanges b/doc/APIchanges index 64d15710c2..cfce48bfcd 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-08-xx - xxxxxxx - lavf 53.4.0 + Add avformat_query_codec(). + 2011-08-xx - xxxxxxx - lavc 53.8.0 Add avcodec_get_type(). diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 957039f64e..2a00a9fea4 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -322,6 +322,14 @@ typedef struct AVOutputFormat { const AVClass *priv_class; ///< AVClass for the private context + /** + * Test if the given codec can be stored in this container. + * + * @return 1 if the codec is supported, 0 if it is not. + * A negative number if unknown. + */ + int (*query_codec)(enum CodecID id, int std_compliance); + /* private fields */ struct AVOutputFormat *next; } AVOutputFormat; @@ -1595,4 +1603,14 @@ attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char */ int av_match_ext(const char *filename, const char *extensions); +/** + * Test if the given container can store a codec. + * + * @param std_compliance standards compliance level, one of FF_COMPLIANCE_* + * + * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot. + * A negative number if this information is not available. + */ +int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance); + #endif /* AVFORMAT_AVFORMAT_H */ diff --git a/libavformat/utils.c b/libavformat/utils.c index b848ebb827..6e3cb2fa54 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3904,3 +3904,17 @@ int64_t ff_iso8601_to_unix_time(const char *datestr) return 0; #endif } + +int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance) +{ + if (ofmt) { + if (ofmt->query_codec) + return ofmt->query_codec(codec_id, std_compliance); + else if (ofmt->codec_tag) + return !!av_codec_get_tag(ofmt->codec_tag, codec_id); + else if (codec_id == ofmt->video_codec || codec_id == ofmt->audio_codec || + codec_id == ofmt->subtitle_codec) + return 1; + } + return AVERROR_PATCHWELCOME; +} From 15c14ce6b2473528f7114028dc0732a4b467b624 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 11 Aug 2011 20:35:46 +0200 Subject: [PATCH 07/11] matroskaenc: implement query_codec() --- libavformat/matroskaenc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index b08f546eb4..6ba750f11a 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1191,6 +1191,22 @@ static int mkv_write_trailer(AVFormatContext *s) return 0; } +static int mkv_query_codec(enum CodecID codec_id, int std_compliance) +{ + int i; + for (i = 0; ff_mkv_codec_tags[i].id != CODEC_ID_NONE; i++) + if (ff_mkv_codec_tags[i].id == codec_id) + return 1; + + if (std_compliance < FF_COMPLIANCE_NORMAL) { // mkv theoretically supports any + enum AVMediaType type = avcodec_get_type(codec_id); // video/audio through VFW/ACM + if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) + return 1; + } + + return 0; +} + #if CONFIG_MATROSKA_MUXER AVOutputFormat ff_matroska_muxer = { .name = "matroska", @@ -1206,6 +1222,7 @@ AVOutputFormat ff_matroska_muxer = { .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, .subtitle_codec = CODEC_ID_SSA, + .query_codec = mkv_query_codec, }; #endif From a3f2f766afe6aa86f56c293875d627f30233cfad Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 16 Aug 2011 06:52:50 +0200 Subject: [PATCH 08/11] matroskaenc: vertical alignment. --- libavformat/matroskaenc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 6ba750f11a..aa767f3535 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1219,9 +1219,9 @@ AVOutputFormat ff_matroska_muxer = { .write_header = mkv_write_header, .write_packet = mkv_write_packet, .write_trailer = mkv_write_trailer, - .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, - .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, - .subtitle_codec = CODEC_ID_SSA, + .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, + .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, + .subtitle_codec = CODEC_ID_SSA, .query_codec = mkv_query_codec, }; #endif From 4f4f33844a7369e5579912cc02f3c5376b1e6872 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 13 Aug 2011 08:37:13 +0200 Subject: [PATCH 09/11] avconv: use stream copy by default when possible. --- avconv.c | 52 +++++++++++++++++++++++---------------- tests/codec-regression.sh | 4 +-- tests/fate.mak | 4 +-- tests/lavf-regression.sh | 20 +++++++-------- tests/regression-funcs.sh | 4 +-- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/avconv.c b/avconv.c index 24f6cd6221..c16bb0547f 100644 --- a/avconv.c +++ b/avconv.c @@ -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; diff --git a/tests/codec-regression.sh b/tests/codec-regression.sh index 708509c29d..881591e798 100755 --- a/tests/codec-regression.sh +++ b/tests/codec-regression.sh @@ -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 diff --git a/tests/fate.mak b/tests/fate.mak index 0e3331178b..8fec278b39 100644 --- a/tests/fate.mak +++ b/tests/fate.mak @@ -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 diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index bb7a497979..8d4a652a86 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -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 diff --git a/tests/regression-funcs.sh b/tests/regression-funcs.sh index bba189092b..60aa4d8d21 100755 --- a/tests/regression-funcs.sh +++ b/tests/regression-funcs.sh @@ -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 } From ad42126abcdee921fd7eaf0b8a83f18aa3dc1371 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 16 Aug 2011 06:58:52 +0200 Subject: [PATCH 10/11] avconv: print stream copy information. --- avconv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/avconv.c b/avconv.c index c16bb0547f..3227deb719 100644 --- a/avconv.c +++ b/avconv.c @@ -2189,6 +2189,8 @@ static int transcode(AVFormatContext **output_files, fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); + if (ost->st->stream_copy) + fprintf(stderr, " (copy)"); fprintf(stderr, "\n"); } } From 6cd9d0f77d527491d0c3626f16b8e125a8a9344b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 16 Aug 2011 20:59:14 +0200 Subject: [PATCH 11/11] Revert "avconv: use stream copy by default when possible." This reverts commit 4f4f33844a7369e5579912cc02f3c5376b1e6872. This commit has some ugly corner cases and needs to be discussed further. --- avconv.c | 52 ++++++++++++++++----------------------- tests/codec-regression.sh | 4 +-- tests/fate.mak | 4 +-- tests/lavf-regression.sh | 20 +++++++-------- tests/regression-funcs.sh | 4 +-- 5 files changed, 37 insertions(+), 47 deletions(-) diff --git a/avconv.c b/avconv.c index 3227deb719..66772aab9c 100644 --- a/avconv.c +++ b/avconv.c @@ -2831,7 +2831,10 @@ static AVCodec *choose_codec(AVFormatContext *s, AVStream *st, enum AVMediaType } if (!codec_name) { - return NULL; + 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); + } } else if (!strcmp(codec_name, "copy")) st->stream_copy = 1; else { @@ -3074,7 +3077,7 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, } } -static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType type, int source_idx) +static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType type) { OutputStream *ost; AVStream *st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); @@ -3101,18 +3104,6 @@ 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); } @@ -3124,13 +3115,13 @@ static OutputStream *new_output_stream(AVFormatContext *oc, enum AVMediaType typ return ost; } -static OutputStream *new_video_stream(AVFormatContext *oc, int source_idx) +static OutputStream *new_video_stream(AVFormatContext *oc) { AVStream *st; OutputStream *ost; AVCodecContext *video_enc; - ost = new_output_stream(oc, AVMEDIA_TYPE_VIDEO, source_idx); + ost = new_output_stream(oc, AVMEDIA_TYPE_VIDEO); st = ost->st; if (!st->stream_copy) { ost->frame_aspect_ratio = frame_aspect_ratio; @@ -3239,13 +3230,13 @@ static OutputStream *new_video_stream(AVFormatContext *oc, int source_idx) return ost; } -static OutputStream *new_audio_stream(AVFormatContext *oc, int source_idx) +static OutputStream *new_audio_stream(AVFormatContext *oc) { AVStream *st; OutputStream *ost; AVCodecContext *audio_enc; - ost = new_output_stream(oc, AVMEDIA_TYPE_AUDIO, source_idx); + ost = new_output_stream(oc, AVMEDIA_TYPE_AUDIO); st = ost->st; ost->bitstream_filters = audio_bitstream_filters; @@ -3285,13 +3276,13 @@ static OutputStream *new_audio_stream(AVFormatContext *oc, int source_idx) return ost; } -static OutputStream *new_data_stream(AVFormatContext *oc, int source_idx) +static OutputStream *new_data_stream(AVFormatContext *oc) { AVStream *st; OutputStream *ost; AVCodecContext *data_enc; - ost = new_output_stream(oc, AVMEDIA_TYPE_DATA, source_idx); + ost = new_output_stream(oc, AVMEDIA_TYPE_DATA); st = ost->st; data_enc = st->codec; if (!st->stream_copy) { @@ -3310,13 +3301,13 @@ static OutputStream *new_data_stream(AVFormatContext *oc, int source_idx) return ost; } -static OutputStream *new_subtitle_stream(AVFormatContext *oc, int source_idx) +static OutputStream *new_subtitle_stream(AVFormatContext *oc) { AVStream *st; OutputStream *ost; AVCodecContext *subtitle_enc; - ost = new_output_stream(oc, AVMEDIA_TYPE_SUBTITLE, source_idx); + ost = new_output_stream(oc, AVMEDIA_TYPE_SUBTITLE); st = ost->st; subtitle_enc = st->codec; @@ -3418,7 +3409,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, -1); + ost = new_output_stream(s, codec->type); st = ost->st; // FIXME: a more elegant solution is needed @@ -3485,7 +3476,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, index);\ + ost = new_ ## type ## _stream(oc);\ ost->source_index = index;\ ost->sync_ist = &input_streams[index];\ input_streams[index].discard = 0;\ @@ -3531,24 +3522,23 @@ 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[source_idx]; + ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index]; switch (ist->st->codec->codec_type) { - 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; + 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; 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 = source_idx; + ost->source_index = input_files[map->file_index].ist_index + map->stream_index; ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index + map->sync_stream_index]; ist->discard = 0; diff --git a/tests/codec-regression.sh b/tests/codec-regression.sh index 881591e798..708509c29d 100755 --- a/tests/codec-regression.sh +++ b/tests/codec-regression.sh @@ -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 -acodec pcm_s16le +do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav $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 -acodec pcm_s16le +do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav $tiny_psnr $pcm_dst $pcm_ref 2 8192 fi diff --git a/tests/fate.mak b/tests/fate.mak index 8fec278b39..0e3331178b 100644 --- a/tests/fate.mak +++ b/tests/fate.mak @@ -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 -vcodec rawvideo -acodec copy -pix_fmt rgb24 +fate-mtv: CMD = framecrc -i $(SAMPLES)/mtv/comedian_auto-partial.mtv -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 -acodec pcm_s16le +fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv FATE_TESTS += fate-oma-demux fate-oma-demux: CMD = crc -i $(SAMPLES)/oma/01-Untitled-partial.oma -acodec copy FATE_TESTS += fate-pcm_dvd diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index 8d4a652a86..bb7a497979 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -44,7 +44,7 @@ do_audio_only() } if [ -n "$do_avi" ] ; then -do_lavf avi "-acodec mp2" +do_lavf avi fi if [ -n "$do_asf" ] ; then @@ -63,11 +63,11 @@ do_lavf mpg fi if [ -n "$do_mxf" ] ; then -do_lavf mxf "-acodec pcm_s16le -ar 48000 -bf 2 -timecode_frame_start 264363" +do_lavf mxf "-ar 48000 -bf 2 -timecode_frame_start 264363" fi if [ -n "$do_mxf_d10" ]; then -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" +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" 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 "-acodec pcm_s16le -ar 48000 -r 25 -s pal -ac 2" +do_lavf dv "-ar 48000 -r 25 -s pal -ac 2" fi if [ -n "$do_gxf" ] ; then -do_lavf gxf "-acodec pcm_s16le -ar 48000 -r 25 -s pal -ac 1" +do_lavf gxf "-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 "-acodec mp2" +do_lavf mkv fi @@ -198,11 +198,11 @@ do_audio_only mmf fi if [ -n "$do_aiff" ] ; then -do_audio_only aif "" "-acodec pcm_s16be" +do_audio_only aif fi if [ -n "$do_voc" ] ; then -do_audio_only voc "" "-acodec pcm_u8" +do_audio_only voc 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 -vcodec rawvideo -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst + $ENC_OPTS -f 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 -vcodec rawvideo -s 352x288 -pix_fmt yuv444p + $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p done fi diff --git a/tests/regression-funcs.sh b/tests/regression-funcs.sh index 60aa4d8d21..bba189092b 100755 --- a/tests/regression-funcs.sh +++ b/tests/regression-funcs.sh @@ -95,7 +95,7 @@ do_avconv_crc() do_video_decoding() { - do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo -vcodec rawvideo $ENC_OPTS -vsync 0 $2 + do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f 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 -acodec pcm_s16le + do_avconv $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav }