[FFmpeg-cvslog] ffmpeg: add support for audio filters.

Anton Khirnov git at videolan.org
Thu May 17 04:12:58 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat May  5 18:22:46 2012 +0200| [fc49f22c3b735db5aaac5f98e40b7124a2be13b8] | committer: Michael Niedermayer

ffmpeg: add support for audio filters.

Some of the FATE changes are due to off-by-one different rounding being used
(lrintf vs av_rescale_q).
Some fate changes are due to 1 audio frame less being encoded (the new variant seems
matching what qatar does and according to ffprobe its closer to the requested duration)
the mapchan feature sadly is lost in this commit because it depends on resampling
being done in ffmpeg.c which is now moved completely into the av filter layer
-async is broken after this commit, this will be fixed in subsequent commits
the new filter reconfiguration system is flawed and will drop a frame on each
parameter change which is why the nelly moser checksums need updating.

Conflicts:

	ffmpeg.c
	tests/ref/fate/smjpeg

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fc49f22c3b735db5aaac5f98e40b7124a2be13b8
---

 ffmpeg.c                        |  925 ++++++++++++++++-----------------------
 libavfilter/buffersrc.h         |    3 +
 tests/Makefile                  |    2 +-
 tests/fate/audio.mak            |    6 +-
 tests/ref/acodec/g723_1         |    6 +-
 tests/ref/fate/adpcm-ima-amv    |   20 +-
 tests/ref/fate/adpcm-ima-smjpeg |   16 +-
 tests/ref/fate/smjpeg           |  425 ++++++++++++++++++
 tests/ref/lavf/asf              |    4 +-
 tests/ref/lavf/avi              |    6 +-
 tests/ref/lavf/dv_fmt           |    6 +-
 tests/ref/lavf/ffm              |    4 +-
 tests/ref/lavf/gxf              |    8 +-
 tests/ref/lavf/mkv              |    6 +-
 tests/ref/lavf/mpg              |   12 +-
 tests/ref/lavf/nut              |    6 +-
 tests/ref/lavf/ogg              |    6 +-
 tests/ref/lavf/rm               |    4 +-
 tests/ref/lavf/ts               |    6 +-
 tests/ref/lavf/wtv              |    4 +-
 tests/ref/seek/lavf_mkv         |    6 +-
 tests/ref/seek/lavf_mpg         |    6 +-
 22 files changed, 882 insertions(+), 605 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 54ad2a3..da763ee 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -96,6 +96,9 @@
 #define VSYNC_VFR         2
 #define VSYNC_DROP        0xff
 
+// #define SRCA
+#define SINKA
+
 const char program_name[] = "ffmpeg";
 const int program_birth_year = 2000;
 
@@ -167,11 +170,6 @@ static int print_stats = 1;
 static int debug_ts = 0;
 static int current_time;
 
-static uint8_t *audio_buf;
-static unsigned int allocated_audio_buf_size;
-static uint8_t *async_buf;
-static unsigned int allocated_async_buf_size;
-
 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
 
 typedef struct InputFilter {
@@ -241,6 +239,11 @@ typedef struct InputStream {
     int resample_width;
     int resample_pix_fmt;
 
+    int      resample_sample_fmt;
+    int      resample_sample_rate;
+    int      resample_channels;
+    uint64_t resample_channel_layout;
+
     /* a pool of free buffers for decoded data */
     FrameBuffer *buffer_pool;
     int dr1;
@@ -276,7 +279,6 @@ typedef struct OutputStream {
     AVBitStreamFilterContext *bitstream_filters;
     AVCodec *enc;
     int64_t max_frames;
-    AVFrame *output_frame;
     AVFrame *filtered_frame;
 
     /* video only */
@@ -292,20 +294,8 @@ typedef struct OutputStream {
     int forced_kf_count;
     int forced_kf_index;
 
-    /* audio only */
-    int audio_resample;
-    int audio_channels_map[SWR_CH_MAX];  ///< list of the channels id to pick from the source stream
-    int audio_channels_mapped;           ///< number of channels in audio_channels_map
-    int resample_sample_fmt;
-    int resample_channels;
-    uint64_t resample_channel_layout;
-    int resample_sample_rate;
-    float rematrix_volume;
-    AVFifoBuffer *fifo;     /* for compression: one audio fifo per codec */
     FILE *logfile;
 
-    SwrContext *swr;
-
     OutputFilter *filter;
     char *avfilter;
 
@@ -363,8 +353,6 @@ typedef struct OptionsContext {
     int        nb_audio_channels;
     SpecifierOpt *audio_sample_rate;
     int        nb_audio_sample_rate;
-    SpecifierOpt *rematrix_volume;
-    int        nb_rematrix_volume;
     SpecifierOpt *frame_rates;
     int        nb_frame_rates;
     SpecifierOpt *frame_sizes;
@@ -705,9 +693,9 @@ static enum PixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum Pixe
     return target;
 }
 
-static char *choose_pixel_fmts(OutputStream *ost)
+static char *choose_pix_fmts(OutputStream *ost)
 {
-    if (ost->keep_pix_fmt) {
+     if (ost->keep_pix_fmt) {
         if (ost->filter)
             avfilter_graph_set_auto_convert(ost->filter->graph->graph,
                                             AVFILTER_AUTO_CONVERT_NONE);
@@ -737,8 +725,10 @@ static char *choose_pixel_fmts(OutputStream *ost)
             }
         }
 
-        for (; *p != PIX_FMT_NONE; p++)
-            avio_printf(s, "%s:", av_get_pix_fmt_name(*p));
+        for (; *p != PIX_FMT_NONE; p++) {
+            const char *name = av_get_pix_fmt_name(*p);
+            avio_printf(s, "%s:", name);
+        }
         len = avio_close_dyn_buf(s, &ret);
         ret[len - 1] = 0;
         return ret;
@@ -746,11 +736,149 @@ static char *choose_pixel_fmts(OutputStream *ost)
         return NULL;
 }
 
-static int configure_video_filters(FilterGraph *fg)
+/**
+ * Define a function for building a string containing a list of
+ * allowed formats,
+ */
+#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name, separator) \
+static char *choose_ ## var ## s(OutputStream *ost)                             \
+{                                                                               \
+    if (ost->st->codec->var != none) {                                          \
+        get_name(ost->st->codec->var);                                          \
+        return av_strdup(name);                                                 \
+    } else if (ost->enc->supported_list) {                                      \
+        const type *p;                                                          \
+        AVIOContext *s = NULL;                                                  \
+        uint8_t *ret;                                                           \
+        int len;                                                                \
+                                                                                \
+        if (avio_open_dyn_buf(&s) < 0)                                          \
+            exit_program(1);                                                    \
+                                                                                \
+        for (p = ost->enc->supported_list; *p != none; p++) {                   \
+            get_name(*p);                                                       \
+            avio_printf(s, "%s" separator, name);                               \
+        }                                                                       \
+        len = avio_close_dyn_buf(s, &ret);                                      \
+        ret[len - 1] = 0;                                                       \
+        return ret;                                                             \
+    } else                                                                      \
+        return NULL;                                                            \
+}
+
+#define GET_PIX_FMT_NAME(pix_fmt)\
+    const char *name = av_get_pix_fmt_name(pix_fmt);
+
+// DEF_CHOOSE_FORMAT(enum PixelFormat, pix_fmt, pix_fmts, PIX_FMT_NONE,
+//                   GET_PIX_FMT_NAME, ":")
+
+#define GET_SAMPLE_FMT_NAME(sample_fmt)\
+    const char *name = av_get_sample_fmt_name(sample_fmt)
+
+DEF_CHOOSE_FORMAT(enum AVSampleFormat, sample_fmt, sample_fmts,
+                  AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME, ",")
+
+#define GET_SAMPLE_RATE_NAME(rate)\
+    char name[16];\
+    snprintf(name, sizeof(name), "%d", rate);
+
+DEF_CHOOSE_FORMAT(int, sample_rate, supported_samplerates, 0,
+                  GET_SAMPLE_RATE_NAME, ",")
+
+#define GET_CH_LAYOUT_NAME(ch_layout)\
+    char name[16];\
+    snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
+
+DEF_CHOOSE_FORMAT(uint64_t, channel_layout, channel_layouts, 0,
+                  GET_CH_LAYOUT_NAME, ",")
+
+static int configure_audio_filters(FilterGraph *fg, AVFilterContext **in_filter,
+                                   AVFilterContext **out_filter)
+{
+    InputStream  *ist = fg->inputs[0]->ist;
+    OutputStream *ost = fg->outputs[0]->ost;
+    AVCodecContext *codec  = ost->st->codec;
+    AVCodecContext *icodec = ist->st->codec;
+    char *sample_fmts, *sample_rates, *channel_layouts;
+    char args[256];
+    int ret;
+
+    avfilter_graph_free(&fg->graph);
+    if (!(fg->graph = avfilter_graph_alloc()))
+        return AVERROR(ENOMEM);
+
+#ifdef SRCA
+    snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:"
+             "channel_layout=0x%"PRIx64, ist->st->time_base.num,
+#else
+    snprintf(args, sizeof(args), "%d/%d:%d:%s:"
+             "0x%"PRIx64, ist->st->time_base.num,
+#endif
+             ist->st->time_base.den, icodec->sample_rate,
+             av_get_sample_fmt_name(icodec->sample_fmt), icodec->channel_layout);
+    ret = avfilter_graph_create_filter(&fg->inputs[0]->filter,
+                                       avfilter_get_by_name("abuffer"),
+                                       "src", args, NULL, fg->graph);
+    if (ret < 0)
+        return ret;
+
+    ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
+                                       avfilter_get_by_name("abuffersink_old"),
+                                       "out", NULL, NULL, fg->graph);
+    if (ret < 0)
+        return ret;
+
+    *in_filter  = fg->inputs[0]->filter;
+    *out_filter = fg->outputs[0]->filter;
+
+    if (codec->channels && !codec->channel_layout)
+        codec->channel_layout = av_get_default_channel_layout(codec->channels);
+
+    sample_fmts     = choose_sample_fmts(ost);
+    sample_rates    = choose_sample_rates(ost);
+    channel_layouts = choose_channel_layouts(ost);
+    if (sample_fmts || sample_rates || channel_layouts) {
+        AVFilterContext *format;
+        char args[256];
+        int len = 0;
+
+        if (sample_fmts)
+            len += snprintf(args + len, sizeof(args) - len, "sample_fmts=%s:",
+                            sample_fmts);
+        if (sample_rates)
+            len += snprintf(args + len, sizeof(args) - len, "sample_rates=%s:",
+                            sample_rates);
+        if (channel_layouts)
+            len += snprintf(args + len, sizeof(args) - len, "channel_layouts=%s:",
+                            channel_layouts);
+        args[len - 1] = 0;
+
+        av_freep(&sample_fmts);
+        av_freep(&sample_rates);
+        av_freep(&channel_layouts);
+
+        ret = avfilter_graph_create_filter(&format,
+                                           avfilter_get_by_name("aformat"),
+                                           "aformat", args, NULL, fg->graph);
+        if (ret < 0)
+            return ret;
+
+        ret = avfilter_link(format, 0, fg->outputs[0]->filter, 0);
+        if (ret < 0)
+            return ret;
+
+        *out_filter = format;
+    }
+
+    return 0;
+}
+
+static int configure_video_filters(FilterGraph *fg, AVFilterContext **in_filter,
+                                   AVFilterContext **out_filter)
 {
     InputStream  *ist = fg->inputs[0]->ist;
     OutputStream *ost = fg->outputs[0]->ost;
-    AVFilterContext *in_filter, *out_filter, *filter;
+    AVFilterContext *filter;
     AVCodecContext *codec = ost->st->codec;
     AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
     char *pix_fmts;
@@ -758,11 +886,6 @@ static int configure_video_filters(FilterGraph *fg)
     char args[255];
     int ret;
 
-    avfilter_graph_free(&fg->graph);
-    fg->graph = avfilter_graph_alloc();
-    if (!fg->graph)
-        return AVERROR(ENOMEM);
-
     if (ist->st->sample_aspect_ratio.num) {
         sample_aspect_ratio = ist->st->sample_aspect_ratio;
     } else
@@ -791,8 +914,8 @@ static int configure_video_filters(FilterGraph *fg)
 
     if (ret < 0)
         return ret;
-    in_filter  = fg->inputs[0]->filter;
-    out_filter = fg->outputs[0]->filter;
+    *in_filter  = fg->inputs[0]->filter;
+    *out_filter = fg->outputs[0]->filter;
 
     if (codec->width || codec->height) {
         snprintf(args, 255, "%d:%d:flags=0x%X",
@@ -802,27 +925,53 @@ static int configure_video_filters(FilterGraph *fg)
         if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
                                                 NULL, args, NULL, fg->graph)) < 0)
             return ret;
-        if ((ret = avfilter_link(in_filter, 0, filter, 0)) < 0)
+        if ((ret = avfilter_link(*in_filter, 0, filter, 0)) < 0)
             return ret;
-        in_filter = filter;
+        *in_filter = filter;
     }
 
-    if ((pix_fmts = choose_pixel_fmts(ost))) {
+    if ((pix_fmts = choose_pix_fmts(ost))) {
         if ((ret = avfilter_graph_create_filter(&filter,
                                                 avfilter_get_by_name("format"),
                                                 "format", pix_fmts, NULL,
                                                 fg->graph)) < 0)
             return ret;
-        if ((ret = avfilter_link(filter, 0, out_filter, 0)) < 0)
+        if ((ret = avfilter_link(filter, 0, *out_filter, 0)) < 0)
             return ret;
 
-        out_filter = filter;
+        *out_filter = filter;
         av_freep(&pix_fmts);
     }
 
     snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
     fg->graph->scale_sws_opts = av_strdup(args);
 
+    return 0;
+}
+
+static int configure_simple_filtergraph(FilterGraph *fg)
+{
+    OutputStream *ost = fg->outputs[0]->ost;
+    AVFilterContext *in_filter, *out_filter;
+    int ret;
+
+    avfilter_graph_free(&fg->graph);
+    fg->graph = avfilter_graph_alloc();
+    if (!fg->graph)
+        return AVERROR(ENOMEM);
+
+    switch (ost->st->codec->codec_type) {
+    case AVMEDIA_TYPE_VIDEO:
+        ret = configure_video_filters(fg, &in_filter, &out_filter);
+        break;
+    case AVMEDIA_TYPE_AUDIO:
+        ret = configure_audio_filters(fg, &in_filter, &out_filter);
+        break;
+    default: av_assert0(0);
+    }
+    if (ret < 0)
+        return ret;
+
     if (ost->avfilter) {
         AVFilterInOut *outputs = avfilter_inout_alloc();
         AVFilterInOut *inputs  = avfilter_inout_alloc();
@@ -1000,7 +1149,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFil
         pad_idx = 0;
     }
 
-    if ((pix_fmts = choose_pixel_fmts(ofilter->ost))) {
+    if ((pix_fmts = choose_pix_fmts(ofilter->ost))) {
         AVFilterContext *filter;
         if ((ret = avfilter_graph_create_filter(&filter,
                                                 avfilter_get_by_name("format"),
@@ -1097,7 +1246,8 @@ static int configure_complex_filters(void)
 
 static int configure_filtergraph(FilterGraph *fg)
 {
-    return fg->graph_desc ? configure_complex_filter(fg) : configure_video_filters(fg);
+    return fg->graph_desc ? configure_complex_filter(fg) :
+                            configure_simple_filtergraph(fg);
 }
 
 static int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
@@ -1258,12 +1408,6 @@ void av_noreturn exit_program(int ret)
         }
         output_streams[i]->bitstream_filters = NULL;
 
-        if (output_streams[i]->output_frame) {
-            AVFrame *frame = output_streams[i]->output_frame;
-            if (frame->extended_data != frame->data)
-                av_freep(&frame->extended_data);
-            av_freep(&frame);
-        }
         av_freep(&output_streams[i]->filtered_frame);
         av_freep(&output_streams[i]);
     }
@@ -1289,10 +1433,6 @@ void av_noreturn exit_program(int ret)
     av_freep(&output_files);
 
     uninit_opts();
-    av_freep(&audio_buf);
-    allocated_audio_buf_size = 0;
-    av_freep(&async_buf);
-    allocated_async_buf_size = 0;
 
     avfilter_uninit();
     avformat_network_deinit();
@@ -1354,37 +1494,6 @@ static void choose_sample_fmt(AVStream *st, AVCodec *codec)
     }
 }
 
-static void choose_sample_rate(AVStream *st, AVCodec *codec)
-{
-    if (codec && codec->supported_samplerates) {
-        const int *p  = codec->supported_samplerates;
-        int best      = 0;
-        int best_dist = INT_MAX;
-        for (; *p; p++) {
-            int dist = abs(st->codec->sample_rate - *p);
-            if (dist < best_dist) {
-                best_dist = dist;
-                best      = *p;
-            }
-        }
-        if (best_dist) {
-            int i;
-            const int *sample_rates = codec->supported_samplerates;
-            av_log(st->codec, AV_LOG_WARNING,
-                   "Requested sampling rate (%dHz) unsupported, using %dHz instead\n"
-                   "Available sampling rates for %s:",
-                   st->codec->sample_rate, best, codec->name);
-            for (i = 0; sample_rates[i]; i++) {
-                if (!sample_rates[i + 1]) av_log(st->codec, AV_LOG_WARNING, " and");
-                else if (i)               av_log(st->codec, AV_LOG_WARNING, ",");
-                av_log(st->codec, AV_LOG_WARNING, " %d", sample_rates[i]);
-            }
-            av_log(st->codec, AV_LOG_WARNING, ".\n");
-        }
-        st->codec->sample_rate = best;
-    }
-}
-
 static double
 get_sync_ipts(const OutputStream *ost, int64_t pts)
 {
@@ -1447,104 +1556,38 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
     }
 }
 
-static void get_default_channel_layouts(OutputStream *ost, InputStream *ist)
-{
-    char layout_name[256];
-    AVCodecContext *enc = ost->st->codec;
-    AVCodecContext *dec = ist->st->codec;
-
-    if (dec->channel_layout &&
-        av_get_channel_layout_nb_channels(dec->channel_layout) != dec->channels) {
-        av_get_channel_layout_string(layout_name, sizeof(layout_name),
-                                     dec->channels, dec->channel_layout);
-        av_log(NULL, AV_LOG_ERROR, "New channel layout (%s) is invalid\n",
-               layout_name);
-        dec->channel_layout = 0;
-    }
-    if (!dec->channel_layout) {
-        if (enc->channel_layout && dec->channels == enc->channels) {
-            dec->channel_layout = enc->channel_layout;
-        } else {
-            dec->channel_layout = av_get_default_channel_layout(dec->channels);
-
-            if (!dec->channel_layout) {
-                av_log(NULL, AV_LOG_FATAL, "Unable to find default channel "
-                       "layout for Input Stream #%d.%d\n", ist->file_index,
-                       ist->st->index);
-                exit_program(1);
-            }
-        }
-        av_get_channel_layout_string(layout_name, sizeof(layout_name),
-                                     dec->channels, dec->channel_layout);
-        av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for  Input Stream "
-               "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
-    }
-    if (!enc->channel_layout) {
-        if (dec->channels == enc->channels) {
-            enc->channel_layout = dec->channel_layout;
-            return;
-        } else {
-            enc->channel_layout = av_get_default_channel_layout(enc->channels);
-        }
-        if (!enc->channel_layout) {
-            av_log(NULL, AV_LOG_FATAL, "Unable to find default channel layout "
-                   "for Output Stream #%d.%d\n", ost->file_index,
-                   ost->st->index);
-            exit_program(1);
-        }
-        av_get_channel_layout_string(layout_name, sizeof(layout_name),
-                                     enc->channels, enc->channel_layout);
-        av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Output Stream "
-               "#%d.%d : %s\n", ost->file_index, ost->st->index, layout_name);
-    }
-}
-
-static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size)
-{
-    int fill_char = 0x00;
-    if (sample_fmt == AV_SAMPLE_FMT_U8)
-        fill_char = 0x80;
-    memset(buf, fill_char, size);
-}
+// static int check_recording_time(OutputStream *ost)
+// {
+//     OutputFile *of = output_files[ost->file_index];
+//
+//     if (of->recording_time != INT64_MAX &&
+//         av_compare_ts(ost->sync_opts - ost->first_pts, ost->st->codec->time_base, of->recording_time,
+//                       AV_TIME_BASE_Q) >= 0) {
+//         ost->is_past_recording_time = 1;
+//         return 0;
+//     }
+//     return 1;
+// }
 
-static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
-                              const uint8_t *buf, int buf_size)
+static void do_audio_out(AVFormatContext *s, OutputStream *ost,
+                         AVFrame *frame)
 {
     AVCodecContext *enc = ost->st->codec;
-    AVFrame *frame = NULL;
     AVPacket pkt;
-    int ret, got_packet;
+    int got_packet = 0;
 
     av_init_packet(&pkt);
     pkt.data = NULL;
     pkt.size = 0;
-
-    if (buf && buf_size) {
-        if (!ost->output_frame) {
-            ost->output_frame = avcodec_alloc_frame();
-            if (!ost->output_frame) {
-                av_log(NULL, AV_LOG_FATAL, "out-of-memory in encode_audio_frame()\n");
-                exit_program(1);
-            }
-        }
-        frame = ost->output_frame;
-        if (frame->extended_data != frame->data)
-            av_freep(&frame->extended_data);
-        avcodec_get_frame_defaults(frame);
-
-        frame->nb_samples  = buf_size /
-                             (enc->channels * av_get_bytes_per_sample(enc->sample_fmt));
-        if ((ret = avcodec_fill_audio_frame(frame, enc->channels, enc->sample_fmt,
-                                            buf, buf_size, 1)) < 0) {
-            av_log(NULL, AV_LOG_FATAL, "Audio encoding failed (avcodec_fill_audio_frame)\n");
-            exit_program(1);
-        }
-
+#if 0
+    if (!check_recording_time(ost))
+        return;
+#endif
+    if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
         frame->pts = ost->sync_opts;
-        ost->sync_opts += frame->nb_samples;
-    }
+    ost->sync_opts = frame->pts + frame->nb_samples;
 
-    got_packet = 0;
+    av_assert0(pkt.size || !pkt.data);
     update_benchmark(NULL);
     if (avcodec_encode_audio2(enc, &pkt, frame, &got_packet) < 0) {
         av_log(NULL, AV_LOG_FATAL, "Audio encoding failed (avcodec_encode_audio2)\n");
@@ -1552,8 +1595,6 @@ static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
     }
     update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
 
-    ret = pkt.size;
-
     if (got_packet) {
         if (pkt.pts != AV_NOPTS_VALUE)
             pkt.pts      = av_rescale_q(pkt.pts,      enc->time_base, ost->st->time_base);
@@ -1568,244 +1609,18 @@ static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
         if (pkt.duration > 0)
             pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);
 
+        if (debug_ts) {
+            av_log(NULL, AV_LOG_INFO, "encoder -> type:audio "
+                   "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
+                   av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base),
+                   av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base));
+        }
+
         write_frame(s, &pkt, ost);
 
         audio_size += pkt.size;
