Browse Source

Merge branch 'master' into oldabi

* master: (109 commits)
  libx264: fix open gop default. Please use -x264opts to force open gop This fixes Ticket268
  avfilter picture pool: double free hotfix
  mpegaudio_parser: be less picky on the start position
  ppc32: Fix movrel
  Replace usages of av_get_bits_per_sample_fmt() with av_get_bytes_per_sample().
  x86: cabac: fix register constraints for 32-bit mode
  cabac: move x86 asm to libavcodec/x86/cabac.h
  x86: h264: cast pointers to intptr_t rather than int
  x86: h264: remove hardcoded edi in decode_significance_8x8_x86()
  x86: h264: remove hardcoded esi in decode_significance[_8x8]_x86()
  x86: h264: remove hardcoded edx in decode_significance[_8x8]_x86()
  x86: h264: remove hardcoded eax in decode_significance[_8x8]_x86()
  x86: cabac: change 'a' constraint to 'r' in get_cabac_inline()
  x86: cabac: remove hardcoded esi in get_cabac_inline()
  x86: cabac: remove hardcoded edx in get_cabac_inline()
  x86: cabac: remove unused macro parameter
  x86: cabac: remove hardcoded ebx in inline asm
  x86: cabac: remove hardcoded struct offsets from inline asm
  cabac: remove inline asm under #if 0
  cabac: remove BRANCHLESS_CABAC_DECODER switch
  ...

Conflicts:
	cmdutils.c
	ffserver.c
	libavfilter/avfilter.h
	libavformat/avformat.h
	libavformat/utils.c
	libavformat/version.h
	libavutil/avutil.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Michael Niedermayer 13 years ago
parent
commit
779d7610c7
10 changed files with 333 additions and 133 deletions
  1. 9 2
      Changelog
  2. 1 0
      RELEASE
  3. 48 70
      cmdutils.c
  4. 1 15
      cmdutils.h
  5. 3 0
      configure
  6. 31 1
      doc/APIchanges
  7. 52 0
      doc/RELEASE_NOTES
  8. 3 7
      doc/ffmpeg.texi
  9. 132 0
      doc/filters.texi
  10. 53 38
      ffmpeg.c

+ 9 - 2
Changelog

@@ -2,7 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release,
 releases are sorted from youngest to oldest.
 
 
-version <next>:
+version 0.7:
 
 - many many things we forgot because we rather write code than changelogs
 - libmpcodecs video filter support (3 times as many filters than before)
@@ -14,17 +14,24 @@ version <next>:
 - floating-point sample format support to the ac3, eac3, dca, aac, and vorbis decoders.
 - H264/MPEG frame-level multi-threading
 - All av_metadata_* functions renamed to av_dict_* and moved to libavutil
+- 4:4:4 H.264 decoding support
+- 10-bit H.264 optimizations for x86
+- lut, lutrgb, and lutyuv filters added
+- buffersink libavfilter sink added
+- Bump libswscale for recently reported ABI break
 
 
 version 0.7_beta2:
 
+- VP8 frame-multithreading
+- NEON optimizations for VP8
 - Lots of deprecated API cruft removed
 - fft and imdct optimizations for AVX (Sandy Bridge) processors
 - showinfo filter added
 - DPX image encoder
 - SMPTE 302M AES3 audio decoder
 - Apple Core Audio Format muxer
-- 9bit and 10bit H.264 decoding
+- 9bit and 10bit per sample support in the H.264 decoder
 - 9bit and 10bit FFV1 encoding / decoding
 - split filter added
 - select filter added

+ 1 - 0
RELEASE

@@ -0,0 +1 @@
+0.7

+ 48 - 70
cmdutils.c

@@ -38,7 +38,8 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/eval.h"
-#include "libavcodec/opt.h"
+#include "libavutil/dict.h"
+#include "libavutil/opt.h"
 #include "cmdutils.h"
 #include "version.h"
 #if CONFIG_NETWORK
@@ -54,6 +55,7 @@ static int opt_name_count;
 AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
 AVFormatContext *avformat_opts;
 struct SwsContext *sws_opts;
+AVDictionary *format_opts, *video_opts, *audio_opts, *sub_opts;
 
 static const int this_year = 2011;
 
