From d39bf3df729bed5f5df5d973ecc7110434416fe3 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 16 May 2011 03:34:20 +0200 Subject: [PATCH 01/14] Remove unused header mpegaudio3.h. The header is a part of an MP3 encoder that never saw the light of day. --- libavcodec/Makefile | 1 - libavcodec/mpegaudio3.h | 53 ----------------------------------------- 2 files changed, 54 deletions(-) delete mode 100644 libavcodec/mpegaudio3.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 9040b32f57..aaf9ceb4f9 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -656,7 +656,6 @@ SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h -SKIPHEADERS += mpegaudio3.h EXAMPLES = api diff --git a/libavcodec/mpegaudio3.h b/libavcodec/mpegaudio3.h deleted file mode 100644 index 7047652f6e..0000000000 --- a/libavcodec/mpegaudio3.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2007 Michael Niedermayer - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* layer 3 "granule" */ -typedef struct GranuleDef { - uint8_t scfsi; - int part2_3_length; - int big_values; - int global_gain; - int scalefac_compress; - uint8_t block_type; - uint8_t switch_point; - int table_select[3]; - int subblock_gain[3]; - uint8_t scalefac_scale; - uint8_t count1table_select; - int region_size[3]; /* number of huffman codes in each region */ - int preflag; - int short_start, long_end; /* long/short band indexes */ - uint8_t scale_factors[40]; - int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ -} GranuleDef; - -void ff_mp3_init(void); - -/** - * Compute huffman coded region sizes. - */ -void ff_init_short_region(MPADecodeContext *s, GranuleDef *g); - -/** - * Compute huffman coded region sizes. - */ -void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2); - -void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g); From 257de5fb25454209ccb3fd152d1ff3c98813e2ce Mon Sep 17 00:00:00 2001 From: Gil Pedersen Date: Mon, 16 May 2011 14:40:56 +0200 Subject: [PATCH 02/14] h264dsp_mmx: Add #ifdefs around some mmxext functions on x86_64. This fixes linking errors due to undefined symbols on x86_64 OS X. Signed-off-by: Diego Biurrun --- libavcodec/x86/h264dsp_mmx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/x86/h264dsp_mmx.c b/libavcodec/x86/h264dsp_mmx.c index 01b11163c8..1c07d14cd0 100644 --- a/libavcodec/x86/h264dsp_mmx.c +++ b/libavcodec/x86/h264dsp_mmx.c @@ -252,6 +252,7 @@ LF_IFUNC(v, chroma_intra, depth, avx) LF_FUNCS( uint8_t, 8) LF_FUNCS(uint16_t, 10) +#if ARCH_X86_32 LF_FUNC (v8, luma, 8, mmxext) static void ff_deblock_v_luma_8_mmxext(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) { @@ -266,6 +267,7 @@ static void ff_deblock_v_luma_intra_8_mmxext(uint8_t *pix, int stride, int alpha ff_deblock_v8_luma_intra_8_mmxext(pix+0, stride, alpha, beta); ff_deblock_v8_luma_intra_8_mmxext(pix+8, stride, alpha, beta); } +#endif /* ARCH_X86_32 */ LF_FUNC (v, luma, 10, mmxext) LF_IFUNC(v, luma_intra, 10, mmxext) From 721d6f2dc5437df21ae17923b29fa2be847764c7 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 16 May 2011 15:57:04 +0100 Subject: [PATCH 03/14] dct: bypass table allocation for DCT_II of size 32 The size-32 DCT_II has a special implementation which doesn't use the normal tables. Skipping allocation of these in this case saves some memory. Signed-off-by: Mans Rullgard --- libavcodec/dct.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavcodec/dct.c b/libavcodec/dct.c index 83ea00f9cb..e7a8f227b7 100644 --- a/libavcodec/dct.c +++ b/libavcodec/dct.c @@ -180,9 +180,14 @@ av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse) int n = 1 << nbits; int i; + memset(s, 0, sizeof(*s)); + s->nbits = nbits; s->inverse = inverse; + if (inverse == DCT_II && nbits == 5) { + s->dct_calc = dct32_func; + } else { ff_init_ff_cos_tabs(nbits+2); s->costab = ff_cos_tabs[nbits+2]; @@ -203,9 +208,7 @@ av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse) case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; case DST_I : s->dct_calc = ff_dst_calc_I_c; break; } - - if (inverse == DCT_II && nbits == 5) - s->dct_calc = dct32_func; + } s->dct32 = dct32; if (HAVE_MMX) ff_dct_init_mmx(s); From 9503fbb859d859fada35c966af8d4765a8b819fa Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 16 May 2011 15:57:36 +0100 Subject: [PATCH 04/14] dct: fix indentation Signed-off-by: Mans Rullgard --- libavcodec/dct.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libavcodec/dct.c b/libavcodec/dct.c index e7a8f227b7..caa6bdb4b4 100644 --- a/libavcodec/dct.c +++ b/libavcodec/dct.c @@ -188,26 +188,26 @@ av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse) if (inverse == DCT_II && nbits == 5) { s->dct_calc = dct32_func; } else { - ff_init_ff_cos_tabs(nbits+2); + ff_init_ff_cos_tabs(nbits+2); - s->costab = ff_cos_tabs[nbits+2]; + s->costab = ff_cos_tabs[nbits+2]; - s->csc2 = av_malloc(n/2 * sizeof(FFTSample)); + s->csc2 = av_malloc(n/2 * sizeof(FFTSample)); - if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) { - av_free(s->csc2); - return -1; - } + if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) { + av_free(s->csc2); + return -1; + } - for (i = 0; i < n/2; i++) - s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); + for (i = 0; i < n/2; i++) + s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); - switch(inverse) { - case DCT_I : s->dct_calc = ff_dct_calc_I_c; break; - case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break; - case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; - case DST_I : s->dct_calc = ff_dst_calc_I_c; break; - } + switch(inverse) { + case DCT_I : s->dct_calc = ff_dct_calc_I_c; break; + case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break; + case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; + case DST_I : s->dct_calc = ff_dst_calc_I_c; break; + } } s->dct32 = dct32; From 5026f946fda58b209334a40319af7c42ceb985fe Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 16 May 2011 15:23:22 +0100 Subject: [PATCH 05/14] Add missing #includes to mp3_header_(de)compress bsf Signed-off-by: Mans Rullgard --- libavcodec/mp3_header_compress_bsf.c | 1 + libavcodec/mp3_header_decompress_bsf.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libavcodec/mp3_header_compress_bsf.c b/libavcodec/mp3_header_compress_bsf.c index 5a693774f9..c880e5e53d 100644 --- a/libavcodec/mp3_header_compress_bsf.c +++ b/libavcodec/mp3_header_compress_bsf.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intreadwrite.h" #include "avcodec.h" #include "mpegaudio.h" diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c index 7dda795db5..b4b4167620 100644 --- a/libavcodec/mp3_header_decompress_bsf.c +++ b/libavcodec/mp3_header_decompress_bsf.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intreadwrite.h" #include "avcodec.h" #include "mpegaudio.h" #include "mpegaudiodata.h" From 92ea249d7db4baf64680f412c6bd99ff85860723 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 16 May 2011 17:13:23 +0100 Subject: [PATCH 06/14] mpegaudio: remove OUT_MIN/MAX macros These macros are no longer needed after the s32 output was removed. Change the relevant code to use av_clip_int16() instead of using explicit limits. Signed-off-by: Mans Rullgard --- libavcodec/mpegaudio.h | 2 -- libavcodec/mpegaudiodec.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libavcodec/mpegaudio.h b/libavcodec/mpegaudio.h index f12b897e23..47d10e91fa 100644 --- a/libavcodec/mpegaudio.h +++ b/libavcodec/mpegaudio.h @@ -70,8 +70,6 @@ typedef float OUT_INT; #define OUT_FMT AV_SAMPLE_FMT_FLT #else typedef int16_t OUT_INT; -#define OUT_MAX INT16_MAX -#define OUT_MIN INT16_MIN #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15) #define OUT_FMT AV_SAMPLE_FMT_S16 #endif diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 7fd6bd2dc6..10a63c57be 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -490,7 +490,7 @@ static inline int round_sample(int64_t *sum) int sum1; sum1 = (int)((*sum) >> OUT_SHIFT); *sum &= (1< Date: Mon, 16 May 2011 17:06:30 +0100 Subject: [PATCH 07/14] mpegaudio: move OUT_FMT macro to mpegaudiodec.c Signed-off-by: Mans Rullgard --- libavcodec/mpegaudio.h | 2 -- libavcodec/mpegaudiodec.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/mpegaudio.h b/libavcodec/mpegaudio.h index 47d10e91fa..2c3f2ec065 100644 --- a/libavcodec/mpegaudio.h +++ b/libavcodec/mpegaudio.h @@ -67,11 +67,9 @@ #if CONFIG_FLOAT typedef float OUT_INT; -#define OUT_FMT AV_SAMPLE_FMT_FLT #else typedef int16_t OUT_INT; #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15) -#define OUT_FMT AV_SAMPLE_FMT_S16 #endif #if CONFIG_FLOAT diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 10a63c57be..8c42e09666 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -47,6 +47,7 @@ # define MULH3(x, y, s) ((s)*(y)*(x)) # define MULLx(x, y, s) ((y)*(x)) # define RENAME(a) a ## _float +# define OUT_FMT AV_SAMPLE_FMT_FLT #else # define SHR(a,b) ((a)>>(b)) # define compute_antialias compute_antialias_integer @@ -57,6 +58,7 @@ # define MULH3(x, y, s) MULH((s)*(x), y) # define MULLx(x, y, s) MULL(x,y,s) # define RENAME(a) a +# define OUT_FMT AV_SAMPLE_FMT_S16 #endif /****************/ From d39facc783c270227e5b7c75db3dec406ed19018 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 15 May 2011 18:34:11 +0200 Subject: [PATCH 08/14] tools: Check the return value of write(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes several warnings of the type: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result --- tools/cws2fws.c | 15 ++++++++++++--- tools/pktdumper.c | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/cws2fws.c b/tools/cws2fws.c index aa7d690be3..5fa51470df 100644 --- a/tools/cws2fws.c +++ b/tools/cws2fws.c @@ -69,7 +69,10 @@ int main(int argc, char *argv[]) // write out modified header buf_in[0] = 'F'; - write(fd_out, &buf_in, 8); + if (write(fd_out, &buf_in, 8) < 8) { + perror("Error writing output file"); + exit(1); + } zstream.zalloc = NULL; zstream.zfree = NULL; @@ -101,7 +104,10 @@ int main(int argc, char *argv[]) zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out, zstream.total_out-last_out); - write(fd_out, &buf_out, zstream.total_out-last_out); + if (write(fd_out, &buf_out, zstream.total_out - last_out) < zstream.total_out - last_out) { + perror("Error writing output file"); + exit(1); + } i += len; @@ -120,7 +126,10 @@ int main(int argc, char *argv[]) buf_in[3] = ((zstream.total_out+8) >> 24) & 0xff; lseek(fd_out, 4, SEEK_SET); - write(fd_out, &buf_in, 4); + if (write(fd_out, &buf_in, 4) < 4) { + perror("Error writing output file"); + exit(1); + } } inflateEnd(&zstream); diff --git a/tools/pktdumper.c b/tools/pktdumper.c index 3ab39ee675..80816d24b9 100644 --- a/tools/pktdumper.c +++ b/tools/pktdumper.c @@ -104,7 +104,11 @@ int main(int argc, char **argv) //printf("open(\"%s\")\n", pktfilename); if (!nowrite) { fd = open(pktfilename, O_WRONLY|O_CREAT, 0644); - write(fd, pkt.data, pkt.size); + err = write(fd, pkt.data, pkt.size); + if (err < 0) { + fprintf(stderr, "write: error %d\n", err); + return 1; + } close(fd); } av_free_packet(&pkt); From c540061f3f552daa3724289b59b0a7a3692ad740 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 15 May 2011 22:17:35 +0200 Subject: [PATCH 09/14] cws2fws: Improve error message wording. --- tools/cws2fws.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/cws2fws.c b/tools/cws2fws.c index 5fa51470df..b8535feaa4 100644 --- a/tools/cws2fws.c +++ b/tools/cws2fws.c @@ -35,14 +35,14 @@ int main(int argc, char *argv[]) fd_in = open(argv[1], O_RDONLY); if (fd_in < 0) { - perror("Error while opening: "); + perror("Error opening input file"); exit(1); } fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644); if (fd_out < 0) { - perror("Error while opening: "); + perror("Error opening output file"); close(fd_in); exit(1); } From 005db470115ebe2c973688bed9695356f487d674 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 16 May 2011 21:31:06 +0100 Subject: [PATCH 10/14] mathops: remove ancient confusing comment Signed-off-by: Mans Rullgard --- libavcodec/mathops.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h index 547bc1aa4f..d74bc1ed70 100644 --- a/libavcodec/mathops.h +++ b/libavcodec/mathops.h @@ -45,9 +45,6 @@ #endif #ifndef MULH -//gcc 3.4 creates an incredibly bloated mess out of this -//# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32) - static av_always_inline int MULH(int a, int b){ return ((int64_t)(a) * (int64_t)(b))>>32; } From 5dc65a3d0374ffd85e5ff1c89f5917d392897920 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 23 Apr 2011 19:55:59 +0200 Subject: [PATCH 11/14] lavfi: print key-frame and picture type information in ff_dlog_ref() Signed-off-by: Stefano Sabatini (cherry picked from commit f7bdffb09da597c5d6afff5359523370470ad072) --- libavfilter/avfilter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 82350d1790..02915036ab 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -237,11 +237,13 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end) ref->pts, ref->pos); if (ref->video) { - av_dlog(ctx, " a:%d/%d s:%dx%d i:%c", + av_dlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c", ref->video->pixel_aspect.num, ref->video->pixel_aspect.den, ref->video->w, ref->video->h, !ref->video->interlaced ? 'P' : /* Progressive */ - ref->video->top_field_first ? 'T' : 'B'); /* Top / Bottom */ + ref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */ + ref->video->key_frame, + av_get_picture_type_char(ref->video->pict_type)); } if (ref->audio) { av_dlog(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d", From 3a7c977417f7904a6213048ed3e57dd79264d3d5 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Tue, 12 Apr 2011 12:06:49 +0200 Subject: [PATCH 12/14] ffplay: remove audio_write_get_buf_size() forward declaration Move up the definition of audio_write_get_buf_size(), so that it is defined before it is used. Simplify. (cherry picked from commit 8776f3d22e401e30d17856e341f6cabbbefa92f7) --- ffplay.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ffplay.c b/ffplay.c index e820c603e3..a5dc358f72 100644 --- a/ffplay.c +++ b/ffplay.c @@ -218,7 +218,6 @@ typedef struct VideoState { } VideoState; static void show_help(void); -static int audio_write_get_buf_size(VideoState *is); /* options specified by the user */ static AVInputFormat *file_iformat; @@ -768,6 +767,13 @@ static void video_image_display(VideoState *is) } } +/* get the current audio output buffer size, in samples. With SDL, we + cannot have a precise information */ +static int audio_write_get_buf_size(VideoState *is) +{ + return is->audio_buf_size - is->audio_buf_index; +} + static inline int compute_mod(int a, int b) { a = a % b; @@ -2146,14 +2152,6 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) } } -/* get the current audio output buffer size, in samples. With SDL, we - cannot have a precise information */ -static int audio_write_get_buf_size(VideoState *is) -{ - return is->audio_buf_size - is->audio_buf_index; -} - - /* prepare a new audio buffer */ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) { From 9d5fa6182dd2e41d5c174b29ef2a1a2f83a02d23 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 14 Feb 2011 23:02:10 +0100 Subject: [PATCH 13/14] Restructure video filter implementation in ffmpeg.c. This fixes several bugs like multiple outputs and -aspect mixed with -vf (cherry picked from commit 1762d9ced70ccc46c5d3e5d64e56a48d0fbbd4f7) (cherry picked from commit 5c20c81bfa526b3a269db9c88b0c9007861f0917) (cherry picked from commit a7844c580d83d8466c161a0e3979b3902d0d9100) --- ffmpeg.c | 139 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 2a8a7d0a68..828e7f1414 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -161,7 +161,6 @@ static int loop_output = AVFMT_NOOUTPUTLOOP; static int qp_hist = 0; #if CONFIG_AVFILTER static char *vfilters = NULL; -static AVFilterGraph *graph = NULL; #endif static int intra_only = 0; @@ -291,6 +290,14 @@ typedef struct AVOutputStream { AVFifoBuffer *fifo; /* for compression: one audio fifo per codec */ FILE *logfile; +#if CONFIG_AVFILTER + AVFilterContext *output_video_filter; + AVFilterContext *input_video_filter; + AVFilterBufferRef *picref; + char *avfilter; + AVFilterGraph *graph; +#endif + int sws_flags; } AVOutputStream; @@ -314,11 +321,8 @@ typedef struct AVInputStream { int showed_multi_packet_warning; int is_past_recording_time; #if CONFIG_AVFILTER - AVFilterContext *output_video_filter; - AVFilterContext *input_video_filter; AVFrame *filter_frame; int has_filter_frame; - AVFilterBufferRef *picref; #endif } AVInputStream; @@ -342,7 +346,7 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) char args[255]; int ret; - graph = avfilter_graph_alloc(); + ost->graph = avfilter_graph_alloc(); if (ist->st->sample_aspect_ratio.num){ sample_aspect_ratio = ist->st->sample_aspect_ratio; @@ -353,15 +357,15 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE, sample_aspect_ratio.num, sample_aspect_ratio.den); - ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"), - "src", args, NULL, graph); + ret = avfilter_graph_create_filter(&ost->input_video_filter, avfilter_get_by_name("buffer"), + "src", args, NULL, ost->graph); if (ret < 0) return ret; - ret = avfilter_graph_create_filter(&ist->output_video_filter, &ffsink, - "out", NULL, &ffsink_ctx, graph); + ret = avfilter_graph_create_filter(&ost->output_video_filter, &ffsink, + "out", NULL, &ffsink_ctx, ost->graph); if (ret < 0) return ret; - last_filter = ist->input_video_filter; + last_filter = ost->input_video_filter; if (codec->width != icodec->width || codec->height != icodec->height) { snprintf(args, 255, "%d:%d:flags=0x%X", @@ -369,7 +373,7 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) codec->height, ost->sws_flags); if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"), - NULL, args, NULL, graph)) < 0) + NULL, args, NULL, ost->graph)) < 0) return ret; if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0) return ret; @@ -377,9 +381,9 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) } snprintf(args, sizeof(args), "flags=0x%X", ost->sws_flags); - graph->scale_sws_opts = av_strdup(args); + ost->graph->scale_sws_opts = av_strdup(args); - if (vfilters) { + if (ost->avfilter) { AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut)); AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut)); @@ -389,25 +393,25 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) outputs->next = NULL; inputs->name = av_strdup("out"); - inputs->filter_ctx = ist->output_video_filter; + inputs->filter_ctx = ost->output_video_filter; inputs->pad_idx = 0; inputs->next = NULL; - if ((ret = avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL)) < 0) + if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, inputs, outputs, NULL)) < 0) return ret; - av_freep(&vfilters); + av_freep(&ost->avfilter); } else { - if ((ret = avfilter_link(last_filter, 0, ist->output_video_filter, 0)) < 0) + if ((ret = avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0) return ret; } - if ((ret = avfilter_graph_config(graph, NULL)) < 0) + if ((ret = avfilter_graph_config(ost->graph, NULL)) < 0) return ret; - codec->width = ist->output_video_filter->inputs[0]->w; - codec->height = ist->output_video_filter->inputs[0]->h; + codec->width = ost->output_video_filter->inputs[0]->w; + codec->height = ost->output_video_filter->inputs[0]->h; codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = - ist->output_video_filter->inputs[0]->sample_aspect_ratio; + ost->output_video_filter->inputs[0]->sample_aspect_ratio; return 0; } @@ -1549,14 +1553,21 @@ static int output_packet(AVInputStream *ist, int ist_index, } #if CONFIG_AVFILTER - if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->input_video_filter) { - AVRational sar; - if (ist->st->sample_aspect_ratio.num) sar = ist->st->sample_aspect_ratio; - else sar = ist->st->codec->sample_aspect_ratio; - // add it to be filtered - av_vsrc_buffer_add_frame(ist->input_video_filter, &picture, - ist->pts, - sar); + if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + for (i = 0; i < nb_ostreams; i++) { + ost = ost_table[i]; + if (ost->input_video_filter && ost->source_index == ist_index) { + AVRational sar; + if (ist->st->sample_aspect_ratio.num) + sar = ist->st->sample_aspect_ratio; + else + sar = ist->st->codec->sample_aspect_ratio; + // add it to be filtered + av_vsrc_buffer_add_frame(ost->input_video_filter, &picture, + ist->pts, + sar); + } + } } #endif @@ -1581,26 +1592,24 @@ static int output_packet(AVInputStream *ist, int ist_index, if (pts > now) usleep(pts - now); } -#if CONFIG_AVFILTER - frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || - !ist->output_video_filter || avfilter_poll_frame(ist->output_video_filter->inputs[0]); -#endif /* if output time reached then transcode raw format, encode packets and output them */ if (start_time == 0 || ist->pts >= start_time) -#if CONFIG_AVFILTER - while (frame_available) { - AVRational ist_pts_tb; - if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->output_video_filter) - get_filtered_video_frame(ist->output_video_filter, &picture, &ist->picref, &ist_pts_tb); - if (ist->picref) - ist->pts = av_rescale_q(ist->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); -#endif for(i=0;isource_index == ist_index) { +#if CONFIG_AVFILTER + frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || + !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]); + while (frame_available) { + AVRational ist_pts_tb; + if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter) + get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb); + if (ost->picref) + ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); +#endif os = output_files[ost->file_index]; /* set the input output pts pairs */ @@ -1614,8 +1623,8 @@ static int output_packet(AVInputStream *ist, int ist_index, break; case AVMEDIA_TYPE_VIDEO: #if CONFIG_AVFILTER - if (ist->picref->video) - ost->st->codec->sample_aspect_ratio = ist->picref->video->pixel_aspect; + if (ost->picref->video) + ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect; #endif do_video_out(os, ost, ist, &picture, &frame_size); if (vstats_filename && frame_size) @@ -1636,7 +1645,11 @@ static int output_packet(AVInputStream *ist, int ist_index, av_init_packet(&opkt); if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes) +#if !CONFIG_AVFILTER continue; +#else + goto cont; +#endif /* no reencoding needed : output the packet directly */ /* force the input stream PTS */ @@ -1684,16 +1697,17 @@ static int output_packet(AVInputStream *ist, int ist_index, ost->frame_number++; av_free_packet(&opkt); } +#if CONFIG_AVFILTER + cont: + frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]); + if (ost->picref) + avfilter_unref_buffer(ost->picref); + } +#endif } } -#if CONFIG_AVFILTER - frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && - ist->output_video_filter && avfilter_poll_frame(ist->output_video_filter->inputs[0]); - if(ist->picref) - avfilter_unref_buffer(ist->picref); - } -#endif av_free(buffer_to_free); /* XXX: allocate the subtitles in the codec ? */ if (subtitle_to_free) { @@ -2611,6 +2625,9 @@ static int transcode(AVFormatContext **output_files, av_freep(&ost->st->codec->stats_in); avcodec_close(ost->st->codec); } +#if CONFIG_AVFILTER + avfilter_graph_free(&ost->graph); +#endif } /* close each decoder */ @@ -2620,9 +2637,6 @@ static int transcode(AVFormatContext **output_files, avcodec_close(ist->st->codec); } } -#if CONFIG_AVFILTER - avfilter_graph_free(&graph); -#endif /* finished ! */ ret = 0; @@ -2765,12 +2779,6 @@ static void opt_frame_aspect_ratio(const char *arg) ffmpeg_exit(1); } frame_aspect_ratio = ar; - -#if CONFIG_AVFILTER - x = vfilters ? strlen(vfilters) : 0; - vfilters = av_realloc(vfilters, x+100); - snprintf(vfilters+x, x+100, "%csetdar=%f\n", x?',':' ', ar); -#endif } static int opt_metadata(const char *opt, const char *arg) @@ -3329,6 +3337,7 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) AVCodecContext *video_enc; enum CodecID codec_id = CODEC_ID_NONE; AVCodec *codec= NULL; + int i; st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); if (!st) { @@ -3348,6 +3357,18 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO); codec = avcodec_find_encoder(codec_id); } + +#if CONFIG_AVFILTER + if (frame_aspect_ratio > 0){ + i = vfilters ? strlen(vfilters) : 0; + vfilters = av_realloc(vfilters, i+100); + snprintf(vfilters+i, i+100, "%csetdar=%f\n", i?',':' ', frame_aspect_ratio); + frame_aspect_ratio=0; + } + + ost->avfilter= vfilters; + vfilters = NULL; +#endif } avcodec_get_context_defaults3(st->codec, codec); From 901ff51116f831c9082e14c80c7481dd3999aa30 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier Date: Fri, 1 Apr 2011 17:30:45 +0200 Subject: [PATCH 14/14] ffmpeg: fix -aspect cli option Redesign the way -aspect option is handled. This is done by making ffmpeg read the sample aspect ratio set in the corresponding input stream by default, and overriding it using the value specified by -aspect. If the output display aspect ratio is specified with -aspect, it is set at the end of the filterchain, thus overriding the value set by filters in the filterchain. This implementation is more robust, since does not modify the filterchain description (which was creating potential syntax errors). (Cherry-pick abf8342aa94bdf06bb324f6723a6743dd628d5c6) Another aspect ratio fix try. This leaves the setdar addition at the end (preferred by people). (Cherry-pick e7c7b0d000e81d24327602e04d8fed400dbb7193) --- ffmpeg.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 828e7f1414..c99c4de024 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -274,6 +274,8 @@ typedef struct AVOutputStream { int resample_width; int resample_pix_fmt; + float frame_aspect_ratio; + /* forced key frames */ int64_t *forced_kf_pts; int forced_kf_count; @@ -411,6 +413,8 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) codec->width = ost->output_video_filter->inputs[0]->w; codec->height = ost->output_video_filter->inputs[0]->h; codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = + ost->frame_aspect_ratio ? // overriden by the -aspect cli option + av_d2q(ost->frame_aspect_ratio*codec->height/codec->width, 255) : ost->output_video_filter->inputs[0]->sample_aspect_ratio; return 0; @@ -1623,7 +1627,7 @@ static int output_packet(AVInputStream *ist, int ist_index, break; case AVMEDIA_TYPE_VIDEO: #if CONFIG_AVFILTER - if (ost->picref->video) + if (ost->picref->video && !ost->frame_aspect_ratio) ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect; #endif do_video_out(os, ost, ist, &picture, &frame_size); @@ -2132,6 +2136,13 @@ static int transcode(AVFormatContext **output_files, codec->width = icodec->width; codec->height = icodec->height; codec->has_b_frames = icodec->has_b_frames; + if (!codec->sample_aspect_ratio.num) { + codec->sample_aspect_ratio = + ost->st->sample_aspect_ratio = + ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : + ist->st->codec->sample_aspect_ratio.num ? + ist->st->codec->sample_aspect_ratio : (AVRational){0, 1}; + } break; case AVMEDIA_TYPE_SUBTITLE: codec->width = icodec->width; @@ -3220,11 +3231,6 @@ static void opt_input_file(const char *filename) set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]); frame_height = dec->height; frame_width = dec->width; - if(ic->streams[i]->sample_aspect_ratio.num) - frame_aspect_ratio=av_q2d(ic->streams[i]->sample_aspect_ratio); - else - frame_aspect_ratio=av_q2d(dec->sample_aspect_ratio); - frame_aspect_ratio *= (float) dec->width / dec->height; frame_pix_fmt = dec->pix_fmt; rfps = ic->streams[i]->r_frame_rate.num; rfps_base = ic->streams[i]->r_frame_rate.den; @@ -3337,7 +3343,6 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) AVCodecContext *video_enc; enum CodecID codec_id = CODEC_ID_NONE; AVCodec *codec= NULL; - int i; st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); if (!st) { @@ -3358,14 +3363,9 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) codec = avcodec_find_encoder(codec_id); } + ost->frame_aspect_ratio = frame_aspect_ratio; + frame_aspect_ratio = 0; #if CONFIG_AVFILTER - if (frame_aspect_ratio > 0){ - i = vfilters ? strlen(vfilters) : 0; - vfilters = av_realloc(vfilters, i+100); - snprintf(vfilters+i, i+100, "%csetdar=%f\n", i?',':' ', frame_aspect_ratio); - frame_aspect_ratio=0; - } - ost->avfilter= vfilters; vfilters = NULL; #endif @@ -3412,7 +3412,6 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) video_enc->width = frame_width; video_enc->height = frame_height; - video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255); video_enc->pix_fmt = frame_pix_fmt; st->sample_aspect_ratio = video_enc->sample_aspect_ratio;