Merge commit '9580818c5d934bde65a95efd2cee61c174721092'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 5 May 2014 13:42:26 +0000 (15:42 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 5 May 2014 13:51:55 +0000 (15:51 +0200)
* commit '9580818c5d934bde65a95efd2cee61c174721092':
  avconv: rename OutputStream.opts to OutputStream.encoder_opts

Conflicts:
ffmpeg.c
ffmpeg.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
ffmpeg.c
ffmpeg.h
ffmpeg_filter.c
ffmpeg_opt.c

diff --cc ffmpeg.c
+++ b/ffmpeg.c
@@@ -2716,9 -1878,17 +2716,9 @@@ static int transcode_init(void
                                                 DEFAULT_PASS_LOGFILENAME_PREFIX,
                           i);
                  if (!strcmp(ost->enc->name, "libx264")) {
-                     av_dict_set(&ost->opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
+                     av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
                  } else {
 -                    if (enc_ctx->flags & CODEC_FLAG_PASS1) {
 -                        f = fopen(logfilename, "wb");
 -                        if (!f) {
 -                            av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n",
 -                                   logfilename, strerror(errno));
 -                            exit_program(1);
 -                        }
 -                        ost->logfile = f;
 -                    } else {
 +                    if (enc_ctx->flags & CODEC_FLAG_PASS2) {
                          char  *logbuffer;
                          size_t logbuffer_size;
                          if (cmdutils_read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
                          ost->file_index, ost->index);
                  goto dump_format;
              }
-             assert_avoptions(ost->opts);
 +            if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
 +                !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
 +                av_buffersink_set_frame_size(ost->filter->filter,
 +                                             ost->st->codec->frame_size);
+             assert_avoptions(ost->encoder_opts);
              if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000)
                  av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
 -                                             "It takes bits/s as argument, not kbits/s\n");
 +                                             " It takes bits/s as argument, not kbits/s\n");
          } else {
-             av_opt_set_dict(ost->st->codec, &ost->opts);
+             av_opt_set_dict(ost->st->codec, &ost->encoder_opts);
          }
      }
  
@@@ -3644,10 -2505,8 +3644,10 @@@ static int transcode(void
                      ost->logfile = NULL;
                  }
                  av_freep(&ost->st->codec->subtitle_header);
 -                av_free(ost->forced_kf_pts);
 +                av_freep(&ost->forced_kf_pts);
 +                av_freep(&ost->apad);
-                 av_dict_free(&ost->opts);
+                 av_dict_free(&ost->encoder_opts);
 +                av_dict_free(&ost->swr_opts);
                  av_dict_free(&ost->resample_opts);
              }
          }
diff --cc ffmpeg.h
+++ b/ffmpeg.h
@@@ -406,16 -334,11 +406,16 @@@ typedef struct OutputStream 
  
      OutputFilter *filter;
      char *avfilter;
 +    char *filters;         ///< filtergraph associated to the -filter option
 +    char *filters_script;  ///< filtergraph script associated to the -filter_script option
  
      int64_t sws_flags;
-     AVDictionary *opts;
+     AVDictionary *encoder_opts;
 +    AVDictionary *swr_opts;
      AVDictionary *resample_opts;
 -    int finished;        /* no more packets should be written for this stream */
 +    char *apad;
 +    OSTFinished finished;        /* no more packets should be written for this stream */
 +    int unavailable;                     /* true if the steram is unavailable (possibly temporarily) */
      int stream_copy;
      const char *attachment_filename;
      int copy_initial_nonkeyframes;
diff --cc ffmpeg_filter.c
  #include "libavutil/opt.h"
  #include "libavutil/pixdesc.h"
  #include "libavutil/pixfmt.h"
 +#include "libavutil/imgutils.h"
  #include "libavutil/samplefmt.h"
  