@@ -86,6 +88,10 @@ void uninit_opts(void)
     av_freep(&opt_names);
     av_freep(&opt_values);
     opt_name_count = 0;
+    av_dict_free(&format_opts);
+    av_dict_free(&video_opts);
+    av_dict_free(&audio_opts);
+    av_dict_free(&sub_opts);
 }
 
 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
@@ -290,6 +296,43 @@ unknown_opt:
     }
 }
 
+#define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
+#define SET_PREFIXED_OPTS(ch, flag, output) \
+    if (opt[0] == ch && avcodec_opts[0] && (o = av_opt_find(avcodec_opts[0], opt+1, NULL, flag, 0)))\
+        av_dict_set(&output, opt+1, arg, FLAGS);
+static int opt_default2(const char *opt, const char *arg)
+{
+    const AVOption *o;
+    if ((o = av_opt_find(avcodec_opts[0], opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
+        if (o->flags & AV_OPT_FLAG_VIDEO_PARAM)
+            av_dict_set(&video_opts, opt, arg, FLAGS);
+        if (o->flags & AV_OPT_FLAG_AUDIO_PARAM)
+            av_dict_set(&audio_opts, opt, arg, FLAGS);
+        if (o->flags & AV_OPT_FLAG_SUBTITLE_PARAM)
+            av_dict_set(&sub_opts, opt, arg, FLAGS);
+    } else if ((o = av_opt_find(avformat_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN)))
+        av_dict_set(&format_opts, opt, arg, FLAGS);
+    else if ((o = av_opt_find(sws_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
+        // XXX we only support sws_flags, not arbitrary sws options
+        int ret = av_set_string3(sws_opts, opt, arg, 1, NULL);
+        if (ret < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
+            return ret;
+        }
+    }
+
+    if (!o) {
+        SET_PREFIXED_OPTS('v', AV_OPT_FLAG_VIDEO_PARAM,    video_opts)
+        SET_PREFIXED_OPTS('a', AV_OPT_FLAG_AUDIO_PARAM,    audio_opts)
+        SET_PREFIXED_OPTS('s', AV_OPT_FLAG_SUBTITLE_PARAM, sub_opts)
+    }
+
+    if (o)
+        return 0;
+    fprintf(stderr, "Unrecognized option '%s'\n", opt);
+    return AVERROR_OPTION_NOT_FOUND;
+}
+
 int opt_default(const char *opt, const char *arg){
     int type;
     int ret= 0;
@@ -322,7 +365,7 @@ int opt_default(const char *opt, const char *arg){
         goto out;
 
     for(type=0; *avcodec_opts && type<AVMEDIA_TYPE_NB && ret>= 0; type++){
-        const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]);
+        const AVOption *o2 = av_opt_find(avcodec_opts[0], opt, NULL, opt_types[type], 0);
         if(o2)
             ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o);
     }
@@ -350,6 +393,9 @@ int opt_default(const char *opt, const char *arg){
     }
 
  out:
+    if ((ret = opt_default2(opt, arg)) < 0)
+        return ret;
+
 //    av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL));
 
     opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
@@ -880,71 +926,3 @@ FILE *get_preset_file(char *filename, size_t filename_size,
 
     return f;
 }
-
-#if CONFIG_AVFILTER
-
-static int ffsink_init(AVFilterContext *ctx, const char *args, void *opaque)
-{
-    FFSinkContext *priv = ctx->priv;
-
-    if (!opaque)
-        return AVERROR(EINVAL);
-    *priv = *(FFSinkContext *)opaque;
-
-    return 0;
-}
-
-static void null_end_frame(AVFilterLink *inlink) { }
-
-static int ffsink_query_formats(AVFilterContext *ctx)
-{
-    FFSinkContext *priv = ctx->priv;
-    enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE };
-
-    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
-    return 0;
-}
-
-AVFilter ffsink = {
-    .name      = "ffsink",
-    .priv_size = sizeof(FFSinkContext),
-    .init      = ffsink_init,
-
-    .query_formats = ffsink_query_formats,
-
-    .inputs    = (AVFilterPad[]) {{ .name          = "default",
-                                    .type          = AVMEDIA_TYPE_VIDEO,
-                                    .end_frame     = null_end_frame,
-                                    .min_perms     = AV_PERM_READ, },
-                                  { .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
-};
-
-int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
-                             AVFilterBufferRef **picref_ptr, AVRational *tb)
-{
-    int ret;
-    AVFilterBufferRef *picref;
-    *picref_ptr = NULL;
-
-    if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0)
-        return ret;
-    if (!(picref = ctx->inputs[0]->cur_buf))
-        return AVERROR(ENOENT);
-    *picref_ptr = picref;
-    ctx->inputs[0]->cur_buf = NULL;
-    *tb = ctx->inputs[0]->time_base;
-
-    memcpy(frame->data,     picref->data,     sizeof(frame->data));
-    memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
-    frame->pkt_pos          = picref->pos;
-    frame->interlaced_frame = picref->video->interlaced;
-    frame->top_field_first  = picref->video->top_field_first;
-    frame->key_frame        = picref->video->key_frame;
-    frame->pict_type        = picref->video->pict_type;
-    frame->sample_aspect_ratio = picref->video->sample_aspect_ratio;
-
-    return 1;
-}
-
-#endif /* CONFIG_AVFILTER */

+ 1 - 15
cmdutils.h

@@ -47,6 +47,7 @@ extern const char **opt_names;
 extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
 extern AVFormatContext *avformat_opts;
 extern struct SwsContext *sws_opts;
+extern AVDictionary *format_opts, *video_opts, *audio_opts, *sub_opts;
 
 /**
  * Initialize the cmdutils option system, in particular
@@ -259,19 +260,4 @@ int read_file(const char *filename, char **bufptr, size_t *size);
 FILE *get_preset_file(char *filename, size_t filename_size,
                       const char *preset_name, int is_path, const char *codec_name);
 
-typedef struct {
-    enum PixelFormat pix_fmt;
-} FFSinkContext;
-
-extern AVFilter ffsink;
-
-/**
- * Extract a frame from sink.
- *
- * @return a negative error in case of failure, 1 if one frame has
- * been extracted successfully.
- */
-int get_filtered_video_frame(AVFilterContext *sink, AVFrame *frame,
-                             AVFilterBufferRef **picref, AVRational *pts_tb);
-
 #endif /* FFMPEG_CMDUTILS_H */

+ 3 - 0
configure

@@ -1500,6 +1500,7 @@ frei0r_src_filter_deps="frei0r dlopen strtok_r"
 hqdn3d_filter_deps="gpl"
 movie_filter_deps="avcodec avformat"
 mp_filter_deps="gpl avcodec"
+negate_filter_deps="lut_filter"
 ocv_filter_deps="libopencv"
 scale_filter_deps="swscale"
 yadif_filter_deps="gpl"
@@ -2099,6 +2100,7 @@ elif $cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
     AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
     speed_cflags='-O2'
     size_cflags='-Os'
+    filter_cflags='filter_out -Wdisabled-optimization'
 elif $cc -v 2>&1 | grep -q Open64; then
     cc_type=open64
     cc_version=__OPEN64__
@@ -2107,6 +2109,7 @@ elif $cc -v 2>&1 | grep -q Open64; then
     AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
     speed_cflags='-O2'
     size_cflags='-Os'
+    filter_cflags='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros'
 fi
 
 test -n "$cc_type" && enable $cc_type ||

+ 31 - 1
doc/APIchanges

@@ -7,12 +7,32 @@ libavdevice: 2011-04-18
 libavfilter: 2011-04-18
 libavformat: 2011-04-18
 libpostproc: 2011-04-18
-libswscale:  2011-04-18
+libswscale:  2011-06-20
 libavutil:   2011-04-18
 
 
 API changes, most recent first:
 
+2011-06-19 - xxxxxxx - lavfi 2.23.0 - avfilter.h
+  Add layout negotiation fields and helper functions.
+
+  In particular, add in_chlayouts and out_chlayouts to AVFilterLink,
+  and the functions:
+  avfilter_set_common_sample_formats()
+  avfilter_set_common_channel_layouts()
+  avfilter_all_channel_layouts()
+
+2011-06-19 - xxxxxxx - lavfi 2.22.0 - AVFilterFormats
+  Change type of AVFilterFormats.formats from int * to int64_t *,
+  and update formats handling API accordingly.
+
+  avfilter_make_format_list() still takes a int32_t array and converts
+  it to int64_t. A new function, avfilter_make_format64_list(), that
+  takes int64_t arrays has been added.
+
+2011-06-19 - xxxxxxx - lavfi 2.21.0 - vsink_buffer.h
+  Add video sink buffer and vsink_buffer.h public header.
+
 2011-06-12 - xxxxxxx - lavfi 2.18.0 - avcodec.h
   Add avfilter_get_video_buffer_ref_from_frame() function in
   libavfilter/avcodec.h.
@@ -23,6 +43,16 @@ API changes, most recent first:
 2011-06-12 - xxxxxxx - lavfi 2.16.0 - avfilter_graph_parse()
   Change avfilter_graph_parse() signature.
 
+2011-06-xx - xxxxxxx - lavf 53.2.0 - avformat.h
+  Add avformat_open_input and avformat_write_header().
+  Deprecate av_open_input_stream, av_open_input_file,
+  AVFormatParameters and av_write_header.
+
+2011-06-xx - xxxxxxx - lavu 51.7.0 - opt.h
+  Add av_opt_set_dict() and av_opt_find().
+  Deprecate av_find_opt().
+  Add AV_DICT_APPEND flag.
+
 2011-06-xx - xxxxxxx - lavu 51.6.0 - opt.h
   Add av_opt_flag_is_set().
 

+ 52 - 0
doc/RELEASE_NOTES

@@ -0,0 +1,52 @@
+Release Notes
+=============
+
+* 0.7 "Love and Peace" June, 2011
+
+General notes
+-------------
+
+This release enables frame-based multithreaded decoding for a number of codecs,
+including VP8, H.263 and H.264. Additionally, there has been a major cleanup of
+both internal and external APIs. For this reason, the major versions of all
+libraries have been bumped. On the one hand, this means that 0.7 can be installed
+side-by-side with previous releases, on the other hand, in order to benefit
+from the new features, applications need to be recompiled.
+
+Other important changes are additions of decoders including, but not limited to,
+AMR-WB, single stream LATM/LOAS, G.722 ADPCM, a native VP8 decoder
+and HE-AACv2. Additionally, many new de/muxers such as WebM in Matroska, Apple
+HTTP Live Streaming, SAP, IEC 61937 (S/PDIF) have been added.
+
+See the Changelog file for a list of significant changes.
+
+Please note that our policy on bug reports has not changed. We still only accept
+bug reports against HEAD of the FFmpeg trunk repository. If you are experiencing
+issues with any formally released version of FFmpeg, please try a current version
+of the development code to check if the issue still exists. If it does, make your
+report against the development code following the usual bug reporting guidelines.
+
+
+API changes
+-----------
+
+Please see the file doc/APIchanges for programmer-centric information. Note that a
+lot of long-time deprecated APIs have been removed. Also, a number of additional
+APIs have been deprecated and are scheduled for removal in the next release.
+
+
+Other notable changes
+---------------------
+
+- many ARM NEON optimizations
+- libswscale cleanup started, optimizations should become easier in the future
+- nonfree libfaad support for AAC decoding removed
+- 4:4:4 H.264 decoding
+- 9/10bit H.264 decoding
+- Win64 Assembler support
+- native MMSH/MMST support
+- Windows TV demuxing
+- native AMR-WB decoding
+- native GSM-MS decoding
+- SMPTE 302M decoding
+- AVS encoding

+ 3 - 7
doc/ffmpeg.texi

@@ -169,7 +169,6 @@ Set frame rate (Hz value, fraction or abbreviation), (default = 25).
 Set frame size. The format is @samp{wxh} (ffserver default = 160x128).
 There is no default for input streams,
 for output streams it is set by default to the size of the source stream.
-If the input file has video streams with different resolutions, the behaviour is undefined.
 The following abbreviations are recognized:
 @table @samp
 @item sqcif
@@ -557,10 +556,8 @@ The timestamps must be specified in ascending order.
 @item -aframes @var{number}
 Set the number of audio frames to record.
 @item -ar @var{freq}
-Set the audio sampling frequency. For input streams it is set by
-default to 44100 Hz, for output streams it is set by default to the
-frequency of the input stream. If the input file has audio streams
-with different frequencies, the behaviour is undefined.
+Set the audio sampling frequency. there is no default for input streams,
+for output streams it is set by default to the frequency of the input stream.
 @item -ab @var{bitrate}
 Set the audio bitrate in bit/s (default = 64k).
 @item -aq @var{q}
@@ -568,8 +565,7 @@ Set the audio quality (codec-specific, VBR).
 @item -ac @var{channels}
 Set the number of audio channels. For input streams it is set by
 default to 1, for output streams it is set by default to the same
-number of audio channels in input. If the input file has audio streams
-with different channel count, the behaviour is undefined.
+number of audio channels in input.
 @item -an
 Disable audio recording.
 @item -acodec @var{codec}

+ 132 - 0
doc/filters.texi

@@ -701,6 +701,118 @@ a float number which specifies chroma temporal strength, defaults to
 @var{luma_tmp}*@var{chroma_spatial}/@var{luma_spatial}
 @end table
 
+@section lut, lutrgb, lutyuv
+
+Compute a look-up table for binding each pixel component input value
+to an output value, and apply it to input video.
+
+@var{lutyuv} applies a lookup table to a YUV input video, @var{lutrgb}
+to an RGB input video.
+
+These filters accept in input a ":"-separated list of options, which
+specify the expressions used for computing the lookup table for the
+corresponding pixel component values.
+
+The @var{lut} filter requires either YUV or RGB pixel formats in
+input, and accepts the options:
+@table @option
+@var{c0} (first  pixel component)
+@var{c1} (second pixel component)
+@var{c2} (third  pixel component)
+@var{c3} (fourth pixel component, corresponds to the alpha component)
+@end table
+
+The exact component associated to each option depends on the format in
+input.
+
+The @var{lutrgb} filter requires RGB pixel formats in input, and
+accepts the options:
+@table @option
+@var{r} (red component)
+@var{g} (green component)
+@var{b} (blue component)
+@var{a} (alpha component)
+@end table
+
+The @var{lutyuv} filter requires YUV pixel formats in input, and
+accepts the options:
+@table @option
+@var{y} (Y/luminance component)
+@var{u} (U/Cb component)
+@var{v} (V/Cr component)
+@var{a} (alpha component)
+@end table
+
+The expressions can contain the following constants and functions:
+
+@table @option
+@item E, PI, PHI
+the corresponding mathematical approximated values for e
+(euler number), pi (greek PI), PHI (golden ratio)
+
+@item w, h
+the input width and heigth
+
+@item val
+input value for the pixel component
+
+@item clipval
+the input value clipped in the @var{minval}-@var{maxval} range
+
+@item maxval
+maximum value for the pixel component
+
+@item minval
+minimum value for the pixel component
+
+@item negval
+the negated value for the pixel component value clipped in the
+@var{minval}-@var{maxval} range , it corresponds to the expression
+"maxval-clipval+minval"
+
+@item clip(val)
+the computed value in @var{val} clipped in the
+@var{minval}-@var{maxval} range
+
+@item gammaval(gamma)
+the computed gamma correction value of the pixel component value
+clipped in the @var{minval}-@var{maxval} range, corresponds to the
+expression
+"pow((clipval-minval)/(maxval-minval)\,@var{gamma})*(maxval-minval)+minval"
+
+@end table
+
+All expressions default to "val".
+
+Some examples follow:
+@example
+# negate input video
+lutrgb="r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val"
+lutyuv="y=maxval+minval-val:u=maxval+minval-val:v=maxval+minval-val"
+
+# the above is the same as
+lutrgb="r=negval:g=negval:b=negval"
+lutyuv="y=negval:u=negval:v=negval"
+
+# negate luminance
+lutyuv=negval
+
+# remove chroma components, turns the video into a graytone image
+lutyuv="u=128:v=128"
+
+# apply a luma burning effect
+lutyuv="y=2*val"
+
+# remove green and blue components
+lutrgb="g=0:b=0"
+
+# set a constant alpha channel value on input
+format=rgba,lutrgb=a="maxval-minval/2"
+
+# correct luminance gamma by a 0.5 factor
+lutyuv=y=gammaval(0.5)
+@end example
+
 @section mp
 
 Apply an MPlayer filter to the input video.
@@ -799,6 +911,13 @@ mp=hue=100:-10
 
 See also mplayer(1), @url{http://www.mplayerhq.hu/}.
 
+@section negate
+
+Negate input video.
+
+This filter accepts an integer in input, if non-zero it negates the
+alpha component (if available). The default value in input is 0.
+
 @section noformat
 
 Force libavfilter not to use any of the specified pixel formats for the
@@ -1858,6 +1977,19 @@ frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
 
 Below is a description of the currently available video sinks.
 
+@section buffersink
+
+Buffer video frames, and make them available to the end of the filter
+graph.
+
+This sink is mainly intended for a programmatic use, in particular
+through the interface defined in @file{libavfilter/vsink_buffer.h}.
+
+It does not require a string parameter in input, but you need to
+specify a pointer to a list of supported pixel formats terminated by
+-1 in the opaque parameter provided to @code{avfilter_init_filter}
+when initializing this sink.
+
 @section nullsink
 
 Null video sink, do absolutely nothing with the input video. It is

+ 53 - 38
ffmpeg.c

@@ -51,6 +51,7 @@
 # include "libavfilter/avcodec.h"
 # include "libavfilter/avfilter.h"
 # include "libavfilter/avfiltergraph.h"
+# include "libavfilter/vsink_buffer.h"
 # include "libavfilter/vsrc_buffer.h"
 #endif
 
@@ -124,9 +125,7 @@ static int nb_input_codecs = 0;
 static int nb_input_files_ts_scale[MAX_FILES] = {0};
 
 static AVFormatContext *output_files[MAX_FILES];
-static AVCodec **output_codecs = NULL;
 static int nb_output_files = 0;
-static int nb_output_codecs = 0;
 
 static AVStreamMap *stream_maps = NULL;
 static int nb_stream_maps;
@@ -278,6 +277,8 @@ typedef struct AVOutputStream {
     struct AVInputStream *sync_ist; /* input stream to sync against */
     int64_t sync_opts;       /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number
     AVBitStreamFilterContext *bitstream_filters;
+    AVCodec *enc;
+
     /* video only */
     int video_resample;
     AVFrame resample_frame;              /* temporary frame for image resampling */
@@ -365,7 +366,7 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
     /** filter graph containing all filters including input & output */
     AVCodecContext *codec = ost->st->codec;
     AVCodecContext *icodec = ist->st->codec;
-    FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
+    enum PixelFormat pix_fmts[] = { codec->pix_fmt, PIX_FMT_NONE };
     AVRational sample_aspect_ratio;
     char args[255];
     int ret;
@@ -385,8 +386,8 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
                                        "src", args, NULL, ost->graph);
     if (ret < 0)
         return ret;
-    ret = avfilter_graph_create_filter(&ost->output_video_filter, &ffsink,
-                                       "out", NULL, &ffsink_ctx, ost->graph);
+    ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"),
+                                       "out", NULL, pix_fmts, ost->graph);
     if (ret < 0)
         return ret;
     last_filter = ost->input_video_filter;
@@ -556,7 +557,6 @@ static int ffmpeg_exit(int ret)
 
     av_free(streamid_map);
     av_free(input_codecs);
-    av_free(output_codecs);
     av_free(stream_maps);
     av_free(meta_data_maps);
 
@@ -620,6 +620,8 @@ static void choose_sample_fmt(AVStream *st, AVCodec *codec)
                 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, "Convertion will not be lossless'\n");
             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),