-
         av_free_packet(&pkt);
     }
-
-    if (debug_ts) {
-        av_log(NULL, AV_LOG_INFO, "encoder -> type:audio "
-               "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
-               av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base),
-               av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base));
-    }
-
-    return ret;
-}
-
-static int alloc_audio_output_buf(AVCodecContext *dec, AVCodecContext *enc,
-                                  int nb_samples, int *buf_linesize)
-{
-    int64_t audio_buf_samples;
-    int audio_buf_size;
-
-    /* calculate required number of samples to allocate */
-    audio_buf_samples = ((int64_t)nb_samples * enc->sample_rate + dec->sample_rate) /
-                        dec->sample_rate;
-    audio_buf_samples = 4 * audio_buf_samples + 10000; // safety factors for resampling
-    audio_buf_samples = FFMAX(audio_buf_samples, enc->frame_size);
-    if (audio_buf_samples > INT_MAX)
-        return AVERROR(EINVAL);
-
-    audio_buf_size = av_samples_get_buffer_size(buf_linesize, enc->channels,
-                                                audio_buf_samples,
-                                                enc->sample_fmt, 0);
-    if (audio_buf_size < 0)
-        return audio_buf_size;
-
-    av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size);
-    if (!audio_buf)
-        return AVERROR(ENOMEM);
-
-    return 0;
-}
-
-static void do_audio_out(AVFormatContext *s, OutputStream *ost,
-                         InputStream *ist, AVFrame *decoded_frame)
-{
-    uint8_t *buftmp;
-    int64_t size_out;
-
-    int frame_bytes, resample_changed;
-    AVCodecContext *enc = ost->st->codec;
-    AVCodecContext *dec = ist->st->codec;
-    int osize = av_get_bytes_per_sample(enc->sample_fmt);
-    int isize = av_get_bytes_per_sample(dec->sample_fmt);
-    uint8_t *buf[AV_NUM_DATA_POINTERS];
-    int size     = decoded_frame->nb_samples * dec->channels * isize;
-    int planes   = av_sample_fmt_is_planar(dec->sample_fmt) ? dec->channels : 1;
-    int i;
-    int out_linesize = 0;
-
-    av_assert0(planes <= AV_NUM_DATA_POINTERS);
-
-    for(i=0; i<planes; i++)
-        buf[i]= decoded_frame->data[i];
-
-
-    get_default_channel_layouts(ost, ist);
-
-    if (alloc_audio_output_buf(dec, enc, decoded_frame->nb_samples, &out_linesize) < 0) {
-        av_log(NULL, AV_LOG_FATAL, "Error allocating audio buffer\n");
-        exit_program(1);
-    }
-
-    if (audio_sync_method > 1                      ||
-        enc->channels       != dec->channels       ||
-        enc->channel_layout != dec->channel_layout ||
-        enc->sample_rate    != dec->sample_rate    ||
-        dec->sample_fmt     != enc->sample_fmt)
-        ost->audio_resample = 1;
-
-    resample_changed = ost->resample_sample_fmt  != dec->sample_fmt ||
-                       ost->resample_channels    != dec->channels   ||
-                       ost->resample_channel_layout != dec->channel_layout ||
-                       ost->resample_sample_rate != dec->sample_rate;
-
-    if ((ost->audio_resample && !ost->swr) || resample_changed || ost->audio_channels_mapped) {
-
-        if (resample_changed) {
-            av_log(NULL, AV_LOG_INFO, "Input stream #%d:%d frame changed from rate:%d fmt:%s ch:%d chl:0x%"PRIx64" to rate:%d fmt:%s ch:%d chl:0x%"PRIx64"\n",
-                   ist->file_index, ist->st->index,
-                   ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt),
-                   ost->resample_channels, ost->resample_channel_layout,
-                   dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt),
-                   dec->channels, dec->channel_layout);
-            ost->resample_sample_fmt  = dec->sample_fmt;
-            ost->resample_channels    = dec->channels;
-            ost->resample_channel_layout = dec->channel_layout;
-            ost->resample_sample_rate = dec->sample_rate;
-            swr_free(&ost->swr);
-        }
-        /* if audio_sync_method is >1 the resampler is needed for audio drift compensation */
-        if (audio_sync_method <= 1 && !ost->audio_channels_mapped &&
-            ost->resample_sample_fmt  == enc->sample_fmt &&
-            ost->resample_channels    == enc->channels   &&
-            ost->resample_channel_layout == enc->channel_layout &&
-            ost->resample_sample_rate == enc->sample_rate) {
-            //ost->swr = NULL;
-            ost->audio_resample = 0;
-        } else {
-            ost->swr = swr_alloc_set_opts(ost->swr,
-                                          enc->channel_layout, enc->sample_fmt, enc->sample_rate,
-                                          dec->channel_layout, dec->sample_fmt, dec->sample_rate,
-                                          0, NULL);
-            av_opt_set_int(ost->swr, "dither_method", ost->swr_dither_method,0);
-            av_opt_set_double(ost->swr, "dither_scale", ost->swr_dither_scale,0);
-            if (ost->audio_channels_mapped)
-                swr_set_channel_mapping(ost->swr, ost->audio_channels_map);
-            av_opt_set_double(ost->swr, "rmvol", ost->rematrix_volume, 0);
-            if (ost->audio_channels_mapped) {
-                av_opt_set_int(ost->swr, "icl", av_get_default_channel_layout(ost->audio_channels_mapped), 0);
-                av_opt_set_int(ost->swr, "uch", ost->audio_channels_mapped, 0);
-            }
-            if (av_opt_set_int(ost->swr, "ich", dec->channels, 0) < 0) {
-                av_log(NULL, AV_LOG_FATAL, "Unsupported number of input channels\n");
-                exit_program(1);
-            }
-            if (av_opt_set_int(ost->swr, "och", enc->channels, 0) < 0) {
-                av_log(NULL, AV_LOG_FATAL, "Unsupported number of output channels\n");
-                exit_program(1);
-            }
-            if(audio_sync_method>1) av_opt_set_int(ost->swr, "flags", SWR_FLAG_RESAMPLE, 0);
-            if(ost->swr && swr_init(ost->swr) < 0){
-                av_log(NULL, AV_LOG_FATAL, "swr_init() failed\n");
-                swr_free(&ost->swr);
-            }
-
-            if (!ost->swr) {
-                av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
-                        dec->channels, dec->sample_rate,
-                        enc->channels, enc->sample_rate);
-                exit_program(1);
-            }
-        }
-    }
-
-    av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt);
-
-    if (audio_sync_method > 0) {
-        double delta = get_sync_ipts(ost, ist->pts) * enc->sample_rate - ost->sync_opts -
-                       av_fifo_size(ost->fifo) / (enc->channels * osize);
-        int idelta = delta * dec->sample_rate / enc->sample_rate;
-        int byte_delta = idelta * isize * dec->channels;
-
-        // FIXME resample delay
-        if (fabs(delta) > 50) {
-            if (ist->is_start || fabs(delta) > audio_drift_threshold*enc->sample_rate) {
-                if (byte_delta < 0) {
-                    byte_delta = FFMAX(byte_delta, -size);
-                    size += byte_delta;
-                    for (i=0; i<planes; i++)
-                        buf[i]  -= byte_delta/planes;
-                    av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n",
-                           -byte_delta / (isize * dec->channels));
-                    if (!size)
-                        return;
-                    ist->is_start = 0;
-                } else {
-                    av_fast_malloc(&async_buf, &allocated_async_buf_size,
-                                   byte_delta + size);
-                    if (!async_buf) {
-                        av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n");
-                        exit_program(1);
-                    }
-
-                    if (alloc_audio_output_buf(dec, enc, decoded_frame->nb_samples + idelta, &out_linesize) < 0) {
-                        av_log(NULL, AV_LOG_FATAL, "Error allocating audio buffer\n");
-                        exit_program(1);
-                    }
-                    ist->is_start = 0;
-
-                    for (i=0; i<planes; i++) {
-                        uint8_t *t = async_buf + i*((byte_delta + size)/planes);
-                        generate_silence(t, dec->sample_fmt, byte_delta/planes);
-                        memcpy(t + byte_delta/planes, buf[i], size/planes);
-                        buf[i] = t;
-                    }
-                    size += byte_delta;
-                    av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", idelta);
-                }
-            } else if (audio_sync_method > 1) {
-                int comp = av_clip(delta, -audio_sync_method, audio_sync_method);
-                av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
-                       delta, comp, enc->sample_rate);
-//                fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
-                swr_set_compensation(ost->swr, comp, enc->sample_rate);
-            }
-        }
-    } else if (audio_sync_method == 0)
-        ost->sync_opts = lrintf(get_sync_ipts(ost, ist->pts) * enc->sample_rate) -
-                                av_fifo_size(ost->fifo) / (enc->channels * osize); // FIXME wrong
-
-    if (ost->audio_resample || ost->audio_channels_mapped) {
-        buftmp = audio_buf;
-        size_out = swr_convert(ost->swr, (      uint8_t*[]){buftmp},
-                                      allocated_audio_buf_size / (enc->channels * osize),
-                                      (const uint8_t **)buf,
-                                      size / (dec->channels * isize));
-        if (size_out < 0) {
-            av_log(NULL, AV_LOG_FATAL, "swr_convert failed\n");
-            exit_program(1);
-        }
-        size_out = size_out * enc->channels * osize;
-    } else {
-        buftmp = buf[0];
-        size_out = size;
-    }
-
-    av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt);
-
-    /* now encode as many frames as possible */
-    if (!(enc->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
-        /* output resampled raw samples */
-        if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) {
-            av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n");
-            exit_program(1);
-        }
-        av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL);
-
-        frame_bytes = enc->frame_size * osize * enc->channels;
-
-        while (av_fifo_size(ost->fifo) >= frame_bytes) {
-            av_fifo_generic_read(ost->fifo, audio_buf, frame_bytes, NULL);
-            encode_audio_frame(s, ost, audio_buf, frame_bytes);
-        }
-    } else {
-        encode_audio_frame(s, ost, buftmp, size_out);
-    }
 }
 
 static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp)
