Merge remote-tracking branch 'qatar/master'

* qatar/master:
  vp6: Fix illegal read.
  avfilter: Don't copy garbage from the stack when setting up video pictures.
  avcodec: Make sure codec_type is set by avcodec_get_context_defaults2
  avcodec: Remove a misplaced and useless attribute_deprecated
  avconv: add -dump_attachment option.
  avconv: add -attach option.
  avconv: make negative mappings disable only streams from the specified file
  fmtconvert: fix int32_to_float_fmul_scalar() for windows x86_64

Conflicts:
	libavcodec/options.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2011-11-04 01:44:06 +01:00
commit 259a960f1b
7 changed files with 312 additions and 49 deletions

154
avconv.c
View File

@ -244,6 +244,7 @@ typedef struct OutputStream {
AVDictionary *opts;
int is_past_recording_time;
int stream_copy;
const char *attachment_filename;
} OutputStream;
#if HAVE_TERMIOS_H
@ -295,6 +296,8 @@ typedef struct OptionsContext {
SpecifierOpt *ts_scale;
int nb_ts_scale;
SpecifierOpt *dump_attachment;
int nb_dump_attachment;
/* output options */
StreamMap *stream_maps;
@ -305,6 +308,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;
@ -2047,6 +2052,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;
@ -2350,6 +2358,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,
@ -2757,7 +2772,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;
@ -2792,6 +2808,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) {
@ -2944,6 +2968,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;
@ -3044,6 +3122,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);
@ -3634,6 +3723,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,25 +3777,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) {
@ -3758,7 +3865,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);
}
@ -4147,6 +4257,8 @@ 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" },
{ "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" },

View File

@ -192,6 +192,39 @@ 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).
@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

158
ffmpeg.c
View File

@ -252,6 +252,7 @@ typedef struct OutputStream {
AVDictionary *opts;
int is_past_recording_time;
int stream_copy;
const char *attachment_filename;
} OutputStream;
@ -306,6 +307,8 @@ typedef struct OptionsContext {
SpecifierOpt *ts_scale;
int nb_ts_scale;
SpecifierOpt *dump_attachment;
int nb_dump_attachment;
/* output options */
StreamMap *stream_maps;
@ -316,6 +319,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;
@ -2059,6 +2064,9 @@ static int transcode_init(OutputFile *output_files, int nb_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;
@ -2368,6 +2376,13 @@ static int transcode_init(OutputFile *output_files, int nb_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,
@ -2840,7 +2855,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;
@ -2875,6 +2891,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) {
@ -3056,6 +3080,62 @@ 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);
term_exit();
if (!read_yesno()) {
av_log(0, AV_LOG_FATAL, "Not overwriting - exiting\n");
exit_program(1);
}
term_init();
}
else {
av_log(0, AV_LOG_FATAL, "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;
@ -3167,6 +3247,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);
@ -3784,6 +3875,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;
@ -3802,27 +3929,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);
term_exit();
if (!read_yesno()) {
av_log(0, AV_LOG_FATAL, "Not overwriting - exiting\n");
exit_program(1);
}
term_init();
}
else {
av_log(0, AV_LOG_FATAL,"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) {
@ -3920,7 +4027,10 @@ static void opt_output_file(void *optctx, const char *filename)
}
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);
}
@ -4361,6 +4471,8 @@ 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" },
{ "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" },

View File

@ -553,7 +553,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

View File

@ -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];
}

View File

@ -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

View File

@ -438,8 +438,8 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin
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));