@@ -809,8 +811,8 @@ static void do_audio_out(AVFormatContext *s,
     int size_out, frame_bytes, ret, resample_changed;
     AVCodecContext *enc= ost->st->codec;
     AVCodecContext *dec= ist->st->codec;
-    int osize= av_get_bits_per_sample_fmt(enc->sample_fmt)/8;
-    int isize= av_get_bits_per_sample_fmt(dec->sample_fmt)/8;
+    int osize = av_get_bytes_per_sample(enc->sample_fmt);
+    int isize = av_get_bytes_per_sample(dec->sample_fmt);
     const int coded_bps = av_get_bits_per_sample(enc->codec->id);
 
 need_realloc:
@@ -1530,7 +1532,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
 #endif
 
     AVPacket avpkt;
-    int bps = av_get_bits_per_sample_fmt(ist->st->codec->sample_fmt)>>3;
+    int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
 
     if(ist->next_pts == AV_NOPTS_VALUE)
         ist->next_pts= ist->pts;
@@ -1708,12 +1710,15 @@ static int output_packet(AVInputStream *ist, int ist_index,
                 frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
                     !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
                 while (frame_available) {
-                    AVRational ist_pts_tb;
-                    if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter)
-                        if (get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb) < 0)
+                    if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter) {
+                        AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
+                        if (av_vsink_buffer_get_video_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0)
                             goto cont;
-                    if (ost->picref)
-                        ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+                        if (ost->picref) {
+                            avfilter_fill_frame_from_video_buffer_ref(&picture, ost->picref);
+                            ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+                        }
+                    }
 #endif
                     os = output_files[ost->file_index];
 
