OSDN Git Service

Merge remote branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 10 May 2011 02:01:29 +0000 (04:01 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 10 May 2011 02:03:17 +0000 (04:03 +0200)
* qatar/master:
  mpegaudiodec: group #includes more sanely
  mpegaudio: remove #if 0 blocks
  ffmpeg.c: reset avoptions after each input/output file.
  ffmpeg.c: store per-output stream sws flags.
  mpegaudio: remove CONFIG_MPEGAUDIO_HP option
  mpegtsenc: Clear st->priv_data when freeing it
  udp: Fix receiving RTP data over multicast
  rtpproto: Remove an unused variable
  regtest: fix wma tests
NOT pulled:  mpegaudio: remove CONFIG_AUDIO_NONSHORT
  regtest: separate flags for encoding and decoding

Conflicts:
ffmpeg.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
14 files changed:
1  2 
cmdutils.c
configure
ffmpeg.c
libavcodec/Makefile
libavcodec/bfin/mathops.h
libavcodec/mpegaudio.h
libavcodec/mpegaudio_tablegen.h
libavcodec/mpegaudiodec.c
libavcodec/mpegaudioenc.c
libavformat/mpegtsenc.c
libavformat/rtpproto.c
libavformat/udp.c
tests/codec-regression.sh
tests/lavfi-regression.sh

diff --combined cmdutils.c
@@@ -2,20 -2,20 +2,20 @@@
   * Various utilities for command line tools
   * Copyright (c) 2000-2003 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -79,11 -79,16 +79,12 @@@ void uninit_opts(void
      av_freep(&sws_opts);
  #endif
      for (i = 0; i < opt_name_count; i++) {
 -        //opt_values are only stored for codec-specific options in which case
 -        //both the name and value are dup'd
 -        if (opt_values[i]) {
 -            av_freep(&opt_names[i]);
 -            av_freep(&opt_values[i]);
 -        }
 +        av_freep(&opt_names[i]);
 +        av_freep(&opt_values[i]);
      }
      av_freep(&opt_names);
      av_freep(&opt_values);
+     opt_name_count = 0;
  }
  
  void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
@@@ -102,8 -107,6 +103,8 @@@ double parse_number_or_die(const char *
          error= "The value for %s was %s which is not within %f - %f\n";
      else if(type == OPT_INT64 && (int64_t)d != d)
          error= "Expected int64 for %s but found %s\n";
 +    else if (type == OPT_INT && (int)d != d)
 +        error= "Expected int for %s but found %s\n";
      else
          return d;
      fprintf(stderr, error, context, numstr, min, max);
@@@ -276,8 -279,6 +277,8 @@@ unknown_opt
                      fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
                      exit(1);
                  }
 +            } else if (po->flags & OPT_DUMMY) {
 +                /* Do nothing for this option */
              } else {
                  po->u.func_arg(arg);
              }
@@@ -295,31 -296,6 +296,31 @@@ int opt_default(const char *opt, const 
      int ret= 0;
      const AVOption *o= NULL;
      int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
 +    AVCodec *p = NULL;
 +    AVOutputFormat *oformat = NULL;
 +    AVInputFormat *iformat = NULL;
 +
 +    while ((p = av_codec_next(p))) {
 +        AVClass *c = p->priv_class;
 +        if (c && av_find_opt(&c, opt, NULL, 0, 0))
 +            break;
 +    }
 +    if (p)
 +        goto out;
 +    while ((oformat = av_oformat_next(oformat))) {
 +        const AVClass *c = oformat->priv_class;
 +        if (c && av_find_opt(&c, opt, NULL, 0, 0))
 +            break;
 +    }
 +    if (oformat)
 +        goto out;
 +    while ((iformat = av_iformat_next(iformat))) {
 +        const AVClass *c = iformat->priv_class;
 +        if (c && av_find_opt(&c, opt, NULL, 0, 0))
 +            break;
 +    }
 +    if (iformat)
 +        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]);
              ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o);
          else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE])
              ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o);
 +        if (ret >= 0)
 +            opt += 1;
      }
      if (o && ret < 0) {
          fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt);
          exit(1);
      }
      if (!o) {
 -        AVCodec *p = NULL;
 -        AVOutputFormat *oformat = NULL;
 -        while ((p=av_codec_next(p))){
 -            AVClass *c= p->priv_class;
 -            if(c && av_find_opt(&c, opt, NULL, 0, 0))
 -                break;
 -        }
 -        if (!p) {
 -            while ((oformat = av_oformat_next(oformat))) {
 -                const AVClass *c = oformat->priv_class;
 -                if (c && av_find_opt(&c, opt, NULL, 0, 0))
 -                    break;
 -            }
 -        }
 -        if(!p && !oformat){
 -            fprintf(stderr, "Unrecognized option '%s'\n", opt);
 -            exit(1);
 -        }
 +        fprintf(stderr, "Unrecognized option '%s'\n", opt);
 +        exit(1);
      }
  
 + out:
  //    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));
  
 -    //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this
      opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
 -    opt_values[opt_name_count]= o ? NULL : av_strdup(arg);
 +    opt_values[opt_name_count] = av_strdup(arg);
      opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
 -    opt_names[opt_name_count++]= o ? o->name : av_strdup(opt);
 +    opt_names[opt_name_count++] = av_strdup(opt);
  
      if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug))
          av_log_set_level(AV_LOG_DEBUG);
@@@ -423,30 -413,21 +424,30 @@@ void set_context_opts(void *ctx, void *
          AVFormatContext *avctx = ctx;
          if (avctx->oformat && avctx->oformat->priv_class) {
              priv_ctx = avctx->priv_data;
 +        } else if (avctx->iformat && avctx->iformat->priv_class) {
 +            priv_ctx = avctx->priv_data;
          }
      }
  
      for(i=0; i<opt_name_count; i++){
          char buf[256];
          const AVOption *opt;
 -        const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
 -        /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
 -        if(str && ((opt->flags & flags) == flags))
 -            av_set_string3(ctx, opt_names[i], str, 1, NULL);
 -        /* We need to use a differnt system to pass options to the private context because
 -           it is not known which codec and thus context kind that will be when parsing options
 -           we thus use opt_values directly instead of opts_ctx */
 -        if(!str && priv_ctx && av_get_string(priv_ctx, opt_names[i], &opt, buf, sizeof(buf))){
 -            av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL);
 +        const char *str;
 +        if (priv_ctx) {
 +            if (av_find_opt(priv_ctx, opt_names[i], NULL, flags, flags)) {
 +                if (av_set_string3(priv_ctx, opt_names[i], opt_values[i], 0, NULL) < 0) {
 +                    fprintf(stderr, "Invalid value '%s' for option '%s'\n",
 +                            opt_names[i], opt_values[i]);
 +                    exit(1);
 +                }
 +            } else
 +                goto global;
 +        } else {
 +        global:
 +            str = av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
 +            /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
 +            if (str && ((opt->flags & flags) == flags))
 +                av_set_string3(ctx, opt_names[i], str, 1, NULL);
          }
      }
  }
