3 #include "libavutil/log.h"
4 #include "libavutil/opt.h"
5 #include "libavformat/avformat.h"
7 AVDictionary *format_opts, *codec_opts;
10 void print_error(const char *filename, int err)
13 const char *errbuf_ptr = errbuf;
15 if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
16 errbuf_ptr = strerror(AVUNERROR(err));
17 av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
21 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
23 int ret = avformat_match_stream_specifier(s, st, spec);
25 av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
29 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
30 AVFormatContext *s, AVStream *st, AVCodec *codec)
32 AVDictionary *ret = NULL;
33 AVDictionaryEntry *t = NULL;
34 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
35 : AV_OPT_FLAG_DECODING_PARAM;
37 const AVClass *cc = avcodec_get_class();
40 codec = s->oformat ? avcodec_find_encoder(codec_id)
41 : avcodec_find_decoder(codec_id);
43 switch (st->codec->codec_type) {
44 case AVMEDIA_TYPE_VIDEO:
46 flags |= AV_OPT_FLAG_VIDEO_PARAM;
48 case AVMEDIA_TYPE_AUDIO:
50 flags |= AV_OPT_FLAG_AUDIO_PARAM;
52 case AVMEDIA_TYPE_SUBTITLE:
54 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
60 while ((t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX))) {
61 char *p = strchr(t->key, ':');
63 /* check stream specification in opt name */
65 switch (check_stream_specifier(s, st, p + 1)) {
66 case 1: *p = 0; break;
71 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
72 (codec && codec->priv_class &&
73 av_opt_find(&codec->priv_class, t->key, NULL, flags,
74 AV_OPT_SEARCH_FAKE_OBJ)))
75 av_dict_set(&ret, t->key, t->value, 0);
76 else if (t->key[0] == prefix &&
77 av_opt_find(&cc, t->key + 1, NULL, flags,
78 AV_OPT_SEARCH_FAKE_OBJ))
79 av_dict_set(&ret, t->key + 1, t->value, 0);
87 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
88 AVDictionary *codec_opts)
95 opts = av_mallocz(s->nb_streams * sizeof(*opts));
97 av_log(NULL, AV_LOG_ERROR,
98 "Could not alloc memory for stream options.\n");
101 for (i = 0; i < s->nb_streams; i++)
102 opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id,
103 s, s->streams[i], NULL);
108 #define FFMPEG_DATADIR "/system/usr/ffmpeg"
109 #include "cmdutils.c" /* external/ffmpeg/cmdutils.c */