-     AVDictionaryEntry *strict_dict = av_dict_get(ost->opts, "strict", NULL, 0);
 +enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target)
 +{
 +    if (codec && codec->pix_fmts) {
 +        const enum AVPixelFormat *p = codec->pix_fmts;
 +        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
 +        int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
 +        enum AVPixelFormat best= AV_PIX_FMT_NONE;
 +        static const enum AVPixelFormat mjpeg_formats[] =
 +            { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_NONE };
 +        static const enum AVPixelFormat ljpeg_formats[] =
 +            { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUV420P,
 +              AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE };
 +
 +        if (st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
 +            if (st->codec->codec_id == AV_CODEC_ID_MJPEG) {
 +                p = mjpeg_formats;
 +            } else if (st->codec->codec_id == AV_CODEC_ID_LJPEG) {
 +                p =ljpeg_formats;
 +            }
 +        }
 +        for (; *p != AV_PIX_FMT_NONE; p++) {
 +            best= avcodec_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
 +            if (*p == target)
 +                break;
 +        }
 +        if (*p == AV_PIX_FMT_NONE) {
 +            if (target != AV_PIX_FMT_NONE)
 +                av_log(NULL, AV_LOG_WARNING,
 +                       "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
 +                       av_get_pix_fmt_name(target),
 +                       codec->name,
 +                       av_get_pix_fmt_name(best));
 +            return best;
 +        }
 +    }
 +    return target;
 +}
 +
 +void choose_sample_fmt(AVStream *st, AVCodec *codec)
 +{
 +    if (codec && codec->sample_fmts) {
 +        const enum AVSampleFormat *p = codec->sample_fmts;
 +        for (; *p != -1; p++) {
 +            if (*p == st->codec->sample_fmt)
 +                break;
 +        }
 +        if (*p == -1) {
 +            if((codec->capabilities & CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codec->sample_fmt) > av_get_sample_fmt_name(codec->sample_fmts[0]))
 +                av_log(NULL, AV_LOG_ERROR, "Conversion will not be lossless.\n");
 +            if(av_get_sample_fmt_name(st->codec->sample_fmt))
 +            av_log(NULL, AV_LOG_WARNING,
 +                   "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
 +                   av_get_sample_fmt_name(st->codec->sample_fmt),
 +                   codec->name,
 +                   av_get_sample_fmt_name(codec->sample_fmts[0]));
 +            st->codec->sample_fmt = codec->sample_fmts[0];
 +        }
 +    }
 +}
 +
 +static char *choose_pix_fmts(OutputStream *ost)
 +{
++    AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
 +    if (strict_dict)
 +        // used by choose_pixel_fmt() and below
 +        av_opt_set(ost->st->codec, "strict", strict_dict->value, 0);
 +
 +     if (ost->keep_pix_fmt) {
 +        if (ost->filter)
 +            avfilter_graph_set_auto_convert(ost->filter->graph->graph,
 +                                            AVFILTER_AUTO_CONVERT_NONE);
 +        if (ost->st->codec->pix_fmt == AV_PIX_FMT_NONE)
 +            return NULL;
 +        return av_strdup(av_get_pix_fmt_name(ost->st->codec->pix_fmt));
 +    }
 +    if (ost->st->codec->pix_fmt != AV_PIX_FMT_NONE) {
 +        return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt)));
 +    } else if (ost->enc && ost->enc->pix_fmts) {
 +        const enum AVPixelFormat *p;
 +        AVIOContext *s = NULL;
 +        uint8_t *ret;
 +        int len;
 +
 +        if (avio_open_dyn_buf(&s) < 0)
 +            exit_program(1);
 +
 +        p = ost->enc->pix_fmts;
 +        if (ost->st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
 +            if (ost->st->codec->codec_id == AV_CODEC_ID_MJPEG) {
 +                p = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_NONE };
 +            } else if (ost->st->codec->codec_id == AV_CODEC_ID_LJPEG) {
 +                p = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUV420P,
 +                                                    AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE };
 +            }
 +        }
 +
 +        for (; *p != AV_PIX_FMT_NONE; p++) {
 +            const char *name = av_get_pix_fmt_name(*p);
 +            avio_printf(s, "%s|", name);
 +        }
 +        len = avio_close_dyn_buf(s, &ret);
 +        ret[len - 1] = 0;
 +        return ret;
 +    } else
 +        return NULL;
 +}
 +
  /* Define a function for building a string containing a list of
   * allowed formats. */
  #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name)           \
@@@ -873,10 -603,6 +873,10 @@@ int configure_filtergraph(FilterGraph *
          if (strlen(args))
              args[strlen(args) - 1] = '\0';
          fg->graph->resample_lavr_opts = av_strdup(args);
-         e = av_dict_get(ost->opts, "threads", NULL, 0);
 +
++        e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
 +        if (e)
 +            av_opt_set(fg->graph, "threads", e->value, 0);
      }
  
      if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
diff --cc ffmpeg_opt.c
@@@ -1355,13 -1133,10 +1355,13 @@@ static OutputStream *new_video_stream(O
          /* two pass mode */
          MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
          if (do_pass) {
 -            if (do_pass == 1) {
 +            if (do_pass & 1) {
                  video_enc->flags |= CODEC_FLAG_PASS1;
-                 av_dict_set(&ost->opts, "flags", "+pass1", AV_DICT_APPEND);
 -            } else {
++                av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
 +            }
 +            if (do_pass & 2) {
                  video_enc->flags |= CODEC_FLAG_PASS2;
-                 av_dict_set(&ost->opts, "flags", "+pass2", AV_DICT_APPEND);
++                av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
              }
          }