@@@ -481,7 -462,7 +482,7 @@@ static int warned_cfg = 0
          }                                                               \
          if (flags & SHOW_CONFIG) {                                      \
              const char *cfg = libname##_configuration();                \
 -            if (strcmp(LIBAV_CONFIGURATION, cfg)) {                     \
 +            if (strcmp(FFMPEG_CONFIGURATION, cfg)) {                    \
                  if (!warned_cfg) {                                      \
                      fprintf(outstream,                                  \
                              "%sWARNING: library configuration mismatch\n", \
@@@ -507,17 -488,17 +508,17 @@@ static void print_all_libs_info(FILE* o
  
  void show_banner(void)
  {
 -    fprintf(stderr, "%s version " LIBAV_VERSION ", Copyright (c) %d-%d the Libav developers\n",
 +    fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
              program_name, program_birth_year, this_year);
      fprintf(stderr, "  built on %s %s with %s %s\n",
              __DATE__, __TIME__, CC_TYPE, CC_VERSION);
 -    fprintf(stderr, "  configuration: " LIBAV_CONFIGURATION "\n");
 +    fprintf(stderr, "  configuration: " FFMPEG_CONFIGURATION "\n");
      print_all_libs_info(stderr, INDENT|SHOW_CONFIG);
      print_all_libs_info(stderr, INDENT|SHOW_VERSION);
  }
  
  void show_version(void) {
 -    printf("%s " LIBAV_VERSION "\n", program_name);
 +    printf("%s " FFMPEG_VERSION "\n", program_name);
      print_all_libs_info(stdout, SHOW_VERSION);
  }
  
@@@ -590,6 -571,16 +591,6 @@@ void show_license(void
      );
  }
  
 -void list_fmts(void (*get_fmt_string)(char *buf, int buf_size, int fmt), int nb_fmts)
 -{
 -    int i;
 -    char fmt_str[128];
 -    for (i=-1; i < nb_fmts; i++) {
 -        get_fmt_string (fmt_str, sizeof(fmt_str), i);
 -        fprintf(stdout, "%s\n", fmt_str);
 -    }
 -}
 -
  void show_formats(void)
  {
      AVInputFormat *ifmt=NULL;
@@@ -727,20 -718,16 +728,20 @@@ void show_bsfs(void
  
  void show_protocols(void)
  {
 -    void *opaque = NULL;
 -    const char *name;
 +    URLProtocol *up=NULL;
  
      printf("Supported file protocols:\n"
 -           "Input:\n");
 -    while ((name = avio_enum_protocols(&opaque, 0)))
 -        printf("%s\n", name);
 -    printf("Output:\n");
 -    while ((name = avio_enum_protocols(&opaque, 1)))
 -        printf("%s\n", name);
 +           "I.. = Input  supported\n"
 +           ".O. = Output supported\n"
 +           "..S = Seek   supported\n"
 +           "FLAGS NAME\n"
 +           "----- \n");
 +    while((up = av_protocol_next(up)))
 +        printf("%c%c%c   %s\n",
 +               up->url_read  ? 'I' : '.',
 +               up->url_write ? 'O' : '.',
 +               up->url_seek  ? 'S' : '.',
 +               up->name);
  }
  
  void show_filters(void)
@@@ -822,6 -809,33 +823,6 @@@ int read_file(const char *filename, cha
      return 0;
  }
  
 -void init_pts_correction(PtsCorrectionContext *ctx)
 -{
 -    ctx->num_faulty_pts = ctx->num_faulty_dts = 0;
 -    ctx->last_pts = ctx->last_dts = INT64_MIN;
 -}
 -
 -int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
 -{
 -    int64_t pts = AV_NOPTS_VALUE;
 -
 -    if (dts != AV_NOPTS_VALUE) {
 -        ctx->num_faulty_dts += dts <= ctx->last_dts;
 -        ctx->last_dts = dts;
 -    }
 -    if (reordered_pts != AV_NOPTS_VALUE) {
 -        ctx->num_faulty_pts += reordered_pts <= ctx->last_pts;
 -        ctx->last_pts = reordered_pts;
 -    }
 -    if ((ctx->num_faulty_pts<=ctx->num_faulty_dts || dts == AV_NOPTS_VALUE)
 -       && reordered_pts != AV_NOPTS_VALUE)
 -        pts = reordered_pts;
 -    else
 -        pts = dts;
 -
 -    return pts;
 -}
 -
  FILE *get_preset_file(char *filename, size_t filename_size,
                        const char *preset_name, int is_path, const char *codec_name)
  {
@@@ -907,12 -921,10 +908,12 @@@ int get_filtered_video_frame(AVFilterCo
  
      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;
  }
diff --combined configure
+++ b/configure
@@@ -1,6 -1,6 +1,6 @@@
  #!/bin/sh
  #
 -# Libav configure script
 +# FFmpeg configure script
  #
  # Copyright (c) 2000-2002 Fabrice Bellard
  # Copyright (c) 2005-2008 Diego Biurrun
@@@ -44,9 -44,9 +44,9 @@@ if test "$E1" != 0 || test "$E2" = 0; t
      echo "No compatible shell script interpreter found."
      echo "This configure script requires a POSIX-compatible shell"
      echo "such as bash or ksh."
 -    echo "THIS IS NOT A BUG IN LIBAV, DO NOT REPORT IT AS SUCH."
 +    echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
      echo "Instead, install a working POSIX-compatible shell."
 -    echo "Disabling this configure test will create a broken Libav."
 +    echo "Disabling this configure test will create a broken FFmpeg."
      if test "$BASH_VERSION" = '2.04.0(1)-release'; then
          echo "This bash version ($BASH_VERSION) is broken on your platform."
          echo "Upgrade to a later version if available."
@@@ -94,7 -94,6 +94,6 @@@ Configuration options
    --enable-w32threads      use Win32 threads [no]
    --enable-x11grab         enable X11 grabbing [no]
    --disable-network        disable network support [no]
-   --disable-mpegaudio-hp   faster (but less accurate) MPEG audio decoding [no]
    --enable-gray            enable full grayscale support (slower color)
    --disable-swscale-alpha  disable alpha channel support in swscale
    --disable-fastdiv        disable table-based division
  External library support:
    --enable-avisynth        enable reading of AVISynth script files [no]
    --enable-bzlib           enable bzlib [autodetect]
 +  --enable-libcelt         enable CELT/Opus decoding via libcelt [no]
    --enable-frei0r          enable frei0r video filtering
    --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
    --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
@@@ -241,12 -239,11 +240,12 @@@ Advanced options (experts only)
    --enable-sram            allow use of on-chip SRAM
    --disable-symver         disable symbol versioning
  
 -Developer options (useful when working on Libav itself):
 +Developer options (useful when working on FFmpeg itself):
    --disable-debug          disable debugging symbols
    --enable-debug=LEVEL     set the debug level [$debuglevel]
    --disable-optimizations  disable compiler optimizations
    --enable-extra-warnings  enable more compiler warnings
 +  --disable-stripping      disable stripping of executables and shared libraries
    --samples=PATH           location of test samples for FATE, if not set use
                             \$FATE_SAMPLES at make invocation time.
  
@@@ -283,7 -280,7 +282,7 @@@ die()
  
  If you think configure made a mistake, make sure you are using the latest
  version from Git.  If the latest version fails, report the problem to the
 -libav-user@libav.org mailing list or IRC #libav on irc.freenode.net.
 +ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
  EOF
      if disabled logging; then
          cat <<EOF
@@@ -761,7 -758,7 +760,7 @@@ check_pkg_config()
      headers="$2"
      funcs="$3"
      shift 3
 -    $pkg_config --exists $pkg || return
 +    $pkg_config --exists $pkg 2>/dev/null || return
      pkg_cflags=$($pkg_config --cflags $pkg)
      pkg_libs=$($pkg_config --libs $pkg)
      check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
@@@ -910,7 -907,6 +909,7 @@@ CONFIG_LIST=
      avformat
      avisynth
      bzlib
 +    crystalhd
      dct
      doc
      dwt
      h264pred
      hardcoded_tables
      huffman
 +    libcelt
      libdc1394
      libdirac
      libfaac
      mdct
      memalign_hack
      mlib
-     mpegaudio_hp
      network
      nonfree
      pic
@@@ -1125,7 -1119,6 +1123,7 @@@ HAVE_LIST=
      sys_soundcard_h
      sys_videoio_h
      ten_operands
 +    termios_h
      threads
      trunc
      truncf
@@@ -1154,7 -1147,6 +1152,7 @@@ CMDLINE_SELECT=
      extra_warnings
      logging
      optimizations
 +    stripping
      symver
      yasm
  "
@@@ -1192,7 -1184,6 +1190,7 @@@ CMDLINE_SET=
      pkg_config
      samples
      source_path
 +    strip
      sysinclude
      sysroot
      target_exec
@@@ -1275,7 -1266,6 +1273,7 @@@ flac_decoder_select="golomb
  flac_encoder_select="golomb lpc"
  flashsv_decoder_select="zlib"
  flashsv_encoder_select="zlib"
 +flashsv2_encoder_select="zlib"
  flv_decoder_select="h263_decoder"
  flv_encoder_select="h263_encoder"
  fraps_decoder_select="huffman"
@@@ -1286,7 -1276,6 +1284,7 @@@ h263_vaapi_hwaccel_select="vaapi h263_d
  h263i_decoder_select="h263_decoder"
  h263p_encoder_select="h263_encoder"
  h264_decoder_select="golomb h264dsp h264pred"
 +h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
  h264_dxva2_hwaccel_deps="dxva2api_h"
  h264_dxva2_hwaccel_select="dxva2 h264_decoder"
  h264_vaapi_hwaccel_select="vaapi"
@@@ -1309,18 -1298,13 +1307,18 @@@ mpeg4_decoder_select="h263_decoder mpeg
  mpeg4_encoder_select="h263_encoder"
  mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
  mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
 +mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder"
 +mpeg2_crystalhd_decoder_select="crystalhd"
  mpeg2_dxva2_hwaccel_deps="dxva2api_h"
  mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
 +mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
  mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
 +mpeg4_crystalhd_decoder_select="crystalhd"
  mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
  mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
  mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
  mpeg_xvmc_decoder_select="mpegvideo_decoder"
 +msmpeg4_crystalhd_decoder_select="crystalhd"
  msmpeg4v1_decoder_select="h263_decoder"
  msmpeg4v1_encoder_select="h263_encoder"
  msmpeg4v2_decoder_select="h263_decoder"
@@@ -1344,9 -1328,6 +1342,9 @@@ shorten_decoder_select="golomb
  sipr_decoder_select="lsp"
  snow_decoder_select="dwt"
  snow_encoder_select="aandct dwt"
 +sonic_decoder_select="golomb"
 +sonic_encoder_select="golomb"
 +sonic_ls_encoder_select="golomb"
  svq1_encoder_select="aandct"
  svq3_decoder_select="golomb h264dsp h264pred"
  svq3_decoder_suggest="zlib"
@@@ -1357,7 -1338,6 +1355,7 @@@ truehd_decoder_select="mlp_decoder
  tscc_decoder_select="zlib"
  twinvq_decoder_select="mdct lsp sinewin"
  vc1_decoder_select="h263_decoder"
 +vc1_crystalhd_decoder_select="crystalhd"
  vc1_dxva2_hwaccel_deps="dxva2api_h DXVA_PictureParameters_wDecodedPictureIndex"
  vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
  vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
@@@ -1379,7 -1359,6 +1377,7 @@@ wmv1_encoder_select="h263_encoder
  wmv2_decoder_select="h263_decoder"
  wmv2_encoder_select="h263_encoder"
  wmv3_decoder_select="vc1_decoder"
 +wmv3_crystalhd_decoder_select="crystalhd"
  wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
  wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
  wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
@@@ -1388,7 -1367,6 +1386,7 @@@ zlib_encoder_select="zlib
  zmbv_decoder_select="zlib"
  zmbv_encoder_select="zlib"
  
 +crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
  vaapi_deps="va_va_h"
  vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
  
  h264_parser_select="golomb h264dsp h264pred"
  
  # external libraries
 +libcelt_decoder_deps="libcelt"
  libdirac_decoder_deps="libdirac !libschroedinger"
  libdirac_encoder_deps="libdirac"
  libfaac_encoder_deps="libfaac"
@@@ -1459,7 -1436,7 +1457,7 @@@ alsa_outdev_deps="alsa_asoundlib_h
  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
  dv1394_indev_deps="dv1394 dv_demuxer"
  fbdev_indev_deps="linux_fb_h"
 -jack_indev_deps="jack_jack_h"
 +jack_indev_deps="jack_jack_h sem_timedwait"
  libdc1394_indev_deps="libdc1394"
  oss_indev_deps_any="soundcard_h sys_soundcard_h"
  oss_outdev_deps_any="soundcard_h sys_soundcard_h"
@@@ -1490,10 -1467,8 +1488,10 @@@ drawtext_filter_deps="libfreetype
  frei0r_filter_deps="frei0r dlopen strtok_r"
  frei0r_src_filter_deps="frei0r dlopen strtok_r"
  hqdn3d_filter_deps="gpl"
 -scale_filter_deps="swscale"
 +movie_filter_deps="avcodec avformat"
 +mp_filter_deps="gpl avcodec"
  ocv_filter_deps="libopencv"
 +scale_filter_deps="swscale"
  yadif_filter_deps="gpl"
  
  # libraries
@@@ -1639,7 -1614,6 +1637,7 @@@ nm_default="nm
  objformat="elf"
  pkg_config_default=pkg-config
  ranlib="ranlib"
 +strip_default="strip"
  yasmexe="yasm"
  nogas=":"
  
@@@ -1667,12 -1641,10 +1665,11 @@@ enable ffmpe
  enable ffplay
  enable ffprobe
  enable ffserver
- enable mpegaudio_hp
  enable network
  enable optimizations
  enable protocols
  enable static
 +enable stripping
  enable swscale
  enable swscale_alpha
  
@@@ -1720,7 -1692,7 +1717,7 @@@ for v in "$@"; d
      r=${v#*=}
      l=${v%"$r"}
      r=$(sh_quote "$r")
 -    LIBAV_CONFIGURATION="${LIBAV_CONFIGURATION# } ${l}${r}"
 +    FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
  done
  
  find_things(){
@@@ -1832,7 -1804,7 +1829,7 @@@ don
  
  disabled logging && logfile=/dev/null
  
 -echo "# $0 $LIBAV_CONFIGURATION" > $logfile
 +echo "# $0 $FFMPEG_CONFIGURATION" > $logfile
  set >> $logfile
  
  test -n "$cross_prefix" && enable cross_compile
@@@ -1849,11 -1821,10 +1846,11 @@@ cc_default="${cross_prefix}${cc_default
  nm_default="${cross_prefix}${nm_default}"
  pkg_config_default="${cross_prefix}${pkg_config_default}"
  ranlib="${cross_prefix}${ranlib}"
 +strip_default="${cross_prefix}${strip_default}"
  
  sysinclude_default="${sysroot}/usr/include"
  
 -set_default cc nm pkg_config sysinclude
 +set_default cc nm pkg_config strip sysinclude
  enabled cross_compile || host_cc_default=$cc
  set_default host_cc
  
@@@ -2398,7 -2369,7 +2395,7 @@@ case $target_os i
      openbsd)
          enable malloc_aligned
          # On OpenBSD 4.5. the compiler does not use PIC unless
 -        # explicitly using -fPIC. Libav builds fine without PIC,
 +        # explicitly using -fPIC. FFmpeg builds fine without PIC,
          # however the generated executable will not do anything
          # (simply quits with exit-code 1, no crash, no output).
          # Thus explicitly enable PIC here.
          ;;
      bsd/os)
          add_extralibs -lpoll -lgnugetopt
 +        strip="strip -d"
          ;;
      darwin)
          enable malloc_aligned
          enabled ppc && add_asflags -force_cpusubtype_ALL
          SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
          enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
 +        strip="${strip} -x"
          add_ldflags -Wl,-dynamic,-search_paths_first
          SLIBSUF=".dylib"
          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
          LIBTARGET=i386
          if enabled x86_64; then
              enable malloc_aligned
 -            LIBTARGET="i386:x86-64"
 +            LIBTARGET=x64
          elif enabled arm; then
              LIBTARGET=arm-wince
          fi
          SLIBSUF=".dll"
          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
          SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
 -        SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
 +        SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)'
          SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"; \
              install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"; \
              install -d "$(LIBDIR)"; \
          SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"'
          SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
          objformat="win32"
 -        dlltool="${cross_prefix}dlltool"
          enable dos_paths
          check_cflags -fno-common
          check_cpp_condition _mingw.h "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) \
          ranlib="echo ignoring ranlib"
          ;;
      os/2*)
 +        strip="lxlite -CS"
          ln_s="cp -f"
          add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap
          SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
          ;;
  esac
  
 -echo "config:$arch:$subarch:$cpu:$target_os:$cc_ident:$LIBAV_CONFIGURATION" >config.fate
 +echo "config:$arch:$subarch:$cpu:$target_os:$cc_ident:$FFMPEG_CONFIGURATION" >config.fate
  
  check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic
  
@@@ -2832,13 -2801,11 +2829,13 @@@ check_func_headers windows.h VirtualAll
  
  check_header dlfcn.h
  check_header dxva2api.h
 +check_header libcrystalhd/libcrystalhd_if.h
  check_header malloc.h
  check_header poll.h
  check_header sys/mman.h
  check_header sys/resource.h
  check_header sys/select.h
 +check_header termios.h
  check_header vdpau/vdpau.h
  check_header vdpau/vdpau_x11.h
  check_header X11/extensions/XvMClib.h
@@@ -2881,7 -2848,6 +2878,7 @@@ for thread in $THREADS_LIST; d
  done
  
  check_lib math.h sin -lm && LIBM="-lm"
 +disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersion -lcrystalhd || disable crystalhd
  enabled vaapi && require vaapi va/va.h vaInitialize -lva
  
  check_mathfunc exp2
@@@ -2899,7 -2865,6 +2896,7 @@@ check_mathfunc trunc
  
  # these are off by default, so fail if requested and not available
  enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32
 +enabled libcelt    && require libcelt celt/celt.h celt_decode -lcelt0
  enabled frei0r     && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
  enabled libdirac   && require_pkg_config dirac                          \
      "libdirac_decoder/dirac_parser.h libdirac_encoder/dirac_encoder.h"  \
@@@ -2923,8 -2888,8 +2920,8 @@@ enabled libvorbis  && require  libvorbi
  enabled libvpx     && {
      enabled libvpx_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
                                  die "ERROR: libvpx decoder version must be >=0.9.1"; }
 -    enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_enc_init_ver -lvpx ||
 -                                die "ERROR: libvpx encoder version must be >=0.9.1"; } }
 +    enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx ||
 +                                die "ERROR: libvpx encoder version must be >=0.9.6"; } }
  enabled libx264    && require  libx264 x264.h x264_encoder_encode -lx264 &&
                        { check_cpp_condition x264.h "X264_BUILD >= 99" ||
                          die "ERROR: libx264 version must be >= 0.99."; }