@@ -2263,6 +2268,8 @@ static int transcode(AVFormatContext **output_files,
                 abort();
             }
         } else {
+            if (!ost->enc)
+                ost->enc = avcodec_find_encoder(ost->st->codec->codec_id);
             switch(codec->codec_type) {
             case AVMEDIA_TYPE_AUDIO:
                 ost->fifo= av_fifo_alloc(1024);
@@ -2274,7 +2281,7 @@ static int transcode(AVFormatContext **output_files,
                     if (icodec->lowres)
                         codec->sample_rate >>= icodec->lowres;
                 }
-                choose_sample_rate(ost->st, codec->codec);
+                choose_sample_rate(ost->st, ost->enc);
                 codec->time_base = (AVRational){1, codec->sample_rate};
                 if (!codec->channels)
                     codec->channels = icodec->channels;
@@ -2289,6 +2296,10 @@ static int transcode(AVFormatContext **output_files,
                 ost->resample_channels    = icodec->channels;
                 break;
             case AVMEDIA_TYPE_VIDEO:
+                if (codec->pix_fmt == PIX_FMT_NONE)
+                    codec->pix_fmt = icodec->pix_fmt;
+                choose_pixel_fmt(ost->st, ost->enc);
+
                 if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
                     fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
                     ffmpeg_exit(1);
@@ -2299,6 +2310,10 @@ static int transcode(AVFormatContext **output_files,
                 if (ost->video_resample) {
                     codec->bits_per_raw_sample= frame_bits_per_raw_sample;
                 }
+                if (!codec->width || !codec->height) {
+                    codec->width  = icodec->width;
+                    codec->height = icodec->height;
+                }
                 ost->resample_height = icodec->height;
                 ost->resample_width  = icodec->width;
                 ost->resample_pix_fmt= icodec->pix_fmt;
@@ -2307,11 +2322,16 @@ static int transcode(AVFormatContext **output_files,
 
                 if (!ost->frame_rate.num)
                     ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
-                if (codec->codec && codec->codec->supported_framerates && !force_fps) {
-                    int idx = av_find_nearest_q_idx(ost->frame_rate, codec->codec->supported_framerates);
-                    ost->frame_rate = codec->codec->supported_framerates[idx];
+                if (ost->enc && ost->enc->supported_framerates && !force_fps) {
+                    int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
+                    ost->frame_rate = ost->enc->supported_framerates[idx];
                 }
                 codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
+                if(   av_q2d(codec->time_base) < 0.001 && video_sync_method
+                   && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){
+                    av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n"
+                                               "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n");
+                }
 
 #if CONFIG_AVFILTER
                 if (configure_video_filters(ist, ost)) {
@@ -2375,10 +2395,8 @@ static int transcode(AVFormatContext **output_files,
     for(i=0;i<nb_ostreams;i++) {
         ost = ost_table[i];
         if (ost->encoding_needed) {
-            AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
+            AVCodec *codec = ost->enc;
             AVCodecContext *dec = input_streams[ost->source_index].st->codec;
-            if (!codec)
-                codec = avcodec_find_encoder(ost->st->codec->codec_id);
             if (!codec) {
                 snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d",
                          ost->st->codec->codec_id, ost->file_index, ost->index);
@@ -3399,17 +3417,12 @@ static int opt_input_file(const char *opt, const char *filename)
             if(!input_codecs[nb_input_codecs-1])
                 input_codecs[nb_input_codecs-1] = avcodec_find_decoder(dec->codec_id);
             set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
-            frame_height = dec->height;
-            frame_width  = dec->width;
-            frame_pix_fmt = dec->pix_fmt;
             rfps      = ic->streams[i]->r_frame_rate.num;
             rfps_base = ic->streams[i]->r_frame_rate.den;
             if (dec->lowres) {
                 dec->flags |= CODEC_FLAG_EMU_EDGE;
-                frame_height >>= dec->lowres;
-                frame_width  >>= dec->lowres;
-                dec->height = frame_height;
-                dec->width  = frame_width;
+                dec->height >>= dec->lowres;
+                dec->width  >>= dec->lowres;
             }
             if(me_threshold)
                 dec->debug |= FF_DEBUG_MV;
@@ -3454,9 +3467,12 @@ static int opt_input_file(const char *opt, const char *filename)
     input_files[nb_input_files - 1].ctx        = ic;
     input_files[nb_input_files - 1].ist_index  = nb_input_streams - ic->nb_streams;
 
-    video_channel = 0;
     top_field_first = -1;
+    video_channel = 0;
     frame_rate    = (AVRational){0, 0};
+    frame_pix_fmt = PIX_FMT_NONE;
+    frame_height = 0;
+    frame_width  = 0;
     audio_sample_rate = 0;
     audio_channels    = 0;
 
@@ -3526,13 +3542,12 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
     }
     ost = new_output_stream(oc, file_idx);
 
-    output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if(!video_stream_copy){
         if (video_codec_name) {
             codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
                                          avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
             codec = avcodec_find_encoder_by_name(video_codec_name);
-            output_codecs[nb_output_codecs-1] = codec;
+            ost->enc = codec;
         } else {
             codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
             codec = avcodec_find_encoder(codec_id);
@@ -3581,8 +3596,6 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
         video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
         st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
 
-        choose_pixel_fmt(st, codec);
-
         if (intra_only)
             video_enc->gop_size = 0;
         if (video_qscale || same_quality) {
@@ -3669,13 +3682,12 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx)
     }
     ost = new_output_stream(oc, file_idx);
 
-    output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if(!audio_stream_copy){
         if (audio_codec_name) {
             codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1,
                                          avcodec_opts[AVMEDIA_TYPE_AUDIO]->strict_std_compliance);
             codec = avcodec_find_encoder_by_name(audio_codec_name);
-            output_codecs[nb_output_codecs-1] = codec;
+            ost->enc = codec;
         } else {
             codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);
             codec = avcodec_find_encoder(codec_id);
@@ -3741,7 +3753,6 @@ static void new_data_stream(AVFormatContext *oc, int file_idx)
     }
     new_output_stream(oc, file_idx);
     data_enc = st->codec;
-    output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if (!data_stream_copy) {
         fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n");
         ffmpeg_exit(1);
@@ -3781,12 +3792,12 @@ static void new_subtitle_stream(AVFormatContext *oc, int file_idx)
     }
     ost = new_output_stream(oc, file_idx);
     subtitle_enc = st->codec;
-    output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if(!subtitle_stream_copy){
         if (subtitle_codec_name) {
             codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,
                                          avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
-            codec= output_codecs[nb_output_codecs-1] = avcodec_find_encoder_by_name(subtitle_codec_name);
+            codec = avcodec_find_encoder_by_name(subtitle_codec_name);
+            ost->enc = codec;
         } else {
             codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_SUBTITLE);
             codec = avcodec_find_encoder(codec_id);
@@ -3990,6 +4001,8 @@ static int opt_output_file(const char *opt, const char *filename)
     set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
 
     frame_rate    = (AVRational){0, 0};
+    frame_width   = 0;
+    frame_height  = 0;
     audio_sample_rate = 0;
     audio_channels    = 0;
 
@@ -4226,6 +4239,7 @@ static int opt_target(const char *opt, const char *arg)
 
         opt_frame_size("s", norm == PAL ? "480x576" : "480x480");
         opt_frame_rate("r", frame_rates[norm]);
+        opt_frame_pix_fmt("pix_fmt", "yuv420p");
         opt_default("g", norm == PAL ? "15" : "18");
 
         opt_default("b", "2040000");
@@ -4248,6 +4262,7 @@ static int opt_target(const char *opt, const char *arg)
 
         opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480");
         opt_frame_rate("r", frame_rates[norm]);
+        opt_frame_pix_fmt("pix_fmt", "yuv420p");
         opt_default("g", norm == PAL ? "15" : "18");
 
         opt_default("b", "6000000");

Some files were not shown because too many files changed in this diff