From 5463e83dbc9825f3962118f0d3328be82aea3308 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 1 Nov 2011 16:57:41 -0400 Subject: [PATCH 1/8] fmtconvert: fix int32_to_float_fmul_scalar() for windows x86_64 The calling convention only allows 4 non-stack parameter, with each float or int register being skipped if not used. fixes Bug 64 --- libavcodec/x86/fmtconvert.asm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/x86/fmtconvert.asm b/libavcodec/x86/fmtconvert.asm index 854954835c..d6210897f6 100644 --- a/libavcodec/x86/fmtconvert.asm +++ b/libavcodec/x86/fmtconvert.asm @@ -28,10 +28,14 @@ SECTION_TEXT ; void int32_to_float_fmul_scalar(float *dst, const int *src, float mul, int len); ;--------------------------------------------------------------------------------- %macro INT32_TO_FLOAT_FMUL_SCALAR 2 -%ifdef ARCH_X86_64 +%ifdef UNIX64 cglobal int32_to_float_fmul_scalar_%1, 3,3,%2, dst, src, len %else cglobal int32_to_float_fmul_scalar_%1, 4,4,%2, dst, src, mul, len +%endif +%ifdef WIN64 + SWAP 0, 2 +%elifdef ARCH_X86_32 movss m0, mulm %endif SPLATD m0 From e6674f685b1dae4088a4ca8c2249956c96898661 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 29 Oct 2011 07:58:23 +0200 Subject: [PATCH 2/8] avconv: make negative mappings disable only streams from the specified file --- avconv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index e3b4e80c3f..e59786f199 100644 --- a/avconv.c +++ b/avconv.c @@ -2638,7 +2638,8 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) /* disable some already defined maps */ for (i = 0; i < o->nb_stream_maps; i++) { m = &o->stream_maps[i]; - if (check_stream_specifier(input_files[m->file_index].ctx, + if (file_idx == m->file_index && + check_stream_specifier(input_files[m->file_index].ctx, input_files[m->file_index].ctx->streams[m->stream_index], *p == ':' ? p + 1 : p) > 0) m->disabled = 1; From 4dbc6ceef5eafbafbe64a12083d70599895299c2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 30 Oct 2011 07:10:08 +0100 Subject: [PATCH 3/8] avconv: add -attach option. It allows attaching arbitrary files, e.g. fonts to Matroska files. --- avconv.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++- doc/avconv.texi | 15 ++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index e59786f199..62ab5189f8 100644 --- a/avconv.c +++ b/avconv.c @@ -228,6 +228,7 @@ typedef struct OutputStream { AVDictionary *opts; int is_past_recording_time; int stream_copy; + const char *attachment_filename; } OutputStream; @@ -284,6 +285,8 @@ typedef struct OptionsContext { int metadata_global_manual; int metadata_streams_manual; int metadata_chapters_manual; + const char **attachments; + int nb_attachments; int chapters_input_file; @@ -1981,6 +1984,9 @@ static int transcode_init(OutputFile *output_files, os = output_files[ost->file_index].ctx; ist = &input_streams[ost->source_index]; + if (ost->attachment_filename) + continue; + codec = ost->st->codec; icodec = ist->st->codec; @@ -2286,6 +2292,13 @@ static int transcode_init(OutputFile *output_files, av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); for (i = 0; i < nb_output_streams; i++) { ost = &output_streams[i]; + + if (ost->attachment_filename) { + /* an attached file */ + av_log(NULL, AV_LOG_INFO, " File %s -> Stream #%d:%d\n", + ost->attachment_filename, ost->file_index, ost->index); + continue; + } av_log(NULL, AV_LOG_INFO, " Stream #%d.%d -> #%d.%d", input_streams[ost->source_index].file_index, input_streams[ost->source_index].st->index, @@ -2674,6 +2687,14 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) return 0; } +static int opt_attach(OptionsContext *o, const char *opt, const char *arg) +{ + o->attachments = grow_array(o->attachments, sizeof(*o->attachments), + &o->nb_attachments, o->nb_attachments + 1); + o->attachments[o->nb_attachments - 1] = arg; + return 0; +} + static void parse_meta_type(char *arg, char *type, int *index) { if (*arg) { @@ -3527,6 +3548,42 @@ static void opt_output_file(void *optctx, const char *filename) } } + /* handle attached files */ + for (i = 0; i < o->nb_attachments; i++) { + AVIOContext *pb; + uint8_t *attachment; + const char *p; + int64_t len; + + if ((err = avio_open(&pb, o->attachments[i], AVIO_FLAG_READ)) < 0) { + av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n", + o->attachments[i]); + exit_program(1); + } + if ((len = avio_size(pb)) <= 0) { + av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n", + o->attachments[i]); + exit_program(1); + } + if (!(attachment = av_malloc(len))) { + av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\n", + o->attachments[i]); + exit_program(1); + } + avio_read(pb, attachment, len); + + ost = new_attachment_stream(o, oc); + ost->stream_copy = 0; + ost->source_index = -1; + ost->attachment_filename = o->attachments[i]; + ost->st->codec->extradata = attachment; + ost->st->codec->extradata_size = len; + + p = strrchr(o->attachments[i], '/'); + av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE); + avio_close(pb); + } + output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1); output_files[nb_output_files - 1].ctx = oc; output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams; @@ -3652,7 +3709,10 @@ static void opt_output_file(void *optctx, const char *filename) AV_DICT_DONT_OVERWRITE); if (!o->metadata_streams_manual) for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) { - InputStream *ist = &input_streams[output_streams[i].source_index]; + InputStream *ist; + if (output_streams[i].source_index < 0) /* this is true e.g. for attached files */ + continue; + ist = &input_streams[output_streams[i].source_index]; av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); } @@ -4025,6 +4085,7 @@ static const OptionDef options[] = { { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(filters)}, "set stream filterchain", "filter_list" }, #endif { "stats", OPT_BOOL, {&print_stats}, "print progress report during encoding", }, + { "attach", HAS_ARG | OPT_FUNC2, {(void*)opt_attach}, "add an attachment to the output file", "filename" }, /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, diff --git a/doc/avconv.texi b/doc/avconv.texi index c298dc5710..e14ab857f4 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -192,6 +192,21 @@ Specify the preset for matching stream(s). @item -stats (@emph{global}) Print encoding progress/statistics. On by default. +@item -attach @var{filename} (@emph{output}) +Add an attachment to the output file. This is supported by a few formats +like Matroska for e.g. fonts used in rendering subtitles. Attachments +are implemented as a specific type of stream, so this option will add +a new stream to the file. It is then possible to use per-stream options +on this stream in the usual way. Attachment streams created with this +option will be created after all the other streams (i.e. those created +with @code{-map} or automatic mappings). + +Note that for Matroska you also have to set the mimetype metadata tag: +@example +avconv -i INPUT -attach DejaVuSans.ttf -metadata:s:2 mimetype=application/x-truetype-font out.mkv +@end example +(assuming that the attachment stream will be third in the output file). + @end table @section Video Options From a2c0b830d5690c4a4250702ff2f1b044ebf9594e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 2 Nov 2011 21:50:54 +0100 Subject: [PATCH 4/8] avconv: add -dump_attachment option. --- avconv.c | 88 ++++++++++++++++++++++++++++++++++++++----------- doc/avconv.texi | 18 ++++++++++ 2 files changed, 87 insertions(+), 19 deletions(-) diff --git a/avconv.c b/avconv.c index 62ab5189f8..8f86c007bf 100644 --- a/avconv.c +++ b/avconv.c @@ -275,6 +275,8 @@ typedef struct OptionsContext { SpecifierOpt *ts_scale; int nb_ts_scale; + SpecifierOpt *dump_attachment; + int nb_dump_attachment; /* output options */ StreamMap *stream_maps; @@ -2843,6 +2845,60 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) } } +static void assert_file_overwrite(const char *filename) +{ + if (!file_overwrite && + (strchr(filename, ':') == NULL || filename[1] == ':' || + av_strstart(filename, "file:", NULL))) { + if (avio_check(filename, 0) == 0) { + if (!using_stdin) { + fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); + fflush(stderr); + if (!read_yesno()) { + fprintf(stderr, "Not overwriting - exiting\n"); + exit_program(1); + } + } + else { + fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); + exit_program(1); + } + } + } +} + +static void dump_attachment(AVStream *st, const char *filename) +{ + int ret; + AVIOContext *out = NULL; + AVDictionaryEntry *e; + + if (!st->codec->extradata_size) { + av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n", + nb_input_files - 1, st->index); + return; + } + if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) + filename = e->value; + if (!*filename) { + av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag" + "in stream #%d:%d.\n", nb_input_files - 1, st->index); + exit_program(1); + } + + assert_file_overwrite(filename); + + if ((ret = avio_open (&out, filename, AVIO_FLAG_WRITE)) < 0) { + av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n", + filename); + exit_program(1); + } + + avio_write(out, st->codec->extradata, st->codec->extradata_size); + avio_flush(out); + avio_close(out); +} + static int opt_input_file(OptionsContext *o, const char *opt, const char *filename) { AVFormatContext *ic; @@ -2943,6 +2999,17 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena input_files[nb_input_files - 1].nb_streams = ic->nb_streams; input_files[nb_input_files - 1].rate_emu = o->rate_emu; + for (i = 0; i < o->nb_dump_attachment; i++) { + int j; + + for (j = 0; j < ic->nb_streams; j++) { + AVStream *st = ic->streams[j]; + + if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1) + dump_attachment(st, o->dump_attachment[i].u.str); + } + } + for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); av_freep(&opts); @@ -3602,25 +3669,7 @@ static void opt_output_file(void *optctx, const char *filename) if (!(oc->oformat->flags & AVFMT_NOFILE)) { /* test if it already exists to avoid loosing precious files */ - if (!file_overwrite && - (strchr(filename, ':') == NULL || - filename[1] == ':' || - av_strstart(filename, "file:", NULL))) { - if (avio_check(filename, 0) == 0) { - if (!using_stdin) { - fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); - fflush(stderr); - if (!read_yesno()) { - fprintf(stderr, "Not overwriting - exiting\n"); - exit_program(1); - } - } - else { - fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); - exit_program(1); - } - } - } + assert_file_overwrite(filename); /* open the file */ if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) { @@ -4086,6 +4135,7 @@ static const OptionDef options[] = { #endif { "stats", OPT_BOOL, {&print_stats}, "print progress report during encoding", }, { "attach", HAS_ARG | OPT_FUNC2, {(void*)opt_attach}, "add an attachment to the output file", "filename" }, + { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(dump_attachment)}, "extract an attachment into a file", "filename" }, /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, diff --git a/doc/avconv.texi b/doc/avconv.texi index e14ab857f4..1075cc7c56 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -207,6 +207,24 @@ avconv -i INPUT -attach DejaVuSans.ttf -metadata:s:2 mimetype=application/x-true @end example (assuming that the attachment stream will be third in the output file). +@item -dump_attachment[:@var{stream_specifier}] @var{filename} (@emph{input,per-stream}) +Extract the matching attachment stream into a file named @var{filename}. If +@var{filename} is empty, then the value of the @code{filename} metadata tag +will be used. + +E.g. to extract the first attachment to a file named 'out.ttf': +@example +avconv -dump_attachment:t:0 out.ttf INPUT +@end example +To extract all attachments to files determined by the @code{filename} tag: +@example +avconv -dump_attachment:t "" INPUT +@end example + +Technical note -- attachments are implemented as codec extradata, so this +option can actually be used to extract extradata from any stream, not just +attachments. + @end table @section Video Options From 1b6da627d49e98fe7661c9aa9ec4e16ab04dfda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 2 Nov 2011 17:54:00 +0200 Subject: [PATCH 5/8] avcodec: Remove a misplaced and useless attribute_deprecated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If attribute_deprecated is used in an enum declaration, it should follow the 'enum' keyword, otherwise it's ignored silently. This is the only case of attribute_deprecated for enum declarations currently. Currently, this attribute_deprecated doesn't have any effect. If moved to the right place, it emits a warning every single time avcodec.h is included, like this: avcodec.h:2827: warning: ‘AVLPCType’ is deprecated (declared at avcodec.h:543) There is already a working attribute_deprecated for the corresponding field in AVCodecContext, so therefore this one shouldn't be needed. Signed-off-by: Martin Storsjö --- libavcodec/avcodec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 649bce488c..c3cd023b6a 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -540,7 +540,7 @@ enum AVChromaLocation{ /** * LPC analysis type */ -attribute_deprecated enum AVLPCType { +enum AVLPCType { AV_LPC_TYPE_DEFAULT = -1, ///< use the codec default LPC type AV_LPC_TYPE_NONE = 0, ///< do not use LPC prediction or use all zero coefficients AV_LPC_TYPE_FIXED = 1, ///< fixed LPC coefficients From cae4f4b77e7dc037ad5dfcc7bc636788f1420ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 3 Nov 2011 11:40:13 +0200 Subject: [PATCH 6/8] avcodec: Make sure codec_type is set by avcodec_get_context_defaults2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function used to set codec_type. With the current fallback implementation based on avcodec_get_context_defaults3, codec_type won't be set to the value passed in, but will be set to AVMEDIA_TYPE_UNKNOWN. Legacy callers of this function might expect this field to be set to the value passed in. Signed-off-by: Martin Storsjö --- libavcodec/options.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/options.c b/libavcodec/options.c index fdc8a71337..a08ed98cce 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -539,6 +539,7 @@ static const AVClass av_codec_context_class = { #if FF_API_ALLOC_CONTEXT void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){ avcodec_get_context_defaults3(s, NULL); + s->codec_type = codec_type; } #endif From 0d7a16a9467eab58aca4508a70cb546741664ac0 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 3 Nov 2011 15:54:04 -0700 Subject: [PATCH 7/8] avfilter: Don't copy garbage from the stack when setting up video pictures. --- libavfilter/avfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index abeae14f79..2f24aa3d98 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -332,8 +332,8 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int picref->type = AVMEDIA_TYPE_VIDEO; pic->format = picref->format = format; - memcpy(pic->data, data, sizeof(pic->data)); - memcpy(pic->linesize, linesize, sizeof(pic->linesize)); + memcpy(pic->data, data, 4*sizeof(data[0])); + memcpy(pic->linesize, linesize, 4*sizeof(linesize[0])); memcpy(picref->data, pic->data, sizeof(picref->data)); memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); From 2a6eb06254df79e96b3d791b6b89b2534ced3119 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 3 Nov 2011 15:55:52 -0700 Subject: [PATCH 8/8] vp6: Fix illegal read. --- libavcodec/vp6.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c index e29f9014aa..03024fa865 100644 --- a/libavcodec/vp6.c +++ b/libavcodec/vp6.c @@ -376,7 +376,7 @@ static void vp6_parse_coeff_huffman(VP56Context *s) if (b > 3) pt = 1; vlc_coeff = &s->dccv_vlc[pt]; - for (coeff_idx=0; coeff_idx<64; ) { + for (coeff_idx = 0;;) { int run = 1; if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) { s->nb_null[coeff_idx][pt]--; @@ -413,6 +413,8 @@ static void vp6_parse_coeff_huffman(VP56Context *s) } } coeff_idx+=run; + if (coeff_idx >= 64) + break; cg = FFMIN(vp6_coeff_groups[coeff_idx], 3); vlc_coeff = &s->ract_vlc[pt][ct][cg]; }