@@@ -2941,11 -2906,7 +2938,11 @@@ if enabled libdc1394; the
      die "ERROR: No version of libdc1394 found "
  fi
  
 -if check_pkg_config sdl SDL_version.h SDL_Linked_Version; then
 +SDL_CONFIG="${cross_prefix}sdl-config"
 +if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
 +    sdl_cflags=$("${SDL_CONFIG}" --cflags)
 +    sdl_libs=$("${SDL_CONFIG}" --libs)
 +    check_func_headers SDL.h SDL_Init $sdl_cflags $sdl_libs &&
      check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
      enable sdl &&
      check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size
@@@ -2973,19 -2934,12 +2970,19 @@@ check_cpp_condition vfw.h "WM_CAP_DRIVE
  check_header dev/ic/bt8xx.h
  
  check_header sndio.h
 -check_header sys/soundcard.h
 +if check_struct sys/soundcard.h audio_buf_info bytes; then
 +    enable_safe sys/soundcard.h
 +else
 +    check_cc -D__BSD_VISIBLE -D__XSI_VISIBLE <<EOF && add_cppflags -D__BSD_VISIBLE -D__XSI_VISIBLE && enable_safe sys/soundcard.h
 +    #include <sys/soundcard.h>
 +    audio_buf_info abc;
 +EOF
 +fi
  check_header soundcard.h
  
  enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
  
 -enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack
 +enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait
  
  enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
  
@@@ -2997,13 -2951,6 +2994,13 @@@ check_func XOpenDisplay -lX1
  check_func XShmCreateImage -lX11 -lXext &&
  check_func XFixesGetCursorImage -lX11 -lXext -lXfixes
  
 +if ! disabled vaapi; then
 +    check_lib va/va.h vaInitialize -lva && {
 +        check_cpp_condition va/va_version.h "VA_CHECK_VERSION(0,32,0)" ||
 +        warn "Please upgrade to VA-API >= 0.32 if you would like full VA-API support.";
 +    } || disable vaapi
 +fi
 +
  if ! disabled vdpau && enabled vdpau_vdpau_h; then
  check_cpp_condition \
      vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
@@@ -3027,7 -2974,6 +3024,7 @@@ check_cflags -Wwrite-string
  check_cflags -Wtype-limits
  check_cflags -Wundef
  check_cflags -Wmissing-prototypes
 +check_cflags -Wno-pointer-to-int-cast
  enabled extra_warnings && check_cflags -Winline
  
  # add some linker flags
@@@ -3180,7 -3126,6 +3177,7 @@@ if enabled sparc; the
      echo "VIS enabled               ${vis-no}"
  fi
  echo "debug symbols             ${debug-no}"
 +echo "strip symbols             ${stripping-no}"
  echo "optimizations             ${optimizations-no}"
  echo "static                    ${static-no}"
  echo "shared                    ${shared-no}"
@@@ -3191,7 -3136,6 +3188,7 @@@ echo "threading support         ${threa
  echo "SDL support               ${sdl-no}"
  echo "Sun medialib support      ${mlib-no}"
  echo "AVISynth enabled          ${avisynth-no}"
 +echo "libcelt enabled           ${libcelt-no}"
  echo "frei0r enabled            ${frei0r-no}"
  echo "libdc1394 support         ${libdc1394-no}"
  echo "libdirac enabled          ${libdirac-no}"
@@@ -3250,8 -3194,6 +3247,8 @@@ if enabled source_path_used; the
          libavdevice
          libavfilter
          libavfilter/$arch
 +        libavfilter/libmpcodecs
 +        libavfilter/libmpcodecs/libvo
          libavformat
          libavutil
          libavutil/$arch
      map 'test -f "$source_path/$v" && $ln_s "$source_path/$v" $v' $FILES
  fi
  
 +enabled stripping || strip="echo skipping strip"
 +
  config_files="$TMPH config.mak"
  
  cat > config.mak <<EOF
  # Automatically generated by configure - do not modify!
 -ifndef LIBAV_CONFIG_MAK
 -LIBAV_CONFIG_MAK=1
 -LIBAV_CONFIGURATION=$LIBAV_CONFIGURATION
 +ifndef FFMPEG_CONFIG_MAK
 +FFMPEG_CONFIG_MAK=1
 +FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION
  prefix=$prefix
  LIBDIR=\$(DESTDIR)$libdir
  SHLIBDIR=\$(DESTDIR)$shlibdir
@@@ -3309,13 -3249,12 +3306,13 @@@ YASM=$yasmex
  YASMDEP=$yasmexe
  AR=$ar
  RANLIB=$ranlib
 +CP=cp -p
  LN_S=$ln_s
 +STRIP=$strip
  CPPFLAGS=$CPPFLAGS
  CFLAGS=$CFLAGS
  ASFLAGS=$ASFLAGS
  CC_O=$CC_O
 -DLLTOOL=$dlltool
  LDFLAGS=$LDFLAGS
  FFSERVERLDFLAGS=$FFSERVERLDFLAGS
  SHFLAGS=$SHFLAGS
@@@ -3377,10 -3316,10 +3374,10 @@@ get_version LIBAVFILTER libavfilter/avf
  
  cat > $TMPH <<EOF
  /* Automatically generated by configure - do not modify! */
 -#ifndef LIBAV_CONFIG_H
 -#define LIBAV_CONFIG_H
 -#define LIBAV_CONFIGURATION "$(c_escape $LIBAV_CONFIGURATION)"
 -#define LIBAV_LICENSE "$(c_escape $license)"
 +#ifndef FFMPEG_CONFIG_H
 +#define FFMPEG_CONFIG_H
 +#define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
 +#define FFMPEG_LICENSE "$(c_escape $license)"
  #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
  #define CC_TYPE "$cc_type"
  #define CC_VERSION $cc_version
@@@ -3431,8 -3370,8 +3428,8 @@@ LAVFI_TESTS=$(print_enabled  -n _test $
  SEEK_TESTS=$(print_enabled   -n _test $SEEK_TESTS)
  EOF
  
 -echo "#endif /* LIBAV_CONFIG_H */" >> $TMPH
 -echo "endif # LIBAV_CONFIG_MAK" >> config.mak
 +echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
 +echo "endif # FFMPEG_CONFIG_MAK" >> config.mak
  
  # Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
  cp_if_changed $TMPH config.h
@@@ -3496,10 -3435,10 +3493,10 @@@ Cflags: -I\${includedir
  EOF
  }
  
 -pkgconfig_generate libavutil "Libav utility library" "$LIBAVUTIL_VERSION" "$LIBM"
 -pkgconfig_generate libavcodec "Libav codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
 -pkgconfig_generate libavformat "Libav container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
 -pkgconfig_generate libavdevice "Libav device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
 -pkgconfig_generate libavfilter "Libav video filtering library" "$LIBAVFILTER_VERSION" "$extralibs"
 -pkgconfig_generate libpostproc "Libav post processing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"
 -pkgconfig_generate libswscale "Libav image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" "$LIBM"
 +pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
 +pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
 +pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs"
 +pkgconfig_generate libpostproc "FFmpeg post processing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"
diff --combined ffmpeg.c
+++ b/ffmpeg.c
@@@ -2,20 -2,20 +2,20 @@@
   * ffmpeg main
   * Copyright (c) 2000-2003 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #include "libavutil/libm.h"
  #include "libavformat/os_support.h"
  
 +#include "libavformat/ffm.h" // not public API
 +
  #if CONFIG_AVFILTER
 +# include "libavfilter/avcodec.h"
  # include "libavfilter/avfilter.h"
  # include "libavfilter/avfiltergraph.h"
  # include "libavfilter/vsrc_buffer.h"
  #include <sys/select.h>
  #endif
  
 -#if HAVE_KBHIT
 +#if HAVE_TERMIOS_H
 +#include <fcntl.h>
 +#include <sys/ioctl.h>
 +#include <sys/time.h>
 +#include <termios.h>
 +#elif HAVE_KBHIT
  #include <conio.h>
  #endif
  #include <time.h>
@@@ -116,6 -108,8 +116,6 @@@ static const OptionDef options[]
  #define MAX_FILES 100
  #define MAX_STREAMS 1024    /* arbitrary sanity check value */
  
 -#define FFM_PACKET_SIZE 4096 //XXX a duplicate of the line in ffm.h
 -
  static const char *last_asked_format = NULL;
  static AVFormatContext *input_files[MAX_FILES];
  static int64_t input_files_ts_offset[MAX_FILES];
@@@ -151,7 -145,6 +151,7 @@@ static int frame_width  = 0
  static int frame_height = 0;
  static float frame_aspect_ratio = 0;
  static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
 +static int frame_bits_per_raw_sample = 0;
  static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE;
  static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
  static AVRational frame_rate;
@@@ -174,8 -167,7 +174,8 @@@ static int loop_output = AVFMT_NOOUTPUT
  static int qp_hist = 0;
  #if CONFIG_AVFILTER
  static char *vfilters = NULL;
 -static AVFilterGraph *graph = NULL;
 +#else
 +static unsigned int sws_flags = SWS_BICUBIC;
  #endif
  
  static int intra_only = 0;
@@@ -212,7 -204,7 +212,7 @@@ static int do_hex_dump = 0
  static int do_pkt_dump = 0;
  static int do_psnr = 0;
  static int do_pass = 0;
 -static char *pass_logfilename_prefix = NULL;
 +static const char *pass_logfilename_prefix;
  static int audio_stream_copy = 0;
  static int video_stream_copy = 0;
  static int subtitle_stream_copy = 0;
@@@ -239,7 -231,6 +239,7 @@@ static int audio_volume = 256
  static int exit_on_error = 0;
  static int using_stdin = 0;
  static int verbose = 1;
 +static int run_as_daemon  = 0;
  static int thread_count= 1;
  static int q_pressed = 0;
  static int64_t video_size = 0;
@@@ -285,13 -276,15 +285,13 @@@ typedef struct AVOutputStream 
      AVBitStreamFilterContext *bitstream_filters;
      /* video only */
      int video_resample;
 -    AVFrame pict_tmp;      /* temporary image for resampling */
 +    AVFrame resample_frame;              /* temporary frame for image resampling */
      struct SwsContext *img_resample_ctx; /* for image resampling */
      int resample_height;
      int resample_width;
      int resample_pix_fmt;
  
 -    /* full frame size of first frame */
 -    int original_height;
 -    int original_width;
 +    float frame_aspect_ratio;
  
      /* forced key frames */
      int64_t *forced_kf_pts;
      AVFifoBuffer *fifo;     /* for compression: one audio fifo per codec */
      FILE *logfile;
  
 +#if CONFIG_AVFILTER
 +    AVFilterContext *output_video_filter;
 +    AVFilterContext *input_video_filter;
 +    AVFilterBufferRef *picref;
 +    char *avfilter;
 +    AVFilterGraph *graph;
 +#endif
++
+    int sws_flags;
  } AVOutputStream;
  
  static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL };
@@@ -333,12 -320,16 +335,12 @@@ typedef struct AVInputStream 
      int64_t       next_pts;  /* synthetic pts for cases where pkt.pts
                                  is not defined */
      int64_t       pts;       /* current pts */
 -    PtsCorrectionContext pts_ctx;
      int is_start;            /* is 1 at the start and after a discontinuity */
      int showed_multi_packet_warning;
      int is_past_recording_time;
  #if CONFIG_AVFILTER
 -    AVFilterContext *output_video_filter;
 -    AVFilterContext *input_video_filter;
      AVFrame *filter_frame;
      int has_filter_frame;
 -    AVFilterBufferRef *picref;
  #endif
  } AVInputStream;
  