@@ -2121,6 +1936,7 @@ static int poll_filters(void)
         for (i = 0; i < nb_output_streams; i++) {
             OutputStream *ost = output_streams[i];
             OutputFile    *of = output_files[ost->file_index];
+            int ret = 0;
 
             if (!ost->filter || ost->is_past_recording_time)
                 continue;
@@ -2133,8 +1949,17 @@ static int poll_filters(void)
 
             while (1) {
                 AVRational ist_pts_tb = ost->filter->filter->inputs[0]->time_base;
-                ret = av_buffersink_get_buffer_ref(ost->filter->filter, &picref,
-                                                   AV_BUFFERSINK_FLAG_NO_REQUEST);
+                if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
+                    !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
+                    ret = av_buffersink_read_samples(ost->filter->filter, &picref,
+                                                    ost->st->codec->frame_size);
+                else
+#ifdef SINKA
+                    ret = av_buffersink_read(ost->filter->filter, &picref);
+#else
+                    ret = av_buffersink_get_buffer_ref(ost->filter->filter, &picref,
+                                                       AV_BUFFERSINK_FLAG_NO_REQUEST);
+#endif
                 if (ret < 0) {
                     if (ret != AVERROR(EAGAIN)) {
                         char buf[256];
@@ -2144,7 +1969,15 @@ static int poll_filters(void)
                     }
                     break;
                 }
-                filtered_frame->pts = frame_pts = av_rescale_q(picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+                if (ost->enc->type == AVMEDIA_TYPE_VIDEO)
+                    filtered_frame->pts = frame_pts = av_rescale_q(picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+                else if (picref->pts != AV_NOPTS_VALUE)
+                    filtered_frame->pts = frame_pts = av_rescale_q(picref->pts,
+                                                    ost->filter->filter->inputs[0]->time_base,
+                                                    ost->st->codec->time_base) -
+                                        av_rescale_q(of->start_time,
+                                                    AV_TIME_BASE_Q,
+                                                    ost->st->codec->time_base);
                 //if (ost->source_index >= 0)
                 //    *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold
 
@@ -2162,8 +1995,13 @@ static int poll_filters(void)
                                  same_quant ? ost->last_quality :
                                               ost->st->codec->global_quality);
                     break;
+                case AVMEDIA_TYPE_AUDIO:
+                    avfilter_copy_buf_props(filtered_frame, picref);
+                    filtered_frame->pts = frame_pts;
+                    do_audio_out(of->ctx, ost, filtered_frame);
+                    break;
                 default:
-                    // TODO support audio/subtitle filters
+                    // TODO support subtitle filters
                     av_assert0(0);
                 }
 
@@ -2346,40 +2184,40 @@ static void flush_encoders(void)
             continue;
 
         for (;;) {
-            AVPacket pkt;
-            int fifo_bytes, got_packet;
-            av_init_packet(&pkt);
-            pkt.data = NULL;
-            pkt.size = 0;
+            int (*encode)(AVCodecContext*, AVPacket*, const AVFrame*, int*) = NULL;
+            const char *desc;
+            int64_t *size;
 
             switch (ost->st->codec->codec_type) {
             case AVMEDIA_TYPE_AUDIO:
-                fifo_bytes = av_fifo_size(ost->fifo);
-                if (fifo_bytes > 0) {
-                    /* encode any samples remaining in fifo */
-                    int frame_bytes = fifo_bytes;
-
-                    av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
-
-                    encode_audio_frame(os, ost, audio_buf, frame_bytes);
-                } else {
-                    /* flush encoder with NULL frames until it is done
-                       returning packets */
-                    if (encode_audio_frame(os, ost, NULL, 0) == 0) {
-                        stop_encoding = 1;
-                        break;
-                    }
-                }
+                encode = avcodec_encode_audio2;
+                desc   = "Audio";
+                size   = &audio_size;
                 break;
             case AVMEDIA_TYPE_VIDEO:
+                encode = avcodec_encode_video2;
+                desc   = "Video";
+                size   = &video_size;
+                break;
+            default:
+                stop_encoding = 1;
+            }
+
+            if (encode) {
+                AVPacket pkt;
+                int got_packet;
+                av_init_packet(&pkt);
+                pkt.data = NULL;
+                pkt.size = 0;
+
                 update_benchmark(NULL);
-                ret = avcodec_encode_video2(enc, &pkt, NULL, &got_packet);
-                update_benchmark("encode_video %d.%d", ost->file_index, ost->index);
+                ret = encode(enc, &pkt, NULL, &got_packet);
+                update_benchmark("flush %s %d.%d", desc, ost->file_index, ost->index);
                 if (ret < 0) {
-                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
+                    av_log(NULL, AV_LOG_FATAL, "%s encoding failed\n", desc);
                     exit_program(1);
                 }
-                video_size += pkt.size;
+                *size += pkt.size;
                 if (ost->logfile && enc->stats_out) {
                     fprintf(ost->logfile, "%s", enc->stats_out);
                 }
@@ -2392,10 +2230,8 @@ static void flush_encoders(void)
                 if (pkt.dts != AV_NOPTS_VALUE)
                     pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
                 write_frame(os, &pkt, ost);
-                break;
-            default:
-                stop_encoding = 1;
             }
+
             if (stop_encoding)
                 break;
         }
@@ -2496,12 +2332,30 @@ static void rate_emu_sleep(InputStream *ist)
     }
 }
 
+static int guess_input_channel_layout(InputStream *ist)
+{
+    AVCodecContext *dec = ist->st->codec;
+
+    if (!dec->channel_layout) {
+        char layout_name[256];
+
+        dec->channel_layout = av_get_default_channel_layout(dec->channels);
+        if (!dec->channel_layout)
+            return 0;
+        av_get_channel_layout_string(layout_name, sizeof(layout_name),
+                                     dec->channels, dec->channel_layout);
+        av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for  Input Stream "
+               "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
+    }
+    return 1;
+}
+
 static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
 {
     AVFrame *decoded_frame;
     AVCodecContext *avctx = ist->st->codec;
     int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
-    int i, ret;
+    int i, ret, resample_changed;
 
     if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
         return AVERROR(ENOMEM);
@@ -2522,6 +2376,13 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
 
     if (!*got_output) {
         /* no audio frame */
+        if (!pkt->size)
+            for (i = 0; i < ist->nb_filters; i++)
+#ifdef SRCA
+                av_buffersrc_buffer(ist->filters[i]->filter, NULL);
+#else
+                av_buffersrc_add_ref(ist->filters[i]->filter, NULL, 0);
+#endif
         return ret;
     }
 
@@ -2529,14 +2390,21 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
        the decoder could be delaying output by a packet or more. */
     if (decoded_frame->pts != AV_NOPTS_VALUE)
         ist->dts = ist->next_dts = ist->pts = ist->next_pts = decoded_frame->pts;
+    else if (pkt->pts != AV_NOPTS_VALUE) {
+        decoded_frame->pts = pkt->pts;
+        pkt->pts           = AV_NOPTS_VALUE;
+    }else
+        decoded_frame->pts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base);
+
 
+#if 1
     /* increment next_dts to use for the case where the input stream does not
        have timestamps or there are multiple frames in the packet */
     ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
                      avctx->sample_rate;
     ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
                      avctx->sample_rate;
