aboutsummaryrefslogtreecommitdiffstats
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-05-10 02:14:44 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-05-10 02:25:41 +0200
commit61930bd0d7154b6f3f8c8d2398c056c20e921652 (patch)
tree54108723e1482e5d20a152f7a46c67ea51441965 /ffmpeg.c
parent35894ebbf9bef18a31dbb90a8a8818fbdc85a184 (diff)
parentc8b4a3999bc7f3732a537cdec6475918a65d6e78 (diff)
downloadffmpeg-61930bd0d7154b6f3f8c8d2398c056c20e921652.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: (27 commits) libxvid: Give more suitable names to libxvid-related files. libxvid: Separate libxvid encoder from libxvid rate control code. jpeglsdec: Remove write-only variable in ff_jpegls_decode_lse(). fate: cosmetics: lowercase some comments fate: Give more consistent names to some RealVideo/RealAudio tests. lavfi: add avfilter_get_audio_buffer_ref_from_arrays(). lavfi: add extended_data to AVFilterBuffer. lavc: check that extended_data is properly set in avcodec_encode_audio2(). lavc: pad last audio frame with silence when needed. samplefmt: add a function for filling a buffer with silence. samplefmt: add a function for copying audio samples. lavr: do not try to copy to uninitialized output audio data. lavr: make avresample_read() with NULL output discard samples. fate: split idroq audio and video into separate tests fate: improve dependencies fate: add convenient shorthands for ea-vp6, libavcodec, libavutil tests fate: split some combined tests into separate audio and video tests fate: fix dependencies for probe tests mips: intreadwrite: fix inline asm for gcc 4.8 mips: intreadwrite: remove unnecessary inline asm ... Conflicts: cmdutils.h configure doc/APIchanges doc/filters.texi ffmpeg.c ffplay.c libavcodec/internal.h libavcodec/jpeglsdec.c libavcodec/libschroedingerdec.c libavcodec/libxvid.c libavcodec/libxvid_rc.c libavcodec/utils.c libavcodec/version.h libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersink.h tests/Makefile tests/fate/aac.mak tests/fate/audio.mak tests/fate/demux.mak tests/fate/ea.mak tests/fate/image.mak tests/fate/libavutil.mak tests/fate/lossless-audio.mak tests/fate/lossless-video.mak tests/fate/microsoft.mak tests/fate/qt.mak tests/fate/real.mak tests/fate/screen.mak tests/fate/video.mak tests/fate/voice.mak tests/fate/vqf.mak tests/ref/fate/ea-mad tests/ref/fate/ea-tqi Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c106
1 files changed, 73 insertions, 33 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 39de517c1e..c5d78fe6d2 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -704,21 +704,34 @@ static enum PixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum Pixe
return target;
}
-static const enum PixelFormat *choose_pixel_fmts(OutputStream *ost)
+static char *choose_pixel_fmts(OutputStream *ost)
{
if (ost->st->codec->pix_fmt != PIX_FMT_NONE) {
- ost->pix_fmts[0] = choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt);
- return ost->pix_fmts;
+ return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt)));
} else if (ost->enc->pix_fmts) {
+ const enum PixelFormat *p;
+ AVIOContext *s = NULL;
+ uint8_t *ret;
+ int len;
+
+ if (avio_open_dyn_buf(&s) < 0)
+ exit_program(1);
+
+ p = ost->enc->pix_fmts;
if (ost->st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
if (ost->st->codec->codec_id == CODEC_ID_MJPEG) {
- return (const enum PixelFormat[]) { PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE };
+ p = (const enum PixelFormat[]) { PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE };
} else if (ost->st->codec->codec_id == CODEC_ID_LJPEG) {
- return (const enum PixelFormat[]) { PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P,
+ p = (const enum PixelFormat[]) { PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P,
PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_BGRA, PIX_FMT_NONE };
}
}
- return ost->enc->pix_fmts;
+
+ for (; *p != PIX_FMT_NONE; p++)
+ avio_printf(s, "%s:", av_get_pix_fmt_name(*p));
+ len = avio_close_dyn_buf(s, &ret);
+ ret[len - 1] = 0;
+ return ret;
} else
return NULL;
}
@@ -727,10 +740,10 @@ static int configure_video_filters(FilterGraph *fg)
{
InputStream *ist = fg->inputs[0]->ist;
OutputStream *ost = fg->outputs[0]->ost;
- AVFilterContext *last_filter, *filter;
+ AVFilterContext *in_filter, *out_filter, *filter;
AVCodecContext *codec = ost->st->codec;
- enum PixelFormat *pix_fmts = choose_pixel_fmts(ost);
AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
+ char *pix_fmts;
AVRational sample_aspect_ratio;
char args[255];
int ret;
@@ -756,18 +769,20 @@ static int configure_video_filters(FilterGraph *fg)
return ret;
#if FF_API_OLD_VSINK_API
- ret = avfilter_graph_create_filter(&fg->outputs[0]->filter, avfilter_get_by_name("buffersink"),
- "out", NULL, pix_fmts, fg->graph);
+ ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
+ avfilter_get_by_name("buffersink"),
+ "out", NULL, NULL, fg->graph);
#else
- buffersink_params->pixel_fmts = pix_fmts;
- ret = avfilter_graph_create_filter(&fg->outputs[0]->filter, avfilter_get_by_name("buffersink"),
+ ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
+ avfilter_get_by_name("buffersink"),
"out", NULL, buffersink_params, fg->graph);
#endif
av_freep(&buffersink_params);
if (ret < 0)
return ret;
- last_filter = fg->inputs[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",
@@ -777,9 +792,22 @@ 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(last_filter, 0, filter, 0)) < 0)
+ if ((ret = avfilter_link(in_filter, 0, filter, 0)) < 0)
return ret;
- last_filter = filter;
+ in_filter = filter;
+ }
+
+ if ((pix_fmts = choose_pixel_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)
+ return ret;
+
+ out_filter = filter;
+ av_freep(&pix_fmts);
}
snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
@@ -790,12 +818,12 @@ static int configure_video_filters(FilterGraph *fg)
AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
- outputs->filter_ctx = last_filter;
+ outputs->filter_ctx = in_filter;
outputs->pad_idx = 0;
outputs->next = NULL;
inputs->name = av_strdup("out");
- inputs->filter_ctx = fg->outputs[0]->filter;
+ inputs->filter_ctx = out_filter;
inputs->pad_idx = 0;
inputs->next = NULL;
@@ -803,7 +831,7 @@ static int configure_video_filters(FilterGraph *fg)
return ret;
av_freep(&ost->avfilter);
} else {
- if ((ret = avfilter_link(last_filter, 0, fg->outputs[0]->filter, 0)) < 0)
+ if ((ret = avfilter_link(in_filter, 0, out_filter, 0)) < 0)
return ret;
}
@@ -919,19 +947,20 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
{
+ char *pix_fmts;
AVCodecContext *codec = ofilter->ost->st->codec;
AVFilterContext *last_filter = out->filter_ctx;
int pad_idx = out->pad_idx;
int ret;
- enum PixelFormat *pix_fmts = choose_pixel_fmts(ofilter->ost);
AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
#if FF_API_OLD_VSINK_API
- ret = avfilter_graph_create_filter(&ofilter->filter, avfilter_get_by_name("buffersink"),
- "out", NULL, pix_fmts, fg->graph);
+ ret = avfilter_graph_create_filter(&ofilter->filter,
+ avfilter_get_by_name("buffersink"),
+ "out", NULL, NULL, fg->graph);
#else
- buffersink_params->pixel_fmts = pix_fmts;
- ret = avfilter_graph_create_filter(&ofilter->filter, avfilter_get_by_name("buffersink"),
+ ret = avfilter_graph_create_filter(&ofilter->filter,
+ avfilter_get_by_name("buffersink"),
"out", NULL, buffersink_params, fg->graph);
#endif
av_freep(&buffersink_params);
@@ -941,18 +970,37 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFil
if (codec->width || codec->height) {
char args[255];
+ AVFilterContext *filter;
+
snprintf(args, sizeof(args), "%d:%d:flags=0x%X",
codec->width,
codec->height,
(unsigned)ofilter->ost->sws_flags);
- if ((ret = avfilter_graph_create_filter(&last_filter, avfilter_get_by_name("scale"),
+ if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
NULL, args, NULL, fg->graph)) < 0)
return ret;
- if ((ret = avfilter_link(out->filter_ctx, out->pad_idx, last_filter, 0)) < 0)
+ if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
return ret;
+
+ last_filter = filter;
pad_idx = 0;
}
+ if ((pix_fmts = choose_pixel_fmts(ofilter->ost))) {
+ AVFilterContext *filter;
+ 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(last_filter, pad_idx, filter, 0)) < 0)
+ return ret;
+
+ last_filter = filter;
+ pad_idx = 0;
+ av_freep(&pix_fmts);
+ }
+
if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
return ret;
@@ -2299,14 +2347,6 @@ static void flush_encoders(void)
av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
- /* pad last frame with silence if needed */
- if (!(enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME)) {
- frame_bytes = enc->frame_size * enc->channels *
- av_get_bytes_per_sample(enc->sample_fmt);
- if (allocated_audio_buf_size < frame_bytes)
- exit_program(1);
- generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
- }
encode_audio_frame(os, ost, audio_buf, frame_bytes);
} else {
/* flush encoder with NULL frames until it is done