@@@ -349,15 -340,9 +351,15 @@@ typedef struct AVInputFile 
      int nb_streams;       /* nb streams we are aware of */
  } AVInputFile;
  
 +#if HAVE_TERMIOS_H
 +
 +/* init terminal so that we can grab keys */
 +static struct termios oldtty;
 +#endif
 +
  #if CONFIG_AVFILTER
  
 -static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
 +static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
  {
      AVFilterContext *last_filter, *filter;
      /** filter graph containing all filters including input & output */
      char args[255];
      int ret;
  
 -    graph = avfilter_graph_alloc();
 +    ost->graph = avfilter_graph_alloc();
  
      if (ist->st->sample_aspect_ratio.num){
          sample_aspect_ratio = ist->st->sample_aspect_ratio;
               ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
               sample_aspect_ratio.num, sample_aspect_ratio.den);
  
 -    ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"),
 -                                       "src", args, NULL, graph);
 +    ret = avfilter_graph_create_filter(&ost->input_video_filter, avfilter_get_by_name("buffer"),
 +                                       "src", args, NULL, ost->graph);
      if (ret < 0)
          return ret;
 -    ret = avfilter_graph_create_filter(&ist->output_video_filter, &ffsink,
 -                                       "out", NULL, &ffsink_ctx, graph);
 +    ret = avfilter_graph_create_filter(&ost->output_video_filter, &ffsink,
 +                                       "out", NULL, &ffsink_ctx, ost->graph);
      if (ret < 0)
          return ret;
 -    last_filter = ist->input_video_filter;
 +    last_filter = ost->input_video_filter;
  
      if (codec->width  != icodec->width || codec->height != icodec->height) {
          snprintf(args, 255, "%d:%d:flags=0x%X",
                   codec->width,
                   codec->height,
-                  (int)av_get_int(sws_opts, "sws_flags", NULL));
+                  ost->sws_flags);
          if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
 -                                                NULL, args, NULL, graph)) < 0)
 +                                                NULL, args, NULL, ost->graph)) < 0)
              return ret;
          if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0)
              return ret;
          last_filter = filter;
      }
  
-     snprintf(args, sizeof(args), "flags=0x%X", (int)av_get_int(sws_opts, "sws_flags", NULL));
+     snprintf(args, sizeof(args), "flags=0x%X", ost->sws_flags);
 -    graph->scale_sws_opts = av_strdup(args);
 +    ost->graph->scale_sws_opts = av_strdup(args);
  
 -    if (vfilters) {
 +    if (ost->avfilter) {
          AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
          AVFilterInOut *inputs  = av_malloc(sizeof(AVFilterInOut));
  
          outputs->next    = NULL;
  
          inputs->name    = av_strdup("out");
 -        inputs->filter_ctx = ist->output_video_filter;
 +        inputs->filter_ctx = ost->output_video_filter;
          inputs->pad_idx = 0;
          inputs->next    = NULL;
  
 -        if ((ret = avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL)) < 0)
 +        if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, inputs, outputs, NULL)) < 0)
              return ret;
 -        av_freep(&vfilters);
 +        av_freep(&ost->avfilter);
      } else {
 -        if ((ret = avfilter_link(last_filter, 0, ist->output_video_filter, 0)) < 0)
 +        if ((ret = avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0)
              return ret;
      }
  
 -    if ((ret = avfilter_graph_config(graph, NULL)) < 0)
 +    if ((ret = avfilter_graph_config(ost->graph, NULL)) < 0)
          return ret;
  
 -    codec->width  = ist->output_video_filter->inputs[0]->w;
 -    codec->height = ist->output_video_filter->inputs[0]->h;
 +    codec->width  = ost->output_video_filter->inputs[0]->w;
 +    codec->height = ost->output_video_filter->inputs[0]->h;
      codec->sample_aspect_ratio = ost->st->sample_aspect_ratio =
 -        ist->output_video_filter->inputs[0]->sample_aspect_ratio;
 +        ost->frame_aspect_ratio ? // overriden by the -aspect cli option
 +        av_d2q(ost->frame_aspect_ratio*codec->height/codec->width, 255) :
 +        ost->output_video_filter->inputs[0]->sample_aspect_ratio;
  
      return 0;
  }
  static void term_exit(void)
  {
      av_log(NULL, AV_LOG_QUIET, "");
 +#if HAVE_TERMIOS_H
 +    if(!run_as_daemon)
 +        tcsetattr (0, TCSANOW, &oldtty);
 +#endif
  }
  
  static volatile int received_sigterm = 0;
@@@ -456,34 -435,11 +458,34 @@@ static voi
  sigterm_handler(int sig)
  {
      received_sigterm = sig;
 +    q_pressed++;
      term_exit();
  }
  
  static void term_init(void)
  {
 +#if HAVE_TERMIOS_H
 +    if(!run_as_daemon){
 +    struct termios tty;
 +
 +    tcgetattr (0, &tty);
 +    oldtty = tty;
 +    atexit(term_exit);
 +
 +    tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
 +                          |INLCR|IGNCR|ICRNL|IXON);
 +    tty.c_oflag |= OPOST;
 +    tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
 +    tty.c_cflag &= ~(CSIZE|PARENB);
 +    tty.c_cflag |= CS8;
 +    tty.c_cc[VMIN] = 1;
 +    tty.c_cc[VTIME] = 0;
 +
 +    tcsetattr (0, TCSANOW, &tty);
 +    signal(SIGQUIT, sigterm_handler); /* Quit (POSIX).  */
 +    }
 +#endif
 +
      signal(SIGINT , sigterm_handler); /* Interrupt (ANSI).  */
      signal(SIGTERM, sigterm_handler); /* Termination (ANSI).  */
  #ifdef SIGXCPU
  /* read a key without blocking */
  static int read_key(void)
  {
 -#if HAVE_KBHIT
 +#if HAVE_TERMIOS_H
 +    int n = 1;
 +    unsigned char ch;
 +    struct timeval tv;
 +    fd_set rfds;
 +
 +    if(run_as_daemon)
 +        return -1;
 +
 +    FD_ZERO(&rfds);
 +    FD_SET(0, &rfds);
 +    tv.tv_sec = 0;
 +    tv.tv_usec = 0;
 +    n = select(1, &rfds, NULL, NULL, &tv);
 +    if (n > 0) {
 +        n = read(0, &ch, 1);
 +        if (n == 1)
 +            return ch;
 +
 +        return n;
 +    }
 +#elif HAVE_KBHIT
      if(kbhit())
          return(getch());
  #endif
  
  static int decode_interrupt_cb(void)
  {
 -    return q_pressed || (q_pressed = read_key() == 'q');
 +    q_pressed += read_key() == 'q';
 +    return q_pressed > 1;
  }
  
  static int ffmpeg_exit(int ret)
@@@ -660,15 -594,8 +662,15 @@@ static void choose_pixel_fmt(AVStream *
              if(*p == st->codec->pix_fmt)
                  break;
          }
 -        if(*p == -1)
 +        if (*p == -1) {
 +            if(st->codec->pix_fmt != PIX_FMT_NONE)
 +            av_log(NULL, AV_LOG_WARNING,
 +                   "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
 +                   av_pix_fmt_descriptors[st->codec->pix_fmt].name,
 +                   codec->name,
 +                   av_pix_fmt_descriptors[codec->pix_fmts[0]].name);
              st->codec->pix_fmt = codec->pix_fmts[0];
 +        }
      }
  }
  
@@@ -690,6 -617,8 +692,8 @@@ static AVOutputStream *new_output_strea
      }
      ost->file_index = file_idx;
      ost->index = idx;
+     ost->sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
      return ost;
  }
  
@@@ -1146,8 -1075,8 +1150,8 @@@ static void do_video_out(AVFormatContex
                           AVFrame *in_picture,
                           int *frame_size)
  {
 -    int nb_frames, i, ret;
 -    AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src;
 +    int nb_frames, i, ret, av_unused resample_changed;
 +    AVFrame *final_picture, *formatted_picture;
      AVCodecContext *enc, *dec;
      double sync_ipts;
  
  
      formatted_picture = in_picture;
      final_picture = formatted_picture;
 -    padding_src = formatted_picture;
 -    resampling_dst = &ost->pict_tmp;
 -
 -    if (   ost->resample_height != ist->st->codec->height
 -        || ost->resample_width  != ist->st->codec->width
 -        || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt) ) {
  
 -        fprintf(stderr,"Input Stream #%d.%d frame size changed to %dx%d, %s\n", ist->file_index, ist->index, ist->st->codec->width,     ist->st->codec->height,avcodec_get_pix_fmt_name(ist->st->codec->pix_fmt));
 -        if(!ost->video_resample)
 -            ffmpeg_exit(1);
 +#if !CONFIG_AVFILTER
 +    resample_changed = ost->resample_width   != dec->width  ||
 +                       ost->resample_height  != dec->height ||
 +                       ost->resample_pix_fmt != dec->pix_fmt;
 +
 +    if (resample_changed) {
 +        av_log(NULL, AV_LOG_INFO,
 +               "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
 +               ist->file_index, ist->index,
 +               ost->resample_width, ost->resample_height, avcodec_get_pix_fmt_name(ost->resample_pix_fmt),
 +               dec->width         , dec->height         , avcodec_get_pix_fmt_name(dec->pix_fmt));
 +        ost->resample_width   = dec->width;
 +        ost->resample_height  = dec->height;
 +        ost->resample_pix_fmt = dec->pix_fmt;
      }
  
 -#if !CONFIG_AVFILTER
 -    if (ost->video_resample) {
 -        padding_src = NULL;
 -        final_picture = &ost->pict_tmp;
 -        if(  ost->resample_height != ist->st->codec->height
 -          || ost->resample_width  != ist->st->codec->width
 -          || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt) ) {
 +    ost->video_resample = dec->width   != enc->width  ||
 +                          dec->height  != enc->height ||
 +                          dec->pix_fmt != enc->pix_fmt;
  
 +    if (ost->video_resample) {
 +        final_picture = &ost->resample_frame;
 +        if (!ost->img_resample_ctx || resample_changed) {
 +            /* initialize the destination picture */
 +            if (!ost->resample_frame.data[0]) {
 +                avcodec_get_frame_defaults(&ost->resample_frame);
 +                if (avpicture_alloc((AVPicture *)&ost->resample_frame, enc->pix_fmt,
 +                                    enc->width, enc->height)) {
 +                    fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
 +                    ffmpeg_exit(1);
 +                }
 +            }
              /* initialize a new scaler context */
              sws_freeContext(ost->img_resample_ctx);
-             sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
 -            ost->img_resample_ctx = sws_getContext(
 -                ist->st->codec->width,
 -                ist->st->codec->height,
 -                ist->st->codec->pix_fmt,
 -                ost->st->codec->width,
 -                ost->st->codec->height,
 -                ost->st->codec->pix_fmt,
 -                ost->sws_flags, NULL, NULL, NULL);
 +            ost->img_resample_ctx = sws_getContext(dec->width, dec->height, dec->pix_fmt,
 +                                                   enc->width, enc->height, enc->pix_fmt,
-                                                    sws_flags, NULL, NULL, NULL);
++                                                   ost->sws_flags, NULL, NULL, NULL);
              if (ost->img_resample_ctx == NULL) {
                  fprintf(stderr, "Cannot get resampling context\n");
                  ffmpeg_exit(1);
              }
          }
          sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
 -              0, ost->resample_height, resampling_dst->data, resampling_dst->linesize);
 +                  0, ost->resample_height, ost->resample_frame.data, ost->resample_frame.linesize);
      }
  #endif
  