-
+#endif
 
     // preprocess audio (volume)
     if (audio_volume != 256) {
@@ -2598,12 +2466,54 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
 
     rate_emu_sleep(ist);
 
-    for (i = 0; i < nb_output_streams; i++) {
-        OutputStream *ost = output_streams[i];
+    resample_changed = ist->resample_sample_fmt     != decoded_frame->format         ||
+                       ist->resample_channels       != avctx->channels               ||
+                       ist->resample_channel_layout != decoded_frame->channel_layout ||
+                       ist->resample_sample_rate    != decoded_frame->sample_rate;
+    if (resample_changed) {
+        char layout1[64], layout2[64];
 
-        if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
-            continue;
-        do_audio_out(output_files[ost->file_index]->ctx, ost, ist, decoded_frame);
+        if (!guess_input_channel_layout(ist)) {
+            av_log(NULL, AV_LOG_FATAL, "Unable to find default channel "
+                   "layout for Input Stream #%d.%d\n", ist->file_index,
+                   ist->st->index);
+            exit_program(1);
+        }
+        decoded_frame->channel_layout = avctx->channel_layout;
+
+        av_get_channel_layout_string(layout1, sizeof(layout1), ist->resample_channels,
+                                     ist->resample_channel_layout);
+        av_get_channel_layout_string(layout2, sizeof(layout2), avctx->channels,
+                                     decoded_frame->channel_layout);
+
+        av_log(NULL, AV_LOG_INFO,
+               "Input stream #%d:%d frame changed from rate:%d fmt:%s ch:%d chl:%s to rate:%d fmt:%s ch:%d chl:%s\n",
+               ist->file_index, ist->st->index,
+               ist->resample_sample_rate,  av_get_sample_fmt_name(ist->resample_sample_fmt),
+               ist->resample_channels, layout1,
+               decoded_frame->sample_rate, av_get_sample_fmt_name(decoded_frame->format),
+               avctx->channels, layout2);
+
+        ist->resample_sample_fmt     = decoded_frame->format;
+        ist->resample_sample_rate    = decoded_frame->sample_rate;
+        ist->resample_channel_layout = decoded_frame->channel_layout;
+        ist->resample_channels       = avctx->channels;
+
+        for (i = 0; i < nb_filtergraphs; i++)
+            if (ist_in_filtergraph(filtergraphs[i], ist) &&
+                configure_filtergraph(filtergraphs[i]) < 0) {
+                av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
+                exit_program(1);
+            }
+    }
+
+    for (i = 0; i < ist->nb_filters; i++) {
+#ifdef SRCA
+        av_buffersrc_write_frame(ist->filters[i]->filter, decoded_frame);
+#else
+        AVFilterBufferRef *fb= avfilter_get_audio_buffer_ref_from_frame(decoded_frame, AV_PERM_WRITE);
+        av_buffersrc_add_ref(ist->filters[i]->filter, fb, 0*AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT);
+#endif
     }
 
     return ret;
@@ -2938,17 +2848,6 @@ static int init_input_stream(int ist_index, char *error, int error_len)
         }
         assert_codec_experimental(ist->st->codec, 0);
         assert_avoptions(ist->opts);
-
-        if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-            for (i = 0; i < nb_output_streams; i++) {
-                OutputStream *ost = output_streams[i];
-                if (ost->source_index == ist_index) {
-                    if (!ist->st->codec->channel_layout || !ost->st->codec->channel_layout)
-                        get_default_channel_layouts(ost, ist);
-                    break;
-                }
-            }
-        }
     }
 
     ist->next_pts = AV_NOPTS_VALUE;
@@ -3146,67 +3045,28 @@ static int transcode_init(void)
                 ist->decoding_needed = 1;
             ost->encoding_needed = 1;
 
-            switch (codec->codec_type) {
-            case AVMEDIA_TYPE_AUDIO:
-                ost->fifo = av_fifo_alloc(1024);
-                if (!ost->fifo) {
-                    return AVERROR(ENOMEM);
-                }
-
-                if (!codec->sample_rate)
-                    codec->sample_rate = icodec->sample_rate;
-                choose_sample_rate(ost->st, ost->enc);
-                codec->time_base = (AVRational){ 1, codec->sample_rate };
-
-                if (codec->sample_fmt == AV_SAMPLE_FMT_NONE)
-                    codec->sample_fmt = icodec->sample_fmt;
-                choose_sample_fmt(ost->st, ost->enc);
-
-                if (ost->audio_channels_mapped) {
-                    /* the requested output channel is set to the number of
-                     * -map_channel only if no -ac are specified */
-                    if (!codec->channels) {
-                        codec->channels       = ost->audio_channels_mapped;
-                        codec->channel_layout = av_get_default_channel_layout(codec->channels);
-                        if (!codec->channel_layout) {
-                            av_log(NULL, AV_LOG_FATAL, "Unable to find an appropriate channel layout for requested number of channel\n");
-                            exit_program(1);
-                        }
-                    }
-                    /* fill unused channel mapping with -1 (which means a muted
-                     * channel in case the number of output channels is bigger
-                     * than the number of mapped channel) */
-                    for (j = ost->audio_channels_mapped; j < FF_ARRAY_ELEMS(ost->audio_channels_map); j++)
-                        ost->audio_channels_map[j] = -1;
-                } else if (!codec->channels) {
-                    codec->channels = icodec->channels;
-                    codec->channel_layout = icodec->channel_layout;
-                }
-                if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels)
-                    codec->channel_layout = 0;
-
-
-//                 ost->audio_resample       = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
-//                 ost->audio_resample      |=    codec->sample_fmt     != icodec->sample_fmt
-//                                             || codec->channel_layout != icodec->channel_layout;
-                icodec->request_channels  = codec-> channels;
-                ost->resample_sample_fmt  = icodec->sample_fmt;
-                ost->resample_sample_rate = icodec->sample_rate;
-                ost->resample_channels    = icodec->channels;
-                ost->resample_channel_layout = icodec->channel_layout;
-                break;
-            case AVMEDIA_TYPE_VIDEO:
-                if (!ost->filter) {
+            if (!ost->filter &&
+                (codec->codec_type == AVMEDIA_TYPE_VIDEO ||
+                 codec->codec_type == AVMEDIA_TYPE_AUDIO)) {
                     FilterGraph *fg;
                     fg = init_simple_filtergraph(ist, ost);
-                    if (configure_video_filters(fg)) {
+                    if (configure_simple_filtergraph(fg)) {
                         av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n");
                         exit(1);
                     }
-                }
+            }
 
+            switch (codec->codec_type) {
+            case AVMEDIA_TYPE_AUDIO:
+                codec->sample_fmt     = ost->filter->filter->inputs[0]->format;
+                codec->sample_rate    = ost->filter->filter->inputs[0]->sample_rate;
+                codec->channel_layout = ost->filter->filter->inputs[0]->channel_layout;
+                codec->channels       = av_get_channel_layout_nb_channels(codec->channel_layout);
+                codec->time_base      = (AVRational){ 1, codec->sample_rate };
+                break;
+            case AVMEDIA_TYPE_VIDEO:
                 if (ist && !ost->frame_rate.num)
-                    ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational) { 25, 1 };
+                    ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25, 1};
                 if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) {
                     int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
                     ost->frame_rate = ost->enc->supported_framerates[idx];
@@ -3409,15 +3269,6 @@ static int transcode_init(void)
                input_streams[ost->source_index]->st->index,
                ost->file_index,
                ost->index);
-        if (ost->audio_channels_mapped) {
-            av_log(NULL, AV_LOG_INFO, " [ch:");
-            for (j = 0; j < ost->audio_channels_mapped; j++)
-                if (ost->audio_channels_map[j] == -1)
-                    av_log(NULL, AV_LOG_INFO, " M");
-                else
-                    av_log(NULL, AV_LOG_INFO, " %d", ost->audio_channels_map[j]);
-            av_log(NULL, AV_LOG_INFO, "]");
-        }
         if (ost->sync_ist != input_streams[ost->source_index])
             av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",
                    ost->sync_ist->file_index,
@@ -3783,11 +3634,8 @@ static int transcode(void)
                     fclose(ost->logfile);
                     ost->logfile = NULL;
                 }
-                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->forced_kf_pts);
-                swr_free(&ost->swr);
                 av_dict_free(&ost->opts);
             }
         }
@@ -4220,6 +4068,14 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
 
             break;
         case AVMEDIA_TYPE_AUDIO:
+            guess_input_channel_layout(ist);
+
+            ist->resample_sample_fmt     = dec->sample_fmt;
+            ist->resample_sample_rate    = dec->sample_rate;
+            ist->resample_channels       = dec->channels;
+            ist->resample_channel_layout = dec->channel_layout;
+
+            break;
         case AVMEDIA_TYPE_DATA:
         case AVMEDIA_TYPE_SUBTITLE:
             if(!ist->dec)
@@ -4793,7 +4649,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
     audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
 
     if (!ost->stream_copy) {
-        char *sample_fmt = NULL;
+        char *sample_fmt = NULL, *filters = NULL;;
 
         MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
 
@@ -4806,23 +4662,9 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
 
         MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
 
-        ost->rematrix_volume=1.0;
-        MATCH_PER_STREAM_OPT(rematrix_volume, f, ost->rematrix_volume, oc, st);
-    }
-
-    /* check for channel mapping for this audio stream */
-    for (n = 0; n < o->nb_audio_channel_maps; n++) {
-        AudioChannelMap *map = &o->audio_channel_maps[n];
-        InputStream *ist = input_streams[ost->source_index];
-        if ((map->channel_idx == -1 || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) &&
-            (map->ofile_idx   == -1 || ost->file_index == map->ofile_idx) &&
-            (map->ostream_idx == -1 || ost->st->index  == map->ostream_idx)) {
-            if (ost->audio_channels_mapped < FF_ARRAY_ELEMS(ost->audio_channels_map))
-                ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
-            else
-                av_log(NULL, AV_LOG_FATAL, "Max channel mapping for output %d.%d reached\n",
-                       ost->file_index, ost->st->index);
-        }
+        MATCH_PER_STREAM_OPT(filters, str, filters, oc, st);
+        if (filters)
+            ost->avfilter = av_strdup(filters);
     }
 
     return ost;
@@ -5697,6 +5539,11 @@ static int opt_video_filters(OptionsContext *o, const char *opt, const char *arg
     return parse_option(o, "filter:v", arg, options);
 }
 
+static int opt_audio_filters(OptionsContext *o, const char *opt, const char *arg)
+{
+    return parse_option(o, "filter:a", arg, options);
+}
+
 static int opt_vsync(const char *opt, const char *arg)
 {
     if      (!av_strcasecmp(arg, "cfr"))         video_sync_method = VSYNC_CFR;
@@ -5879,8 +5726,8 @@ static const OptionDef options[] = {
     { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_old2new}, "force audio tag/fourcc", "fourcc/tag" },
     { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
     { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" },
-    { "rmvol", HAS_ARG | OPT_AUDIO | OPT_FLOAT | OPT_SPEC, {.off = OFFSET(rematrix_volume)}, "rematrix volume (as factor)", "volume" },
     { "channel_layout", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_channel_layout}, "set channel layout", "layout" },
+    { "af", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_filters}, "audio filters", "filter list" },
 
     /* subtitle options */
     { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" },
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index cd6492e..27fc286 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -27,6 +27,7 @@
 
 #include "avfilter.h"
 
+#if 1
 enum {
 
     /**
@@ -62,6 +63,7 @@ int av_buffersrc_add_ref(AVFilterContext *buffer_src,
  */
 unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src);
 
+#else
 /**
  * Add a buffer to the filtergraph s.
  *
@@ -81,5 +83,6 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
  *          hit. Use av_buffersrc_buffer() to avoid copying the data.
  */
 int av_buffersrc_write_frame(AVFilterContext *s, AVFrame *frame);
+#endif
 
 #endif /* AVFILTER_BUFFERSRC_H */
diff --git a/tests/Makefile b/tests/Makefile
index 03e2b30..d656c7d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -55,7 +55,7 @@ include $(SRC_PATH)/tests/fate/image.mak
 include $(SRC_PATH)/tests/fate/indeo.mak
 include $(SRC_PATH)/tests/fate/libavcodec.mak
 include $(SRC_PATH)/tests/fate/libavutil.mak
-include $(SRC_PATH)/tests/fate/mapchan.mak
+#include $(SRC_PATH)/tests/fate/mapchan.mak
 include $(SRC_PATH)/tests/fate/lossless-audio.mak
 include $(SRC_PATH)/tests/fate/lossless-video.mak
 include $(SRC_PATH)/tests/fate/microsoft.mak
diff --git a/tests/fate/audio.mak b/tests/fate/audio.mak
index 6ba46d9..19d2398 100644
--- a/tests/fate/audio.mak
+++ b/tests/fate/audio.mak
@@ -40,8 +40,10 @@ fate-nellymoser-aref-encode: CMD = enc_dec_pcm flv wav s16le $(REF) -c:a nellymo
 fate-nellymoser-aref-encode: CMP = stddev
 fate-nellymoser-aref-encode: REF = ./tests/data/acodec-16000-1.ref.wav
 fate-nellymoser-aref-encode: CMP_SHIFT = -1172
-fate-nellymoser-aref-encode: CMP_TARGET = 9617
-fate-nellymoser-aref-encode: SIZE_TOLERANCE = 268
+#fate-nellymoser-aref-encode: CMP_TARGET = 9617
+#fate-nellymoser-aref-encode: SIZE_TOLERANCE = 268
+fate-nellymoser-aref-encode: CMP_TARGET = 10216
+fate-nellymoser-aref-encode: SIZE_TOLERANCE = 1300
 
 FATE_AUDIO += fate-sierra-vmd-audio
 fate-sierra-vmd-audio: CMD = framecrc -i $(SAMPLES)/vmd/12.vmd -vn
diff --git a/tests/ref/acodec/g723_1 b/tests/ref/acodec/g723_1
index 57b80dd..7615bad 100644
--- a/tests/ref/acodec/g723_1
+++ b/tests/ref/acodec/g723_1
@@ -1,4 +1,4 @@
-5815887898457847a7717fbe60d9cfb6 *./tests/data/acodec/g723_1.tco
+afd309546b14cff772f3f28ee650452f *./tests/data/acodec/g723_1.tco
 4800 ./tests/data/acodec/g723_1.tco
-5d706e32b8e8fa991f2b1a309ea5e917 *./tests/data/g723_1.acodec.out.wav
-stddev: 8507.20 PSNR: 17.73 MAXDIFF:26473 bytes:    96000/  1058400
+99030194774ea673817a56f52a04843d *./tests/data/g723_1.acodec.out.wav
+stddev: 8503.56 PSNR: 17.74 MAXDIFF:26473 bytes:    96000/  1058400
diff --git a/tests/ref/fate/adpcm-ima-amv b/tests/ref/fate/adpcm-ima-amv
index 977c125..6c2fa32 100644
--- a/tests/ref/fate/adpcm-ima-amv
+++ b/tests/ref/fate/adpcm-ima-amv
@@ -3,7 +3,7 @@
 0,       1378,       1378,     1378,     2756, 0x8462443f
 0,       2756,       2756,     1378,     2756, 0x9f493ba6
 0,       4134,       4134,     1378,     2756, 0x634e5f06
-0,       5512,       5512,     1380,     2760, 0x51f35cd4
+0,       5513,       5513,     1380,     2760, 0x51f35cd4
 0,       6891,       6891,     1378,     2756, 0x011c51e5
 0,       8269,       8269,     1378,     2756, 0x8c2c198c
 0,       9647,       9647,     1378,     2756, 0x2b4a3397
@@ -19,7 +19,7 @@
 0,      23428,      23428,     1378,     2756, 0x96346ba6
 0,      24806,      24806,     1378,     2756, 0x3d54543b
 0,      26184,      26184,     1380,     2760, 0x601786e1
-0,      27562,      27562,     1378,     2756, 0xf22a5793
+0,      27563,      27563,     1378,     2756, 0xf22a5793
 0,      28941,      28941,     1378,     2756, 0x21f54d49
 0,      30319,      30319,     1378,     2756, 0x0c6d4399
 0,      31697,      31697,     1378,     2756, 0x17282f8e
@@ -35,7 +35,7 @@
 0,      45478,      45478,     1380,     2760, 0x98a76091
 0,      46856,      46856,     1378,     2756, 0x5d357141
 0,      48234,      48234,     1378,     2756, 0x65ea2657
-0,      49612,      49612,     1378,     2756, 0xb5e1334a
+0,      49613,      49613,     1378,     2756, 0xb5e1334a
 0,      50991,      50991,     1378,     2756, 0x32cd5d91
 0,      52369,      52369,     1378,     2756, 0xdc23722b
 0,      53747,      53747,     1378,     2756, 0x2ba34684
@@ -51,7 +51,7 @@
 0,      67528,      67528,     1378,     2756, 0x39c2586c
 0,      68906,      68906,     1378,     2756, 0x7ffc46e5
 0,      70284,      70284,     1378,     2756, 0xa2766664
-0,      71662,      71662,     1378,     2756, 0xacb50c6c
+0,      71663,      71663,     1378,     2756, 0xacb50c6c
 0,      73041,      73041,     1378,     2756, 0x7f659084
 0,      74419,      74419,     1378,     2756, 0xc72e6a12
 0,      75797,      75797,     1380,     2760, 0xdb6944df
@@ -67,7 +67,7 @@
 0,      89578,      89578,     1378,     2756, 0x5c17abef
 0,      90956,      90956,     1378,     2756, 0xb3235184
 0,      92334,      92334,     1378,     2756, 0xdabb64a6
-0,      93712,      93712,     1378,     2756, 0xa95dc58d
+0,      93713,      93713,     1378,     2756, 0xa95dc58d
 0,      95091,      95091,     1380,     2760, 0x8e7ac9eb
 0,      96469,      96469,     1378,     2756, 0x492b658e
 0,      97847,      97847,     1378,     2756, 0x377483ab
@@ -83,7 +83,7 @@
 0,     111628,     111628,     1378,     2756, 0xf0de66ae
 0,     113006,     113006,     1378,     2756, 0xeabf3c32
 0,     114384,     114384,     1378,     2756, 0xe98e81d1
-0,     115762,     115762,     1380,     2760, 0x56aa5889
+0,     115763,     115763,     1380,     2760, 0x56aa5889
 0,     117141,     117141,     1378,     2756, 0x4fd34c0e
 0,     118519,     118519,     1378,     2756, 0x67cf6912
 0,     119897,     119897,     1378,     2756, 0xfa944def
@@ -99,7 +99,7 @@
 0,     133678,     133678,     1378,     2756, 0x2e0e3f2e
 0,     135056,     135056,     1380,     2760, 0xdf534478
 0,     136434,     136434,     1378,     2756, 0xca000a2e
-0,     137812,     137812,     1378,     2756, 0x87472df3
+0,     137813,     137813,     1378,     2756, 0x87472df3
 0,     139191,     139191,     1378,     2756, 0x16733810
 0,     140569,     140569,     1378,     2756, 0xfa0734b4
 0,     141947,     141947,     1378,     2756, 0x5eff3fc4
@@ -115,7 +115,7 @@
 0,     155728,     155728,     1380,     2760, 0x8eca4bdb
 0,     157106,     157106,     1378,     2756, 0x62bd4162
 0,     158484,     158484,     1378,     2756, 0x9f744aa4
-0,     159862,     159862,     1378,     2756, 0x0f3f6409
+0,     159863,     159863,     1378,     2756, 0x0f3f6409
 0,     161241,     161241,     1378,     2756, 0x3fee827a
 0,     162619,     162619,     1378,     2756, 0x48a0ac19
 0,     163997,     163997,     1378,     2756, 0x8e4ce0d0
@@ -131,7 +131,7 @@
 0,     177778,     177778,     1378,     2756, 0xab01fb12
 0,     179156,     179156,     1378,     2756, 0x04cffe5c
 0,     180534,     180534,     1378,     2756, 0xef661c5e
-0,     181912,     181912,     1378,     2756, 0x094c5fc5
+0,     181913,     181913,     1378,     2756, 0x094c5fc5
 0,     183291,     183291,     1378,     2756, 0xe0c1486a
 0,     184669,     184669,     1380,     2760, 0x8c3535b7
 0,     186047,     186047,     1378,     2756, 0x594934aa
@@ -147,7 +147,7 @@
 0,     199828,     199828,     1378,     2756, 0x448e681d
 0,     201206,     201206,     1378,     2756, 0x0ba9826e
 0,     202584,     202584,     1378,     2756, 0x049f36fa
-0,     203962,     203962,     1378,     2756, 0x096a2b62
+0,     203963,     203963,     1378,     2756, 0x096a2b62
 0,     205341,     205341,     1380,     2760, 0x579e2035
 0,     206719,     206719,     1378,     2756, 0xd13e30e1
 0,     208097,     208097,     1378,     2756, 0x30b6412b
diff --git a/tests/ref/fate/adpcm-ima-smjpeg b/tests/ref/fate/adpcm-ima-smjpeg
index 287e8a0..45cb97b 100644
--- a/tests/ref/fate/adpcm-ima-smjpeg
+++ b/tests/ref/fate/adpcm-ima-smjpeg
@@ -27,7 +27,7 @@
 0,      12789,      12789,      512,     1024, 0x3866b03b
 0,      13296,      13296,      512,     1024, 0xbc005403
 0,      13803,      13803,      512,     1024, 0xe9dfcc51
-0,      14332,      14332,      512,     1024, 0x83c837cb
+0,      14333,      14333,      512,     1024, 0x83c837cb
 0,      14840,      14840,      512,     1024, 0xfa649580
 0,      15347,      15347,      512,     1024, 0x519452ea
 0,      15854,      15854,      512,     1024, 0xd4978774
@@ -108,7 +108,7 @@
 0,      54265,      54265,      512,     1024, 0xd6ece2a1
 0,      54772,      54772,      512,     1024, 0x33ab9553
 0,      55279,      55279,      512,     1024, 0xd50c73a6
-0,      55786,      55786,      512,     1024, 0xfe25b63a
+0,      55787,      55787,      512,     1024, 0xfe25b63a
 0,      56316,      56316,      512,     1024, 0x7e2959e3
 0,      56823,      56823,      512,     1024, 0xa4c07b34
 0,      57330,      57330,      512,     1024, 0xd6d8f15c
@@ -139,7 +139,7 @@
 0,      70141,      70141,      512,     1024, 0xc434d238
 0,      70648,      70648,      512,     1024, 0xe9ad7562
 0,      71155,      71155,      512,     1024, 0xb51b6b50
-0,      71662,      71662,      512,     1024, 0xe70aecd3
+0,      71663,      71663,      512,     1024, 0xe70aecd3
 0,      72192,      72192,      512,     1024, 0x03c816b2
 0,      72699,      72699,      512,     1024, 0x869fdf25
 0,      73206,      73206,      512,     1024, 0xd40a0a62
@@ -170,7 +170,7 @@
 0,      85995,      85995,      512,     1024, 0xaa919ccc
 0,      86524,      86524,      512,     1024, 0x15993dbc
 0,      87031,      87031,      512,     1024, 0xbe01a7b9
-0,      87538,      87538,      512,     1024, 0xefe93c09
+0,      87539,      87539,      512,     1024, 0xefe93c09
 0,      88046,      88046,      512,     1024, 0x1bb566e5
 0,      88575,      88575,      512,     1024, 0x15ce6237
 0,      89082,      89082,      512,     1024, 0xa8552e66
@@ -201,7 +201,7 @@
 0,     101871,     101871,      512,     1024, 0x1e01fb02
 0,     102378,     102378,      512,     1024, 0x4ed2c1d8
 0,     102907,     102907,      512,     1024, 0xf2fdbe63
-0,     103414,     103414,      512,     1024, 0x8d6f63a1
+0,     103415,     103415,      512,     1024, 0x8d6f63a1
 0,     103922,     103922,      512,     1024, 0xded468d9
 0,     104429,     104429,      512,     1024, 0xccad839e
 0,     104958,     104958,      512,     1024, 0xdde7c082
@@ -232,7 +232,7 @@
 0,     117747,     117747,      512,     1024, 0xb01e2365
 0,     118254,     118254,      512,     1024, 0x14e200d3
 0,     118783,     118783,      512,     1024, 0xd1184c98
-0,     119290,     119290,      512,     1024, 0xef9140e9
+0,     119291,     119291,      512,     1024, 0xef9140e9
 0,     119798,     119798,      512,     1024, 0x4cbb645e
 0,     120305,     120305,      512,     1024, 0xe7fe2f06
 0,     120812,     120812,      512,     1024, 0xf8c45028
@@ -263,7 +263,7 @@
 0,     133623,     133623,      512,     1024, 0xa5099687
 0,     134130,     134130,      512,     1024, 0xbff10707
 0,     134637,     134637,      512,     1024, 0x37c4ffc0
-0,     135166,     135166,      512,     1024, 0xf9fb6caa
+0,     135167,     135167,      512,     1024, 0xf9fb6caa
 0,     135674,     135674,      512,     1024, 0x3b6a3a1f
 0,     136181,     136181,      512,     1024, 0x83431edb
 0,     136688,     136688,      512,     1024, 0x1eb713cf
@@ -344,7 +344,7 @@
 0,     175099,     175099,      512,     1024, 0xd009a7ca
 0,     175606,     175606,      512,     1024, 0xb6d5a938
 0,     176113,     176113,      512,     1024, 0xf3d45e47
-0,     176620,     176620,      512,     1024, 0xea8e04fc
+0,     176621,     176621,      512,     1024, 0xea8e04fc
 0,     177150,     177150,      512,     1024, 0x0b928bd8
 0,     177657,     177657,      512,     1024, 0x0f02caec
 0,     178164,     178164,      512,     1024, 0xe2b137a8
diff --git a/tests/ref/fate/smjpeg b/tests/ref/fate/smjpeg
new file mode 100644
index 0000000..7aac52f
--- /dev/null
+++ b/tests/ref/fate/smjpeg
@@ -0,0 +1,425 @@
+#tb 0: 1/1000
+#tb 1: 1/22050
+0,          0,          0,        0,      734, 0x5a042c2c
+1,          0,          0,      512,     1024, 0x00000000
+1,        507,        507,      512,     1024, 0x00000000
+1,       1014,       1014,      512,     1024, 0xd89a448e
+1,       1521,       1521,      512,     1024, 0x695b369c
+1,       2029,       2029,      512,     1024, 0xc8ba5707
+0,        111,        111,        0,      763, 0xb5893f2f
+1,       2558,       2558,      512,     1024, 0xdf241fc6
+1,       3065,       3065,      512,     1024, 0x61cf4166
+1,       3572,       3572,      512,     1024, 0x97cbc386
+1,       4079,       4079,      512,     1024, 0x44899d04
+1,       4586,       4586,      512,     1024, 0xa7cbaa62
+0,        222,        222,        0,     3023, 0x0f3907d3
+1,       5116,       5116,      512,     1024, 0xa7aea60c
+1,       5623,       5623,      512,     1024, 0xd7b18a89
+1,       6130,       6130,      512,     1024, 0x268e81f6
+1,       6637,       6637,      512,     1024, 0x9cf83a2f
+1,       7166,       7166,      512,     1024, 0x5559b508
+0,        333,        333,        0,     4800, 0x22e6e18a
+1,       7673,       7673,      512,     1024, 0xe1b9e71c
+1,       8181,       8181,      512,     1024, 0xdcee733e
+1,       8688,       8688,      512,     1024, 0xe5918f60
+1,       9195,       9195,      512,     1024, 0x29dbd209
+1,       9724,       9724,      512,     1024, 0x9bcbcf16
+0,        444,        444,        0,     6417, 0x427adde5
+1,      10231,      10231,      512,     1024, 0x86f5f458
+1,      10738,      10738,      512,     1024, 0xabcbda86
+1,      11246,      11246,      512,     1024, 0xc51f77b9
+1,      11775,      11775,      512,     1024, 0xf6b3a504
+0,        555,        555,        0,     6776, 0x7a74c6ad
+1,      12282,      12282,      512,     1024, 0x1af3e40e
+1,      12789,      12789,      512,     1024, 0x3866b03b
+1,      13296,      13296,      512,     1024, 0xbc005403
+1,      13803,      13803,      512,     1024, 0xe9dfcc51
+1,      14333,      14333,      512,     1024, 0x83c837cb
+0,        666,        666,        0,     6808, 0x1f6eb7c3
+1,      14840,      14840,      512,     1024, 0xfa649580
+1,      15347,      15347,      512,     1024, 0x519452ea
+1,      15854,      15854,      512,     1024, 0xd4978774
+1,      16383,      16383,      512,     1024, 0xe2a3b1cd
+1,      16890,      16890,      512,     1024, 0x9a9472ad
+0,        777,        777,        0,     6726, 0x452087e6
+1,      17397,      17397,      512,     1024, 0xa12d4060
+1,      17905,      17905,      512,     1024, 0x31fb0646
+1,      18412,      18412,      512,     1024, 0xfc44343f
+1,      18941,      18941,      512,     1024, 0x0847751a
+1,      19448,      19448,      512,     1024, 0x227968a2
+0,        888,        888,        0,     6829, 0xee82b109
+1,      19955,      19955,      512,     1024, 0x7cce9f1c
+1,      20462,      20462,      512,     1024, 0xb8356713
+1,      20992,      20992,      512,     1024, 0xb29f6e6f
+1,      21499,      21499,      512,     1024, 0x9e1430ab
+1,      22006,      22006,      512,     1024, 0x26d85423
+0,        999,        999,        0,     7055, 0xf41f1108
+1,      22513,      22513,      512,     1024, 0x6496547d
+1,      23020,      23020,      512,     1024, 0x316b1a86
+1,      23549,      23549,      512,     1024, 0x3cd83afc
+1,      24057,      24057,      512,     1024, 0x993ff633
+0,       1111,       1111,        0,     6977, 0xf8fe1ede
+1,      24564,      24564,      512,     1024, 0x0708d1a2
+1,      25071,      25071,      512,     1024, 0xd7230db9
+1,      25578,      25578,      512,     1024, 0xbb0779ca
+1,      26107,      26107,      512,     1024, 0xc6094e1b
+1,      26614,      26614,      512,     1024, 0x15a8b039
+0,       1222,       1222,        0,     6942, 0x9ad105c6
+1,      27122,      27122,      512,     1024, 0xd6dbe88c
+1,      27629,      27629,      512,     1024, 0x7e8d1140
+1,      28158,      28158,      512,     1024, 0xef88e525
+1,      28665,      28665,      512,     1024, 0x44e21149
+1,      29172,      29172,      512,     1024, 0x65b0f5f4
+0,       1333,       1333,        0,     6926, 0xe239dad6
+1,      29679,      29679,      512,     1024, 0xb955f687
+1,      30186,      30186,      512,     1024, 0xc85fba9c
+1,      30716,      30716,      512,     1024, 0xf59655ad
+1,      31223,      31223,      512,     1024, 0x6de80bf1
+1,      31730,      31730,      512,     1024, 0x2dcf6e41
+0,       1444,       1444,        0,     6966, 0x81dcfab1
+1,      32237,      32237,      512,     1024, 0xd0ddcf8a
+1,      32766,      32766,      512,     1024, 0x00135c2d
+1,      33273,      33273,      512,     1024, 0x697f8efd
+1,      33781,      33781,      512,     1024, 0x7a9bada5
+0,       1555,       1555,        0,     6896, 0x31e6cc02
+1,      34288,      34288,      512,     1024, 0x0d22783c
+1,      34795,      34795,      512,     1024, 0x7726d07d
+1,      35324,      35324,      512,     1024, 0xa2f14f67
+1,      35831,      35831,      512,     1024, 0x7f51060d
+1,      36338,      36338,      512,     1024, 0xc4ec6aea
+0,       1666,       1666,        0,     6889, 0x1cc1006e
+1,      36846,      36846,      512,     1024, 0x9bb37ca4
+1,      37375,      37375,      512,     1024, 0x9b085577
+1,      37882,      37882,      512,     1024, 0x8812f8af
+1,      38389,      38389,      512,     1024, 0x788f5221
+1,      38896,      38896,      512,     1024, 0x3a2ce642
+0,       1777,       1777,        0,     6933, 0xc303f87f
+1,      39403,      39403,      512,     1024, 0x72415692
+1,      39933,      39933,      512,     1024, 0xe3dcc105
+1,      40440,      40440,      512,     1024, 0xb26c0599
+1,      40947,      40947,      512,     1024, 0x5c9e55eb
+1,      41454,      41454,      512,     1024, 0x8fe88707
+0,       1888,       1888,        0,     7034, 0xb4970a20
+1,      41983,      41983,      512,     1024, 0xc5d7beb6
+1,      42490,      42490,      512,     1024, 0xe1d3a3b4
+1,      42998,      42998,      512,     1024, 0x012da0c6
+1,      43505,      43505,      512,     1024, 0x8d010922
+1,      44012,      44012,      512,     1024, 0x3366eb0d
+0,       1999,       1999,        0,     6961, 0xf064095d
+1,      44541,      44541,      512,     1024, 0xc9381a27
+1,      45048,      45048,      512,     1024, 0x0774f685
+1,      45555,      45555,      512,     1024, 0xc5cae0a5
+1,      46062,      46062,      512,     1024, 0xa6f4737c
+0,       2111,       2111,        0,     7089, 0x5ba350f9
+1,      46592,      46592,      512,     1024, 0x8fb6d0d1
+1,      47099,      47099,      512,     1024, 0x05f579c2
+1,      47606,      47606,      512,     1024, 0x56905d99
+1,      48113,      48113,      512,     1024, 0x002ee18d
+1,      48620,      48620,      512,     1024, 0xeb37ef51
+0,       2222,       2222,        0,     7078, 0xa83f3e88
+1,      49149,      49149,      512,     1024, 0x38025635
+1,      49657,      49657,      512,     1024, 0x4fe643c8
+1,      50164,      50164,      512,     1024, 0x11d66ab1
+1,      50671,      50671,      512,     1024, 0xcc3051e9
+1,      51178,      51178,      512,     1024, 0xcd93e854
+0,       2333,       2333,        0,     7147, 0xcda66cfc
+1,      51707,      51707,      512,     1024, 0x38f1196d
+1,      52214,      52214,      512,     1024, 0x657a15fc
+1,      52722,      52722,      512,     1024, 0x669ce2a9
+1,      53229,      53229,      512,     1024, 0x95862dda
+1,      53758,      53758,      512,     1024, 0x1726a7b2
+0,       2444,       2444,        0,     7173, 0xb7455859
+1,      54265,      54265,      512,     1024, 0xd6ece2a1
+1,      54772,      54772,      512,     1024, 0x33ab9553
+1,      55279,      55279,      512,     1024, 0xd50c73a6
+1,      55787,      55787,      512,     1024, 0xfe25b63a
+1,      56316,      56316,      512,     1024, 0x7e2959e3
+0,       2555,       2555,        0,     7213, 0x97b89994
+1,      56823,      56823,      512,     1024, 0xa4c07b34
+1,      57330,      57330,      512,     1024, 0xd6d8f15c
+1,      57837,      57837,      512,     1024, 0x1eccddd7
+1,      58366,      58366,      512,     1024, 0x2b69f9cb
+0,       2666,       2666,        0,     7170, 0xca8b2948
+1,      58874,      58874,      512,     1024, 0x667b775f
+1,      59381,      59381,      512,     1024, 0xad3b84e9
+1,      59888,      59888,      512,     1024, 0x4f29fc67
+1,      60395,      60395,      512,     1024, 0x8d611ab7
+1,      60924,      60924,      512,     1024, 0x278966ea
+0,       2777,       2777,        0,     7174, 0xc7cc6bbb
+1,      61431,      61431,      512,     1024, 0xaf33812b
+1,      61938,      61938,      512,     1024, 0xa55f4265
+1,      62446,      62446,      512,     1024, 0x023cb51c
+1,      62975,      62975,      512,     1024, 0x1d1f1005
+1,      63482,      63482,      512,     1024, 0x874cccf7
+0,       2888,       2888,        0,     7235, 0xc2e68d2b
+1,      63989,      63989,      512,     1024, 0xda705428
+1,      64496,      64496,      512,     1024, 0x48d9b440
+1,      65003,      65003,      512,     1024, 0xa14e0712
+1,      65533,      65533,      512,     1024, 0x7efbad1f
+1,      66040,      66040,      512,     1024, 0xdb82c17f
+0,       3000,       3000,        0,     7261, 0x8204a423
+1,      66547,      66547,      512,     1024, 0xcbe87613
+1,      67054,      67054,      512,     1024, 0x3a63df1d
+1,      67583,      67583,      512,     1024, 0xd5636bba
+1,      68090,      68090,      512,     1024, 0x9397af23
+0,       3111,       3111,        0,     7353, 0xacc7e7c0
+1,      68598,      68598,      512,     1024, 0x32a07c98
+1,      69105,      69105,      512,     1024, 0x202ca667
+1,      69612,      69612,      512,     1024, 0xdf969011
+1,      70141,      70141,      512,     1024, 0xc434d238
+1,      70648,      70648,      512,     1024, 0xe9ad7562
+0,       3222,       3222,        0,     7065, 0x45035c5c
+1,      71155,      71155,      512,     1024, 0xb51b6b50
+1,      71663,      71663,      512,     1024, 0xe70aecd3
+1,      72192,      72192,      512,     1024, 0x03c816b2
+1,      72699,      72699,      512,     1024, 0x869fdf25
+1,      73206,      73206,      512,     1024, 0xd40a0a62
+0,       3333,       3333,        0,     7269, 0x72edbb76
+1,      73713,      73713,      512,     1024, 0x5af7dd35
+1,      74220,      74220,      512,     1024, 0x891ffc72
+1,      74750,      74750,      512,     1024, 0x1ff68a08
+1,      75257,      75257,      512,     1024, 0x5a7517a9
+1,      75764,      75764,      512,     1024, 0x0f959f74
+0,       3444,       3444,        0,     7220, 0xb926772f
+1,      76271,      76271,      512,     1024, 0xe92a12a2
+1,      76778,      76778,      512,     1024, 0x38000e55
+1,      77307,      77307,      512,     1024, 0x39fbdd70
+1,      77814,      77814,      512,     1024, 0xca3d9184
+1,      78322,      78322,      512,     1024, 0x66c8995b
+0,       3555,       3555,        0,     7326, 0x0a66c632
+1,      78829,      78829,      512,     1024, 0xac25acea
+1,      79358,      79358,      512,     1024, 0x3cd1046c
+1,      79865,      79865,      512,     1024, 0x6a1df31c
+1,      80372,      80372,      512,     1024, 0x21ca10a1
+0,       3666,       3666,        0,     7225, 0xe39076ab
+1,      80879,      80879,      512,     1024, 0x1aeccedc
+1,      81387,      81387,      512,     1024, 0xddea1335
+1,      81916,      81916,      512,     1024, 0x19f5ca9f
+1,      82423,      82423,      512,     1024, 0x88e95e43
+1,      82930,      82930,      512,     1024, 0x726284fe
+0,       3777,       3777,        0,     7265, 0xe0209036
+1,      83437,      83437,      512,     1024, 0x6b85b40e
+1,      83966,      83966,      512,     1024, 0x111fee2a
+1,      84474,      84474,      512,     1024, 0x3656b588
+1,      84981,      84981,      512,     1024, 0xa5a2b552
+1,      85488,      85488,      512,     1024, 0x38fb2467
+0,       3888,       3888,        0,     7337, 0x7a5dc093
+1,      85995,      85995,      512,     1024, 0xaa919ccc
+1,      86524,      86524,      512,     1024, 0x15993dbc
+1,      87031,      87031,      512,     1024, 0xbe01a7b9
+1,      87539,      87539,      512,     1024, 0xefe93c09
+1,      88046,      88046,      512,     1024, 0x1bb566e5
+0,       4000,       4000,        0,     7246, 0x519a7a3c
+1,      88575,      88575,      512,     1024, 0x15ce6237
+1,      89082,      89082,      512,     1024, 0xa8552e66
+1,      89589,      89589,      512,     1024, 0x9d80187e
+1,      90096,      90096,      512,     1024, 0x5df3fc30
+1,      90603,      90603,      512,     1024, 0x1a312aa5
+0,       4111,       4111,        0,     7266, 0x352c8078
+1,      91133,      91133,      512,     1024, 0x6bb8e302
+1,      91640,      91640,      512,     1024, 0xbd9684bb
+1,      92147,      92147,      512,     1024, 0x78b0b166
+1,      92654,      92654,      512,     1024, 0xd9af5eae
+0,       4222,       4222,        0,     7323, 0xcaf69d7c
+1,      93183,      93183,      512,     1024, 0xdb90fe82
+1,      93690,      93690,      512,     1024, 0x327614e9
+1,      94198,      94198,      512,     1024, 0x1f19b7fe
+1,      94705,      94705,      512,     1024, 0x46c53f96
+1,      95212,      95212,      512,     1024, 0x921b2189
+0,       4333,       4333,        0,     7309, 0x98c1e6f7
+1,      95741,      95741,      512,     1024, 0xa8fbc85a
+1,      96248,      96248,      512,     1024, 0xabfdaaae
+1,      96755,      96755,      512,     1024, 0x6acc7387
+1,      97263,      97263,      512,     1024, 0x0d9c27b5
+1,      97792,      97792,      512,     1024, 0xba4dd809
+0,       4444,       4444,        0,     7121, 0x913d5bd6
+1,      98299,      98299,      512,     1024, 0x2a2ad521
+1,      98806,      98806,      512,     1024, 0x892de38a
+1,      99313,      99313,      512,     1024, 0xdc97a2eb
+1,      99820,      99820,      512,     1024, 0x4f614ca4
+1,     100350,     100350,      512,     1024, 0x9c8a77ea
+0,       4555,       4555,      111,     7088, 0x56302362
+1,     100857,     100857,      512,     1024, 0x2d30e646
+1,     101364,     101364,      512,     1024, 0x74e800a7
+1,     101871,     101871,      512,     1024, 0x1e01fb02
+1,     102378,     102378,      512,     1024, 0x4ed2c1d8
+0,       4666,       4666,      111,     7104, 0xc0d14f78
+1,     102907,     102907,      512,     1024, 0xf2fdbe63
+1,     103415,     103415,      512,     1024, 0x8d6f63a1
+1,     103922,     103922,      512,     1024, 0xded468d9
+1,     104429,     104429,      512,     1024, 0xccad839e
+1,     104958,     104958,      512,     1024, 0xdde7c082
+0,       4777,       4777,      111,     7169, 0xd03c825b
+1,     105465,     105465,      512,     1024, 0x548613c5
+1,     105972,     105972,      512,     1024, 0x383909bd
+1,     106479,     106479,      512,     1024, 0xfd37627b
+1,     106987,     106987,      512,     1024, 0x6d95a481
+1,     107516,     107516,      512,     1024, 0x56aa87fa
+0,       4888,       4888,      111,     7038, 0x1ecc201d
+1,     108023,     108023,      512,     1024, 0x7b67258c
+1,     108530,     108530,      512,     1024, 0x7dd99a92
+1,     109037,     109037,      512,     1024, 0x4a66d102
+1,     109566,     109566,      512,     1024, 0x7b3fce51
+1,     110074,     110074,      512,     1024, 0xbbd968aa
+0,       5000,       5000,      111,     7015, 0x83c94454
+1,     110581,     110581,      512,     1024, 0x8283ec36
+1,     111088,     111088,      512,     1024, 0x3c96493d
+1,     111595,     111595,      512,     1024, 0xfa4f8cf8
+1,     112124,     112124,      512,     1024, 0xe2cf872d
+1,     112631,     112631,      512,     1024, 0x0a9e7aa6
+0,       5111,       5111,      111,     6983, 0x9e51f54d
+1,     113139,     113139,      512,     1024, 0x6e7a0550
+1,     113646,     113646,      512,     1024, 0x3acfea2f
+1,     114175,     114175,      512,     1024, 0x7111d0fa
+1,     114682,     114682,      512,     1024, 0xe9a1eca9
+0,       5222,       5222,      111,     7088, 0x70d33de1
+1,     115189,     115189,      512,     1024, 0x24da6c46
+1,     115696,     115696,      512,     1024, 0x117cff37
+1,     116204,     116204,      512,     1024, 0x0f27cab6
+1,     116733,     116733,      512,     1024, 0x69b6b4e6
+1,     117240,     117240,      512,     1024, 0x1e6cc841
+0,       5333,       5333,      111,     7096, 0x4d0f81b5
+1,     117747,     117747,      512,     1024, 0xb01e2365
+1,     118254,     118254,      512,     1024, 0x14e200d3
+1,     118783,     118783,      512,     1024, 0xd1184c98
+1,     119291,     119291,      512,     1024, 0xef9140e9
+1,     119798,     119798,      512,     1024, 0x4cbb645e
+0,       5444,       5444,      111,     7106, 0xd1a83ddc
+1,     120305,     120305,      512,     1024, 0xe7fe2f06
+1,     120812,     120812,      512,     1024, 0xf8c45028
+1,     121341,     121341,      512,     1024, 0x561358f4
+1,     121848,     121848,      512,     1024, 0xd0129b77
+1,     122355,     122355,      512,     1024, 0xcc636e88
+0,       5555,       5555,      111,     7219, 0x20f47fe4
+1,     122863,     122863,      512,     1024, 0xe9406321
+1,     123392,     123392,      512,     1024, 0x9f16a041
+1,     123899,     123899,      512,     1024, 0x468bf409
+1,     124406,     124406,      512,     1024, 0x3df70f7b
+1,     124913,     124913,      512,     1024, 0xa880b11b
+0,       5666,       5666,      111,     7184, 0x45dc6a0e
+1,     125420,     125420,      512,     1024, 0x3286c489
+1,     125950,     125950,      512,     1024, 0x39fe9ebc
+1,     126457,     126457,      512,     1024, 0xc533d83b
+1,     126964,     126964,      512,     1024, 0x153b195d
+0,       5777,       5777,      111,     7222, 0x488c6499
+1,     127471,     127471,      512,     1024, 0xd84786a1
+1,     127978,     127978,      512,     1024, 0xdc295aaa
+1,     128507,     128507,      512,     1024, 0xfb764d8c
+1,     129015,     129015,      512,     1024, 0xeebc9db9
+1,     129522,     129522,      512,     1024, 0x7ba9403e
+0,       5888,       5888,      111,     7254, 0xbd097ba7
+1,     130029,     130029,      512,     1024, 0x4e5571ec
+1,     130558,     130558,      512,     1024, 0xd965fad4
+1,     131065,     131065,      512,     1024, 0x87e259f2
+1,     131572,     131572,      512,     1024, 0xae7e533b
+1,     132080,     132080,      512,     1024, 0x313cf4d6
+0,       6000,       6000,      111,     7189, 0x46e06d43
+1,     132587,     132587,      512,     1024, 0xe1844c90
+1,     133116,     133116,      512,     1024, 0xbb057b44
+1,     133623,     133623,      512,     1024, 0xa5099687
+1,     134130,     134130,      512,     1024, 0xbff10707
+1,     134637,     134637,      512,     1024, 0x37c4ffc0
+0,       6111,       6111,      111,     7283, 0x19dd7319
+1,     135167,     135167,      512,     1024, 0xf9fb6caa
+1,     135674,     135674,      512,     1024, 0x3b6a3a1f
+1,     136181,     136181,      512,     1024, 0x83431edb
+1,     136688,     136688,      512,     1024, 0x1eb713cf
+1,     137195,     137195,      512,     1024, 0xd7b07a6d
+0,       6222,       6222,      111,     7161, 0x23171d02
+1,     137724,     137724,      512,     1024, 0x81ae3391
+1,     138231,     138231,      512,     1024, 0xf150130a
+1,     138739,     138739,      512,     1024, 0x09678eaa
+1,     139246,     139246,      512,     1024, 0xb94e06f1
+0,       6333,       6333,      111,     6976, 0xcc610c26
+1,     139775,     139775,      512,     1024, 0x67b1dbc9
+1,     140282,     140282,      512,     1024, 0xd6edc235
+1,     140789,     140789,      512,     1024, 0x34e4c499
+1,     141296,     141296,      512,     1024, 0xeefd89c0
+1,     141804,     141804,      512,     1024, 0x38afdaf1
+0,       6444,       6444,      111,     7056, 0x6cd917b0
+1,     142333,     142333,      512,     1024, 0x29a60d76
+1,     142840,     142840,      512,     1024, 0xe28a4372
+1,     143347,     143347,      512,     1024, 0x7089454d
+1,     143854,     143854,      512,     1024, 0x0c01bb7b
+1,     144383,     144383,      512,     1024, 0xbd776a72
+0,       6555,       6555,      111,     6736, 0x02b78951
+1,     144891,     144891,      512,     1024, 0x86776fd0
+1,     145398,     145398,      512,     1024, 0xb37c88f7
+1,     145905,     145905,      512,     1024, 0x5f90aaf8
+1,     146412,     146412,      512,     1024, 0x203d4222
+1,     146941,     146941,      512,     1024, 0x382692a6
+0,       6666,       6666,      111,     6540, 0x767e0854
+1,     147448,     147448,      512,     1024, 0xf37c95fd
+1,     147956,     147956,      512,     1024, 0x6c0b8877
+1,     148463,     148463,      512,     1024, 0x2e54a8b6
+1,     148992,     148992,      512,     1024, 0x7f266488
+0,       6777,       6777,      111,     6170, 0xc84962fb
+1,     149499,     149499,      512,     1024, 0xfbf20f9a
+1,     150006,     150006,      512,     1024, 0xf2985cc0
+1,     150513,     150513,      512,     1024, 0xc7075340
+1,     151020,     151020,      512,     1024, 0xe4585695
+1,     151550,     151550,      512,     1024, 0xbdffa380
+0,       6888,       6888,      111,     6169, 0x27e06c03
+1,     152057,     152057,      512,     1024, 0x2422a8a9
+1,     152564,     152564,      512,     1024, 0x59cbd75f
+1,     153071,     153071,      512,     1024, 0x04ad1a8c
+1,     153578,     153578,      512,     1024, 0x33c09191
+1,     154107,     154107,      512,     1024, 0x55efa6fd
+0,       7000,       7000,      111,     5864, 0xd14db83f
+1,     154615,     154615,      512,     1024, 0xf73d0e5d
+1,     155122,     155122,      512,     1024, 0x6141ebae
+1,     155629,     155629,      512,     1024, 0x7db17a68
+1,     156158,     156158,      512,     1024, 0xa6c690b6
+1,     156665,     156665,      512,     1024, 0xa6fd6725
+0,       7111,       7111,      111,     5375, 0x4a21055d
+1,     157172,     157172,      512,     1024, 0x50a90b9b
+1,     157680,     157680,      512,     1024, 0xef990dc8
+1,     158187,     158187,      512,     1024, 0x75adf6b5
+1,     158716,     158716,      512,     1024, 0x61eac43e
+1,     159223,     159223,      512,     1024, 0x67797a19
+0,       7222,       7222,      111,     5206, 0x95ead3cb
+1,     159730,     159730,      512,     1024, 0xf325277a
+1,     160237,     160237,      512,     1024, 0x18bf254a
+1,     160767,     160767,      512,     1024, 0x2ce6bee3
+1,     161274,     161274,      512,     1024, 0x8d320860
+0,       7333,       7333,      111,     5220, 0xcfdcc37e
+1,     161781,     161781,      512,     1024, 0xc979b6e8
+1,     162288,     162288,      512,     1024, 0xdb644b41
+1,     162795,     162795,      512,     1024, 0xe1b368ba
+1,     163324,     163324,      512,     1024, 0xacc53d15
+1,     163832,     163832,      512,     1024, 0x42ea8c18
+0,       7444,       7444,      111,     4946, 0x2d864a77
+1,     164339,     164339,      512,     1024, 0xe52c99a4
+1,     164846,     164846,      512,     1024, 0xd7db54a6
+1,     165375,     165375,      512,     1024, 0x7f27a7e3
+1,     165882,     165882,      512,     1024, 0xf7ffeaa9
+1,     166389,     166389,      512,     1024, 0x792b6088
+0,       7555,       7555,      111,     4390, 0x2ab9f462
+1,     166896,     166896,      512,     1024, 0x61d99724
+1,     167404,     167404,      512,     1024, 0x5213720e
+1,     167933,     167933,      512,     1024, 0xac09dd30
+1,     168440,     168440,      512,     1024, 0x960bf6bb
+1,     168947,     168947,      512,     1024, 0xc90168e1
+0,       7666,       7666,      111,     4051, 0x1d09592e
+1,     169454,     169454,      512,     1024, 0x43b45768
+1,     169983,     169983,      512,     1024, 0x935d60a1
+1,     170491,     170491,      512,     1024, 0x9a342ef2
+1,     170998,     170998,      512,     1024, 0xc894709f
+0,       7777,       7777,      111,     3680, 0x39bd6a12
+1,     171505,     171505,      512,     1024, 0x59b43b07
+1,     172012,     172012,      512,     1024, 0x36a1a98d
+1,     172541,     172541,      512,     1024, 0x9e1a121c
+1,     173048,     173048,      512,     1024, 0x02208b78
+1,     173556,     173556,      512,     1024, 0xd1d7b274
+0,       7888,       7888,      111,     2910, 0x6337ece9
+1,     174063,     174063,      512,     1024, 0xdacd5096
+1,     174592,     174592,      512,     1024, 0x51b71ead
+1,     175099,     175099,      512,     1024, 0xd009a7ca
+1,     175606,     175606,      512,     1024, 0xb6d5a938
+1,     176113,     176113,      512,     1024, 0xf3d45e47
+0,       8000,       8000,      111,     2153, 0xf4e3bc17
+1,     176621,     176621,      512,     1024, 0xea8e04fc
+1,     177150,     177150,      512,     1024, 0x0b928bd8
+1,     177657,     177657,      512,     1024, 0x0f02caec
+1,     178164,     178164,      512,     1024, 0xe2b137a8
+1,     178671,     178671,      512,     1024, 0xd5f94892
diff --git a/tests/ref/lavf/asf b/tests/ref/lavf/asf
index 1298748..5777d8b 100644
--- a/tests/ref/lavf/asf
+++ b/tests/ref/lavf/asf
@@ -1,3 +1,3 @@
-0c314dcdf9a4f9afda244f0ffdaaeffb *./tests/data/lavf/lavf.asf
+6dfad1f3d0f2638ea46f08edaf482f26 *./tests/data/lavf/lavf.asf
 333581 ./tests/data/lavf/lavf.asf
-./tests/data/lavf/lavf.asf CRC=0x9f5ab3e6
+./tests/data/lavf/lavf.asf CRC=0x51485213
diff --git a/tests/ref/lavf/avi b/tests/ref/lavf/avi
index e2ebadf..819c4eb 100644
--- a/tests/ref/lavf/avi
+++ b/tests/ref/lavf/avi
@@ -1,3 +1,3 @@
-a326b284ab0b34727323bf58585c9d29 *./tests/data/lavf/lavf.avi
-331050 ./tests/data/lavf/lavf.avi
-./tests/data/lavf/lavf.avi CRC=0x2a83e6b0
+dbd400a0a791360ad87eb436829ddef9 *./tests/data/lavf/lavf.avi
+330816 ./tests/data/lavf/lavf.avi
+./tests/data/lavf/lavf.avi CRC=0xa79b84dd
diff --git a/tests/ref/lavf/dv_fmt b/tests/ref/lavf/dv_fmt
index 2a228b2..7661eb6 100644
--- a/tests/ref/lavf/dv_fmt
+++ b/tests/ref/lavf/dv_fmt
@@ -1,9 +1,9 @@
 6f9cfff48f536fa727696f2f9fb3ac08 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
 ./tests/data/lavf/lavf.dv CRC=0x5ce4e5e4
-cc33ae4f9e6828914dea0f09d1241b7e *./tests/data/lavf/lavf.dv
-3480000 ./tests/data/lavf/lavf.dv
-./tests/data/lavf/lavf.dv CRC=0x8d5e9e8f
+1ca94d11b585f80b25b90c6e9dae0f75 *./tests/data/lavf/lavf.dv
+3360000 ./tests/data/lavf/lavf.dv
+./tests/data/lavf/lavf.dv CRC=0x897791b1
 87d3b20f656235671383a7eaa2f66330 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
 ./tests/data/lavf/lavf.dv CRC=0x0e868a82
diff --git a/tests/ref/lavf/ffm b/tests/ref/lavf/ffm
index e35f7a6..7453973 100644
--- a/tests/ref/lavf/ffm
+++ b/tests/ref/lavf/ffm
@@ -1,3 +1,3 @@
-793e977bc8b7f0d86f785a9062c4d978 *./tests/data/lavf/lavf.ffm
+0063b1b49d8641dcbf354092529a58a4 *./tests/data/lavf/lavf.ffm
 376832 ./tests/data/lavf/lavf.ffm
-./tests/data/lavf/lavf.ffm CRC=0xf361ed74
+./tests/data/lavf/lavf.ffm CRC=0x88f58ba1
diff --git a/tests/ref/lavf/gxf b/tests/ref/lavf/gxf
index 63101b8..d16a706 100644
--- a/tests/ref/lavf/gxf
+++ b/tests/ref/lavf/gxf
@@ -1,9 +1,9 @@
-befc1a39c37a4ecd9264942a3e34b3f6 *./tests/data/lavf/lavf.gxf
+480a13e0051adcf839ea392c91cb1e18 *./tests/data/lavf/lavf.gxf
 796392 ./tests/data/lavf/lavf.gxf
-./tests/data/lavf/lavf.gxf CRC=0x102918fd
-267d2b2b6e357209d76c366302cf35c3 *./tests/data/lavf/lavf.gxf
+./tests/data/lavf/lavf.gxf CRC=0x0052f91f
+89af7c3f7b7867bce1971123a9e03f4f *./tests/data/lavf/lavf.gxf
 794572 ./tests/data/lavf/lavf.gxf
-./tests/data/lavf/lavf.gxf CRC=0xab47d02d
+./tests/data/lavf/lavf.gxf CRC=0xe570b05e
 0a1a37fa79b62435545271b4e8e882f5 *./tests/data/lavf/lavf.gxf
 796392 ./tests/data/lavf/lavf.gxf
 ./tests/data/lavf/lavf.gxf CRC=0x3b1a8e91
diff --git a/tests/ref/lavf/mkv b/tests/ref/lavf/mkv
index a88b47b..576bd05 100644
--- a/tests/ref/lavf/mkv
+++ b/tests/ref/lavf/mkv
@@ -1,3 +1,3 @@
-19c989b2a18dc352ede9754af5fcb5f2 *./tests/data/lavf/lavf.mkv
-320521 ./tests/data/lavf/lavf.mkv
-./tests/data/lavf/lavf.mkv CRC=0x5b4ae6b0
+d8e8858db2fe4920d19d4267059933d6 *./tests/data/lavf/lavf.mkv
+320305 ./tests/data/lavf/lavf.mkv
+./tests/data/lavf/lavf.mkv CRC=0xd86284dd
diff --git a/tests/ref/lavf/mpg b/tests/ref/lavf/mpg
index fe55f51..8d2f862 100644
--- a/tests/ref/lavf/mpg
+++ b/tests/ref/lavf/mpg
@@ -1,9 +1,9 @@
-855384c0cd3d0e3843d48698441c1384 *./tests/data/lavf/lavf.mpg
+8d47f1d92230442d475477ed4ec0c778 *./tests/data/lavf/lavf.mpg
 372736 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0xf361ed74
-612b686e2c035b18175ccefdacf9532c *./tests/data/lavf/lavf.mpg
+./tests/data/lavf/lavf.mpg CRC=0x88f58ba1
+ac56ba7cec2d2be0a1ca17473e5b152c *./tests/data/lavf/lavf.mpg
 387072 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0x3d6ddf56
-fcf2c242b41373186d43de3d5c518e5a *./tests/data/lavf/lavf.mpg
+./tests/data/lavf/lavf.mpg CRC=0xe8637d83
+af32acbc73ee486b05a37d53e516d5e7 *./tests/data/lavf/lavf.mpg
 372736 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0xf361ed74
+./tests/data/lavf/lavf.mpg CRC=0x88f58ba1
diff --git a/tests/ref/lavf/nut b/tests/ref/lavf/nut
index f8756eb..a34895a 100644
--- a/tests/ref/lavf/nut
+++ b/tests/ref/lavf/nut
@@ -1,3 +1,3 @@
-bf59c686c1bb739434109dadc04eeec6 *./tests/data/lavf/lavf.nut
-319904 ./tests/data/lavf/lavf.nut
-./tests/data/lavf/lavf.nut CRC=0x2a83e6b0
+fbb54212668e5299b6ab1c086d644b04 *./tests/data/lavf/lavf.nut
+319696 ./tests/data/lavf/lavf.nut
+./tests/data/lavf/lavf.nut CRC=0xa79b84dd
diff --git a/tests/ref/lavf/ogg b/tests/ref/lavf/ogg
index 59f2e81..bfc62de 100644
--- a/tests/ref/lavf/ogg
+++ b/tests/ref/lavf/ogg
@@ -1,3 +1,3 @@
-010f31817f41bb99899ffcc5c3943938 *./tests/data/lavf/lavf.ogg
-13838 ./tests/data/lavf/lavf.ogg
-./tests/data/lavf/lavf.ogg CRC=0xf1ae5536
+810fbac66c4c65fd155b3c7f27ce69c5 *./tests/data/lavf/lavf.ogg
+12610 ./tests/data/lavf/lavf.ogg
+./tests/data/lavf/lavf.ogg CRC=0xf651632a
diff --git a/tests/ref/lavf/rm b/tests/ref/lavf/rm
index d2a0947..a9deabe 100644
--- a/tests/ref/lavf/rm
+++ b/tests/ref/lavf/rm
@@ -1,2 +1,2 @@
-be73bce6e371fd543f93f668406f3430 *./tests/data/lavf/lavf.rm
-346714 ./tests/data/lavf/lavf.rm
+a13a746ded146a9ede1605e5155e7164 *./tests/data/lavf/lavf.rm
+346422 ./tests/data/lavf/lavf.rm
diff --git a/tests/ref/lavf/ts b/tests/ref/lavf/ts
index 13afe02..5215e21 100644
--- a/tests/ref/lavf/ts
+++ b/tests/ref/lavf/ts
@@ -1,3 +1,3 @@
-258a64dbc1724438e90560294be4be5c *./tests/data/lavf/lavf.ts
-406644 ./tests/data/lavf/lavf.ts
-./tests/data/lavf/lavf.ts CRC=0x133216c1
+be30cf5903b9da47024c783767966804 *./tests/data/lavf/lavf.ts
+406456 ./tests/data/lavf/lavf.ts
+./tests/data/lavf/lavf.ts CRC=0x64fab4df
diff --git a/tests/ref/lavf/wtv b/tests/ref/lavf/wtv
index d0a3ad7..d50f1ca 100644
--- a/tests/ref/lavf/wtv
+++ b/tests/ref/lavf/wtv
@@ -1,3 +1,3 @@
-de9c3be54bafeba1b7f9618609bd0f62 *./tests/data/lavf/lavf.wtv
+451f7e3ed8af12e4edb5b4de51181a4e *./tests/data/lavf/lavf.wtv
 413696 ./tests/data/lavf/lavf.wtv
-./tests/data/lavf/lavf.wtv CRC=0x133216c1
+./tests/data/lavf/lavf.wtv CRC=0x64fab4df
diff --git a/tests/ref/seek/lavf_mkv b/tests/ref/seek/lavf_mkv
index 278d2dc..6c6c10e 100644
--- a/tests/ref/seek/lavf_mkv
+++ b/tests/ref/seek/lavf_mkv
@@ -9,7 +9,7 @@ ret: 0         st: 0 flags:1  ts:-0.317000
 ret: 0         st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos:    555 size:   208
 ret:-1         st: 1 flags:0  ts: 2.577000
 ret: 0         st: 1 flags:1  ts: 1.471000
-ret: 0         st: 1 flags:1 dts: 1.008000 pts: 1.008000 pos: 320250 size:   209
+ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320034 size:   209
 ret: 0         st:-1 flags:0  ts: 0.365002
 ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146746 size: 27925
 ret: 0         st:-1 flags:1  ts:-0.740831
@@ -20,7 +20,7 @@ ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292193 size: 27834
 ret: 0         st: 1 flags:0  ts:-0.058000
 ret: 0         st: 1 flags:1 dts: 0.015000 pts: 0.015000 pos:    555 size:   208
 ret: 0         st: 1 flags:1  ts: 2.836000
-ret: 0         st: 1 flags:1 dts: 1.008000 pts: 1.008000 pos: 320250 size:   209
+ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320034 size:   209
 ret:-1         st:-1 flags:0  ts: 1.730004
 ret: 0         st:-1 flags:1  ts: 0.624171
 ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146746 size: 27925
@@ -41,7 +41,7 @@ ret: 0         st: 0 flags:1  ts:-0.222000
 ret: 0         st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos:    555 size:   208
 ret:-1         st: 1 flags:0  ts: 2.672000
 ret: 0         st: 1 flags:1  ts: 1.566000
-ret: 0         st: 1 flags:1 dts: 1.008000 pts: 1.008000 pos: 320250 size:   209
+ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320034 size:   209
 ret: 0         st:-1 flags:0  ts: 0.460008
 ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146746 size: 27925
 ret: 0         st:-1 flags:1  ts:-0.645825
diff --git a/tests/ref/seek/lavf_mpg b/tests/ref/seek/lavf_mpg
index 52e289b..6948aa9 100644
--- a/tests/ref/seek/lavf_mpg
+++ b/tests/ref/seek/lavf_mpg
@@ -8,7 +8,7 @@ ret: 0         st: 1 flags:1 dts: 0.989089 pts: 0.989089 pos:   2048 size:   208
 ret: 0         st: 0 flags:1  ts:-0.317500
 ret: 0         st: 1 flags:1 dts: 0.989089 pts: 0.989089 pos:   2048 size:   208
 ret: 0         st: 1 flags:0  ts: 2.576667
-ret: 0         st: 1 flags:1 dts: 2.007867 pts: 2.007867 pos: 370700 size:   235
+ret: 0         st: 1 flags:1 dts: 1.772767 pts: 1.772767 pos: 368652 size:   379
 ret: 0         st: 1 flags:1  ts: 1.470833
 ret: 0         st: 1 flags:1 dts: 1.250322 pts: 1.250322 pos: 145408 size:   261
 ret: 0         st:-1 flags:0  ts: 0.365002
@@ -22,7 +22,7 @@ ret: 0         st: 0 flags:0 dts: 1.040000 pts: 1.080000 pos:  40960 size: 16073
 ret: 0         st: 1 flags:0  ts:-0.058333
 ret: 0         st: 1 flags:1 dts: 0.989089 pts: 0.989089 pos:   2048 size:   208
 ret: 0         st: 1 flags:1  ts: 2.835833
-ret: 0         st: 1 flags:1 dts: 2.007867 pts: 2.007867 pos: 370700 size:   235
+ret: 0         st: 1 flags:1 dts: 1.772767 pts: 1.772767 pos: 368652 size:   379
 ret: 0         st:-1 flags:0  ts: 1.730004
 ret: 0         st: 0 flags:0 dts: 1.760000 pts: 1.800000 pos: 292864 size: 13170
 ret: 0         st:-1 flags:1  ts: 0.624171
@@ -44,7 +44,7 @@ ret: 0         st: 1 flags:1 dts: 0.989089 pts: 0.989089 pos:   2048 size:   208
 ret: 0         st: 0 flags:1  ts:-0.222489
 ret: 0         st: 1 flags:1 dts: 0.989089 pts: 0.989089 pos:   2048 size:   208
 ret: 0         st: 1 flags:0  ts: 2.671678
-ret: 0         st: 1 flags:1 dts: 2.007867 pts: 2.007867 pos: 370700 size:   235
+ret: 0         st: 1 flags:1 dts: 1.772767 pts: 1.772767 pos: 368652 size:   379
 ret: 0         st: 1 flags:1  ts: 1.565844
 ret: 0         st: 1 flags:1 dts: 1.511544 pts: 1.511544 pos: 342028 size:   314
 ret: 0         st:-1 flags:0  ts: 0.460008



More information about the ffmpeg-cvslog mailing list