@@@ -1402,25 -1322,26 +1405,25 @@@ static void print_report(AVFormatContex
      ti1 = 1e10;
      vid = 0;
      for(i=0;i<nb_ostreams;i++) {
 +        float q= -1;
          ost = ost_table[i];
          enc = ost->st->codec;
 +        if(!ost->st->stream_copy && enc->coded_frame)
 +            q= enc->coded_frame->quality/(float)FF_QP2LAMBDA;
          if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 -            snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ",
 -                     !ost->st->stream_copy ?
 -                     enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
 +            snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q);
          }
          if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
              float t = (av_gettime()-timer_start) / 1000000.0;
  
              frame_number = ost->frame_number;
              snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",
 -                     frame_number, (t>1)?(int)(frame_number/t+0.5) : 0,
 -                     !ost->st->stream_copy ?
 -                     enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
 +                     frame_number, (t>1)?(int)(frame_number/t+0.5) : 0, q);
              if(is_last_report)
                  snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
              if(qp_hist){
                  int j;
 -                int qp= lrintf(enc->coded_frame->quality/(float)FF_QP2LAMBDA);
 +                int qp= lrintf(q);
                  if(qp>=0 && qp<FF_ARRAY_ELEMS(qp_histogram))
                      qp_histogram[qp]++;
                  for(j=0; j<32; j++)
      if (ti1 < 0.01)
          ti1 = 0.01;
  
 -    if (verbose || is_last_report) {
 +    if (verbose > 0 || is_last_report) {
          bitrate = (double)(total_size * 8) / ti1 / 1000.0;
  
          snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
@@@ -1504,7 -1425,7 +1507,7 @@@ static int output_packet(AVInputStream 
      int ret, i;
      int got_picture;
      AVFrame picture;
 -    void *buffer_to_free;
 +    void *buffer_to_free = NULL;
      static unsigned int samples_size= 0;
      AVSubtitle subtitle, *subtitle_to_free;
      int64_t pkt_pts = AV_NOPTS_VALUE;
                          /* no picture yet */
                          goto discard_packet;
                      }
 -                    ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, picture.pkt_pts, picture.pkt_dts);
 +                    ist->next_pts = ist->pts = picture.best_effort_timestamp;
                      if (ist->st->codec->time_base.num != 0) {
                          int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
                          ist->next_pts += ((int64_t)AV_TIME_BASE *
                              ist->st->codec->time_base.den;
                      }
                      avpkt.size = 0;
 +                    buffer_to_free = NULL;
 +                    pre_process_video_frame(ist, (AVPicture *)&picture, &buffer_to_free);
                      break;
              case AVMEDIA_TYPE_SUBTITLE:
                  ret = avcodec_decode_subtitle2(ist->st->codec,
              avpkt.size = 0;
          }
  
 -        buffer_to_free = NULL;
 -        if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
 -            pre_process_video_frame(ist, (AVPicture *)&picture,
 -                                    &buffer_to_free);
 -        }
 -
  #if CONFIG_AVFILTER
 -        if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->input_video_filter) {
 -            AVRational sar;
 -            if (ist->st->sample_aspect_ratio.num) sar = ist->st->sample_aspect_ratio;
 -            else                                  sar = ist->st->codec->sample_aspect_ratio;
 -            // add it to be filtered
 -            av_vsrc_buffer_add_frame(ist->input_video_filter, &picture,
 -                                     ist->pts,
 -                                     sar);
 +        if(ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
 +            for(i=0;i<nb_ostreams;i++) {
 +                ost = ost_table[i];
 +                if (ost->input_video_filter && ost->source_index == ist_index) {
 +                    if (!picture.sample_aspect_ratio.num)
 +                        picture.sample_aspect_ratio = ist->st->sample_aspect_ratio;
 +                    picture.pts = ist->pts;
 +                    // add it to be filtered
 +                    av_vsrc_buffer_add_frame2(ost->input_video_filter, &picture, ""); //TODO user setable params
 +                }
 +            }
          }
  #endif
  
              if (pts > now)
                  usleep(pts - now);
          }
 -#if CONFIG_AVFILTER
 -        frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
 -            !ist->output_video_filter || avfilter_poll_frame(ist->output_video_filter->inputs[0]);
 -#endif
          /* if output time reached then transcode raw format,
             encode packets and output them */
          if (start_time == 0 || ist->pts >= start_time)
 -#if CONFIG_AVFILTER
 -        while (frame_available) {
 -            AVRational ist_pts_tb;
 -            if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->output_video_filter)
 -                get_filtered_video_frame(ist->output_video_filter, &picture, &ist->picref, &ist_pts_tb);
 -            if (ist->picref)
 -                ist->pts = av_rescale_q(ist->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
 -#endif
              for(i=0;i<nb_ostreams;i++) {
                  int frame_size;
  
                  ost = ost_table[i];
                  if (ost->source_index == ist_index) {
 +#if CONFIG_AVFILTER
 +                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)
 +                        get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb);
 +                    if (ost->picref)
 +                        ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
 +#endif
                      os = output_files[ost->file_index];
  
                      /* set the input output pts pairs */
                              break;
                          case AVMEDIA_TYPE_VIDEO:
  #if CONFIG_AVFILTER
 -                            if (ist->picref->video)
 -                                ost->st->codec->sample_aspect_ratio = ist->picref->video->pixel_aspect;
 +                            if (ost->picref->video && !ost->frame_aspect_ratio)
 +                                ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio;
  #endif
                              do_video_out(os, ost, ist, &picture, &frame_size);
                              if (vstats_filename && frame_size)
                          av_init_packet(&opkt);
  
                          if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)
 +#if !CONFIG_AVFILTER
                              continue;
 +#else
 +                            goto cont;
 +#endif
  
                          /* no reencoding needed : output the packet directly */
                          /* force the input stream PTS */
                          ost->frame_number++;
                          av_free_packet(&opkt);
                      }
 +#if CONFIG_AVFILTER
 +                    cont:
 +                    frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
 +                                       ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);
 +                    if(ost->picref)
 +                        avfilter_unref_buffer(ost->picref);
 +                }
 +#endif
                  }
              }
  
 -#if CONFIG_AVFILTER
 -            frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
 -                              ist->output_video_filter && avfilter_poll_frame(ist->output_video_filter->inputs[0]);
 -            if(ist->picref)
 -                avfilter_unref_buffer(ist->picref);
 -        }
 -#endif
          av_free(buffer_to_free);
          /* XXX: allocate the subtitles in the codec ? */
          if (subtitle_to_free) {
@@@ -1972,7 -1891,7 +1975,7 @@@ static int transcode(AVFormatContext **
                       int nb_input_files,
                       AVStreamMap *stream_maps, int nb_stream_maps)
  {
 -    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
 +    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0, step;
      AVFormatContext *is, *os;
      AVCodecContext *codec, *icodec;
      AVOutputStream *ost, **ost_table = NULL;
      int want_sdp = 1;
      uint8_t no_packet[MAX_FILES]={0};
      int no_packet_count=0;
 +    int nb_frame_threshold[AVMEDIA_TYPE_NB]={0};
 +    int nb_streams[AVMEDIA_TYPE_NB]={0};
  
      file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
      if (!file_table)
      ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
      if (!ost_table)
          goto fail;
 +
 +    for(k=0;k<nb_output_files;k++) {
 +        os = output_files[k];
 +        for(i=0;i<os->nb_streams;i++,n++) {
 +            nb_streams[os->streams[i]->codec->codec_type]++;
 +        }
 +    }
 +    for(step=1<<30; step; step>>=1){
 +        int found_streams[AVMEDIA_TYPE_NB]={0};
 +        for(j=0; j<AVMEDIA_TYPE_NB; j++)
 +            nb_frame_threshold[j] += step;
 +
 +        for(j=0; j<nb_istreams; j++) {
 +            int skip=0;
 +            ist = ist_table[j];
 +            if(opt_programid){
 +                int pi,si;
 +                AVFormatContext *f= input_files[ ist->file_index ];
 +                skip=1;
 +                for(pi=0; pi<f->nb_programs; pi++){
 +                    AVProgram *p= f->programs[pi];
 +                    if(p->id == opt_programid)
 +                        for(si=0; si<p->nb_stream_indexes; si++){
 +                            if(f->streams[ p->stream_index[si] ] == ist->st)
 +                                skip=0;
 +                        }
 +                }
 +            }
 +            if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip
 +                && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){
 +                found_streams[ist->st->codec->codec_type]++;
 +            }
 +        }
 +        for(j=0; j<AVMEDIA_TYPE_NB; j++)
 +            if(found_streams[j] < nb_streams[j])
 +                nb_frame_threshold[j] -= step;
 +    }
      n = 0;
      for(k=0;k<nb_output_files;k++) {
          os = output_files[k];
                  }
  
              } else {
 -                int best_nb_frames=-1;
                  /* get corresponding input stream index : we select the first one with the right type */
                  found = 0;
                  for(j=0;j<nb_istreams;j++) {
                          }
                      }
                      if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip &&
 -                        ist->st->codec->codec_type == ost->st->codec->codec_type) {
 -                        if(best_nb_frames < ist->st->codec_info_nb_frames){
 -                            best_nb_frames= ist->st->codec_info_nb_frames;
 +                        ist->st->codec->codec_type == ost->st->codec->codec_type &&
 +                        nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) {
                              ost->source_index = j;
                              found = 1;
 -                        }
 +                            break;
                      }
                  }
  
                  codec->width = icodec->width;
                  codec->height = icodec->height;
                  codec->has_b_frames = icodec->has_b_frames;
 +                if (!codec->sample_aspect_ratio.num) {
 +                    codec->sample_aspect_ratio =
 +                    ost->st->sample_aspect_ratio =
 +                        ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
 +                        ist->st->codec->sample_aspect_ratio.num ?
 +                        ist->st->codec->sample_aspect_ratio : (AVRational){0, 1};
 +                }
                  break;
              case AVMEDIA_TYPE_SUBTITLE:
                  codec->width = icodec->width;
                      fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
                      ffmpeg_exit(1);
                  }
 -                ost->video_resample = (codec->width != icodec->width   ||
 -                                       codec->height != icodec->height ||
 -                        (codec->pix_fmt != icodec->pix_fmt));
 +                ost->video_resample = codec->width   != icodec->width  ||
 +                                      codec->height  != icodec->height ||
 +                                      codec->pix_fmt != icodec->pix_fmt;
                  if (ost->video_resample) {
 -#if !CONFIG_AVFILTER
 -                    avcodec_get_frame_defaults(&ost->pict_tmp);
 -                    if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt,
 -                                         codec->width, codec->height)) {
 -                        fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
 -                        ffmpeg_exit(1);
 -                    }
 -                    ost->img_resample_ctx = sws_getContext(
 -                        icodec->width,
 -                        icodec->height,
 -                            icodec->pix_fmt,
 -                            codec->width,
 -                            codec->height,
 -                            codec->pix_fmt,
 -                            ost->sws_flags, NULL, NULL, NULL);
 -                    if (ost->img_resample_ctx == NULL) {
 -                        fprintf(stderr, "Cannot get resampling context\n");
 -                        ffmpeg_exit(1);
 -                    }
 -
 -                    ost->original_height = icodec->height;
 -                    ost->original_width  = icodec->width;
 -#endif
 -                    codec->bits_per_raw_sample= 0;
 +                    codec->bits_per_raw_sample= frame_bits_per_raw_sample;
                  }
                  ost->resample_height = icodec->height;
                  ost->resample_width  = icodec->width;
                  ist->decoding_needed = 1;
  
  #if CONFIG_AVFILTER
 -                if (configure_filters(ist, ost)) {
 +                if (configure_video_filters(ist, ost)) {
                      fprintf(stderr, "Error opening filters!\n");
                      exit(1);
                  }
                  break;
              }
              /* two pass mode */
 -            if (ost->encoding_needed &&
 +            if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 &&
                  (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
                  char logfilename[1024];
                  FILE *f;
              }
          }
          if(codec->codec_type == AVMEDIA_TYPE_VIDEO){
 +            /* maximum video buffer size is 6-bytes per pixel, plus DPX header size */
              int size= codec->width * codec->height;
 -            bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 200);
 +            bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 1664);
          }
      }
  
          st= ist->st;
          ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0;
          ist->next_pts = AV_NOPTS_VALUE;
 -        init_pts_correction(&ist->pts_ctx);
          ist->is_start = 1;
      }
  
          print_sdp(output_files, nb_output_files);
      }
  
 -    if (!using_stdin && verbose >= 0) {
 -#if HAVE_KBHIT
 -        fprintf(stderr, "Press [q] to stop encoding\n");
 -#else
 -        fprintf(stderr, "Press ctrl-c to stop encoding\n");
 -#endif
 +    if (!using_stdin) {
 +        if(verbose >= 0)
 +            fprintf(stderr, "Press [q] to stop encoding\n");
          avio_set_interrupt_cb(decode_interrupt_cb);
      }
      term_init();
              av_freep(&ost->st->codec->stats_in);
              avcodec_close(ost->st->codec);
          }
 +#if CONFIG_AVFILTER
 +        avfilter_graph_free(&ost->graph);
 +#endif
      }
  
      /* close each decoder */
              avcodec_close(ist->st->codec);
          }
      }
 -#if CONFIG_AVFILTER
 -    avfilter_graph_free(&graph);
 -#endif
  
      /* finished ! */
      ret = 0;
                  av_fifo_free(ost->fifo); /* works even if fifo is not
                                               initialized but set to zero */
                  av_freep(&ost->st->codec->subtitle_header);
 -                av_free(ost->pict_tmp.data[0]);
 +                av_free(ost->resample_frame.data[0]);
                  av_free(ost->forced_kf_pts);
                  if (ost->video_resample)
                      sws_freeContext(ost->img_resample_ctx);
@@@ -2901,6 -2802,10 +2904,6 @@@ static void opt_frame_aspect_ratio(cons
          ffmpeg_exit(1);
      }
      frame_aspect_ratio = ar;
 -
 -    x = vfilters ? strlen(vfilters) : 0;
 -    vfilters = av_realloc(vfilters, x+100);
 -    snprintf(vfilters+x, x+100, "%csetdar=%f\n", x?',':' ', ar);
  }
  
  static int opt_metadata(const char *opt, const char *arg)
      return 0;
  }
  
 -static void opt_qscale(const char *arg)
 +static int opt_qscale(const char *opt, const char *arg)
  {
 -    video_qscale = atof(arg);
 -    if (video_qscale <= 0 ||
 -        video_qscale > 255) {
 +    video_qscale = parse_number_or_die(opt, arg, OPT_FLOAT, 0, 255);
 +    if (video_qscale <= 0 || video_qscale > 255) {
          fprintf(stderr, "qscale must be > 0.0 and <= 255\n");
 -        ffmpeg_exit(1);
 +        return AVERROR(EINVAL);
      }
 +    return 0;
  }
  
 -static void opt_top_field_first(const char *arg)
 +static int opt_top_field_first(const char *opt, const char *arg)
  {
 -    top_field_first= atoi(arg);
 +    top_field_first = parse_number_or_die(opt, arg, OPT_INT, 0, 1);
 +    return 0;
  }
  
  static int opt_thread_count(const char *opt, const char *arg)
@@@ -2953,10 -2857,7 +2956,10 @@@ static void opt_audio_sample_fmt(const 
              ffmpeg_exit(1);
          }
      } else {
 -        list_fmts(av_get_sample_fmt_string, AV_SAMPLE_FMT_NB);
 +        int i;
 +        char fmt_str[128];
 +        for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
 +            printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
          ffmpeg_exit(0);
      }
  }
@@@ -2973,10 -2874,9 +2976,10 @@@ static int opt_audio_channels(const cha
      return 0;
  }
  
 -static void opt_video_channel(const char *arg)
 +static int opt_video_channel(const char *opt, const char *arg)
  {
 -    video_channel = strtol(arg, NULL, 0);
 +    video_channel = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
 +    return 0;
  }
  
  static void opt_video_standard(const char *arg)
@@@ -3256,16 -3156,10 +3259,16 @@@ static void opt_input_file(const char *
      ic->subtitle_codec_id=
          find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0,
                            avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
 -    ic->flags |= AVFMT_FLAG_NONBLOCK;
 +    ic->flags |= AVFMT_FLAG_NONBLOCK | AVFMT_FLAG_PRIV_OPT;
  
      /* open the input file with generic libav function */
      err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
 +    if(err >= 0){
 +        set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
 +        err = av_demuxer_open(ic, ap);
 +        if(err < 0)
 +            avformat_free_context(ic);
 +    }
      if (err < 0) {
          print_error(filename, err);
          ffmpeg_exit(1);
              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;
 -            if(ic->streams[i]->sample_aspect_ratio.num)
 -                frame_aspect_ratio=av_q2d(ic->streams[i]->sample_aspect_ratio);
 -            else
 -                frame_aspect_ratio=av_q2d(dec->sample_aspect_ratio);
 -            frame_aspect_ratio *= (float) dec->width / dec->height;
              frame_pix_fmt = dec->pix_fmt;
              rfps      = ic->streams[i]->r_frame_rate.num;
              rfps_base = ic->streams[i]->r_frame_rate.den;
      av_freep(&video_codec_name);
      av_freep(&audio_codec_name);
      av_freep(&subtitle_codec_name);
+     uninit_opts();
+     init_opts();
  }
  
  static void check_inputs(int *has_video_ptr,
@@@ -3477,12 -3378,6 +3482,12 @@@ static void new_video_stream(AVFormatCo
              codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
              codec = avcodec_find_encoder(codec_id);
          }
 +        ost->frame_aspect_ratio = frame_aspect_ratio;
 +        frame_aspect_ratio = 0;
 +#if CONFIG_AVFILTER
 +        ost->avfilter= vfilters;
 +        vfilters= NULL;
 +#endif
      }
  
      avcodec_get_context_defaults3(st->codec, codec);
  
          video_enc->width = frame_width;
          video_enc->height = frame_height;
 -        video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);
          video_enc->pix_fmt = frame_pix_fmt;
 +        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);
@@@ -3828,13 -3723,30 +3833,13 @@@ static void opt_output_file(const char 
      if (!strcmp(filename, "-"))
          filename = "pipe:";
  
 -    oc = avformat_alloc_context();
 +    oc = avformat_alloc_output_context(last_asked_format, NULL, filename);
 +    last_asked_format = NULL;
      if (!oc) {
          print_error(filename, AVERROR(ENOMEM));
          ffmpeg_exit(1);
      }
 -
 -    if (last_asked_format) {
 -        file_oformat = av_guess_format(last_asked_format, NULL, NULL);
 -        if (!file_oformat) {
 -            fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
 -            ffmpeg_exit(1);
 -        }
 -        last_asked_format = NULL;
 -    } else {
 -        file_oformat = av_guess_format(NULL, filename, NULL);
 -        if (!file_oformat) {
 -            fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
 -                    filename);
 -            ffmpeg_exit(1);
 -        }
 -    }
 -
 -    oc->oformat = file_oformat;
 -    av_strlcpy(oc->filename, filename, sizeof(oc->filename));
 +    file_oformat= oc->oformat;
  
      if (!strcmp(file_oformat->name, "ffm") &&
          av_strstart(filename, "http:", NULL)) {
      oc->preload= (int)(mux_preload*AV_TIME_BASE);
      oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
      oc->loop_output = loop_output;
 -    oc->flags |= AVFMT_FLAG_NONBLOCK;
  
      set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
  
      av_freep(&forced_key_frames);
+     uninit_opts();
+     init_opts();
  }
  
  /* same option as mencoder */
 -static void opt_pass(const char *pass_str)
 +static int opt_pass(const char *opt, const char *arg)
  {
 -    int pass;
 -    pass = atoi(pass_str);
 -    if (pass != 1 && pass != 2) {
 -        fprintf(stderr, "pass number can be only 1 or 2\n");
 -        ffmpeg_exit(1);
 -    }
 -    do_pass = pass;
 +    do_pass = parse_number_or_die(opt, arg, OPT_INT, 1, 2);
 +    return 0;
  }
  
  static int64_t getutime(void)
@@@ -4122,7 -4042,7 +4129,7 @@@ static void opt_target(const char *arg
                  }
              }
          }
 -        if(verbose && norm != UNKNOWN)
 +        if(verbose > 0 && norm != UNKNOWN)
              fprintf(stderr, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
      }
  
@@@ -4301,16 -4221,6 +4308,16 @@@ static int opt_preset(const char *opt, 
      return 0;
  }
  
 +static void log_callback_null(void* ptr, int level, const char* fmt, va_list vl)
 +{
 +}
 +
 +static void opt_passlogfile(const char *arg)
 +{
 +    pass_logfilename_prefix = arg;
 +    opt_default("passlogfile", arg);
 +}
 +
  static const OptionDef options[] = {
      /* main options */
  #include "cmdutils_common_opts.h"
      { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
      { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
      { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" },
 +    { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&frame_bits_per_raw_sample}, "set the number of bits per raw sample", "number" },
      { "croptop", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
      { "cropbottom", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
      { "cropleft", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
      { "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"},
      { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
      { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
 -    { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
 +    { "qscale", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
      { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
      { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
      { "me_threshold", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold",  "threshold" },
      { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
        "use same quantizer as source (implies VBR)" },
 -    { "pass", HAS_ARG | OPT_VIDEO, {(void*)&opt_pass}, "select the pass number (1 or 2)", "n" },
 -    { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" },
 +    { "pass", HAS_ARG | OPT_FUNC2 | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" },
 +    { "passlogfile", HAS_ARG | OPT_VIDEO, {(void*)&opt_passlogfile}, "select two pass log file name prefix", "prefix" },
      { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
        "deinterlace pictures" },
      { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
  #endif
      { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
      { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
 -    { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
 +    { "top", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
      { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
      { "vtag", OPT_FUNC2 | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_codec_tag}, "force video tag/fourcc", "fourcc/tag" },
      { "newvideo", OPT_VIDEO | OPT_FUNC2, {(void*)opt_new_stream}, "add a new video stream to the current output stream" },
      { "stag", OPT_FUNC2 | HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_codec_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
  
      /* grab options */
 -    { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" },
 +    { "vc", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" },
      { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "set television standard (NTSC, PAL (SECAM))", "standard" },
      { "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
  
@@@ -4456,14 -4365,6 +4463,14 @@@ int main(int argc, char **argv
  
      av_log_set_flags(AV_LOG_SKIP_REPEATED);
  
 +    if(argc>1 && !strcmp(argv[1], "-d")){
 +        run_as_daemon=1;
 +        verbose=-1;
 +        av_log_set_callback(log_callback_null);
 +        argc--;
 +        argv++;
 +    }
 +
      avcodec_register_all();
  #if CONFIG_AVDEVICE
      avdevice_register_all();
diff --combined libavcodec/Makefile
@@@ -26,7 -26,6 +26,7 @@@ OBJS = allcodecs.
  # parts needed for many different codecs
  OBJS-$(CONFIG_AANDCT)                  += aandcttab.o
  OBJS-$(CONFIG_AC3DSP)                  += ac3dsp.o
 +OBJS-$(CONFIG_CRYSTALHD)               += crystalhd.o
  OBJS-$(CONFIG_ENCODERS)                += faandct.o jfdctfst.o jfdctint.o
  OBJS-$(CONFIG_DCT)                     += dct.o
  OBJS-$(CONFIG_DWT)                     += dwt.o
@@@ -58,8 -57,7 +58,8 @@@ OBJS-$(CONFIG_AAC_ENCODER)             
                                            mpeg4audio.o kbdwin.o
  OBJS-$(CONFIG_AASC_DECODER)            += aasc.o msrledec.o
  OBJS-$(CONFIG_AC3_DECODER)             += ac3dec.o ac3dec_data.o ac3.o kbdwin.o
 -OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_float.o ac3tab.o ac3.o kbdwin.o
 +OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_combined.o ac3enc_fixed.o ac3enc_float.o ac3tab.o ac3.o kbdwin.o
 +OBJS-$(CONFIG_AC3_FLOAT_ENCODER)       += ac3enc_float.o ac3tab.o ac3.o kbdwin.o
  OBJS-$(CONFIG_AC3_FIXED_ENCODER)       += ac3enc_fixed.o ac3tab.o ac3.o
  OBJS-$(CONFIG_ALAC_DECODER)            += alac.o
  OBJS-$(CONFIG_ALAC_ENCODER)            += alacenc.o
@@@ -76,7 -74,7 +76,7 @@@ OBJS-$(CONFIG_AMV_DECODER)             
  OBJS-$(CONFIG_ANM_DECODER)             += anm.o
  OBJS-$(CONFIG_ANSI_DECODER)            += ansi.o cga_data.o
  OBJS-$(CONFIG_APE_DECODER)             += apedec.o
 -OBJS-$(CONFIG_ASS_DECODER)             += assdec.o ass.o
 +OBJS-$(CONFIG_ASS_DECODER)             += assdec.o ass.o ass_split.o
  OBJS-$(CONFIG_ASS_ENCODER)             += assenc.o ass.o
  OBJS-$(CONFIG_ASV1_DECODER)            += asv1.o mpeg12data.o
  OBJS-$(CONFIG_ASV1_ENCODER)            += asv1.o mpeg12data.o
@@@ -105,7 -103,6 +105,7 @@@ OBJS-$(CONFIG_COOK_DECODER)            
  OBJS-$(CONFIG_CSCD_DECODER)            += cscd.o
  OBJS-$(CONFIG_CYUV_DECODER)            += cyuv.o
  OBJS-$(CONFIG_DCA_DECODER)             += dca.o synth_filter.o dcadsp.o
 +OBJS-$(CONFIG_DCA_ENCODER)             += dcaenc.o
  OBJS-$(CONFIG_DFA_DECODER)             += dfa.o
  OBJS-$(CONFIG_DNXHD_DECODER)           += dnxhddec.o dnxhddata.o
  OBJS-$(CONFIG_DNXHD_ENCODER)           += dnxhdenc.o dnxhddata.o       \
@@@ -141,11 -138,10 +141,11 @@@ OBJS-$(CONFIG_FFV1_DECODER)            
  OBJS-$(CONFIG_FFV1_ENCODER)            += ffv1.o rangecoder.o
  OBJS-$(CONFIG_FFVHUFF_DECODER)         += huffyuv.o
  OBJS-$(CONFIG_FFVHUFF_ENCODER)         += huffyuv.o
 -OBJS-$(CONFIG_FLAC_DECODER)            += flacdec.o flacdata.o flac.o
 -OBJS-$(CONFIG_FLAC_ENCODER)            += flacenc.o flacdata.o flac.o
 +OBJS-$(CONFIG_FLAC_DECODER)            += flacdec.o flacdata.o flac.o vorbis_data.o
 +OBJS-$(CONFIG_FLAC_ENCODER)            += flacenc.o flacdata.o flac.o vorbis_data.o
  OBJS-$(CONFIG_FLASHSV_DECODER)         += flashsv.o
  OBJS-$(CONFIG_FLASHSV_ENCODER)         += flashsvenc.o
 +OBJS-$(CONFIG_FLASHSV2_ENCODER)        += flashsv2enc.o
  OBJS-$(CONFIG_FLIC_DECODER)            += flicvideo.o
  OBJS-$(CONFIG_FOURXM_DECODER)          += 4xm.o
  OBJS-$(CONFIG_FRAPS_DECODER)           += fraps.o
@@@ -170,7 -166,7 +170,7 @@@ OBJS-$(CONFIG_H263_ENCODER)            
                                            ratecontrol.o h263.o ituh263enc.o \
                                            flvenc.o mpeg12data.o             \
                                            mpegvideo.o error_resilience.o
 -OBJS-$(CONFIG_H264_DECODER)            += h264.o                               \
 +OBJS-$(CONFIG_H264_DECODER)            += h264.o h264_hl_motion.o              \
                                            h264_loopfilter.o h264_direct.o      \
                                            cabac.o h264_sei.o h264_ps.o         \
                                            h264_refs.o h264_cavlc.o h264_cabac.o\
@@@ -275,7 -271,6 +275,7 @@@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER)       
                                            h263.o ituh263dec.o mpeg4videodec.o
  OBJS-$(CONFIG_MSRLE_DECODER)           += msrle.o msrledec.o
  OBJS-$(CONFIG_MSVIDEO1_DECODER)        += msvideo1.o
 +OBJS-$(CONFIG_MSVIDEO1_ENCODER)        += msvideo1enc.o elbg.o
  OBJS-$(CONFIG_MSZH_DECODER)            += lcldec.o
  OBJS-$(CONFIG_MXPEG_DECODER)           += mxpegdec.o mjpegdec.o mjpeg.o
  OBJS-$(CONFIG_NELLYMOSER_DECODER)      += nellymoserdec.o nellymoser.o
@@@ -346,12 -341,8 +346,12 @@@ OBJS-$(CONFIG_SNOW_ENCODER)            
                                            ituh263enc.o mpegvideo_enc.o     \
                                            mpeg12data.o
  OBJS-$(CONFIG_SOL_DPCM_DECODER)        += dpcm.o
 +OBJS-$(CONFIG_SONIC_DECODER)           += sonic.o
 +OBJS-$(CONFIG_SONIC_ENCODER)           += sonic.o
 +OBJS-$(CONFIG_SONIC_LS_ENCODER)        += sonic.o
  OBJS-$(CONFIG_SP5X_DECODER)            += sp5xdec.o mjpegdec.o mjpeg.o
  OBJS-$(CONFIG_SRT_DECODER)             += srtdec.o ass.o
 +OBJS-$(CONFIG_SRT_ENCODER)             += srtenc.o ass_split.o
  OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
  OBJS-$(CONFIG_SVQ1_DECODER)            += svq1dec.o svq1.o h263.o \
                                            mpegvideo.o error_resilience.o
@@@ -360,7 -351,7 +360,7 @@@ OBJS-$(CONFIG_SVQ1_ENCODER)            
                                            mpegvideo.o error_resilience.o \
                                            ituh263enc.o mpegvideo_enc.o   \
                                            ratecontrol.o mpeg12data.o
 -OBJS-$(CONFIG_SVQ3_DECODER)            += h264.o svq3.o                       \
 +OBJS-$(CONFIG_SVQ3_DECODER)            += h264.o svq3.o h264_hl_motion.o      \
                                            h264_loopfilter.o h264_direct.o     \
                                            h264_sei.o h264_ps.o h264_refs.o    \
                                            h264_cavlc.o h264_cabac.o cabac.o   \
@@@ -531,35 -522,33 +531,35 @@@ OBJS-$(CONFIG_ADTS_MUXER)              
  OBJS-$(CONFIG_CAF_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_DV_DEMUXER)              += dvdata.o
  OBJS-$(CONFIG_DV_MUXER)                += dvdata.o
 -OBJS-$(CONFIG_FLAC_DEMUXER)            += flacdec.o flacdata.o flac.o
 -OBJS-$(CONFIG_FLAC_MUXER)              += flacdec.o flacdata.o flac.o
 +OBJS-$(CONFIG_FLAC_DEMUXER)            += flacdec.o flacdata.o flac.o vorbis_data.o
 +OBJS-$(CONFIG_FLAC_MUXER)              += flacdec.o flacdata.o flac.o vorbis_data.o
  OBJS-$(CONFIG_FLV_DEMUXER)             += mpeg4audio.o
  OBJS-$(CONFIG_GXF_DEMUXER)             += mpeg12data.o
  OBJS-$(CONFIG_IFF_DEMUXER)             += iff.o
 -OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)    += xiph.o mpeg4audio.o \
 +OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)    += xiph.o mpeg4audio.o vorbis_data.o \
                                            flacdec.o flacdata.o flac.o
  OBJS-$(CONFIG_MATROSKA_DEMUXER)        += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_MATROSKA_MUXER)          += xiph.o mpeg4audio.o \
                                            flacdec.o flacdata.o flac.o \
 -                                          mpegaudiodata.o
 +                                          mpegaudiodata.o vorbis_data.o
  OBJS-$(CONFIG_MOV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_MOV_MUXER)               += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_MPEGTS_MUXER)            += mpegvideo.o mpeg4audio.o
  OBJS-$(CONFIG_MPEGTS_DEMUXER)          += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_NUT_MUXER)               += mpegaudiodata.o
  OBJS-$(CONFIG_OGG_DEMUXER)             += flacdec.o flacdata.o flac.o \
 -                                          dirac.o mpeg12data.o
 -OBJS-$(CONFIG_OGG_MUXER)               += xiph.o flacdec.o flacdata.o flac.o
 +                                          dirac.o mpeg12data.o vorbis_data.o
 +OBJS-$(CONFIG_OGG_MUXER)               += xiph.o flacdec.o flacdata.o flac.o \
 +                                          vorbis_data.o
  OBJS-$(CONFIG_RTP_MUXER)               += mpegvideo.o xiph.o
  OBJS-$(CONFIG_SPDIF_DEMUXER)           += aacadtsdec.o mpeg4audio.o
  OBJS-$(CONFIG_WEBM_MUXER)              += xiph.o mpeg4audio.o \
                                            flacdec.o flacdata.o flac.o \
 -                                          mpegaudiodata.o
 +                                          mpegaudiodata.o vorbis_data.o
  OBJS-$(CONFIG_WTV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
  
  # external codec libraries
 +OBJS-$(CONFIG_LIBCELT_DECODER)            += libcelt_dec.o
  OBJS-$(CONFIG_LIBDIRAC_DECODER)           += libdiracdec.o
  OBJS-$(CONFIG_LIBDIRAC_ENCODER)           += libdiracenc.o libdirac_libschro.o
  OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o
@@@ -600,11 -589,10 +600,11 @@@ OBJS-$(CONFIG_DIRAC_PARSER)            
  OBJS-$(CONFIG_DNXHD_PARSER)            += dnxhd_parser.o
  OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
  OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsub_parser.o
 -OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o
 +OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o \
 +                                          vorbis_data.o
  OBJS-$(CONFIG_H261_PARSER)             += h261_parser.o
  OBJS-$(CONFIG_H263_PARSER)             += h263_parser.o
 -OBJS-$(CONFIG_H264_PARSER)             += h264_parser.o h264.o            \
 +OBJS-$(CONFIG_H264_PARSER)             += h264_parser.o h264.o h264_hl_motion.o \
                                            cabac.o                         \
                                            h264_refs.o h264_sei.o h264_direct.o \
                                            h264_loopfilter.o h264_cabac.o \
@@@ -694,14 -682,6 +694,6 @@@ $(SUBDIR)cos_fixed_tables.c: $(SUBDIR)c
  $(SUBDIR)sin_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF)
        $(M)./$< sin > $@
  
- ifdef CONFIG_MPEGAUDIO_HP
- $(SUBDIR)mpegaudio_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DFRAC_BITS=23
- $(SUBDIR)mpegaudio_tablegen.ho: CPPFLAGS += -DFRAC_BITS=23
- else
- $(SUBDIR)mpegaudio_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DFRAC_BITS=15
- $(SUBDIR)mpegaudio_tablegen.ho: CPPFLAGS += -DFRAC_BITS=15
- endif
  ifdef CONFIG_SMALL
  $(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DCONFIG_SMALL=1
  else
@@@ -3,20 -3,20 +3,20 @@@
   *
   * Copyright (C) 2007 Marc Hoffman <mmhoffm@gmail.com>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  #ifndef AVCODEC_BFIN_MATHOPS_H
@@@ -24,7 -24,6 +24,6 @@@
  
  #include "config.h"
  
- #if CONFIG_MPEGAUDIO_HP
  #define MULH(X,Y) ({ int xxo;                           \
      __asm__ (                                               \
          "a1 = %2.L * %1.L (FU);\n\t"                    \
          "a1 = a1 >>> 16;\n\t"                           \
          "%0 = (a0 += a1);\n\t"                          \
          : "=d" (xxo) : "d" (X), "d" (Y) : "A0","A1"); xxo; })
- #else
- #define MULH(X,Y) ({ int xxo;                           \
-     __asm__ (                                               \
-         "a1 = %2.H * %1.L (IS,M);\n\t"                  \
-         "a0 = %1.H * %2.H, a1+= %1.H * %2.L (IS,M);\n\t"\
-         "a1 = a1 >>> 16;\n\t"                           \
-         "%0 = (a0 += a1);\n\t"                          \
-         : "=d" (xxo) : "d" (X), "d" (Y) : "A0","A1"); xxo; })
- #endif
  
  /* signed 16x16 -> 32 multiply */
  #define MUL16(a, b) ({ int xxo;                         \
diff --combined libavcodec/mpegaudio.h
@@@ -1,20 -1,20 +1,20 @@@
  /*
   * copyright (c) 2001 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -35,8 -35,6 +35,8 @@@
  #include "dsputil.h"
  #include "dct.h"
  
 +#define CONFIG_AUDIO_NONSHORT 0
 +
  /* max frame size, in samples */
  #define MPA_FRAME_SIZE 1152
  
  
  #define MP3_MASK 0xFFFE0CCF
  
- #if CONFIG_MPEGAUDIO_HP
+ #ifndef FRAC_BITS
  #define FRAC_BITS   23   /* fractional bits for sb_samples and dct */
  #define WFRAC_BITS  16   /* fractional bits for window */
- #else
- #define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
- #define WFRAC_BITS  14   /* fractional bits for window */
  #endif
  
  #define FRAC_ONE    (1 << FRAC_BITS)
  #if CONFIG_FLOAT
  typedef float OUT_INT;
  #define OUT_FMT AV_SAMPLE_FMT_FLT
 +#elif CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
 +typedef int32_t OUT_INT;
 +#define OUT_MAX INT32_MAX
 +#define OUT_MIN INT32_MIN
 +#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
 +#define OUT_FMT AV_SAMPLE_FMT_S32
  #else
  typedef int16_t OUT_INT;
  #define OUT_MAX INT16_MAX
@@@ -3,20 -3,20 +3,20 @@@
   *
   * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -38,6 -38,8 +38,8 @@@ static uint32_t expval_table[512][16]
  static float exp_table_float[512];
  static float expval_table_float[512][16];
  
+ #define FRAC_BITS 23
  static void mpegaudio_tableinit(void)
  {
      int i, value, exponent;
@@@ -2,20 -2,20 +2,20 @@@
   * MPEG Audio decoder
   * Copyright (c) 2001, 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #include "avcodec.h"
  #include "get_bits.h"
  #include "dsputil.h"
+ #include "mathops.h"
  
  /*
   * TODO:
-  *  - in low precision mode, use more 16 bit multiplies in synth filter
   *  - test lsf / mpeg25 extensively.
   */
  
  #include "mpegaudio.h"
  #include "mpegaudiodecheader.h"
  
- #include "mathops.h"
  #if CONFIG_FLOAT
  #   define SHR(a,b)       ((a)*(1.0f/(1<<(b))))
  #   define compute_antialias compute_antialias_float
@@@ -248,14 -246,6 +246,6 @@@ static inline int l3_unscale(int value
  
  static int dev_4_3_coefs[DEV_ORDER];
  
- #if 0 /* unused */
- static int pow_mult3[3] = {
-     POW_FIX(1.0),
-     POW_FIX(1.25992104989487316476),
-     POW_FIX(1.58740105196819947474),
- };
- #endif
  static av_cold void int_pow_init(void)
  {
      int i, a;
      }
  }
  
- #if 0 /* unused, remove? */
- /* return the mantissa and the binary exponent */
- static int int_pow(int i, int *exp_ptr)
- {
-     int e, er, eq, j;
-     int a, a1;
-     /* renormalize */
-     a = i;
-     e = POW_FRAC_BITS;
-     while (a < (1 << (POW_FRAC_BITS - 1))) {
-         a = a << 1;
-         e--;
-     }
-     a -= (1 << POW_FRAC_BITS);
-     a1 = 0;
-     for(j = DEV_ORDER - 1; j >= 0; j--)
-         a1 = POW_MULL(a, dev_4_3_coefs[j] + a1);
-     a = (1 << POW_FRAC_BITS) + a1;
-     /* exponent compute (exact) */
-     e = e * 4;
-     er = e % 3;
-     eq = e / 3;
-     a = POW_MULL(a, pow_mult3[er]);
-     while (a >= 2 * POW_FRAC_ONE) {
-         a = a >> 1;
-         eq++;
-     }
-     /* convert to float */
-     while (a < POW_FRAC_ONE) {
-         a = a << 1;
-         eq--;
-     }
-     /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */
- #if POW_FRAC_BITS > FRAC_BITS
-     a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS);
-     /* correct overflow */
-     if (a >= 2 * (1 << FRAC_BITS)) {
-         a = a >> 1;
-         eq++;
-     }
- #endif
-     *exp_ptr = eq;
-     return a;
- }
- #endif
  static av_cold int decode_init(AVCodecContext * avctx)
  {
      MPADecodeContext *s = avctx->priv_data;
@@@ -540,24 -483,6 +483,6 @@@ static inline float round_sample(float 
  
  #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
  
- #elif FRAC_BITS <= 15
- static inline int round_sample(int *sum)
- {
-     int sum1;
-     sum1 = (*sum) >> OUT_SHIFT;
-     *sum &= (1<<OUT_SHIFT)-1;
-     return av_clip(sum1, OUT_MIN, OUT_MAX);
- }
- /* signed 16x16 -> 32 multiply add accumulate */
- #define MACS(rt, ra, rb) MAC16(rt, ra, rb)
- /* signed 16x16 -> 32 multiply */
- #define MULS(ra, rb) MUL16(ra, rb)
- #define MLSS(rt, ra, rb) MLS16(rt, ra, rb)
  #else
  
  static inline int round_sample(int64_t *sum)
@@@ -624,8 -549,6 +549,6 @@@ void av_cold RENAME(ff_mpa_synth_init)(
          v = ff_mpa_enwindow[i];
  #if CONFIG_FLOAT
          v *= 1.0 / (1LL<<(16 + FRAC_BITS));
- #elif WFRAC_BITS < 16
-         v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
  #endif
          window[i] = v;
          if ((i & 63) != 0)
@@@ -652,8 -575,6 +575,6 @@@ static void apply_window_mp3_c(MPA_INT 
      OUT_INT *samples2;
  #if CONFIG_FLOAT
      float sum, sum2;
- #elif FRAC_BITS <= 15
-     int sum, sum2;
  #else
      int64_t sum, sum2;
  #endif
@@@ -710,25 -631,11 +631,11 @@@ void ff_mpa_synth_filter(MPA_INT *synth
  {
      register MPA_INT *synth_buf;
      int offset;
- #if FRAC_BITS <= 15
-     int32_t tmp[32];
-     int j;
- #endif
  
      offset = *synth_buf_offset;
      synth_buf = synth_buf_ptr + offset;
  
- #if FRAC_BITS <= 15
-     dct32(tmp, sb_samples);
-     for(j=0;j<32;j++) {
-         /* NOTE: can cause a loss in precision if very high amplitude
-            sound */
-         synth_buf[j] = av_clip_int16(tmp[j]);
-     }
- #else
      dct32(synth_buf, sb_samples);
- #endif
      apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);
  
      offset = (offset - 32) & 511;
@@@ -2,20 -2,20 +2,20 @@@
   * The simplest mpeg audio layer 2 encoder
   * Copyright (c) 2000, 2001 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -27,8 -27,9 +27,9 @@@
  #include "avcodec.h"
  #include "put_bits.h"
  
- #undef  CONFIG_MPEGAUDIO_HP
- #define CONFIG_MPEGAUDIO_HP 0
+ #define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
+ #define WFRAC_BITS  14   /* fractional bits for window */
  #include "mpegaudio.h"
  
  /* currently, cannot change these constants (need to modify
@@@ -399,10 -400,8 +400,10 @@@ static void compute_scale_factors(unsig
                  index = 62; /* value 63 is not allowed */
              }
  
 -            av_dlog(NULL, "%2d:%d in=%x %x %d\n",
 -                    j, i, vmax, scale_factor_table[index], index);
 +#if 0
 +            printf("%2d:%d in=%x %x %d\n",
 +                   j, i, vmax, scale_factor_table[index], index);
 +#endif
              /* store the scale factor */
              assert(index >=0 && index <= 63);
              sf[i] = index;
              code = 0;           /* kill warning */
          }
  
 -        av_dlog(NULL, "%d: %2d %2d %2d %d %d -> %d\n", j,
 -                sf[0], sf[1], sf[2], d1, d2, code);
 +#if 0
 +        printf("%d: %2d %2d %2d %d %d -> %d\n", j,
 +               sf[0], sf[1], sf[2], d1, d2, code);
 +#endif
          scale_code[j] = code;
          sf += 3;
      }
@@@ -547,11 -544,9 +548,11 @@@ static void compute_bit_allocation(Mpeg
                  }
              }
          }
 -        av_dlog(NULL, "current=%d max=%d max_sb=%d alloc=%d\n",
 -                current_frame_size, max_frame_size, max_sb,
 -                bit_alloc[max_sb]);
 +#if 0
 +        printf("current=%d max=%d max_sb=%d alloc=%d\n",
 +               current_frame_size, max_frame_size, max_sb,
 +               bit_alloc[max_sb]);
 +#endif
          if (max_sb < 0)
              break;
  
diff --combined libavformat/mpegtsenc.c
@@@ -2,20 -2,20 +2,20 @@@
   * MPEG2 transport stream (aka DVB) muxer
   * Copyright (c) 2003 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -76,23 -76,23 +76,23 @@@ typedef struct MpegTSWrite 
  
  static const AVOption options[] = {
      { "mpegts_transport_stream_id", "Set transport_stream_id field.",
 -      offsetof(MpegTSWrite, transport_stream_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
 +      offsetof(MpegTSWrite, transport_stream_id), FF_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
      { "mpegts_original_network_id", "Set original_network_id field.",
 -      offsetof(MpegTSWrite, original_network_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
 +      offsetof(MpegTSWrite, original_network_id), FF_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
      { "mpegts_service_id", "Set service_id field.",
 -      offsetof(MpegTSWrite, service_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
 +      offsetof(MpegTSWrite, service_id), FF_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
      { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
 -      offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, 0x1000, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM},
 +      offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, {.dbl = 0x1000 }, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM},
      { "mpegts_start_pid", "Set the first pid.",
 -      offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, 0x0100, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM},
 +      offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, {.dbl = 0x0100 }, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM},
      { NULL },
  };
  
  static const AVClass mpegts_muxer_class = {
 -    "MPEGTS muxer",
 -    av_default_item_name,
 -    options,
 -    LIBAVUTIL_VERSION_INT,
 +    .class_name     = "MPEGTS muxer",
 +    .item_name      = av_default_item_name,
 +    .option         = options,
 +    .version        = LIBAVUTIL_VERSION_INT,
  };
  
  /* NOTE: 4 bytes must be left at the end for the crc32 */
@@@ -181,7 -181,7 +181,7 @@@ static int mpegts_write_section1(MpegTS
  /*********************************************/
  /* mpegts writer */
  
 -#define DEFAULT_PROVIDER_NAME   "Libav"
 +#define DEFAULT_PROVIDER_NAME   "FFmpeg"
  #define DEFAULT_SERVICE_NAME    "Service01"
  
  /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
@@@ -588,7 -588,7 +588,7 @@@ static int mpegts_write_header(AVFormat
      av_free(pids);
      for(i = 0;i < s->nb_streams; i++) {
          st = s->streams[i];
-         av_free(st->priv_data);
+         av_freep(&st->priv_data);
      }
      return -1;
  }
diff --combined libavformat/rtpproto.c
@@@ -2,20 -2,20 +2,20 @@@
   * RTP network protocol
   * Copyright (c) 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -138,15 -138,13 +138,13 @@@ static int rtp_open(URLContext *h, cons
  {
      RTPContext *s;
      int rtp_port, rtcp_port,
-         is_output, ttl, connect,
+         ttl, connect,
          local_rtp_port, local_rtcp_port, max_packet_size;
      char hostname[256];
      char buf[1024];
      char path[1024];
      const char *p;
  
-     is_output = (flags & AVIO_FLAG_WRITE);
      s = av_mallocz(sizeof(RTPContext));
      if (!s)
          return AVERROR(ENOMEM);
diff --combined libavformat/udp.c
@@@ -2,20 -2,20 +2,20 @@@
   * UDP prototype streaming system
   * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -315,7 -315,7 +315,7 @@@ static int udp_open(URLContext *h, cons
      h->is_streamed = 1;
      h->max_packet_size = 1472;
  
-     is_output = (flags & AVIO_FLAG_WRITE);
+     is_output = !(flags & AVIO_FLAG_READ);
  
      s = av_mallocz(sizeof(UDPContext));
      if (!s)
      /* XXX: fix av_url_split */
      if (hostname[0] == '\0' || hostname[0] == '?') {
          /* only accepts null hostname if input */
-         if (flags & AVIO_FLAG_WRITE)
+         if (!(flags & AVIO_FLAG_READ))
              goto fail;
      } else {
          if (ff_udp_set_remote_url(h, uri) < 0)
              goto fail;
      }
  
-     if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE))
+     if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
          s->local_port = port;
      udp_fd = udp_socket_create(s, &my_addr, &len);
      if (udp_fd < 0)
  
      /* the bind is needed to give a port to the socket now */
      /* if multicast, try the multicast address bind first */
-     if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE)) {
+     if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) {
          bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);
      }
      /* bind to the local address if not multicast or if the multicast
      s->local_port = udp_port(&my_addr, len);
  
      if (s->is_multicast) {
-         if (h->flags & AVIO_FLAG_WRITE) {
+         if (!(h->flags & AVIO_FLAG_READ)) {
              /* output */
              if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
                  goto fail;
@@@ -478,7 -478,7 +478,7 @@@ static int udp_close(URLContext *h
  {
      UDPContext *s = h->priv_data;
  
-     if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE))
+     if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
          udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
      closesocket(s->udp_fd);
      av_free(s);
@@@ -61,7 -61,7 +61,7 @@@ do_video_decodin
  
  # mpeg2 encoding interlaced
  file=${outfile}mpeg2reuse.mpg
- do_ffmpeg $file -sameq -me_threshold 256 -mb_threshold 1024 -i ${target_path}/${outfile}mpeg2thread.mpg -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
+ do_ffmpeg $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -sameq -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
  do_video_decoding
  fi
  
@@@ -75,11 -75,6 +75,11 @@@ do_video_encoding msmpeg4.avi "-qscale 
  do_video_decoding
  fi
  
 +if [ -n "$do_msvideo1" ] ; then
 +do_video_encoding msvideo1.avi "-an -vcodec msvideo1"
 +do_video_decoding "" "-pix_fmt yuv420p"
 +fi
 +
  if [ -n "$do_wmv1" ] ; then
  do_video_encoding wmv1.avi "-qscale 10 -an -vcodec wmv1"
  do_video_decoding
@@@ -248,11 -243,6 +248,11 @@@ do_video_encoding flashsv.flv "-an -vco
  do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact"
  fi
  
 +if [ -n "$do_flashsv2" ] ; then
 +do_video_encoding flashsv2.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental"
 +#do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact"
 +fi
 +
  if [ -n "$do_roq" ] ; then
  do_video_encoding roqav.roq "-vframes 5"
  do_video_decoding "" "-pix_fmt yuv420p"
  
  if [ -n "$do_wmav1" ] ; then
  do_audio_encoding wmav1.asf "-acodec wmav1"
- do_ffmpeg_nomd5 $pcm_dst -i $target_path/$file -f wav
+ do_ffmpeg_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
  $tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile
  fi
  if [ -n "$do_wmav2" ] ; then
  do_audio_encoding wmav2.asf "-acodec wmav2"
- do_ffmpeg_nomd5 $pcm_dst -i $target_path/$file -f wav
+ do_ffmpeg_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
  $tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile
  fi
  
@@@ -19,8 -19,8 +19,8 @@@ do_video_filter() 
      filters=$2
      shift 2
      printf '%-20s' $label >>$logfile
-     run_ffmpeg -f image2 -vcodec pgmyuv -i $raw_src    \
-         -vf "$filters" -vcodec rawvideo $* -f nut md5: >>$logfile
+     run_ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src    \
+         $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5: >>$logfile
  }
  
  do_lavfi() {
@@@ -55,7 -55,7 +55,7 @@@ do_lavfi_pixfmts()
      $ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts
      $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
  
 -    pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
 +    pix_fmts=$($showfiltfmts $filter $filter_args | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
      for pix_fmt in $pix_fmts; do
          do_video_filter $pix_fmt "slicify=random,format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
      done