ffmpeg-cvslog
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
September 2016
- 5 participants
- 404 discussions
ffmpeg | branch: master | Clément Bœsch <clement(a)stupeflix.com> | Wed Sep 21 15:39:16 2016 +0200| [5ef19590802f000299e418143fc2301e3f43affe] | committer: James Almer
ffmpeg: switch to the new BSF API
This commit is initially largely based on commit 4426540 from Anton
Khirnov <anton(a)khirnov.net> and two following fixes (80fb19b and
fe7b21c) which were previously skipped respectively in 98e3153, c9ee36e,
and 7fe7cdc.
mpeg4-bsf-unpack-bframes FATE reference is updated because the bsf
filter now actually fixes the extradata (mpeg4_unpack_bframes_init()
changing one byte is now honored on the output extradata).
The FATE references for remove_extra change because the packet flags
were wrong and the keyframes weren't marked, causing the bsf relying on
these proprieties to not actually work as intended.
The following was fixed by James Almer:
The filter option arguments are now also parsed correctly.
A hack to propagate extradata changed by bitstream filters after the
first av_bsf_receive_packet() call is added to maintain the current
behavior. This was previously done by av_bitstream_filter_filter() and
is needed for the aac_adtstoasc bsf.
The exit_on_error was not being checked anymore, and led to an exit
error in the last frame of h264_mp4toannexb test. Restoring this
behaviour prevents erroring out. The test is still changed as a result
due to the badly filtered frame now not being written after the failure.
Signed-off-by: Clément Bœsch <u(a)pkh.me>
Signed-off-by: James Almer <jamrial(a)gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5ef19590802f00029…
---
cmdutils.c | 5 +-
ffmpeg.c | 154 ++++++++++++++++++++++-------
ffmpeg.h | 6 +-
ffmpeg_opt.c | 73 ++++++++++----
tests/ref/fate/ffmpeg-bsf-remove-k | 55 ++++++-----
tests/ref/fate/ffmpeg-bsf-remove-r | 55 +++++------
tests/ref/fate/h264_mp4toannexb_ticket2991 | 6 +-
tests/ref/fate/mpeg4-bsf-unpack-bframes | 2 +-
8 files changed, 237 insertions(+), 119 deletions(-)
diff --git a/cmdutils.c b/cmdutils.c
index 68deed9..71b3b2f 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1579,10 +1579,11 @@ int show_encoders(void *optctx, const char *opt, const char *arg)
int show_bsfs(void *optctx, const char *opt, const char *arg)
{
- AVBitStreamFilter *bsf = NULL;
+ const AVBitStreamFilter *bsf = NULL;
+ void *opaque = NULL;
printf("Bitstream filters:\n");
- while ((bsf = av_bitstream_filter_next(bsf)))
+ while ((bsf = av_bsf_next(&opaque)))
printf("%s\n", bsf->name);
printf("\n");
return 0;
diff --git a/ffmpeg.c b/ffmpeg.c
index 5535b40..1b363f7 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -502,18 +502,15 @@ static void ffmpeg_cleanup(int ret)
}
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
- AVBitStreamFilterContext *bsfc;
if (!ost)
continue;
- bsfc = ost->bitstream_filters;
- while (bsfc) {
- AVBitStreamFilterContext *next = bsfc->next;
- av_bitstream_filter_close(bsfc);
- bsfc = next;
- }
- ost->bitstream_filters = NULL;
+ for (j = 0; j < ost->nb_bitstream_filters; j++)
+ av_bsf_free(&ost->bsf_ctx[j]);
+ av_freep(&ost->bsf_ctx);
+ av_freep(&ost->bsf_extradata_updated);
+
av_frame_free(&ost->filtered_frame);
av_frame_free(&ost->last_frame);
@@ -633,11 +630,9 @@ static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream,
}
}
-static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
+static void write_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
{
AVStream *st = ost->st;
- AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
- AVCodecContext *avctx = ost->encoding_needed ? ost->enc_ctx : ost->st->codec;
int ret;
if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) ||
@@ -680,26 +675,6 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
}
}
- if (bsfc)
- av_packet_split_side_data(pkt);
-
- if ((ret = av_apply_bitstream_filters(avctx, pkt, bsfc)) < 0) {
- print_error("", ret);
- if (exit_on_error)
- exit_program(1);
- }
- if (pkt->size == 0 && pkt->side_data_elems == 0)
- return;
- if (!st->codecpar->extradata_size && avctx->extradata_size) {
- st->codecpar->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codecpar->extradata) {
- av_log(NULL, AV_LOG_ERROR, "Could not allocate extradata buffer to copy parser data.\n");
- exit_program(1);
- }
- st->codecpar->extradata_size = avctx->extradata_size;
- memcpy(st->codecpar->extradata, avctx->extradata, avctx->extradata_size);
- }
-
if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
if (pkt->dts != AV_NOPTS_VALUE &&
pkt->pts != AV_NOPTS_VALUE &&
@@ -772,6 +747,68 @@ static void close_output_stream(OutputStream *ost)
}
}
+static void output_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
+{
+ int ret = 0;
+
+ /* apply the output bitstream filters, if any */
+ if (ost->nb_bitstream_filters) {
+ int idx;
+
+ ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);
+ if (ret < 0)
+ goto finish;
+
+ idx = 1;
+ while (idx) {
+ /* get a packet from the previous filter up the chain */
+ ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);
+ /* HACK! - aac_adtstoasc updates extradata after filtering the first frame when
+ * the api states this shouldn't happen after init(). Propagate it here to the
+ * muxer and to the next filters in the chain to workaround this.
+ * TODO/FIXME - Make aac_adtstoasc use new packet side data instead of changing
+ * par_out->extradata and adapt muxers accordingly to get rid of this. */
+ if (!(ost->bsf_extradata_updated[idx - 1] & 1)) {
+ ret = avcodec_parameters_copy(ost->st->codecpar, ost->bsf_ctx[idx - 1]->par_out);
+ if (ret < 0)
+ goto finish;
+ ost->bsf_extradata_updated[idx - 1] |= 1;
+ }
+ if (ret == AVERROR(EAGAIN)) {
+ ret = 0;
+ idx--;
+ continue;
+ } else if (ret < 0)
+ goto finish;
+
+ /* send it to the next filter down the chain or to the muxer */
+ if (idx < ost->nb_bitstream_filters) {
+ /* HACK/FIXME! - See above */
+ if (!(ost->bsf_extradata_updated[idx] & 2)) {
+ ret = avcodec_parameters_copy(ost->bsf_ctx[idx]->par_out, ost->bsf_ctx[idx - 1]->par_out);
+ if (ret < 0)
+ goto finish;
+ ost->bsf_extradata_updated[idx] |= 2;
+ }
+ ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);
+ if (ret < 0)
+ goto finish;
+ idx++;
+ } else
+ write_packet(s, pkt, ost);
+ }
+ } else
+ write_packet(s, pkt, ost);
+
+finish:
+ if (ret < 0 && ret != AVERROR_EOF) {
+ av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "
+ "packet for stream #%d:%d.\n", ost->file_index, ost->index);
+ if(exit_on_error)
+ exit_program(1);
+ }
+}
+
static int check_recording_time(OutputStream *ost)
{
OutputFile *of = output_files[ost->file_index];
@@ -830,7 +867,7 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base));
}
- write_frame(s, &pkt, ost);
+ output_packet(s, &pkt, ost);
}
}
@@ -914,7 +951,7 @@ static void do_subtitle_out(AVFormatContext *s,
pkt.pts += 90 * sub->end_display_time;
}
pkt.dts = pkt.pts;
- write_frame(s, &pkt, ost);
+ output_packet(s, &pkt, ost);
}
}
@@ -1095,7 +1132,7 @@ static void do_video_out(AVFormatContext *s,
pkt.pts = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base);
pkt.flags |= AV_PKT_FLAG_KEY;
- write_frame(s, &pkt, ost);
+ output_packet(s, &pkt, ost);
} else
#endif
{
@@ -1194,7 +1231,7 @@ static void do_video_out(AVFormatContext *s,
}
frame_size = pkt.size;
- write_frame(s, &pkt, ost);
+ output_packet(s, &pkt, ost);
/* if two pass, output log */
if (ost->logfile && enc->stats_out) {
@@ -1756,7 +1793,7 @@ static void flush_encoders(void)
}
av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
pkt_size = pkt.size;
- write_frame(os, &pkt, ost);
+ output_packet(os, &pkt, ost);
if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) {
do_video_stats(ost, pkt_size);
}
@@ -1898,7 +1935,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
}
#endif
- write_frame(of->ctx, &opkt, ost);
+ output_packet(of->ctx, &opkt, ost);
}
int guess_input_channel_layout(InputStream *ist)
@@ -2591,6 +2628,42 @@ static int compare_int64(const void *a, const void *b)
return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
}
+static int init_output_bsfs(OutputStream *ost)
+{
+ AVBSFContext *ctx;
+ int i, ret;
+
+ if (!ost->nb_bitstream_filters)
+ return 0;
+
+ for (i = 0; i < ost->nb_bitstream_filters; i++) {
+ ctx = ost->bsf_ctx[i];
+
+ ret = avcodec_parameters_copy(ctx->par_in,
+ i ? ost->bsf_ctx[i - 1]->par_out : ost->st->codecpar);
+ if (ret < 0)
+ return ret;
+
+ ctx->time_base_in = i ? ost->bsf_ctx[i - 1]->time_base_out : ost->st->time_base;
+
+ ret = av_bsf_init(ctx);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error initializing bistream filter: %s\n",
+ ost->bsf_ctx[i]->filter->name);
+ return ret;
+ }
+ }
+
+ ctx = ost->bsf_ctx[ost->nb_bitstream_filters - 1];
+ ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
+ if (ret < 0)
+ return ret;
+
+ ost->st->time_base = ctx->time_base_out;
+
+ return 0;
+}
+
static int init_output_stream(OutputStream *ost, char *error, int error_len)
{
int ret = 0;
@@ -2696,6 +2769,13 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
return ret;
}
+ /* initialize bitstream filters for the output stream
+ * needs to be done here, because the codec id for streamcopy is not
+ * known until now */
+ ret = init_output_bsfs(ost);
+ if (ret < 0)
+ return ret;
+
return ret;
}
diff --git a/ffmpeg.h b/ffmpeg.h
index 5caf584..b7f8b7a 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -416,7 +416,11 @@ typedef struct OutputStream {
int64_t first_pts;
/* dts of the last packet sent to the muxer */
int64_t last_mux_dts;
- AVBitStreamFilterContext *bitstream_filters;
+
+ int nb_bitstream_filters;
+ uint8_t *bsf_extradata_updated;
+ AVBSFContext **bsf_ctx;
+
AVCodecContext *enc_ctx;
AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */
AVCodec *enc;
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 8169f20..0dfdbd6 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -1229,8 +1229,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
OutputStream *ost;
AVStream *st = avformat_new_stream(oc, NULL);
int idx = oc->nb_streams - 1, ret = 0;
- char *bsf = NULL, *next, *codec_tag = NULL;
- AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
+ const char *bsfs = NULL;
+ char *next, *codec_tag = NULL;
double qscale = -1;
int i;
@@ -1319,29 +1319,62 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
ost->copy_prior_start = -1;
MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
- MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
- while (bsf) {
- char *arg = NULL;
- if (next = strchr(bsf, ','))
- *next++ = 0;
- if (arg = strchr(bsf, '='))
- *arg++ = 0;
- if (!(bsfc = av_bitstream_filter_init(bsf))) {
- av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
+ MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
+ while (bsfs && *bsfs) {
+ const AVBitStreamFilter *filter;
+ char *bsf, *bsf_options_str, *bsf_name;
+
+ bsf = av_get_token(&bsfs, ",");
+ if (!bsf)
+ exit_program(1);
+ bsf_name = av_strtok(bsf, "=", &bsf_options_str);
+ if (!bsf_name)
+ exit_program(1);
+
+ filter = av_bsf_get_by_name(bsf_name);
+ if (!filter) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
exit_program(1);
}
- if (bsfc_prev)
- bsfc_prev->next = bsfc;
- else
- ost->bitstream_filters = bsfc;
- if (arg)
- if (!(bsfc->args = av_strdup(arg))) {
- av_log(NULL, AV_LOG_FATAL, "Bitstream filter memory allocation failed\n");
+
+ ost->bsf_ctx = av_realloc_array(ost->bsf_ctx,
+ ost->nb_bitstream_filters + 1,
+ sizeof(*ost->bsf_ctx));
+ if (!ost->bsf_ctx)
+ exit_program(1);
+
+ ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error allocating a bistream filter context\n");
+ exit_program(1);
+ }
+
+ if (bsf_options_str && filter->priv_class) {
+ const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, NULL);
+ const char * shorthand[2] = {NULL};
+
+ if (opt)
+ shorthand[0] = opt->name;
+
+ ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, bsf_options_str, shorthand, "=", ":");
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
exit_program(1);
}
+ }
+ av_freep(&bsf);
- bsfc_prev = bsfc;
- bsf = next;
+ ost->nb_bitstream_filters++;
+
+ if (*bsfs)
+ bsfs++;
+ }
+ if (ost->nb_bitstream_filters) {
+ ost->bsf_extradata_updated = av_mallocz_array(ost->nb_bitstream_filters, sizeof(*ost->bsf_extradata_updated));
+ if (!ost->bsf_extradata_updated) {
+ av_log(NULL, AV_LOG_FATAL, "Bitstream filter memory allocation failed\n");
+ exit_program(1);
+ }
}
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
diff --git a/tests/ref/fate/ffmpeg-bsf-remove-k b/tests/ref/fate/ffmpeg-bsf-remove-k
index bc2295a..9c1f54e 100644
--- a/tests/ref/fate/ffmpeg-bsf-remove-k
+++ b/tests/ref/fate/ffmpeg-bsf-remove-k
@@ -1,32 +1,33 @@
-d6c688432b88ca62ea8abb885272af52 *tests/data/fate/ffmpeg-bsf-remove-k.avi
-129982 tests/data/fate/ffmpeg-bsf-remove-k.avi
+6196f1d6b59d16c045de627221d8685f *tests/data/fate/ffmpeg-bsf-remove-k.avi
+130072 tests/data/fate/ffmpeg-bsf-remove-k.avi
+#extradata 0: 30, 0x4a4d065a
#tb 0: 1/25
#media_type 0: video
#codec_id 0: mpeg4
#dimensions 0: 716x236
#sar 0: 1/1
-0, 0, -9223372036854775808, 1, 20164, 0x66bf5e52
-0, 1, -9223372036854775808, 1, 17878, 0xc081a405, F=0x0
-0, 2, -9223372036854775808, 1, 22723, 0x60935d28, F=0x0
-0, 3, -9223372036854775808, 1, 18655, 0xe5c33ada, F=0x0
-0, 4, -9223372036854775808, 1, 12928, 0x84d6a9d7, F=0x0
-0, 5, -9223372036854775808, 1, 4788, 0xbf9e1939, F=0x0
-0, 6, -9223372036854775808, 1, 3160, 0x867423c7, F=0x0
-0, 7, -9223372036854775808, 1, 2049, 0x523ffd85, F=0x0
-0, 8, -9223372036854775808, 1, 1440, 0x363ff725, F=0x0
-0, 9, -9223372036854775808, 1, 1300, 0x0d3c9c74, F=0x0
-0, 10, -9223372036854775808, 1, 1081, 0xbfb0365c, F=0x0
-0, 11, -9223372036854775808, 1, 1011, 0x9d310f90, F=0x0
-0, 12, -9223372036854775808, 1, 2513, 0xbcd803b5
-0, 13, -9223372036854775808, 1, 881, 0x7492d262, F=0x0
-0, 14, -9223372036854775808, 1, 896, 0x1ff1d335, F=0x0
-0, 15, -9223372036854775808, 1, 973, 0x72c1fc04, F=0x0
-0, 16, -9223372036854775808, 1, 1075, 0xa5881d73, F=0x0
-0, 17, -9223372036854775808, 1, 933, 0xf0aae974, F=0x0
-0, 18, -9223372036854775808, 1, 1079, 0xbdce1b40, F=0x0
-0, 19, -9223372036854775808, 1, 964, 0x323fe4ab, F=0x0
-0, 20, -9223372036854775808, 1, 1015, 0x78a4fe96, F=0x0
-0, 21, -9223372036854775808, 1, 990, 0x9cd4ff25, F=0x0
-0, 22, -9223372036854775808, 1, 1093, 0x98712e2e, F=0x0
-0, 23, -9223372036854775808, 1, 1200, 0x37957156, F=0x0
-0, 24, -9223372036854775808, 1, 2851, 0xb05be8a1
+0, 0, 0, 1, 20194, 0x174f64ac
+0, 1, 1, 1, 17878, 0xc081a405, F=0x0
+0, 2, 2, 1, 22723, 0x60935d28, F=0x0
+0, 3, 3, 1, 18655, 0xe5c33ada, F=0x0
+0, 4, 4, 1, 12928, 0x84d6a9d7, F=0x0
+0, 5, 5, 1, 4788, 0xbf9e1939, F=0x0
+0, 6, 6, 1, 3160, 0x867423c7, F=0x0
+0, 7, 7, 1, 2049, 0x523ffd85, F=0x0
+0, 8, 8, 1, 1440, 0x363ff725, F=0x0
+0, 9, 9, 1, 1300, 0x0d3c9c74, F=0x0
+0, 10, 10, 1, 1081, 0xbfb0365c, F=0x0
+0, 11, 11, 1, 1011, 0x9d310f90, F=0x0
+0, 12, 12, 1, 2543, 0x64500a0f
+0, 13, 13, 1, 881, 0x7492d262, F=0x0
+0, 14, 14, 1, 896, 0x1ff1d335, F=0x0
+0, 15, 15, 1, 973, 0x72c1fc04, F=0x0
+0, 16, 16, 1, 1075, 0xa5881d73, F=0x0
+0, 17, 17, 1, 933, 0xf0aae974, F=0x0
+0, 18, 18, 1, 1079, 0xbdce1b40, F=0x0
+0, 19, 19, 1, 964, 0x323fe4ab, F=0x0
+0, 20, 20, 1, 1015, 0x78a4fe96, F=0x0
+0, 21, 21, 1, 990, 0x9cd4ff25, F=0x0
+0, 22, 22, 1, 1093, 0x98712e2e, F=0x0
+0, 23, 23, 1, 1200, 0x37957156, F=0x0
+0, 24, 24, 1, 2881, 0xbb1feefb
diff --git a/tests/ref/fate/ffmpeg-bsf-remove-r b/tests/ref/fate/ffmpeg-bsf-remove-r
index fc33032..c533aaa 100644
--- a/tests/ref/fate/ffmpeg-bsf-remove-r
+++ b/tests/ref/fate/ffmpeg-bsf-remove-r
@@ -1,33 +1,32 @@
-6196f1d6b59d16c045de627221d8685f *tests/data/fate/ffmpeg-bsf-remove-r.avi
-130072 tests/data/fate/ffmpeg-bsf-remove-r.avi
-#extradata 0: 30, 0x4a4d065a
+d6c688432b88ca62ea8abb885272af52 *tests/data/fate/ffmpeg-bsf-remove-r.avi
+129982 tests/data/fate/ffmpeg-bsf-remove-r.avi
#tb 0: 1/25
#media_type 0: video
#codec_id 0: mpeg4
#dimensions 0: 716x236
#sar 0: 1/1
-0, 0, 0, 1, 20194, 0x174f64ac
-0, 1, 1, 1, 17878, 0xc081a405, F=0x0
-0, 2, 2, 1, 22723, 0x60935d28, F=0x0
-0, 3, 3, 1, 18655, 0xe5c33ada, F=0x0
-0, 4, 4, 1, 12928, 0x84d6a9d7, F=0x0
-0, 5, 5, 1, 4788, 0xbf9e1939, F=0x0
-0, 6, 6, 1, 3160, 0x867423c7, F=0x0
-0, 7, 7, 1, 2049, 0x523ffd85, F=0x0
-0, 8, 8, 1, 1440, 0x363ff725, F=0x0
-0, 9, 9, 1, 1300, 0x0d3c9c74, F=0x0
-0, 10, 10, 1, 1081, 0xbfb0365c, F=0x0
-0, 11, 11, 1, 1011, 0x9d310f90, F=0x0
-0, 12, 12, 1, 2543, 0x64500a0f
-0, 13, 13, 1, 881, 0x7492d262, F=0x0
-0, 14, 14, 1, 896, 0x1ff1d335, F=0x0
-0, 15, 15, 1, 973, 0x72c1fc04, F=0x0
-0, 16, 16, 1, 1075, 0xa5881d73, F=0x0
-0, 17, 17, 1, 933, 0xf0aae974, F=0x0
-0, 18, 18, 1, 1079, 0xbdce1b40, F=0x0
-0, 19, 19, 1, 964, 0x323fe4ab, F=0x0
-0, 20, 20, 1, 1015, 0x78a4fe96, F=0x0
-0, 21, 21, 1, 990, 0x9cd4ff25, F=0x0
-0, 22, 22, 1, 1093, 0x98712e2e, F=0x0
-0, 23, 23, 1, 1200, 0x37957156, F=0x0
-0, 24, 24, 1, 2881, 0xbb1feefb
+0, 0, -9223372036854775808, 1, 20164, 0x66bf5e52
+0, 1, -9223372036854775808, 1, 17878, 0xc081a405, F=0x0
+0, 2, -9223372036854775808, 1, 22723, 0x60935d28, F=0x0
+0, 3, -9223372036854775808, 1, 18655, 0xe5c33ada, F=0x0
+0, 4, -9223372036854775808, 1, 12928, 0x84d6a9d7, F=0x0
+0, 5, -9223372036854775808, 1, 4788, 0xbf9e1939, F=0x0
+0, 6, -9223372036854775808, 1, 3160, 0x867423c7, F=0x0
+0, 7, -9223372036854775808, 1, 2049, 0x523ffd85, F=0x0
+0, 8, -9223372036854775808, 1, 1440, 0x363ff725, F=0x0
+0, 9, -9223372036854775808, 1, 1300, 0x0d3c9c74, F=0x0
+0, 10, -9223372036854775808, 1, 1081, 0xbfb0365c, F=0x0
+0, 11, -9223372036854775808, 1, 1011, 0x9d310f90, F=0x0
+0, 12, -9223372036854775808, 1, 2513, 0xbcd803b5
+0, 13, -9223372036854775808, 1, 881, 0x7492d262, F=0x0
+0, 14, -9223372036854775808, 1, 896, 0x1ff1d335, F=0x0
+0, 15, -9223372036854775808, 1, 973, 0x72c1fc04, F=0x0
+0, 16, -9223372036854775808, 1, 1075, 0xa5881d73, F=0x0
+0, 17, -9223372036854775808, 1, 933, 0xf0aae974, F=0x0
+0, 18, -9223372036854775808, 1, 1079, 0xbdce1b40, F=0x0
+0, 19, -9223372036854775808, 1, 964, 0x323fe4ab, F=0x0
+0, 20, -9223372036854775808, 1, 1015, 0x78a4fe96, F=0x0
+0, 21, -9223372036854775808, 1, 990, 0x9cd4ff25, F=0x0
+0, 22, -9223372036854775808, 1, 1093, 0x98712e2e, F=0x0
+0, 23, -9223372036854775808, 1, 1200, 0x37957156, F=0x0
+0, 24, -9223372036854775808, 1, 2851, 0xb05be8a1
diff --git a/tests/ref/fate/h264_mp4toannexb_ticket2991 b/tests/ref/fate/h264_mp4toannexb_ticket2991
index 27630d5..4c73d7d 100644
--- a/tests/ref/fate/h264_mp4toannexb_ticket2991
+++ b/tests/ref/fate/h264_mp4toannexb_ticket2991
@@ -1,5 +1,5 @@
-f52716e8110147553567ee617bfe6af8 *tests/data/fate/h264_mp4toannexb_ticket2991.h264
-1999668 tests/data/fate/h264_mp4toannexb_ticket2991.h264
+05d66e60ab22ee004720e0051af0fe74 *tests/data/fate/h264_mp4toannexb_ticket2991.h264
+1985815 tests/data/fate/h264_mp4toannexb_ticket2991.h264
#extradata 0: 79, 0x1ec61105
#tb 0: 1/1200000
#media_type 0: video
@@ -124,4 +124,4 @@ f52716e8110147553567ee617bfe6af8 *tests/data/fate/h264_mp4toannexb_ticket2991.h2
0, 4612606, 4612606, 40040, 11198, 0x6a9de1fb, F=0x0
0, 4652646, 4652646, 40040, 15572, 0xd6cb6c4b, F=0x0
0, 4692686, 4692686, 40040, 12072, 0x8928b77f, F=0x0
-0, 4732727, 4732727, 40040, 33025, 0x79359fc1, F=0x0
+0, 4732727, 4732727, 40040, 19172, 0x549b6b87, F=0x0
diff --git a/tests/ref/fate/mpeg4-bsf-unpack-bframes b/tests/ref/fate/mpeg4-bsf-unpack-bframes
index 21e58f6..162d436 100644
--- a/tests/ref/fate/mpeg4-bsf-unpack-bframes
+++ b/tests/ref/fate/mpeg4-bsf-unpack-bframes
@@ -1 +1 @@
-5db6b7b766c7a9fd5f42292d7467a36d
+c9535e459c2ee4ead6d84b93bc7e9f46
1
0
24 Sep '16
ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos(a)ag.or.at> | Sat Sep 24 18:56:40 2016 +0200| [159aa1275e5d9c94edc313a51d65220e887d790b] | committer: Carl Eugen Hoyos
lavd/sdl2: Fix 32bit rgb formats on little-endian hardware.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=159aa1275e5d9c94e…
---
libavdevice/sdl2.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
index d083d29..e8252f0 100644
--- a/libavdevice/sdl2.c
+++ b/libavdevice/sdl2.c
@@ -67,8 +67,6 @@ static const struct sdl_texture_format_entry {
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_RGBA5551 },
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ABGR1555 },
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_BGRA5551 },
- * { AV_PIX_FMT_RGB24,SDL_PIXELFORMAT_RGB888 },
- * { AV_PIX_FMT_BGR24,SDL_PIXELFORMAT_BGR888 },
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB2101010 },
*/
{ AV_PIX_FMT_RGB8, SDL_PIXELFORMAT_RGB332 },
@@ -79,12 +77,19 @@ static const struct sdl_texture_format_entry {
{ AV_PIX_FMT_BGR565, SDL_PIXELFORMAT_BGR565 },
{ AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB24 },
{ AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR24 },
- { AV_PIX_FMT_RGB0, SDL_PIXELFORMAT_RGBX8888 }, // needs to be checked
- { AV_PIX_FMT_BGR0, SDL_PIXELFORMAT_BGRX8888 }, // "
- { AV_PIX_FMT_ARGB, SDL_PIXELFORMAT_ARGB8888 }, // "
- { AV_PIX_FMT_RGBA, SDL_PIXELFORMAT_RGBA8888 },
- { AV_PIX_FMT_ABGR, SDL_PIXELFORMAT_ABGR8888 },
- { AV_PIX_FMT_BGRA, SDL_PIXELFORMAT_BGRA8888 },
+ { AV_PIX_FMT_0RGB32, SDL_PIXELFORMAT_RGB888 },
+ { AV_PIX_FMT_0BGR32, SDL_PIXELFORMAT_BGR888 },
+#if HAVE_BIGENDIAN
+ { AV_PIX_FMT_RGB0, SDL_PIXELFORMAT_RGBX8888 },
+ { AV_PIX_FMT_BGR0, SDL_PIXELFORMAT_BGRX8888 },
+#else
+ { AV_PIX_FMT_0BGR, SDL_PIXELFORMAT_RGBX8888 },
+ { AV_PIX_FMT_0RGB, SDL_PIXELFORMAT_BGRX8888 },
+#endif
+ { AV_PIX_FMT_RGB32, SDL_PIXELFORMAT_ARGB8888 },
+ { AV_PIX_FMT_RGB32_1, SDL_PIXELFORMAT_RGBA8888 },
+ { AV_PIX_FMT_BGR32, SDL_PIXELFORMAT_ABGR8888 },
+ { AV_PIX_FMT_BGR32_1, SDL_PIXELFORMAT_BGRA8888 },
{ AV_PIX_FMT_YUV420P, SDL_PIXELFORMAT_IYUV },
{ AV_PIX_FMT_YUYV422, SDL_PIXELFORMAT_YUY2 },
{ AV_PIX_FMT_UYVY422, SDL_PIXELFORMAT_UYVY },
1
0
24 Sep '16
ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos(a)ag.or.at> | Sat Sep 24 18:35:15 2016 +0200| [1d92256d60df76ea9a892a4a1fc35badea4948c8] | committer: Carl Eugen Hoyos
lavd/sdl2: Move unsupported formats SDL_PIXELFORMAT_xxx888 updwards.
There is a paragraph for unsupported SDL formats.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1d92256d60df76ea9…
---
libavdevice/sdl2.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
index 3d1ea42..d083d29 100644
--- a/libavdevice/sdl2.c
+++ b/libavdevice/sdl2.c
@@ -67,6 +67,8 @@ static const struct sdl_texture_format_entry {
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_RGBA5551 },
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ABGR1555 },
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_BGRA5551 },
+ * { AV_PIX_FMT_RGB24,SDL_PIXELFORMAT_RGB888 },
+ * { AV_PIX_FMT_BGR24,SDL_PIXELFORMAT_BGR888 },
* { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB2101010 },
*/
{ AV_PIX_FMT_RGB8, SDL_PIXELFORMAT_RGB332 },
@@ -77,8 +79,6 @@ static const struct sdl_texture_format_entry {
{ AV_PIX_FMT_BGR565, SDL_PIXELFORMAT_BGR565 },
{ AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB24 },
{ AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR24 },
- { AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB888 },
- { AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR888 },
{ AV_PIX_FMT_RGB0, SDL_PIXELFORMAT_RGBX8888 }, // needs to be checked
{ AV_PIX_FMT_BGR0, SDL_PIXELFORMAT_BGRX8888 }, // "
{ AV_PIX_FMT_ARGB, SDL_PIXELFORMAT_ARGB8888 }, // "
1
0
24 Sep '16
ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos(a)ag.or.at> | Sat Sep 24 15:09:27 2016 +0200| [04fa20d53c57fb120f53e4ee9ae0fab6fd348bc8] | committer: Carl Eugen Hoyos
lavf/aacdec: Do not autodetect a single frame inside the file.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=04fa20d53c57fb120…
---
libavformat/aacdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index aa23756..fecb1e3 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -70,7 +70,7 @@ static int adts_aac_probe(AVProbeData *p)
return AVPROBE_SCORE_EXTENSION;
else if (max_frames >= 3)
return AVPROBE_SCORE_EXTENSION / 2;
- else if (max_frames >= 1)
+ else if (first_frames >= 1)
return 1;
else
return 0;
1
0
ffmpeg | branch: master | Josh de Kock <josh(a)itanimul.li> | Thu Sep 22 19:20:24 2016 +0100| [47ea6f5c9d1bb5a3a6b9429857dbd6ee32809b0e] | committer: Josh de Kock
lavd: drop SDL1 device and SDL1 support
Signed-off-by: Josh de Kock <josh(a)itanimul.li>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=47ea6f5c9d1bb5a3a…
---
Changelog | 1 +
configure | 33 +----
libavdevice/Makefile | 1 -
libavdevice/alldevices.c | 1 -
libavdevice/sdl.c | 377 -----------------------------------------------
5 files changed, 2 insertions(+), 411 deletions(-)
diff --git a/Changelog b/Changelog
index 590e082..4e4b4bf 100644
--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,7 @@ version <next>:
- Non-Local Means (nlmeans) denoising filter
- sdl2 output device
- sdl2 support for ffplay
+- sdl1 output device and sdl1 support removed
version 3.1:
diff --git a/configure b/configure
index eabd9ce..f593191 100755
--- a/configure
+++ b/configure
@@ -291,7 +291,6 @@ External library support:
if gnutls is not used [no]
--disable-schannel disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used [autodetect]
- --disable-sdl disable sdl [autodetect]
--disable-sdl2 disable sdl2 [autodetect]
--disable-securetransport disable Secure Transport, needed for TLS support
on OSX if openssl and gnutls are not used [autodetect]
@@ -1548,7 +1547,6 @@ EXTERNAL_LIBRARY_LIST="
opengl
openssl
schannel
- sdl
sdl2
securetransport
videotoolbox
@@ -2023,7 +2021,6 @@ HAVE_LIST="
MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS
perl
pod2man
- sdl
sdl2
section_data_rel_ro
texi2html
@@ -2950,7 +2947,6 @@ pulse_indev_deps="libpulse"
pulse_outdev_deps="libpulse"
qtkit_indev_extralibs="-framework QTKit -framework Foundation -framework QuartzCore"
qtkit_indev_select="qtkit"
-sdl_outdev_deps="sdl"
sdl2_outdev_deps="sdl2"
sndio_indev_deps="sndio_h"
sndio_outdev_deps="sndio_h"
@@ -5850,7 +5846,7 @@ if enabled gcrypt; then
fi
fi
-if ! disabled sdl2 && ! enabled sdl; then
+if ! disabled sdl2; then
SDL2_CONFIG="${cross_prefix}sdl2-config"
if check_pkg_config sdl2 SDL_events.h SDL_PollEvent; then
check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags &&
@@ -5871,32 +5867,6 @@ if ! disabled sdl2 && ! enabled sdl; then
fi
enabled sdl2 && add_cflags $sdl2_cflags && add_extralibs $sdl2_libs
-if ! disabled sdl && ! enabled sdl2; then
- SDL_CONFIG="${cross_prefix}sdl-config"
- if check_pkg_config sdl SDL_events.h SDL_PollEvent; then
- check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
- check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x010300" $sdl_cflags &&
- enable sdl
- else
- if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
- sdl_cflags=$("${SDL_CONFIG}" --cflags)
- sdl_libs=$("${SDL_CONFIG}" --libs)
- check_func_headers SDL_version.h SDL_Linked_Version $sdl_cflags $sdl_libs &&
- check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
- check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x010300" $sdl_cflags &&
- enable sdl
- elif enabled sdl ; then
- die "ERROR: SDL not found"
- else
- disable sdl
- fi
- fi
- if test $target_os = "mingw32"; then
- sdl_libs="$sdl_libs -mconsole"
- fi
-fi
-enabled sdl && add_cflags $sdl_cflags && add_extralibs $sdl_libs
-
disabled securetransport || { check_func SecIdentityCreate "-Wl,-framework,CoreFoundation -Wl,-framework,Security" &&
check_lib2 "Security/SecureTransport.h Security/Security.h" "SSLCreateContext SecItemImport" "-Wl,-framework,CoreFoundation -Wl,-framework,Security" &&
enable securetransport; }
@@ -6500,7 +6470,6 @@ echo "new filter support ${avfilter-no}"
echo "network support ${network-no}"
echo "threading support ${thread_type-no}"
echo "safe bitstream reader ${safe_bitstream_reader-no}"
-echo "SDL support ${sdl-no}"
echo "SDL2 support ${sdl2-no}"
echo "opencl enabled ${opencl-no}"
echo "JNI support ${jni-no}"
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 1c4b4d3..256e140 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -40,7 +40,6 @@ OBJS-$(CONFIG_PULSE_INDEV) += pulse_audio_dec.o \
OBJS-$(CONFIG_PULSE_OUTDEV) += pulse_audio_enc.o \
pulse_audio_common.o
OBJS-$(CONFIG_QTKIT_INDEV) += qtkit.o
-OBJS-$(CONFIG_SDL_OUTDEV) += sdl.o
OBJS-$(CONFIG_SDL2_OUTDEV) += sdl2.o
OBJS-$(CONFIG_SNDIO_INDEV) += sndio_dec.o sndio.o
OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_enc.o sndio.o
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index c0a9d9a..a761be4 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -63,7 +63,6 @@ void avdevice_register_all(void)
REGISTER_INOUTDEV(OSS, oss);
REGISTER_INOUTDEV(PULSE, pulse);
REGISTER_INDEV (QTKIT, qtkit);
- REGISTER_OUTDEV (SDL, sdl);
REGISTER_OUTDEV (SDL2, sdl2);
REGISTER_INOUTDEV(SNDIO, sndio);
REGISTER_INOUTDEV(V4L2, v4l2);
diff --git a/libavdevice/sdl.c b/libavdevice/sdl.c
deleted file mode 100644
index 4322750..0000000
--- a/libavdevice/sdl.c
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Copyright (c) 2011 Stefano Sabatini
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * libSDL output device
- */
-
-#include <SDL.h>
-#include <SDL_thread.h>
-
-#include "libavutil/avstring.h"
-#include "libavutil/imgutils.h"
-#include "libavutil/opt.h"
-#include "libavutil/parseutils.h"
-#include "libavutil/pixdesc.h"
-#include "libavutil/time.h"
-#include "avdevice.h"
-
-typedef struct {
- AVClass *class;
- SDL_Surface *surface;
- SDL_Overlay *overlay;
- char *window_title;
- char *icon_title;
- int window_width, window_height; /**< size of the window */
- int window_fullscreen;
-
- SDL_Rect overlay_rect;
- int overlay_fmt;
-
- int sdl_was_already_inited;
- SDL_Thread *event_thread;
- SDL_mutex *mutex;
- SDL_cond *init_cond;
- int init_ret; /* return code used to signal initialization errors */
- int inited;
- int quit;
-} SDLContext;
-
-static const struct sdl_overlay_pix_fmt_entry {
- enum AVPixelFormat pix_fmt; int overlay_fmt;
-} sdl_overlay_pix_fmt_map[] = {
- { AV_PIX_FMT_YUV420P, SDL_IYUV_OVERLAY },
- { AV_PIX_FMT_YUYV422, SDL_YUY2_OVERLAY },
- { AV_PIX_FMT_UYVY422, SDL_UYVY_OVERLAY },
- { AV_PIX_FMT_NONE, 0 },
-};
-
-static int sdl_write_trailer(AVFormatContext *s)
-{
- SDLContext *sdl = s->priv_data;
-
- sdl->quit = 1;
-
- if (sdl->overlay)
- SDL_FreeYUVOverlay(sdl->overlay);
- sdl->overlay = NULL;
- if (sdl->event_thread)
- SDL_WaitThread(sdl->event_thread, NULL);
- sdl->event_thread = NULL;
- if (sdl->mutex)
- SDL_DestroyMutex(sdl->mutex);
- sdl->mutex = NULL;
- if (sdl->init_cond)
- SDL_DestroyCond(sdl->init_cond);
- sdl->init_cond = NULL;
-
- if (!sdl->sdl_was_already_inited)
- SDL_Quit();
-
- return 0;
-}
-
-static void compute_overlay_rect(AVFormatContext *s)
-{
- AVRational sar, dar; /* sample and display aspect ratios */
- SDLContext *sdl = s->priv_data;
- AVStream *st = s->streams[0];
- AVCodecParameters *par = st->codecpar;
- SDL_Rect *overlay_rect = &sdl->overlay_rect;
-
- /* compute overlay width and height from the codec context information */
- sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 };
- dar = av_mul_q(sar, (AVRational){ par->width, par->height });
-
- /* we suppose the screen has a 1/1 sample aspect ratio */
- if (sdl->window_width && sdl->window_height) {
- /* fit in the window */
- if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) {
- /* fit in width */
- overlay_rect->w = sdl->window_width;
- overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num);
- } else {
- /* fit in height */
- overlay_rect->h = sdl->window_height;
- overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den);
- }
- } else {
- if (sar.num > sar.den) {
- overlay_rect->w = par->width;
- overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num);
- } else {
- overlay_rect->h = par->height;
- overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den);
- }
- sdl->window_width = overlay_rect->w;
- sdl->window_height = overlay_rect->h;
- }
-
- overlay_rect->x = (sdl->window_width - overlay_rect->w) / 2;
- overlay_rect->y = (sdl->window_height - overlay_rect->h) / 2;
-}
-
-#define SDL_BASE_FLAGS (SDL_SWSURFACE|SDL_RESIZABLE)
-
-static int event_thread(void *arg)
-{
- AVFormatContext *s = arg;
- SDLContext *sdl = s->priv_data;
- int flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_FULLSCREEN : 0);
- AVStream *st = s->streams[0];
- AVCodecParameters *par = st->codecpar;
-
- /* initialization */
- if (SDL_Init(SDL_INIT_VIDEO) != 0) {
- av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
- sdl->init_ret = AVERROR(EINVAL);
- goto init_end;
- }
-
- SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);
- sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,
- 24, flags);
- if (!sdl->surface) {
- av_log(sdl, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());
- sdl->init_ret = AVERROR(EINVAL);
- goto init_end;
- }
-
- sdl->overlay = SDL_CreateYUVOverlay(par->width, par->height,
- sdl->overlay_fmt, sdl->surface);
- if (!sdl->overlay || sdl->overlay->pitches[0] < par->width) {
- av_log(s, AV_LOG_ERROR,
- "SDL does not support an overlay with size of %dx%d pixels\n",
- par->width, par->height);
- sdl->init_ret = AVERROR(EINVAL);
- goto init_end;
- }
-
- sdl->init_ret = 0;
- av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s -> w:%d h:%d\n",
- par->width, par->height, av_get_pix_fmt_name(par->format),
- sdl->overlay_rect.w, sdl->overlay_rect.h);
-
-init_end:
- SDL_LockMutex(sdl->mutex);
- sdl->inited = 1;
- SDL_UnlockMutex(sdl->mutex);
- SDL_CondSignal(sdl->init_cond);
-
- if (sdl->init_ret < 0)
- return sdl->init_ret;
-
- /* event loop */
- while (!sdl->quit) {
- int ret;
- SDL_Event event;
- SDL_PumpEvents();
- ret = SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS);
- if (ret < 0) {
- av_log(s, AV_LOG_ERROR, "Error when getting SDL event: %s\n", SDL_GetError());
- continue;
- }
- if (ret == 0) {
- SDL_Delay(10);
- continue;
- }
-
- switch (event.type) {
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- case SDLK_ESCAPE:
- case SDLK_q:
- sdl->quit = 1;
- break;
- }
- break;
- case SDL_QUIT:
- sdl->quit = 1;
- break;
-
- case SDL_VIDEORESIZE:
- sdl->window_width = event.resize.w;
- sdl->window_height = event.resize.h;
-
- SDL_LockMutex(sdl->mutex);
- sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height, 24, SDL_BASE_FLAGS);
- if (!sdl->surface) {
- av_log(s, AV_LOG_ERROR, "Failed to set SDL video mode: %s\n", SDL_GetError());
- sdl->quit = 1;
- } else {
- compute_overlay_rect(s);
- }
- SDL_UnlockMutex(sdl->mutex);
- break;
-
- default:
- break;
- }
- }
-
- return 0;
-}
-
-static int sdl_write_header(AVFormatContext *s)
-{
- SDLContext *sdl = s->priv_data;
- AVStream *st = s->streams[0];
- AVCodecParameters *par = st->codecpar;
- int i, ret;
-
- if (!sdl->window_title)
- sdl->window_title = av_strdup(s->filename);
- if (!sdl->icon_title)
- sdl->icon_title = av_strdup(sdl->window_title);
-
- if (SDL_WasInit(SDL_INIT_VIDEO)) {
- av_log(s, AV_LOG_ERROR,
- "SDL video subsystem was already inited, aborting\n");
- sdl->sdl_was_already_inited = 1;
- ret = AVERROR(EINVAL);
- goto fail;
- }
-
- if ( s->nb_streams > 1
- || par->codec_type != AVMEDIA_TYPE_VIDEO
- || par->codec_id != AV_CODEC_ID_RAWVIDEO) {
- av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n");
- ret = AVERROR(EINVAL);
- goto fail;
- }
-
- for (i = 0; sdl_overlay_pix_fmt_map[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
- if (sdl_overlay_pix_fmt_map[i].pix_fmt == par->format) {
- sdl->overlay_fmt = sdl_overlay_pix_fmt_map[i].overlay_fmt;
- break;
- }
- }
-
- if (!sdl->overlay_fmt) {
- av_log(s, AV_LOG_ERROR,
- "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, or uyvy422\n",
- av_get_pix_fmt_name(par->format));
- ret = AVERROR(EINVAL);
- goto fail;
- }
-
- /* compute overlay width and height from the codec context information */
- compute_overlay_rect(s);
-
- sdl->init_cond = SDL_CreateCond();
- if (!sdl->init_cond) {
- av_log(s, AV_LOG_ERROR, "Could not create SDL condition variable: %s\n", SDL_GetError());
- ret = AVERROR_EXTERNAL;
- goto fail;
- }
- sdl->mutex = SDL_CreateMutex();
- if (!sdl->mutex) {
- av_log(s, AV_LOG_ERROR, "Could not create SDL mutex: %s\n", SDL_GetError());
- ret = AVERROR_EXTERNAL;
- goto fail;
- }
- sdl->event_thread = SDL_CreateThread(event_thread, s);
- if (!sdl->event_thread) {
- av_log(s, AV_LOG_ERROR, "Could not create SDL event thread: %s\n", SDL_GetError());
- ret = AVERROR_EXTERNAL;
- goto fail;
- }
-
- /* wait until the video system has been inited */
- SDL_LockMutex(sdl->mutex);
- while (!sdl->inited) {
- SDL_CondWait(sdl->init_cond, sdl->mutex);
- }
- SDL_UnlockMutex(sdl->mutex);
- if (sdl->init_ret < 0) {
- ret = sdl->init_ret;
- goto fail;
- }
- return 0;
-
-fail:
- sdl_write_trailer(s);
- return ret;
-}
-
-static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt)
-{
- SDLContext *sdl = s->priv_data;
- AVCodecParameters *par = s->streams[0]->codecpar;
- uint8_t *data[4];
- int linesize[4];
- int i;
-
- if (sdl->quit) {
- sdl_write_trailer(s);
- return AVERROR(EIO);
- }
- av_image_fill_arrays(data, linesize, pkt->data, par->format, par->width, par->height, 1);
-
- SDL_LockMutex(sdl->mutex);
- SDL_FillRect(sdl->surface, &sdl->surface->clip_rect,
- SDL_MapRGB(sdl->surface->format, 0, 0, 0));
- SDL_LockYUVOverlay(sdl->overlay);
- for (i = 0; i < 3; i++) {
- sdl->overlay->pixels [i] = data [i];
- sdl->overlay->pitches[i] = linesize[i];
- }
- SDL_DisplayYUVOverlay(sdl->overlay, &sdl->overlay_rect);
- SDL_UnlockYUVOverlay(sdl->overlay);
-
- SDL_UpdateRect(sdl->surface,
- sdl->overlay_rect.x, sdl->overlay_rect.y,
- sdl->overlay_rect.w, sdl->overlay_rect.h);
- SDL_UnlockMutex(sdl->mutex);
-
- return 0;
-}
-
-#define OFFSET(x) offsetof(SDLContext,x)
-
-static const AVOption options[] = {
- { "window_title", "set SDL window title", OFFSET(window_title), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
- { "icon_title", "set SDL iconified window title", OFFSET(icon_title) , AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
- { "window_size", "set SDL window forced size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
- { "window_fullscreen", "set SDL window fullscreen", OFFSET(window_fullscreen), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
- { NULL },
-};
-
-static const AVClass sdl_class = {
- .class_name = "sdl outdev",
- .item_name = av_default_item_name,
- .option = options,
- .version = LIBAVUTIL_VERSION_INT,
- .category = AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
-};
-
-AVOutputFormat ff_sdl_muxer = {
- .name = "sdl",
- .long_name = NULL_IF_CONFIG_SMALL("SDL output device"),
- .priv_data_size = sizeof(SDLContext),
- .audio_codec = AV_CODEC_ID_NONE,
- .video_codec = AV_CODEC_ID_RAWVIDEO,
- .write_header = sdl_write_header,
- .write_packet = sdl_write_packet,
- .write_trailer = sdl_write_trailer,
- .flags = AVFMT_NOFILE | AVFMT_VARIABLE_FPS | AVFMT_NOTIMESTAMPS,
- .priv_class = &sdl_class,
-};
1
0
ffmpeg | branch: master | Marton Balint <cus(a)passwd.hu> | Tue Feb 23 20:43:41 2016 +0000| [9c5fab5ed421da4e55cafcbff0482e1ad926c27b] | committer: Josh de Kock
ffplay: add SDL2 support
This commit also drops SDL1 support for ffplay.
Tested-by: James Almer <jamrial(a)gmail.com> (Windows, mingw-w64)
Signed-off-by: Josh de Kock <josh(a)itanimul.li>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9c5fab5ed421da4e5…
---
Changelog | 1 +
configure | 6 +-
ffplay.c | 594 ++++++++++++++++++++++++++------------------------------------
3 files changed, 250 insertions(+), 351 deletions(-)
diff --git a/Changelog b/Changelog
index acf843e..590e082 100644
--- a/Changelog
+++ b/Changelog
@@ -33,6 +33,7 @@ version <next>:
- Meridian Lossless Packing (MLP) encoder
- Non-Local Means (nlmeans) denoising filter
- sdl2 output device
+- sdl2 support for ffplay
version 3.1:
diff --git a/configure b/configure
index 5434fa1..eabd9ce 100755
--- a/configure
+++ b/configure
@@ -3141,8 +3141,8 @@ ffmpeg_deps="avcodec avfilter avformat swresample"
ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter
null_filter
setpts_filter trim_filter"
-ffplay_deps="avcodec avformat swscale swresample sdl"
-ffplay_libs='$sdl_libs'
+ffplay_deps="avcodec avformat swscale swresample sdl2"
+ffplay_libs='$sdl2_libs'
ffplay_select="rdft crop_filter transpose_filter hflip_filter vflip_filter rotate_filter"
ffprobe_deps="avcodec avformat"
ffserver_deps="avformat fork sarestart"
@@ -6661,7 +6661,7 @@ HOSTLD_O=$HOSTLD_O
TARGET_EXEC=$target_exec $target_exec_args
TARGET_PATH=$target_path
TARGET_SAMPLES=${target_samples:-\$(SAMPLES)}
-CFLAGS-ffplay=$sdl_cflags
+CFLAGS-ffplay=${sdl2_cflags}
ZLIB=$($ldflags_filter -lz)
LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
EXTRALIBS=$extralibs
diff --git a/ffplay.c b/ffplay.c
index adbe9cb..e64909a 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -105,6 +105,8 @@ const int program_birth_year = 2003;
#define CURSOR_HIDE_DELAY 1000000
+#define USE_ONEPASS_SUBTITLE_RENDER 1
+
static unsigned sws_flags = SWS_BICUBIC;
typedef struct MyAVPacketList {
@@ -152,17 +154,17 @@ typedef struct Clock {
typedef struct Frame {
AVFrame *frame;
AVSubtitle sub;
- AVSubtitleRect **subrects; /* rescaled subtitle rectangles in yuva */
int serial;
double pts; /* presentation timestamp for the frame */
double duration; /* estimated duration of the frame */
int64_t pos; /* byte position of the frame in the input file */
- SDL_Overlay *bmp;
+ SDL_Texture *bmp;
int allocated;
- int reallocate;
int width;
int height;
+ int format;
AVRational sar;
+ int uploaded;
} Frame;
typedef struct FrameQueue {
@@ -272,6 +274,8 @@ typedef struct VideoState {
FFTSample *rdft_data;
int xpos;
double last_vis_time;
+ SDL_Texture *vis_texture;
+ SDL_Texture *sub_texture;
int subtitle_stream;
AVStream *subtitle_st;
@@ -284,11 +288,8 @@ typedef struct VideoState {
AVStream *video_st;
PacketQueue videoq;
double max_frame_duration; // maximum duration of a frame - above this, we consider the jump a timestamp discontinuity
-#if !CONFIG_AVFILTER
struct SwsContext *img_convert_ctx;
-#endif
struct SwsContext *sub_convert_ctx;
- SDL_Rect last_display_rect;
int eof;
char *filename;
@@ -313,8 +314,6 @@ typedef struct VideoState {
static AVInputFormat *file_iformat;
static const char *input_filename;
static const char *window_title;
-static int fs_screen_width;
-static int fs_screen_height;
static int default_width = 640;
static int default_height = 480;
static int screen_width = 0;
@@ -362,7 +361,8 @@ static AVPacket flush_pkt;
#define FF_ALLOC_EVENT (SDL_USEREVENT)
#define FF_QUIT_EVENT (SDL_USEREVENT + 2)
-static SDL_Surface *screen;
+static SDL_Window *window;
+static SDL_Renderer *renderer;
#if CONFIG_AVFILTER
static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
@@ -650,12 +650,6 @@ static void decoder_destroy(Decoder *d) {
static void frame_queue_unref_item(Frame *vp)
{
- int i;
- for (i = 0; i < vp->sub.num_rects; i++) {
- av_freep(&vp->subrects[i]->data[0]);
- av_freep(&vp->subrects[i]);
- }
- av_freep(&vp->subrects);
av_frame_unref(vp->frame);
avsubtitle_free(&vp->sub);
}
@@ -798,113 +792,47 @@ static void decoder_abort(Decoder *d, FrameQueue *fq)
packet_queue_flush(d->queue);
}
-static inline void fill_rectangle(SDL_Surface *screen,
- int x, int y, int w, int h, int color, int update)
+static inline void fill_rectangle(int x, int y, int w, int h)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
- SDL_FillRect(screen, &rect, color);
- if (update && w > 0 && h > 0)
- SDL_UpdateRect(screen, x, y, w, h);
-}
-
-/* draw only the border of a rectangle */
-static void fill_border(int xleft, int ytop, int width, int height, int x, int y, int w, int h, int color, int update)
-{
- int w1, w2, h1, h2;
-
- /* fill the background */
- w1 = x;
- if (w1 < 0)
- w1 = 0;
- w2 = width - (x + w);
- if (w2 < 0)
- w2 = 0;
- h1 = y;
- if (h1 < 0)
- h1 = 0;
- h2 = height - (y + h);
- if (h2 < 0)
- h2 = 0;
- fill_rectangle(screen,
- xleft, ytop,
- w1, height,
- color, update);
- fill_rectangle(screen,
- xleft + width - w2, ytop,
- w2, height,
- color, update);
- fill_rectangle(screen,
- xleft + w1, ytop,
- width - w1 - w2, h1,
- color, update);
- fill_rectangle(screen,
- xleft + w1, ytop + height - h2,
- width - w1 - w2, h2,
- color, update);
-}
-
-#define ALPHA_BLEND(a, oldp, newp, s)\
-((((oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s))
-
-
-
-#define BPP 1
-
-static void blend_subrect(uint8_t **data, int *linesize, const AVSubtitleRect *rect, int imgw, int imgh)
-{
- int x, y, Y, U, V, A;
- uint8_t *lum, *cb, *cr;
- int dstx, dsty, dstw, dsth;
- const AVSubtitleRect *src = rect;
-
- dstw = av_clip(rect->w, 0, imgw);
- dsth = av_clip(rect->h, 0, imgh);
- dstx = av_clip(rect->x, 0, imgw - dstw);
- dsty = av_clip(rect->y, 0, imgh - dsth);
- lum = data[0] + dstx + dsty * linesize[0];
- cb = data[1] + dstx/2 + (dsty >> 1) * linesize[1];
- cr = data[2] + dstx/2 + (dsty >> 1) * linesize[2];
-
- for (y = 0; y<dsth; y++) {
- for (x = 0; x<dstw; x++) {
- Y = src->data[0][x + y*src->linesize[0]];
- A = src->data[3][x + y*src->linesize[3]];
- lum[0] = ALPHA_BLEND(A, lum[0], Y, 0);
- lum++;
- }
- lum += linesize[0] - dstw;
- }
-
- for (y = 0; y<dsth/2; y++) {
- for (x = 0; x<dstw/2; x++) {
- U = src->data[1][x + y*src->linesize[1]];
- V = src->data[2][x + y*src->linesize[2]];
- A = src->data[3][2*x + 2*y *src->linesize[3]]
- + src->data[3][2*x + 1 + 2*y *src->linesize[3]]
- + src->data[3][2*x + 1 + (2*y+1)*src->linesize[3]]
- + src->data[3][2*x + (2*y+1)*src->linesize[3]];
- cb[0] = ALPHA_BLEND(A>>2, cb[0], U, 0);
- cr[0] = ALPHA_BLEND(A>>2, cr[0], V, 0);
- cb++;
- cr++;
- }
- cb += linesize[1] - dstw/2;
- cr += linesize[2] - dstw/2;
- }
+ if (w && h)
+ SDL_RenderFillRect(renderer, &rect);
}
static void free_picture(Frame *vp)
{
if (vp->bmp) {
- SDL_FreeYUVOverlay(vp->bmp);
+ SDL_DestroyTexture(vp->bmp);
vp->bmp = NULL;
}
}
+static int realloc_texture(SDL_Texture **texture, Uint32 new_format, int new_width, int new_height, SDL_BlendMode blendmode, int init_texture)
+{
+ Uint32 format;
+ int access, w, h;
+ if (SDL_QueryTexture(*texture, &format, &access, &w, &h) < 0 || new_width != w || new_height != h || new_format != format) {
+ void *pixels;
+ int pitch;
+ SDL_DestroyTexture(*texture);
+ if (!(*texture = SDL_CreateTexture(renderer, new_format, SDL_TEXTUREACCESS_STREAMING, new_width, new_height)))
+ return -1;
+ if (SDL_SetTextureBlendMode(*texture, blendmode) < 0)
+ return -1;
+ if (init_texture) {
+ if (SDL_LockTexture(*texture, NULL, &pixels, &pitch) < 0)
+ return -1;
+ memset(pixels, 0, pitch * new_height);
+ SDL_UnlockTexture(*texture);
+ }
+ }
+ return 0;
+}
+
static void calculate_display_rect(SDL_Rect *rect,
int scr_xleft, int scr_ytop, int scr_width, int scr_height,
int pic_width, int pic_height, AVRational pic_sar)
@@ -936,12 +864,44 @@ static void calculate_display_rect(SDL_Rect *rect,
rect->h = FFMAX(height, 1);
}
+static int upload_texture(SDL_Texture *tex, AVFrame *frame, struct SwsContext **img_convert_ctx) {
+ int ret = 0;
+ switch (frame->format) {
+ case AV_PIX_FMT_YUV420P:
+ ret = SDL_UpdateYUVTexture(tex, NULL, frame->data[0], frame->linesize[0],
+ frame->data[1], frame->linesize[1],
+ frame->data[2], frame->linesize[2]);
+ break;
+ case AV_PIX_FMT_BGRA:
+ ret = SDL_UpdateTexture(tex, NULL, frame->data[0], frame->linesize[0]);
+ break;
+ default:
+ /* This should only happen if we are not using avfilter... */
+ *img_convert_ctx = sws_getCachedContext(*img_convert_ctx,
+ frame->width, frame->height, frame->format, frame->width, frame->height,
+ AV_PIX_FMT_BGRA, sws_flags, NULL, NULL, NULL);
+ if (*img_convert_ctx != NULL) {
+ uint8_t *pixels;
+ int pitch;
+ if (!SDL_LockTexture(tex, NULL, (void **)&pixels, &pitch)) {
+ sws_scale(*img_convert_ctx, (const uint8_t * const *)frame->data, frame->linesize,
+ 0, frame->height, &pixels, &pitch);
+ SDL_UnlockTexture(tex);
+ }
+ } else {
+ av_log(NULL, AV_LOG_FATAL, "Cannot initialize the conversion context\n");
+ ret = -1;
+ }
+ break;
+ }
+ return ret;
+}
+
static void video_image_display(VideoState *is)
{
Frame *vp;
- Frame *sp;
+ Frame *sp = NULL;
SDL_Rect rect;
- int i;
vp = frame_queue_peek_last(&is->pictq);
if (vp->bmp) {
@@ -950,36 +910,71 @@ static void video_image_display(VideoState *is)
sp = frame_queue_peek(&is->subpq);
if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 1000)) {
- uint8_t *data[4];
- int linesize[4];
-
- SDL_LockYUVOverlay (vp->bmp);
-
- data[0] = vp->bmp->pixels[0];
- data[1] = vp->bmp->pixels[2];
- data[2] = vp->bmp->pixels[1];
-
- linesize[0] = vp->bmp->pitches[0];
- linesize[1] = vp->bmp->pitches[2];
- linesize[2] = vp->bmp->pitches[1];
-
- for (i = 0; i < sp->sub.num_rects; i++)
- blend_subrect(data, linesize, sp->subrects[i],
- vp->bmp->w, vp->bmp->h);
-
- SDL_UnlockYUVOverlay (vp->bmp);
- }
+ if (!sp->uploaded) {
+ uint8_t *pixels;
+ int pitch;
+ int i;
+ if (!sp->width || !sp->height) {
+ sp->width = vp->width;
+ sp->height = vp->height;
+ }
+ if (realloc_texture(&is->sub_texture, SDL_PIXELFORMAT_ARGB8888, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
+ return;
+
+ for (i = 0; i < sp->sub.num_rects; i++) {
+ AVSubtitleRect *sub_rect = sp->sub.rects[i];
+
+ sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
+ sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
+ sub_rect->w = av_clip(sub_rect->w, 0, sp->width - sub_rect->x);
+ sub_rect->h = av_clip(sub_rect->h, 0, sp->height - sub_rect->y);
+
+ is->sub_convert_ctx = sws_getCachedContext(is->sub_convert_ctx,
+ sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
+ sub_rect->w, sub_rect->h, AV_PIX_FMT_BGRA,
+ 0, NULL, NULL, NULL);
+ if (!is->sub_convert_ctx) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot initialize the conversion context\n");
+ return;
+ }
+ if (!SDL_LockTexture(is->sub_texture, (SDL_Rect *)sub_rect, (void **)&pixels, &pitch)) {
+ sws_scale(is->sub_convert_ctx, (const uint8_t * const *)sub_rect->data, sub_rect->linesize,
+ 0, sub_rect->h, &pixels, &pitch);
+ SDL_UnlockTexture(is->sub_texture);
+ }
+ }
+ sp->uploaded = 1;
+ }
+ } else
+ sp = NULL;
}
}
calculate_display_rect(&rect, is->xleft, is->ytop, is->width, is->height, vp->width, vp->height, vp->sar);
- SDL_DisplayYUVOverlay(vp->bmp, &rect);
+ if (!vp->uploaded) {
+ if (upload_texture(vp->bmp, vp->frame, &is->img_convert_ctx) < 0)
+ return;
+ vp->uploaded = 1;
+ }
- if (rect.x != is->last_display_rect.x || rect.y != is->last_display_rect.y || rect.w != is->last_display_rect.w || rect.h != is->last_display_rect.h || is->force_refresh) {
- int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
- fill_border(is->xleft, is->ytop, is->width, is->height, rect.x, rect.y, rect.w, rect.h, bgcolor, 1);
- is->last_display_rect = rect;
+ SDL_RenderCopy(renderer, vp->bmp, NULL, &rect);
+ if (sp) {
+#if USE_ONEPASS_SUBTITLE_RENDER
+ SDL_RenderCopy(renderer, is->sub_texture, NULL, &rect);
+#else
+ int i;
+ double xratio = (double)rect.w / (double)sp->width;
+ double yratio = (double)rect.h / (double)sp->height;
+ for (i = 0; i < sp->sub.num_rects; i++) {
+ SDL_Rect *sub_rect = (SDL_Rect*)sp->sub.rects[i];
+ SDL_Rect target = {.x = rect.x + sub_rect->x * xratio,
+ .y = rect.y + sub_rect->y * yratio,
+ .w = sub_rect->w * xratio,
+ .h = sub_rect->h * yratio};
+ SDL_RenderCopy(renderer, is->sub_texture, sub_rect, &target);
+ }
+#endif
}
}
}
@@ -992,7 +987,7 @@ static inline int compute_mod(int a, int b)
static void video_audio_display(VideoState *s)
{
int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
- int ch, channels, h, h2, bgcolor, fgcolor;
+ int ch, channels, h, h2;
int64_t time_diff;
int rdft_bits, nb_freq;
@@ -1042,13 +1037,8 @@ static void video_audio_display(VideoState *s)
i_start = s->last_i_start;
}
- bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
if (s->show_mode == SHOW_MODE_WAVES) {
- fill_rectangle(screen,
- s->xleft, s->ytop, s->width, s->height,
- bgcolor, 0);
-
- fgcolor = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff);
+ SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
/* total height for one channel */
h = s->height / nb_display_channels;
@@ -1065,25 +1055,23 @@ static void video_audio_display(VideoState *s)
} else {
ys = y1;
}
- fill_rectangle(screen,
- s->xleft + x, ys, 1, y,
- fgcolor, 0);
+ fill_rectangle(s->xleft + x, ys, 1, y);
i += channels;
if (i >= SAMPLE_ARRAY_SIZE)
i -= SAMPLE_ARRAY_SIZE;
}
}
- fgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
+ SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
for (ch = 1; ch < nb_display_channels; ch++) {
y = s->ytop + ch * h;
- fill_rectangle(screen,
- s->xleft, y, s->width, 1,
- fgcolor, 0);
+ fill_rectangle(s->xleft, y, s->width, 1);
}
- SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height);
} else {
+ if (realloc_texture(&s->vis_texture, SDL_PIXELFORMAT_ARGB8888, s->width, s->height, SDL_BLENDMODE_NONE, 1) < 0)
+ return;
+
nb_display_channels= FFMIN(nb_display_channels, 2);
if (rdft_bits != s->rdft_bits) {
av_rdft_end(s->rdft);
@@ -1097,6 +1085,9 @@ static void video_audio_display(VideoState *s)
s->show_mode = SHOW_MODE_WAVES;
} else {
FFTSample *data[2];
+ SDL_Rect rect = {.x = s->xpos, .y = 0, .w = 1, .h = s->height};
+ uint32_t *pixels;
+ int pitch;
for (ch = 0; ch < nb_display_channels; ch++) {
data[ch] = s->rdft_data + 2 * nb_freq * ch;
i = i_start + ch;
@@ -1111,21 +1102,23 @@ static void video_audio_display(VideoState *s)
}
/* Least efficient way to do this, we should of course
* directly access it but it is more than fast enough. */
- for (y = 0; y < s->height; y++) {
- double w = 1 / sqrt(nb_freq);
- int a = sqrt(w * hypot(data[0][2 * y + 0], data[0][2 * y + 1]));
- int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][2 * y + 0], data[1][2 * y + 1]))
- : a;
- a = FFMIN(a, 255);
- b = FFMIN(b, 255);
- fgcolor = SDL_MapRGB(screen->format, a, b, (a + b) / 2);
-
- fill_rectangle(screen,
- s->xpos, s->height-y, 1, 1,
- fgcolor, 0);
+ if (!SDL_LockTexture(s->vis_texture, &rect, (void **)&pixels, &pitch)) {
+ pitch >>= 2;
+ pixels += pitch * s->height;
+ for (y = 0; y < s->height; y++) {
+ double w = 1 / sqrt(nb_freq);
+ int a = sqrt(w * sqrt(data[0][2 * y + 0] * data[0][2 * y + 0] + data[0][2 * y + 1] * data[0][2 * y + 1]));
+ int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][2 * y + 0], data[1][2 * y + 1]))
+ : a;
+ a = FFMIN(a, 255);
+ b = FFMIN(b, 255);
+ pixels -= pitch;
+ *pixels = (a << 16) + (b << 8) + ((a+b) >> 1);
+ }
+ SDL_UnlockTexture(s->vis_texture);
}
+ SDL_RenderCopy(renderer, s->vis_texture, NULL, NULL);
}
- SDL_UpdateRect(screen, s->xpos, s->ytop, 1, s->height);
if (!s->paused)
s->xpos++;
if (s->xpos >= s->width)
@@ -1215,11 +1208,13 @@ static void stream_close(VideoState *is)
frame_queue_destory(&is->sampq);
frame_queue_destory(&is->subpq);
SDL_DestroyCond(is->continue_read_thread);
-#if !CONFIG_AVFILTER
sws_freeContext(is->img_convert_ctx);
-#endif
sws_freeContext(is->sub_convert_ctx);
av_free(is->filename);
+ if (is->vis_texture)
+ SDL_DestroyTexture(is->vis_texture);
+ if (is->sub_texture)
+ SDL_DestroyTexture(is->sub_texture);
av_free(is);
}
@@ -1228,6 +1223,10 @@ static void do_exit(VideoState *is)
if (is) {
stream_close(is);
}
+ if (renderer)
+ SDL_DestroyRenderer(renderer);
+ if (window)
+ SDL_DestroyWindow(window);
av_lockmgr_register(NULL);
uninit_opts();
#if CONFIG_AVFILTER
@@ -1254,42 +1253,48 @@ static void set_default_window_size(int width, int height, AVRational sar)
default_height = rect.h;
}
-static int video_open(VideoState *is, int force_set_video_mode, Frame *vp)
+static int video_open(VideoState *is, Frame *vp)
{
- int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
int w,h;
- if (is_full_screen) flags |= SDL_FULLSCREEN;
- else flags |= SDL_RESIZABLE;
-
if (vp && vp->width)
set_default_window_size(vp->width, vp->height, vp->sar);
- if (is_full_screen && fs_screen_width) {
- w = fs_screen_width;
- h = fs_screen_height;
- } else if (!is_full_screen && screen_width) {
+ if (screen_width) {
w = screen_width;
h = screen_height;
} else {
w = default_width;
h = default_height;
}
- w = FFMIN(16383, w);
- if (screen && is->width == screen->w && screen->w == w
- && is->height== screen->h && screen->h == h && !force_set_video_mode)
- return 0;
- screen = SDL_SetVideoMode(w, h, 0, flags);
- if (!screen) {
+
+ if (!window) {
+ int flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE;
+ if (!window_title)
+ window_title = input_filename;
+ if (is_full_screen)
+ flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+ window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags);
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+ if (window) {
+ SDL_RendererInfo info;
+ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
+ if (renderer) {
+ if (!SDL_GetRendererInfo(renderer, &info))
+ av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", info.name);
+ }
+ }
+ } else {
+ SDL_SetWindowSize(window, w, h);
+ }
+
+ if (!window || !renderer) {
av_log(NULL, AV_LOG_FATAL, "SDL: could not set video mode - exiting\n");
do_exit(is);
}
- if (!window_title)
- window_title = input_filename;
- SDL_WM_SetCaption(window_title, window_title);
- is->width = screen->w;
- is->height = screen->h;
+ is->width = w;
+ is->height = h;
return 0;
}
@@ -1297,12 +1302,16 @@ static int video_open(VideoState *is, int force_set_video_mode, Frame *vp)
/* display the current picture, if any */
static void video_display(VideoState *is)
{
- if (!screen)
- video_open(is, 0, NULL);
+ if (!window)
+ video_open(is, NULL);
+
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_RenderClear(renderer);
if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
video_audio_display(is);
else if (is->video_st)
video_image_display(is);
+ SDL_RenderPresent(renderer);
}
static double get_clock(Clock *c)
@@ -1587,6 +1596,20 @@ retry:
|| (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
|| (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000))))
{
+ if (sp->uploaded) {
+ int i;
+ for (i = 0; i < sp->sub.num_rects; i++) {
+ AVSubtitleRect *sub_rect = sp->sub.rects[i];
+ uint8_t *pixels;
+ int pitch, j;
+
+ if (!SDL_LockTexture(is->sub_texture, (SDL_Rect *)sub_rect, (void **)&pixels, &pitch)) {
+ for (j = 0; j < sub_rect->h; j++, pixels += pitch)
+ memset(pixels, 0, sub_rect->w << 2);
+ SDL_UnlockTexture(is->sub_texture);
+ }
+ }
+ }
frame_queue_next(&is->subpq);
} else {
break;
@@ -1652,19 +1675,18 @@ display:
static void alloc_picture(VideoState *is)
{
Frame *vp;
- int64_t bufferdiff;
+ int sdl_format;
vp = &is->pictq.queue[is->pictq.windex];
- free_picture(vp);
+ video_open(is, vp);
- video_open(is, 0, vp);
+ if (vp->format == AV_PIX_FMT_YUV420P)
+ sdl_format = SDL_PIXELFORMAT_YV12;
+ else
+ sdl_format = SDL_PIXELFORMAT_ARGB8888;
- vp->bmp = SDL_CreateYUVOverlay(vp->width, vp->height,
- SDL_YV12_OVERLAY,
- screen);
- bufferdiff = vp->bmp ? FFMAX(vp->bmp->pixels[0], vp->bmp->pixels[1]) - FFMIN(vp->bmp->pixels[0], vp->bmp->pixels[1]) : 0;
- if (!vp->bmp || vp->bmp->pitches[0] < vp->width || bufferdiff < (int64_t)vp->height * vp->bmp->pitches[0]) {
+ if (realloc_texture(&vp->bmp, sdl_format, vp->width, vp->height, SDL_BLENDMODE_NONE, 0) < 0) {
/* SDL allocates a buffer smaller than requested if the video
* overlay hardware is unable to support the requested size. */
av_log(NULL, AV_LOG_FATAL,
@@ -1680,24 +1702,6 @@ static void alloc_picture(VideoState *is)
SDL_UnlockMutex(is->pictq.mutex);
}
-static void duplicate_right_border_pixels(SDL_Overlay *bmp) {
- int i, width, height;
- Uint8 *p, *maxp;
- for (i = 0; i < 3; i++) {
- width = bmp->w;
- height = bmp->h;
- if (i > 0) {
- width >>= 1;
- height >>= 1;
- }
- if (bmp->pitches[i] > width) {
- maxp = bmp->pixels[i] + bmp->pitches[i] * height - 1;
- for (p = bmp->pixels[i] + width - 1; p < maxp; p += bmp->pitches[i])
- *(p+1) = *p;
- }
- }
-}
-
static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double duration, int64_t pos, int serial)
{
Frame *vp;
@@ -1711,17 +1715,19 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double
return -1;
vp->sar = src_frame->sample_aspect_ratio;
+ vp->uploaded = 0;
/* alloc or resize hardware picture buffer */
- if (!vp->bmp || vp->reallocate || !vp->allocated ||
+ if (!vp->bmp || !vp->allocated ||
vp->width != src_frame->width ||
- vp->height != src_frame->height) {
+ vp->height != src_frame->height ||
+ vp->format != src_frame->format) {
SDL_Event event;
- vp->allocated = 0;
- vp->reallocate = 0;
+ vp->allocated = 0;
vp->width = src_frame->width;
vp->height = src_frame->height;
+ vp->format = src_frame->format;
/* the allocation must be done in the main thread to avoid
locking problems. */
@@ -1735,7 +1741,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double
SDL_CondWait(is->pictq.cond, is->pictq.mutex);
}
/* if the queue is aborted, we have to pop the pending ALLOC event or wait for the allocation to complete */
- if (is->videoq.abort_request && SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(FF_ALLOC_EVENT)) != 1) {
+ if (is->videoq.abort_request && SDL_PeepEvents(&event, 1, SDL_GETEVENT, FF_ALLOC_EVENT, FF_ALLOC_EVENT) != 1) {
while (!vp->allocated && !is->abort_request) {
SDL_CondWait(is->pictq.cond, is->pictq.mutex);
}
@@ -1748,58 +1754,12 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double
/* if the frame is not skipped, then display it */
if (vp->bmp) {
- uint8_t *data[4];
- int linesize[4];
-
- /* get a pointer on the bitmap */
- SDL_LockYUVOverlay (vp->bmp);
-
- data[0] = vp->bmp->pixels[0];
- data[1] = vp->bmp->pixels[2];
- data[2] = vp->bmp->pixels[1];
-
- linesize[0] = vp->bmp->pitches[0];
- linesize[1] = vp->bmp->pitches[2];
- linesize[2] = vp->bmp->pitches[1];
-
-#if CONFIG_AVFILTER
- // FIXME use direct rendering
- av_image_copy(data, linesize, (const uint8_t **)src_frame->data, src_frame->linesize,
- src_frame->format, vp->width, vp->height);
-#else
- {
- AVDictionaryEntry *e = av_dict_get(sws_dict, "sws_flags", NULL, 0);
- if (e) {
- const AVClass *class = sws_get_class();
- const AVOption *o = av_opt_find(&class, "sws_flags", NULL, 0,
- AV_OPT_SEARCH_FAKE_OBJ);
- int ret = av_opt_eval_flags(&class, o, e->value, &sws_flags);
- if (ret < 0)
- exit(1);
- }
- }
-
- is->img_convert_ctx = sws_getCachedContext(is->img_convert_ctx,
- vp->width, vp->height, src_frame->format, vp->width, vp->height,
- AV_PIX_FMT_YUV420P, sws_flags, NULL, NULL, NULL);
- if (!is->img_convert_ctx) {
- av_log(NULL, AV_LOG_FATAL, "Cannot initialize the conversion context\n");
- exit(1);
- }
- sws_scale(is->img_convert_ctx, src_frame->data, src_frame->linesize,
- 0, vp->height, data, linesize);
-#endif
- /* workaround SDL PITCH_WORKAROUND */
- duplicate_right_border_pixels(vp->bmp);
- /* update the bitmap content */
- SDL_UnlockYUVOverlay(vp->bmp);
-
vp->pts = pts;
vp->duration = duration;
vp->pos = pos;
vp->serial = serial;
- /* now we can update the picture count */
+ av_frame_move_ref(vp->frame, src_frame);
frame_queue_push(&is->pictq);
}
return 0;
@@ -1887,7 +1847,7 @@ fail:
static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters, AVFrame *frame)
{
- static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE };
+ static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE };
char sws_flags_str[512] = "";
char buffersrc_args[256];
int ret;
@@ -1950,10 +1910,6 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
last_filter = filt_ctx; \
} while (0)
- /* SDL YUV code is not handling odd width/height for some driver
- * combinations, therefore we crop the picture to an even width/height. */
- INSERT_FILT("crop", "floor(in_w/2)*2:floor(in_h/2)*2");
-
if (autorotate) {
double theta = get_rotation(is->video_st);
@@ -2148,7 +2104,7 @@ static int audio_thread(void *arg)
static int decoder_start(Decoder *d, int (*fn)(void *), void *arg)
{
packet_queue_start(d->queue);
- d->decoder_tid = SDL_CreateThread(fn, arg);
+ d->decoder_tid = SDL_CreateThread(fn, "decoder", arg);
if (!d->decoder_tid) {
av_log(NULL, AV_LOG_ERROR, "SDL_CreateThread(): %s\n", SDL_GetError());
return AVERROR(ENOMEM);
@@ -2268,10 +2224,10 @@ static int video_thread(void *arg)
static int subtitle_thread(void *arg)
{
VideoState *is = arg;
+ AVCodecParameters *codecpar = is->subtitle_st->codecpar;
Frame *sp;
int got_subtitle;
double pts;
- int i;
for (;;) {
if (!(sp = frame_queue_peek_writable(&is->subpq)))
@@ -2287,42 +2243,9 @@ static int subtitle_thread(void *arg)
pts = sp->sub.pts / (double)AV_TIME_BASE;
sp->pts = pts;
sp->serial = is->subdec.pkt_serial;
- if (!(sp->subrects = av_mallocz_array(sp->sub.num_rects, sizeof(AVSubtitleRect*)))) {
- av_log(NULL, AV_LOG_FATAL, "Cannot allocate subrects\n");
- exit(1);
- }
-
- for (i = 0; i < sp->sub.num_rects; i++)
- {
- int in_w = sp->sub.rects[i]->w;
- int in_h = sp->sub.rects[i]->h;
- int subw = is->subdec.avctx->width ? is->subdec.avctx->width : is->viddec_width;
- int subh = is->subdec.avctx->height ? is->subdec.avctx->height : is->viddec_height;
- int out_w = is->viddec_width ? in_w * is->viddec_width / subw : in_w;
- int out_h = is->viddec_height ? in_h * is->viddec_height / subh : in_h;
-
- if (!(sp->subrects[i] = av_mallocz(sizeof(AVSubtitleRect))) ||
- av_image_alloc(sp->subrects[i]->data, sp->subrects[i]->linesize, out_w, out_h, AV_PIX_FMT_YUVA420P, 16) < 0) {
- av_log(NULL, AV_LOG_FATAL, "Cannot allocate subtitle data\n");
- exit(1);
- }
-
- is->sub_convert_ctx = sws_getCachedContext(is->sub_convert_ctx,
- in_w, in_h, AV_PIX_FMT_PAL8, out_w, out_h,
- AV_PIX_FMT_YUVA420P, sws_flags, NULL, NULL, NULL);
- if (!is->sub_convert_ctx) {
- av_log(NULL, AV_LOG_FATAL, "Cannot initialize the sub conversion context\n");
- exit(1);
- }
- sws_scale(is->sub_convert_ctx,
- (void*)sp->sub.rects[i]->data, sp->sub.rects[i]->linesize,
- 0, in_h, sp->subrects[i]->data, sp->subrects[i]->linesize);
-
- sp->subrects[i]->w = out_w;
- sp->subrects[i]->h = out_h;
- sp->subrects[i]->x = sp->sub.rects[i]->x * out_w / in_w;
- sp->subrects[i]->y = sp->sub.rects[i]->y * out_h / in_h;
- }
+ sp->width = codecpar->width;
+ sp->height = codecpar->height;
+ sp->uploaded = 0;
/* now we can update the picture count */
frame_queue_push(&is->subpq);
@@ -3185,7 +3108,7 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
is->audio_volume = SDL_MIX_MAXVOLUME;
is->muted = 0;
is->av_sync_type = av_sync_type;
- is->read_tid = SDL_CreateThread(read_thread, is);
+ is->read_tid = SDL_CreateThread(read_thread, "read_thread", is);
if (!is->read_tid) {
av_log(NULL, AV_LOG_FATAL, "SDL_CreateThread(): %s\n", SDL_GetError());
fail:
@@ -3276,27 +3199,17 @@ static void stream_cycle_channel(VideoState *is, int codec_type)
static void toggle_full_screen(VideoState *is)
{
-#if defined(__APPLE__) && SDL_VERSION_ATLEAST(1, 2, 14)
- /* OS X needs to reallocate the SDL overlays */
- int i;
- for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++)
- is->pictq.queue[i].reallocate = 1;
-#endif
is_full_screen = !is_full_screen;
- video_open(is, 1, NULL);
+ SDL_SetWindowFullscreen(window, is_full_screen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
}
static void toggle_audio_display(VideoState *is)
{
- int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
int next = is->show_mode;
do {
next = (next + 1) % SHOW_MODE_NB;
} while (next != is->show_mode && (next == SHOW_MODE_VIDEO && !is->video_st || next != SHOW_MODE_VIDEO && !is->audio_st));
if (is->show_mode != next) {
- fill_rectangle(screen,
- is->xleft, is->ytop, is->width, is->height,
- bgcolor, 1);
is->force_refresh = 1;
is->show_mode = next;
}
@@ -3305,7 +3218,7 @@ static void toggle_audio_display(VideoState *is)
static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) {
double remaining_time = 0.0;
SDL_PumpEvents();
- while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
+ while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
if (!cursor_hidden && av_gettime_relative() - cursor_last_shown > CURSOR_HIDE_DELAY) {
SDL_ShowCursor(0);
cursor_hidden = 1;
@@ -3469,9 +3382,6 @@ static void event_loop(VideoState *cur_stream)
break;
}
break;
- case SDL_VIDEOEXPOSE:
- cur_stream->force_refresh = 1;
- break;
case SDL_MOUSEBUTTONDOWN:
if (exit_on_mousedown) {
do_exit(cur_stream);
@@ -3527,16 +3437,18 @@ static void event_loop(VideoState *cur_stream)
stream_seek(cur_stream, ts, 0, 0);
}
break;
- case SDL_VIDEORESIZE:
- screen = SDL_SetVideoMode(FFMIN(16383, event.resize.w), event.resize.h, 0,
- SDL_HWSURFACE|(is_full_screen?SDL_FULLSCREEN:SDL_RESIZABLE)|SDL_ASYNCBLIT|SDL_HWACCEL);
- if (!screen) {
- av_log(NULL, AV_LOG_FATAL, "Failed to set video mode\n");
- do_exit(cur_stream);
- }
- screen_width = cur_stream->width = screen->w;
- screen_height = cur_stream->height = screen->h;
- cur_stream->force_refresh = 1;
+ case SDL_WINDOWEVENT:
+ switch (event.window.event) {
+ case SDL_WINDOWEVENT_RESIZED:
+ screen_width = cur_stream->width = event.window.data1;
+ screen_height = cur_stream->height = event.window.data2;
+ if (cur_stream->vis_texture) {
+ SDL_DestroyTexture(cur_stream->vis_texture);
+ cur_stream->vis_texture = NULL;
+ }
+ case SDL_WINDOWEVENT_EXPOSED:
+ cur_stream->force_refresh = 1;
+ }
break;
case SDL_QUIT:
case FF_QUIT_EVENT:
@@ -3773,8 +3685,6 @@ int main(int argc, char **argv)
{
int flags;
VideoState *is;
- char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy";
- char alsa_bufsize[] = "SDL_AUDIO_ALSA_SET_BUFFER_SIZE=1";
init_dynload();
@@ -3818,31 +3728,19 @@ int main(int argc, char **argv)
/* Try to work around an occasional ALSA buffer underflow issue when the
* period size is NPOT due to ALSA resampling by forcing the buffer size. */
if (!SDL_getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE"))
- SDL_putenv(alsa_bufsize);
+ SDL_setenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE","1", 1);
}
if (display_disable)
- SDL_putenv(dummy_videodriver); /* For the event queue, we always need a video driver. */
-#if !defined(_WIN32) && !defined(__APPLE__)
- flags |= SDL_INIT_EVENTTHREAD; /* Not supported on Windows or Mac OS X */
-#endif
+ flags &= ~SDL_INIT_VIDEO;
if (SDL_Init (flags)) {
av_log(NULL, AV_LOG_FATAL, "Could not initialize SDL - %s\n", SDL_GetError());
av_log(NULL, AV_LOG_FATAL, "(Did you set the DISPLAY variable?)\n");
exit(1);
}
- if (!display_disable) {
- const SDL_VideoInfo *vi = SDL_GetVideoInfo();
- fs_screen_width = vi->current_w;
- fs_screen_height = vi->current_h;
- }
-
- SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-
if (av_lockmgr_register(lockmgr)) {
av_log(NULL, AV_LOG_FATAL, "Could not initialize lock manager!\n");
do_exit(NULL);
1
0
ffmpeg | branch: master | Lukasz Marek <lukasz.m.luki2(a)gmail.com> | Sun Sep 18 19:13:12 2016 +0200| [645353829f27ed91cbee8dfec0a3283672caa4f9] | committer: Josh de Kock
lavd/opengl: use SDL2
Signed-off-by: Lukasz Marek <lukasz.m.luki2(a)gmail.com>
Signed-off-by: Josh de Kock <josh(a)itanimul.li>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=645353829f27ed91c…
---
libavdevice/opengl_enc.c | 109 +++++++++++++++++++++--------------------------
1 file changed, 49 insertions(+), 60 deletions(-)
diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 1dbbb80..94259a2 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -46,7 +46,7 @@
#include <GL/glx.h>
#endif
-#if HAVE_SDL
+#if HAVE_SDL2
#include <SDL.h>
#endif
@@ -174,8 +174,9 @@ static const GLushort g_index[6] =
typedef struct OpenGLContext {
AVClass *class; ///< class for private options
-#if HAVE_SDL
- SDL_Surface *surface;
+#if HAVE_SDL2
+ SDL_Window *window;
+ SDL_GLContext glcontext;
#endif
FFOpenGLFunctions glprocs;
@@ -341,30 +342,14 @@ static int opengl_control_message(AVFormatContext *h, int type, void *data, size
return AVERROR(ENOSYS);
}
-#if HAVE_SDL
-static int opengl_sdl_recreate_window(OpenGLContext *opengl, int width, int height)
-{
- opengl->surface = SDL_SetVideoMode(width, height,
- 32, SDL_OPENGL | SDL_RESIZABLE);
- if (!opengl->surface) {
- av_log(opengl, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());
- return AVERROR_EXTERNAL;
- }
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- return 0;
-}
-
+#if HAVE_SDL2
static int opengl_sdl_process_events(AVFormatContext *h)
{
- int ret;
OpenGLContext *opengl = h->priv_data;
+ AVDeviceRect message;
SDL_Event event;
SDL_PumpEvents();
- while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0) {
+ while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0) {
switch (event.type) {
case SDL_QUIT:
return AVERROR(EIO);
@@ -375,23 +360,14 @@ static int opengl_sdl_process_events(AVFormatContext *h)
return AVERROR(EIO);
}
return 0;
- case SDL_VIDEORESIZE: {
- char buffer[100];
- int reinit;
- AVDeviceRect message;
- /* clean up old context because SDL_SetVideoMode may lose its state. */
- SDL_VideoDriverName(buffer, sizeof(buffer));
- reinit = !av_strncasecmp(buffer, "quartz", sizeof(buffer));
- if (reinit) {
- opengl_deinit_context(opengl);
- }
- if ((ret = opengl_sdl_recreate_window(opengl, event.resize.w, event.resize.h)) < 0)
- return ret;
- if (reinit && (ret = opengl_init_context(opengl)) < 0)
- return ret;
- message.width = opengl->surface->w;
- message.height = opengl->surface->h;
- return opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect));
+ case SDL_WINDOWEVENT:
+ switch(event.window.event) {
+ case SDL_WINDOWEVENT_RESIZED:
+ case SDL_WINDOWEVENT_SIZE_CHANGED:
+ SDL_GL_GetDrawableSize(opengl->window, &message.width, &message.height);
+ return opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect));
+ default:
+ break;
}
}
}
@@ -400,23 +376,34 @@ static int opengl_sdl_process_events(AVFormatContext *h)
static int av_cold opengl_sdl_create_window(AVFormatContext *h)
{
- int ret;
- char buffer[100];
OpenGLContext *opengl = h->priv_data;
AVDeviceRect message;
if (SDL_Init(SDL_INIT_VIDEO)) {
av_log(opengl, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
return AVERROR_EXTERNAL;
}
- if ((ret = opengl_sdl_recreate_window(opengl, opengl->window_width,
- opengl->window_height)) < 0)
- return ret;
- av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_VideoDriverName(buffer, sizeof(buffer)));
- message.width = opengl->surface->w;
- message.height = opengl->surface->h;
- SDL_WM_SetCaption(opengl->window_title, NULL);
- opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect));
- return 0;
+ opengl->window = SDL_CreateWindow(opengl->window_title,
+ SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED,
+ opengl->window_width, opengl->window_height,
+ SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
+ if (!opengl->window) {
+ av_log(opengl, AV_LOG_ERROR, "Unable to create default window: %s\n", SDL_GetError());
+ return AVERROR_EXTERNAL;
+ }
+ opengl->glcontext = SDL_GL_CreateContext(opengl->window);
+ if (!opengl->glcontext) {
+ av_log(opengl, AV_LOG_ERROR, "Unable to create OpenGL context on default window: %s\n", SDL_GetError());
+ return AVERROR_EXTERNAL;
+ }
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_GetCurrentVideoDriver());
+ SDL_GL_GetDrawableSize(opengl->window, &message.width, &message.height);
+ return opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect));
}
static int av_cold opengl_sdl_load_procedures(OpenGLContext *opengl)
@@ -460,14 +447,14 @@ static int av_cold opengl_sdl_load_procedures(OpenGLContext *opengl)
#undef LOAD_OPENGL_FUN
}
-#endif /* HAVE_SDL */
+#endif /* HAVE_SDL2 */
#if defined(__APPLE__)
static int av_cold opengl_load_procedures(OpenGLContext *opengl)
{
FFOpenGLFunctions *procs = &opengl->glprocs;
-#if HAVE_SDL
+#if HAVE_SDL2
if (!opengl->no_window)
return opengl_sdl_load_procedures(opengl);
#endif
@@ -517,7 +504,7 @@ static int av_cold opengl_load_procedures(OpenGLContext *opengl)
return AVERROR(ENOSYS); \
}
-#if HAVE_SDL
+#if HAVE_SDL2
if (!opengl->no_window)
return opengl_sdl_load_procedures(opengl);
#endif
@@ -943,7 +930,7 @@ static int opengl_create_window(AVFormatContext *h)
int ret;
if (!opengl->no_window) {
-#if HAVE_SDL
+#if HAVE_SDL2
if ((ret = opengl_sdl_create_window(h)) < 0) {
av_log(opengl, AV_LOG_ERROR, "Cannot create default SDL window.\n");
return ret;
@@ -975,7 +962,9 @@ static int opengl_release_window(AVFormatContext *h)
int ret;
OpenGLContext *opengl = h->priv_data;
if (!opengl->no_window) {
-#if HAVE_SDL
+#if HAVE_SDL2
+ SDL_GL_DeleteContext(opengl->glcontext);
+ SDL_DestroyWindow(opengl->window);
SDL_Quit();
#endif
} else if ((ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER, NULL , 0)) < 0) {
@@ -1109,9 +1098,9 @@ static av_cold int opengl_write_header(AVFormatContext *h)
glClear(GL_COLOR_BUFFER_BIT);
-#if HAVE_SDL
+#if HAVE_SDL2
if (!opengl->no_window)
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapWindow(opengl->window);
#endif
if (opengl->no_window &&
(ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER, NULL , 0)) < 0) {
@@ -1204,7 +1193,7 @@ static int opengl_draw(AVFormatContext *h, void *input, int repaint, int is_pkt)
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int ret;
-#if HAVE_SDL
+#if HAVE_SDL2
if (!opengl->no_window && (ret = opengl_sdl_process_events(h)) < 0)
goto fail;
#endif
@@ -1245,9 +1234,9 @@ static int opengl_draw(AVFormatContext *h, void *input, int repaint, int is_pkt)
ret = AVERROR_EXTERNAL;
OPENGL_ERROR_CHECK(opengl);
-#if HAVE_SDL
+#if HAVE_SDL2
if (!opengl->no_window)
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapWindow(opengl->window);
#endif
if (opengl->no_window &&
(ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER, NULL , 0)) < 0) {
1
0
ffmpeg | branch: master | Josh de Kock <josh(a)itanimul.li> | Wed Sep 14 22:43:33 2016 +0100| [f94b8d2557c6becec9caf89df50d54221931eb39] | committer: Josh de Kock
MAINTAINERS: update my entries
Acked-by: Michael Niedermayer <michael(a)niedermayer.cc>
Signed-off-by: Josh de Kock <josh(a)itanimul.li>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f94b8d2557c6becec…
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index f1f991d..d1e487a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -285,6 +285,7 @@ libavdevice
pulse_audio_enc.c Lukasz Marek
qtkit.m Thilo Borgmann
sdl Stefano Sabatini
+ sdl2.c Josh de Kock
v4l2.c Giorgio Vazzana
vfwcap.c Ramiro Polla
xv.c Lukasz Marek
1
0
ffmpeg | branch: master | Josh de Kock <josh(a)itanimul.li> | Wed Feb 24 23:31:02 2016 +0000| [3877e3d8a8bdd09f6f13b99a555d963bdb0f16f5] | committer: Josh de Kock
lavd: Add SDL2 output device
Acked-by: Michael Niedermayer
Signed-off-by: Josh de Kock <josh(a)itanimul.li>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3877e3d8a8bdd09f6…
---
Changelog | 1 +
configure | 28 +++-
libavdevice/Makefile | 1 +
libavdevice/alldevices.c | 1 +
libavdevice/sdl2.c | 377 +++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 407 insertions(+), 1 deletion(-)
diff --git a/Changelog b/Changelog
index a6916be..acf843e 100644
--- a/Changelog
+++ b/Changelog
@@ -32,6 +32,7 @@ version <next>:
- TrueHD encoder
- Meridian Lossless Packing (MLP) encoder
- Non-Local Means (nlmeans) denoising filter
+- sdl2 output device
version 3.1:
diff --git a/configure b/configure
index c0c1c8a..5434fa1 100755
--- a/configure
+++ b/configure
@@ -292,6 +292,7 @@ External library support:
--disable-schannel disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used [autodetect]
--disable-sdl disable sdl [autodetect]
+ --disable-sdl2 disable sdl2 [autodetect]
--disable-securetransport disable Secure Transport, needed for TLS support
on OSX if openssl and gnutls are not used [autodetect]
--enable-x11grab enable X11 grabbing (legacy) [no]
@@ -1548,6 +1549,7 @@ EXTERNAL_LIBRARY_LIST="
openssl
schannel
sdl
+ sdl2
securetransport
videotoolbox
x11grab
@@ -2022,6 +2024,7 @@ HAVE_LIST="
perl
pod2man
sdl
+ sdl2
section_data_rel_ro
texi2html
threads
@@ -2948,6 +2951,7 @@ pulse_outdev_deps="libpulse"
qtkit_indev_extralibs="-framework QTKit -framework Foundation -framework QuartzCore"
qtkit_indev_select="qtkit"
sdl_outdev_deps="sdl"
+sdl2_outdev_deps="sdl2"
sndio_indev_deps="sndio_h"
sndio_outdev_deps="sndio_h"
v4l_indev_deps="linux_videodev_h"
@@ -5846,7 +5850,28 @@ if enabled gcrypt; then
fi
fi
-if ! disabled sdl; then
+if ! disabled sdl2 && ! enabled sdl; then
+ SDL2_CONFIG="${cross_prefix}sdl2-config"
+ if check_pkg_config sdl2 SDL_events.h SDL_PollEvent; then
+ check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags &&
+ check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags &&
+ check_func SDL_Init $sdl2_libs $sdl2_cflags && enable sdl2
+ else
+ if "${SDL2_CONFIG}" --version > /dev/null 2>&1; then
+ sdl2_cflags=$("${SDL2_CONFIG}" --cflags)
+ sdl2_libs=$("${SDL2_CONFIG}" --libs)
+ check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags &&
+ check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags &&
+ check_func SDL_Init $sdl2_libs $sdl2_cflags && enable sdl2
+ fi
+ fi
+ if test $target_os = "mingw32"; then
+ sdl2_libs="$sdl2_libs -mconsole"
+ fi
+fi
+enabled sdl2 && add_cflags $sdl2_cflags && add_extralibs $sdl2_libs
+
+if ! disabled sdl && ! enabled sdl2; then
SDL_CONFIG="${cross_prefix}sdl-config"
if check_pkg_config sdl SDL_events.h SDL_PollEvent; then
check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
@@ -6476,6 +6501,7 @@ echo "network support ${network-no}"
echo "threading support ${thread_type-no}"
echo "safe bitstream reader ${safe_bitstream_reader-no}"
echo "SDL support ${sdl-no}"
+echo "SDL2 support ${sdl2-no}"
echo "opencl enabled ${opencl-no}"
echo "JNI support ${jni-no}"
echo "texi2html enabled ${texi2html-no}"
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 585827b..1c4b4d3 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -41,6 +41,7 @@ OBJS-$(CONFIG_PULSE_OUTDEV) += pulse_audio_enc.o \
pulse_audio_common.o
OBJS-$(CONFIG_QTKIT_INDEV) += qtkit.o
OBJS-$(CONFIG_SDL_OUTDEV) += sdl.o
+OBJS-$(CONFIG_SDL2_OUTDEV) += sdl2.o
OBJS-$(CONFIG_SNDIO_INDEV) += sndio_dec.o sndio.o
OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_enc.o sndio.o
OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o v4l2-common.o timefilter.o
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 26aecf2..c0a9d9a 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -64,6 +64,7 @@ void avdevice_register_all(void)
REGISTER_INOUTDEV(PULSE, pulse);
REGISTER_INDEV (QTKIT, qtkit);
REGISTER_OUTDEV (SDL, sdl);
+ REGISTER_OUTDEV (SDL2, sdl2);
REGISTER_INOUTDEV(SNDIO, sndio);
REGISTER_INOUTDEV(V4L2, v4l2);
// REGISTER_INDEV (V4L, v4l
diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
new file mode 100644
index 0000000..3d1ea42
--- /dev/null
+++ b/libavdevice/sdl2.c
@@ -0,0 +1,377 @@
+/*
+ * Copyright (c) 2016 Josh de Kock
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * libSDL2 output device
+ */
+
+#include <SDL.h>
+#include <SDL_thread.h>
+
+#include "libavutil/avstring.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/time.h"
+#include "avdevice.h"
+
+typedef struct {
+ AVClass *class;
+ SDL_Window *window;
+ SDL_Renderer *renderer;
+ char *window_title;
+ int window_width, window_height; /**< size of the window */
+ int window_fullscreen;
+ int window_borderless;
+
+ SDL_Texture *texture;
+ int texture_fmt;
+ SDL_Rect texture_rect;
+
+ int inited;
+ SDL_Thread *event_thread;
+ SDL_mutex *mutex;
+ SDL_cond *init_cond;
+ int quit;
+} SDLContext;
+
+static const struct sdl_texture_format_entry {
+ enum AVPixelFormat format; int texture_fmt;
+} sdl_texture_format_map[] = {
+ /*
+ * Not implemented in FFmpeg, but leaving here for completeness.
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB4444 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_RGBA4444 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ABGR4444 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_BGRA4444 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB1555 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_RGBA5551 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ABGR1555 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_BGRA5551 },
+ * { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB2101010 },
+ */
+ { AV_PIX_FMT_RGB8, SDL_PIXELFORMAT_RGB332 },
+ { AV_PIX_FMT_RGB444, SDL_PIXELFORMAT_RGB444 },
+ { AV_PIX_FMT_RGB555, SDL_PIXELFORMAT_RGB555 },
+ { AV_PIX_FMT_BGR555, SDL_PIXELFORMAT_BGR555 },
+ { AV_PIX_FMT_RGB565, SDL_PIXELFORMAT_RGB565 },
+ { AV_PIX_FMT_BGR565, SDL_PIXELFORMAT_BGR565 },
+ { AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB24 },
+ { AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR24 },
+ { AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB888 },
+ { AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR888 },
+ { AV_PIX_FMT_RGB0, SDL_PIXELFORMAT_RGBX8888 }, // needs to be checked
+ { AV_PIX_FMT_BGR0, SDL_PIXELFORMAT_BGRX8888 }, // "
+ { AV_PIX_FMT_ARGB, SDL_PIXELFORMAT_ARGB8888 }, // "
+ { AV_PIX_FMT_RGBA, SDL_PIXELFORMAT_RGBA8888 },
+ { AV_PIX_FMT_ABGR, SDL_PIXELFORMAT_ABGR8888 },
+ { AV_PIX_FMT_BGRA, SDL_PIXELFORMAT_BGRA8888 },
+ { AV_PIX_FMT_YUV420P, SDL_PIXELFORMAT_IYUV },
+ { AV_PIX_FMT_YUYV422, SDL_PIXELFORMAT_YUY2 },
+ { AV_PIX_FMT_UYVY422, SDL_PIXELFORMAT_UYVY },
+ { AV_PIX_FMT_NONE, 0 },
+};
+
+static void compute_texture_rect(AVFormatContext *s)
+{
+ AVRational sar, dar; /* sample and display aspect ratios */
+ SDLContext *sdl = s->priv_data;
+ AVStream *st = s->streams[0];
+ AVCodecParameters *codecpar = st->codecpar;
+ SDL_Rect *texture_rect = &sdl->texture_rect;
+
+ /* compute texture width and height from the codec context information */
+ sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 };
+ dar = av_mul_q(sar, (AVRational){ codecpar->width, codecpar->height });
+
+ /* we suppose the screen has a 1/1 sample aspect ratio */
+ if (sdl->window_width && sdl->window_height) {
+ /* fit in the window */
+ if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) {
+ /* fit in width */
+ texture_rect->w = sdl->window_width;
+ texture_rect->h = av_rescale(texture_rect->w, dar.den, dar.num);
+ } else {
+ /* fit in height */
+ texture_rect->h = sdl->window_height;
+ texture_rect->w = av_rescale(texture_rect->h, dar.num, dar.den);
+ }
+ } else {
+ if (sar.num > sar.den) {
+ texture_rect->w = codecpar->width;
+ texture_rect->h = av_rescale(texture_rect->w, dar.den, dar.num);
+ } else {
+ texture_rect->h = codecpar->height;
+ texture_rect->w = av_rescale(texture_rect->h, dar.num, dar.den);
+ }
+ sdl->window_width = texture_rect->w;
+ sdl->window_height = texture_rect->h;
+ }
+
+ texture_rect->x = (sdl->window_width - texture_rect->w) / 2;
+ texture_rect->y = (sdl->window_height - texture_rect->h) / 2;
+}
+
+static int sdl2_write_trailer(AVFormatContext *s)
+{
+ SDLContext *sdl = s->priv_data;
+
+ sdl->quit = 1;
+
+ if (sdl->texture)
+ SDL_DestroyTexture(sdl->texture);
+ sdl->texture = NULL;
+ if (sdl->event_thread)
+ SDL_WaitThread(sdl->event_thread, NULL);
+ sdl->event_thread = NULL;
+ if (sdl->mutex)
+ SDL_DestroyMutex(sdl->mutex);
+ sdl->mutex = NULL;
+ if (sdl->init_cond)
+ SDL_DestroyCond(sdl->init_cond);
+ sdl->init_cond = NULL;
+
+ if (sdl->renderer)
+ SDL_DestroyRenderer(sdl->renderer);
+ sdl->renderer = NULL;
+
+ if (sdl->window)
+ SDL_DestroyWindow(sdl->window);
+ sdl->window = NULL;
+
+ if (!sdl->inited)
+ SDL_Quit();
+
+ return 0;
+}
+
+#define SDL_BASE_FLAGS (SDL_SWSURFACE|SDL_WINDOW_RESIZABLE)
+
+static int sdl2_write_header(AVFormatContext *s)
+{
+ SDLContext *sdl = s->priv_data;
+ AVStream *st = s->streams[0];
+ AVCodecParameters *codecpar = st->codecpar;
+ int i, ret = 0;
+ int flags = 0;
+
+ if (!sdl->window_title)
+ sdl->window_title = av_strdup(s->filename);
+
+ if (SDL_WasInit(SDL_INIT_VIDEO)) {
+ av_log(s, AV_LOG_WARNING,
+ "SDL video subsystem was already inited, you could have multiple SDL outputs. This may cause unknown behaviour.\n");
+ sdl->inited = 1;
+ }
+
+ if ( s->nb_streams > 1
+ || codecpar->codec_type != AVMEDIA_TYPE_VIDEO
+ || codecpar->codec_id != AV_CODEC_ID_RAWVIDEO) {
+ av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n");
+ goto fail;
+ }
+
+ for (i = 0; sdl_texture_format_map[i].format != AV_PIX_FMT_NONE; i++) {
+ if (sdl_texture_format_map[i].format == codecpar->format) {
+ sdl->texture_fmt = sdl_texture_format_map[i].texture_fmt;
+ break;
+ }
+ }
+
+ if (!sdl->texture_fmt) {
+ av_log(s, AV_LOG_ERROR,
+ "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, uyvy422, BGRA\n",
+ av_get_pix_fmt_name(codecpar->format));
+ goto fail;
+ }
+
+ /* resize texture to width and height from the codec context information */
+ flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_WINDOW_FULLSCREEN : 0) |
+ (sdl->window_borderless ? SDL_WINDOW_BORDERLESS : 0);
+
+ /* initialization */
+ if (!sdl->inited){
+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
+ goto fail;
+ }
+ }
+
+ sdl->window_width = sdl->texture_rect.w = codecpar->width;
+ sdl->window_height = sdl->texture_rect.h = codecpar->height;
+ sdl->texture_rect.x = sdl->texture_rect.y = 0;
+
+ if (SDL_CreateWindowAndRenderer(sdl->window_width, sdl->window_height,
+ flags, &sdl->window, &sdl->renderer) != 0){
+ av_log(sdl, AV_LOG_ERROR, "Couldn't create window and renderer: %s\n", SDL_GetError());
+ goto fail;
+ }
+
+ SDL_SetWindowTitle(sdl->window, sdl->window_title);
+
+ sdl->texture = SDL_CreateTexture(sdl->renderer, sdl->texture_fmt, SDL_TEXTUREACCESS_STREAMING,
+ sdl->window_width, sdl->window_height);
+
+ if (!sdl->texture) {
+ av_log(sdl, AV_LOG_ERROR, "Unable to set create mode: %s\n", SDL_GetError());
+ goto fail;
+ }
+
+ av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s -> w:%d h:%d\n",
+ codecpar->width, codecpar->height, av_get_pix_fmt_name(codecpar->format),
+ sdl->window_width, sdl->window_height);
+
+ sdl->inited = 1;
+
+ return 0;
+fail:
+ sdl2_write_trailer(s);
+ return ret;
+}
+
+static int sdl2_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret = 0;
+ SDLContext *sdl = s->priv_data;
+ AVCodecParameters *codecpar = s->streams[0]->codecpar;
+ uint8_t *data[4];
+ int linesize[4];
+
+ SDL_Event event;
+ if (SDL_PollEvent(&event)){
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ sdl->quit = 1;
+ break;
+ default:
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ sdl->quit = 1;
+ break;
+ case SDL_WINDOWEVENT:
+ switch(event.window.event){
+ case SDL_WINDOWEVENT_RESIZED:
+ case SDL_WINDOWEVENT_SIZE_CHANGED:
+ sdl->window_width = event.window.data1;
+ sdl->window_height = event.window.data2;
+ compute_texture_rect(s);
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (sdl->quit) {
+ sdl2_write_trailer(s);
+ return AVERROR(EIO);
+ }
+
+ av_image_fill_arrays(data, linesize, pkt->data, codecpar->format, codecpar->width, codecpar->height, 1);
+ SDL_LockMutex(sdl->mutex);
+ switch (sdl->texture_fmt) {
+ /* case SDL_PIXELFORMAT_ARGB4444:
+ * case SDL_PIXELFORMAT_RGBA4444:
+ * case SDL_PIXELFORMAT_ABGR4444:
+ * case SDL_PIXELFORMAT_BGRA4444:
+ * case SDL_PIXELFORMAT_ARGB1555:
+ * case SDL_PIXELFORMAT_RGBA5551:
+ * case SDL_PIXELFORMAT_ABGR1555:
+ * case SDL_PIXELFORMAT_BGRA5551:
+ * case SDL_PIXELFORMAT_ARGB2101010:
+ */
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_YUY2:
+ case SDL_PIXELFORMAT_UYVY:
+ ret = SDL_UpdateYUVTexture(sdl->texture, NULL,
+ data[0], linesize[0],
+ data[1], linesize[1],
+ data[2], linesize[2]);
+ break;
+ case SDL_PIXELFORMAT_RGB332:
+ case SDL_PIXELFORMAT_RGB444:
+ case SDL_PIXELFORMAT_RGB555:
+ case SDL_PIXELFORMAT_BGR555:
+ case SDL_PIXELFORMAT_RGB565:
+ case SDL_PIXELFORMAT_BGR565:
+ case SDL_PIXELFORMAT_RGB24:
+ case SDL_PIXELFORMAT_BGR24:
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ ret = SDL_UpdateTexture(sdl->texture, NULL, data[0], linesize[0]);
+ break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Unsupported pixel format\n");
+ ret = -1;
+ break;
+ }
+ SDL_RenderClear(sdl->renderer);
+ SDL_RenderCopy(sdl->renderer, sdl->texture, NULL, &sdl->texture_rect);
+ SDL_RenderPresent(sdl->renderer);
+ SDL_UnlockMutex(sdl->mutex);
+ return ret;
+}
+
+#define OFFSET(x) offsetof(SDLContext,x)
+
+static const AVOption options[] = {
+ { "window_title", "set SDL window title", OFFSET(window_title), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+ { "window_size", "set SDL window forced size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+ { "window_fullscreen", "set SDL window fullscreen", OFFSET(window_fullscreen), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
+ { "window_borderless", "set SDL window border off", OFFSET(window_borderless), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
+ { NULL },
+};
+
+static const AVClass sdl2_class = {
+ .class_name = "sdl2 outdev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+ .category = AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
+};
+
+AVOutputFormat ff_sdl2_muxer = {
+ .name = "sdl2",
+ .long_name = NULL_IF_CONFIG_SMALL("SDL2 output device"),
+ .priv_data_size = sizeof(SDLContext),
+ .audio_codec = AV_CODEC_ID_NONE,
+ .video_codec = AV_CODEC_ID_RAWVIDEO,
+ .write_header = sdl2_write_header,
+ .write_packet = sdl2_write_packet,
+ .write_trailer = sdl2_write_trailer,
+ .flags = AVFMT_NOFILE | AVFMT_VARIABLE_FPS | AVFMT_NOTIMESTAMPS,
+ .priv_class = &sdl2_class,
+};
1
0
ffmpeg | branch: master | Clément Bœsch <u(a)pkh.me> | Wed Sep 30 20:29:30 2015 +0200| [c29b532a942233b5c804e620d475b3b888fe6e72] | committer: Clément Bœsch
lavfi: add nlmeans filter
Fixes Ticket #4910
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c29b532a942233b5c…
---
Changelog | 1 +
doc/filters.texi | 35 +++
libavfilter/Makefile | 3 +-
libavfilter/allfilters.c | 1 +
libavfilter/tests/integral.c | 92 ++++++++
libavfilter/version.h | 2 +-
libavfilter/vf_nlmeans.c | 551 +++++++++++++++++++++++++++++++++++++++++++
7 files changed, 683 insertions(+), 2 deletions(-)
diff --git a/Changelog b/Changelog
index 2d0a449..a6916be 100644
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,7 @@ version <next>:
- MediaCodec HEVC decoding
- TrueHD encoder
- Meridian Lossless Packing (MLP) encoder
+- Non-Local Means (nlmeans) denoising filter
version 3.1:
diff --git a/doc/filters.texi b/doc/filters.texi
index 070e57d..7aa541f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9695,6 +9695,41 @@ Negate input video.
It accepts an integer in input; if non-zero it negates the
alpha component (if available). The default value in input is 0.
+@section nlmeans
+
+Denoise frames using Non-Local Means algorithm.
+
+Each pixel is adjusted by looking for other pixels with similar contexts. This
+context similarity is defined by comparing their surrounding patches of size
+@option{p}x@option{p}. Patches are searched in an area of @option{r}x@option{r}
+around the pixel.
+
+Note that the research area defines centers for patches, which means some
+patches will be made of pixels outside that research area.
+
+The filter accepts the following options.
+
+@table @option
+@item s
+Set denoising strength.
+
+@item p
+Set patch size.
+
+@item pc
+Same as @option{p} but for chroma planes.
+
+The default value is @var{0} and means automatic.
+
+@item r
+Set research size.
+
+@item rc
+Same as @option{r} but for chroma planes.
+
+The default value is @var{0} and means automatic.
+@end table
+
@section nnedi
Deinterlace video using neural network edge directed interpolation.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 5cd10fa..57a38d3 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -220,6 +220,7 @@ OBJS-$(CONFIG_METADATA_FILTER) += f_metadata.o
OBJS-$(CONFIG_MINTERPOLATE_FILTER) += vf_minterpolate.o motion_estimation.o
OBJS-$(CONFIG_MPDECIMATE_FILTER) += vf_mpdecimate.o
OBJS-$(CONFIG_NEGATE_FILTER) += vf_lut.o
+OBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o
OBJS-$(CONFIG_NNEDI_FILTER) += vf_nnedi.o
OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
OBJS-$(CONFIG_NOISE_FILTER) += vf_noise.o
@@ -354,7 +355,7 @@ SKIPHEADERS-$(CONFIG_OPENCL) += opencl_internal.h deshake_opencl
OBJS-$(CONFIG_SHARED) += log2_tab.o
TOOLS = graph2dot
-TESTPROGS = drawutils filtfmts formats
+TESTPROGS = drawutils filtfmts formats integral
TOOLS-$(CONFIG_LIBZMQ) += zmqsend
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 47d95f5..8f542fd 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -237,6 +237,7 @@ void avfilter_register_all(void)
REGISTER_FILTER(MINTERPOLATE, minterpolate, vf);
REGISTER_FILTER(MPDECIMATE, mpdecimate, vf);
REGISTER_FILTER(NEGATE, negate, vf);
+ REGISTER_FILTER(NLMEANS, nlmeans, vf);
REGISTER_FILTER(NNEDI, nnedi, vf);
REGISTER_FILTER(NOFORMAT, noformat, vf);
REGISTER_FILTER(NOISE, noise, vf);
diff --git a/libavfilter/tests/integral.c b/libavfilter/tests/integral.c
new file mode 100644
index 0000000..8a2286b
--- /dev/null
+++ b/libavfilter/tests/integral.c
@@ -0,0 +1,92 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavfilter/vf_nlmeans.c"
+
+static void display_integral(const uint32_t *ii, int w, int h, int lz_32)
+{
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++)
+ printf(" %7x", ii[y*lz_32 + x]);
+ printf("\n");
+ }
+ printf("---------------\n");
+}
+
+int main(void)
+{
+ int ret = 0, xoff, yoff;
+
+ // arbitrary test source of size 6x4 and linesize=8
+ const int w = 6, h = 5, lz = 8;
+ static const uint8_t src[] = {
+ 0xb0, 0x71, 0xfb, 0xd8, 0x01, 0xd9, /***/ 0x01, 0x02,
+ 0x51, 0x8e, 0x41, 0x0f, 0x84, 0x58, /***/ 0x03, 0x04,
+ 0xc7, 0x8d, 0x07, 0x70, 0x5c, 0x47, /***/ 0x05, 0x06,
+ 0x09, 0x4e, 0xfc, 0x74, 0x8f, 0x9a, /***/ 0x07, 0x08,
+ 0x60, 0x8e, 0x20, 0xaa, 0x95, 0x7d, /***/ 0x09, 0x0a,
+ };
+
+ const int e = 3;
+ const int ii_w = w+e*2, ii_h = h+e*2;
+
+ // align to 4 the linesize, "+1" is for the space of the left 0-column
+ const int ii_lz_32 = ((ii_w + 1) + 3) & ~3;
+
+ // "+1" is for the space of the top 0-line
+ uint32_t *ii = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii));
+ uint32_t *ii2 = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii2));
+
+ uint32_t *ii_start = ii + ii_lz_32 + 1; // skip top 0-line and left 0-column
+ uint32_t *ii_start2 = ii2 + ii_lz_32 + 1; // skip top 0-line and left 0-column
+
+ if (!ii || !ii2)
+ return -1;
+
+ for (yoff = -e; yoff <= e; yoff++) {
+ for (xoff = -e; xoff <= e; xoff++) {
+ int x, y;
+
+ printf("xoff=%d yoff=%d\n", xoff, yoff);
+
+ compute_ssd_integral_image(ii_start, ii_lz_32,
+ src, lz, xoff, yoff, e, w, h);
+ display_integral(ii_start, ii_w, ii_h, ii_lz_32);
+
+ compute_unsafe_ssd_integral_image(ii_start2, ii_lz_32,
+ 0, 0,
+ src, lz,
+ xoff, yoff, e, w, h,
+ ii_w, ii_h);
+ display_integral(ii_start2, ii_w, ii_h, ii_lz_32);
+
+ if (memcmp(ii, ii2, (ii_h+1) * ii_lz_32 * sizeof(*ii))) {
+ printf("Integral mismatch\n");
+ ret = 1;
+ goto end;
+ }
+ }
+ }
+
+end:
+ av_freep(&ii);
+ av_freep(&ii2);
+ return ret;
+}
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 1a7a1b5..93d249b 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#include "libavutil/version.h"
#define LIBAVFILTER_VERSION_MAJOR 6
-#define LIBAVFILTER_VERSION_MINOR 62
+#define LIBAVFILTER_VERSION_MINOR 63
#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
new file mode 100644
index 0000000..2487813
--- /dev/null
+++ b/libavfilter/vf_nlmeans.c
@@ -0,0 +1,551 @@
+/*
+ * Copyright (c) 2016 Clément Bœsch <u pkh me>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @todo
+ * - SIMD for compute_safe_ssd_integral_image
+ * - SIMD for final weighted averaging
+ * - better automatic defaults? see "Parameters" @ http://www.ipol.im/pub/art/2011/bcm_nlm/
+ * - temporal support (probably doesn't need any displacement according to
+ * "Denoising image sequences does not require motion estimation")
+ * - Bayer pixel format support for at least raw photos? (DNG support would be
+ * handy here)
+ * - FATE test (probably needs visual threshold test mechanism due to the use
+ * of floats)
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+struct weighted_avg {
+ double total_weight;
+ double sum;
+};
+
+#define WEIGHT_LUT_NBITS 9
+#define WEIGHT_LUT_SIZE (1<<WEIGHT_LUT_NBITS)
+
+typedef struct {
+ const AVClass *class;
+ int nb_planes;
+ int chroma_w, chroma_h;
+ double pdiff_scale; // invert of the filtering parameter (sigma*10) squared
+ double sigma; // denoising strength
+ int patch_size, patch_hsize; // patch size and half size
+ int patch_size_uv, patch_hsize_uv; // patch size and half size for chroma planes
+ int research_size, research_hsize; // research size and half size
+ int research_size_uv, research_hsize_uv; // research size and half size for chroma planes
+ uint32_t *ii_orig; // integral image
+ uint32_t *ii; // integral image starting after the 0-line and 0-column
+ int ii_w, ii_h; // width and height of the integral image
+ int ii_lz_32; // linesize in 32-bit units of the integral image
+ struct weighted_avg *wa; // weighted average of every pixel
+ int wa_linesize; // linesize for wa in struct size unit
+ double weight_lut[WEIGHT_LUT_SIZE]; // lookup table mapping (scaled) patch differences to their associated weights
+ double pdiff_lut_scale; // scale factor for patch differences before looking into the LUT
+ int max_meaningful_diff; // maximum difference considered (if the patch difference is too high we ignore the pixel)
+} NLMeansContext;
+
+#define OFFSET(x) offsetof(NLMeansContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption nlmeans_options[] = {
+ { "s", "denoising strength", OFFSET(sigma), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 1.0, 30.0, FLAGS },
+ { "p", "patch size", OFFSET(patch_size), AV_OPT_TYPE_INT, { .i64 = 3*2+1 }, 0, 99, FLAGS },
+ { "pc", "patch size for chroma planes", OFFSET(patch_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
+ { "r", "research window", OFFSET(research_size), AV_OPT_TYPE_INT, { .i64 = 7*2+1 }, 0, 99, FLAGS },
+ { "rc", "research window for chroma planes", OFFSET(research_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(nlmeans);
+
+static int query_formats(AVFilterContext *ctx)
+{
+ static const enum AVPixelFormat pix_fmts[] = {
+ AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
+ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
+ AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
+ AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
+ AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
+ AV_PIX_FMT_YUVJ411P,
+ AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP,
+ AV_PIX_FMT_NONE
+ };
+
+ AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
+ if (!fmts_list)
+ return AVERROR(ENOMEM);
+ return ff_set_common_formats(ctx, fmts_list);
+}
+
+/*
+ * M is a discrete map where every entry contains the sum of all the entries
+ * in the rectangle from the top-left origin of M to its coordinate. In the
+ * following schema, "i" contains the sum of the whole map:
+ *
+ * M = +----------+-----------------+----+
+ * | | | |
+ * | | | |
+ * | a| b| c|
+ * +----------+-----------------+----+
+ * | | | |
+ * | | | |
+ * | | X | |
+ * | | | |
+ * | d| e| f|
+ * +----------+-----------------+----+
+ * | | | |
+ * | g| h| i|
+ * +----------+-----------------+----+
+ *
+ * The sum of the X box can be calculated with:
+ * X = e-d-b+a
+ *
+ * See https://en.wikipedia.org/wiki/Summed_area_table
+ *
+ * The compute*_ssd functions compute the integral image M where every entry
+ * contains the sum of the squared difference of every corresponding pixels of
+ * two input planes of the same size as M.
+ */
+static inline int get_integral_patch_value(const uint32_t *ii, int ii_lz_32, int x, int y, int p)
+{
+ const int e = ii[(y + p ) * ii_lz_32 + (x + p )];
+ const int d = ii[(y + p ) * ii_lz_32 + (x - p - 1)];
+ const int b = ii[(y - p - 1) * ii_lz_32 + (x + p )];
+ const int a = ii[(y - p - 1) * ii_lz_32 + (x - p - 1)];
+ return e - d - b + a;
+}
+
+/**
+ * Compute squared difference of the safe area (the zone where s1 and s2
+ * overlap). It is likely the largest integral zone, so it is interesting to do
+ * as little checks as possible; contrary to the unsafe version of this
+ * function, we do not need any clipping here.
+ *
+ * The line above dst and the column to its left are always readable.
+ *
+ * This C version computes the SSD integral image using a scalar accumulator,
+ * while for SIMD implementation it is likely more interesting to use the
+ * two-loops algorithm variant.
+ */
+static void compute_safe_ssd_integral_image_c(uint32_t *dst, int dst_linesize_32,
+ const uint8_t *s1, int linesize1,
+ const uint8_t *s2, int linesize2,
+ int w, int h)
+{
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ uint32_t acc = dst[-1] - dst[-dst_linesize_32 - 1];
+
+ for (x = 0; x < w; x++) {
+ const int d = s1[x] - s2[x];
+ acc += d * d;
+ dst[x] = dst[-dst_linesize_32 + x] + acc;
+ }
+ s1 += linesize1;
+ s2 += linesize2;
+ dst += dst_linesize_32;
+ }
+}
+
+/**
+ * Compute squared difference of an unsafe area (the zone nor s1 nor s2 could
+ * be readable).
+ *
+ * On the other hand, the line above dst and the column to its left are always
+ * readable.
+ *
+ * There is little point in having this function SIMDified as it is likely too
+ * complex and only handle small portions of the image.
+ *
+ * @param dst integral image
+ * @param dst_linesize_32 integral image linesize (in 32-bit integers unit)
+ * @param startx integral starting x position
+ * @param starty integral starting y position
+ * @param src source plane buffer
+ * @param linesize source plane linesize
+ * @param offx source offsetting in x
+ * @param offy source offsetting in y
+ * @paran r absolute maximum source offsetting
+ * @param sw source width
+ * @param sh source height
+ * @param w width to compute
+ * @param h height to compute
+ */
+static inline void compute_unsafe_ssd_integral_image(uint32_t *dst, int dst_linesize_32,
+ int startx, int starty,
+ const uint8_t *src, int linesize,
+ int offx, int offy, int r, int sw, int sh,
+ int w, int h)
+{
+ int x, y;
+
+ for (y = starty; y < starty + h; y++) {
+ uint32_t acc = dst[y*dst_linesize_32 + startx - 1] - dst[(y-1)*dst_linesize_32 + startx - 1];
+ const int s1y = av_clip(y - r, 0, sh - 1);
+ const int s2y = av_clip(y - (r + offy), 0, sh - 1);
+
+ for (x = startx; x < startx + w; x++) {
+ const int s1x = av_clip(x - r, 0, sw - 1);
+ const int s2x = av_clip(x - (r + offx), 0, sw - 1);
+ const uint8_t v1 = src[s1y*linesize + s1x];
+ const uint8_t v2 = src[s2y*linesize + s2x];
+ const int d = v1 - v2;
+ acc += d * d;
+ dst[y*dst_linesize_32 + x] = dst[(y-1)*dst_linesize_32 + x] + acc;
+ }
+ }
+}
+
+/*
+ * Compute the sum of squared difference integral image
+ * http://www.ipol.im/pub/art/2014/57/
+ * Integral Images for Block Matching - Gabriele Facciolo, Nicolas Limare, Enric Meinhardt-Llopis
+ *
+ * @param ii integral image of dimension (w+e*2) x (h+e*2) with
+ * an additional zeroed top line and column already
+ * "applied" to the pointer value
+ * @param ii_linesize_32 integral image linesize (in 32-bit integers unit)
+ * @param src source plane buffer
+ * @param linesize source plane linesize
+ * @param offx x-offsetting ranging in [-e;e]
+ * @param offy y-offsetting ranging in [-e;e]
+ * @param w source width
+ * @param h source height
+ * @param e research padding edge
+ */
+static void compute_ssd_integral_image(uint32_t *ii, int ii_linesize_32,
+ const uint8_t *src, int linesize, int offx, int offy,
+ int e, int w, int h)
+{
+ // ii has a surrounding padding of thickness "e"
+ const int ii_w = w + e*2;
+ const int ii_h = h + e*2;
+
+ // we center the first source
+ const int s1x = e;
+ const int s1y = e;
+
+ // 2nd source is the frame with offsetting
+ const int s2x = e + offx;
+ const int s2y = e + offy;
+
+ // get the dimension of the overlapping rectangle where it is always safe
+ // to compare the 2 sources pixels
+ const int startx_safe = FFMAX(s1x, s2x);
+ const int starty_safe = FFMAX(s1y, s2y);
+ const int endx_safe = FFMIN(s1x + w, s2x + w);
+ const int endy_safe = FFMIN(s1y + h, s2y + h);
+
+ // top part where only one of s1 and s2 is still readable, or none at all
+ compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
+ 0, 0,
+ src, linesize,
+ offx, offy, e, w, h,
+ ii_w, starty_safe);
+
+ // fill the left column integral required to compute the central
+ // overlapping one
+ compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
+ 0, starty_safe,
+ src, linesize,
+ offx, offy, e, w, h,
+ startx_safe, endy_safe - starty_safe);
+
+ // main and safe part of the integral
+ av_assert1(startx_safe - s1x >= 0); av_assert1(startx_safe - s1x < w);
+ av_assert1(starty_safe - s1y >= 0); av_assert1(starty_safe - s1y < h);
+ av_assert1(startx_safe - s2x >= 0); av_assert1(startx_safe - s2x < w);
+ av_assert1(starty_safe - s2y >= 0); av_assert1(starty_safe - s2y < h);
+ compute_safe_ssd_integral_image_c(ii + starty_safe*ii_linesize_32 + startx_safe, ii_linesize_32,
+ src + (starty_safe - s1y) * linesize + (startx_safe - s1x), linesize,
+ src + (starty_safe - s2y) * linesize + (startx_safe - s2x), linesize,
+ endx_safe - startx_safe, endy_safe - starty_safe);
+
+ // right part of the integral
+ compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
+ endx_safe, starty_safe,
+ src, linesize,
+ offx, offy, e, w, h,
+ ii_w - endx_safe, endy_safe - starty_safe);
+
+ // bottom part where only one of s1 and s2 is still readable, or none at all
+ compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
+ 0, endy_safe,
+ src, linesize,
+ offx, offy, e, w, h,
+ ii_w, ii_h - endy_safe);
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ NLMeansContext *s = ctx->priv;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+ const int e = FFMAX(s->research_hsize, s->research_hsize_uv)
+ + FFMAX(s->patch_hsize, s->patch_hsize_uv);
+
+ s->chroma_w = FF_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
+ s->chroma_h = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
+ s->nb_planes = av_pix_fmt_count_planes(inlink->format);
+
+ /* Allocate the integral image with extra edges of thickness "e"
+ *
+ * +_+-------------------------------+
+ * |0|0000000000000000000000000000000|
+ * +-x-------------------------------+
+ * |0|\ ^ |
+ * |0| ii | e |
+ * |0| v |
+ * |0| +-----------------------+ |
+ * |0| | | |
+ * |0|<->| | |
+ * |0| e | | |
+ * |0| | | |
+ * |0| +-----------------------+ |
+ * |0| |
+ * |0| |
+ * |0| |
+ * +-+-------------------------------+
+ */
+ s->ii_w = inlink->w + e*2;
+ s->ii_h = inlink->h + e*2;
+
+ // align to 4 the linesize, "+1" is for the space of the left 0-column
+ s->ii_lz_32 = FFALIGN(s->ii_w + 1, 4);
+
+ // "+1" is for the space of the top 0-line
+ s->ii_orig = av_mallocz_array(s->ii_h + 1, s->ii_lz_32 * sizeof(*s->ii_orig));
+ if (!s->ii_orig)
+ return AVERROR(ENOMEM);
+
+ // skip top 0-line and left 0-column
+ s->ii = s->ii_orig + s->ii_lz_32 + 1;
+
+ // allocate weighted average for every pixel
+ s->wa_linesize = inlink->w;
+ s->wa = av_malloc_array(s->wa_linesize, inlink->h * sizeof(*s->wa));
+ if (!s->wa)
+ return AVERROR(ENOMEM);
+
+ return 0;
+}
+
+struct thread_data {
+ const uint8_t *src;
+ int src_linesize;
+ int startx, starty;
+ int endx, endy;
+ const uint32_t *ii_start;
+ int p;
+};
+
+static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+{
+ int x, y;
+ NLMeansContext *s = ctx->priv;
+ const struct thread_data *td = arg;
+ const uint8_t *src = td->src;
+ const int src_linesize = td->src_linesize;
+ const int process_h = td->endy - td->starty;
+ const int slice_start = (process_h * jobnr ) / nb_jobs;
+ const int slice_end = (process_h * (jobnr+1)) / nb_jobs;
+ const int starty = td->starty + slice_start;
+ const int endy = td->starty + slice_end;
+
+ for (y = starty; y < endy; y++) {
+ for (x = td->startx; x < td->endx; x++) {
+ const int patch_diff_sq = get_integral_patch_value(td->ii_start, s->ii_lz_32, x, y, td->p);
+ if (patch_diff_sq < s->max_meaningful_diff) {
+ struct weighted_avg *wa = &s->wa[y*s->wa_linesize + x];
+ const int weight_lut_idx = patch_diff_sq * s->pdiff_lut_scale;
+ const double weight = s->weight_lut[weight_lut_idx]; // exp(-patch_diff_sq * s->pdiff_scale)
+ wa->total_weight += weight;
+ wa->sum += weight * src[y*src_linesize + x];
+ }
+ }
+ }
+ return 0;
+}
+
+static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r,
+ uint8_t *dst, int dst_linesize,
+ const uint8_t *src, int src_linesize)
+{
+ int x, y;
+ int offx, offy;
+ NLMeansContext *s = ctx->priv;
+ /* patches center points cover the whole research window so the patches
+ * themselves overflow the research window */
+ const int e = r + p;
+ /* focus an integral pointer on the centered image (s1) */
+ const uint32_t *centered_ii = s->ii + e*s->ii_lz_32 + e;
+
+ memset(s->wa, 0, s->wa_linesize * h * sizeof(*s->wa));
+
+ for (offy = -r; offy <= r; offy++) {
+ for (offx = -r; offx <= r; offx++) {
+ if (offx || offy) {
+ struct thread_data td = {
+ .src = src + offy*src_linesize + offx,
+ .src_linesize = src_linesize,
+ .startx = FFMAX(0, -offx),
+ .starty = FFMAX(0, -offy),
+ .endx = FFMIN(w, w - offx),
+ .endy = FFMIN(h, h - offy),
+ .ii_start = centered_ii + offy*s->ii_lz_32 + offx,
+ .p = p,
+ };
+
+ compute_ssd_integral_image(s->ii, s->ii_lz_32,
+ src, src_linesize,
+ offx, offy, e, w, h);
+ ctx->internal->execute(ctx, nlmeans_slice, &td, NULL,
+ FFMIN(td.endy - td.starty, ff_filter_get_nb_threads(ctx)));
+ }
+ }
+ }
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
+ struct weighted_avg *wa = &s->wa[y*s->wa_linesize + x];
+
+ // Also weight the centered pixel
+ wa->total_weight += 1.0;
+ wa->sum += 1.0 * src[y*src_linesize + x];
+
+ dst[y*dst_linesize + x] = av_clip_uint8(wa->sum / wa->total_weight);
+ }
+ }
+ return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+ int i;
+ AVFilterContext *ctx = inlink->dst;
+ NLMeansContext *s = ctx->priv;
+ AVFilterLink *outlink = ctx->outputs[0];
+
+ AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+ if (!out) {
+ av_frame_free(&in);
+ return AVERROR(ENOMEM);
+ }
+ av_frame_copy_props(out, in);
+
+ for (i = 0; i < s->nb_planes; i++) {
+ const int w = i ? s->chroma_w : inlink->w;
+ const int h = i ? s->chroma_h : inlink->h;
+ const int p = i ? s->patch_hsize_uv : s->patch_hsize;
+ const int r = i ? s->research_hsize_uv : s->research_hsize;
+ nlmeans_plane(ctx, w, h, p, r,
+ out->data[i], out->linesize[i],
+ in->data[i], in->linesize[i]);
+ }
+
+ av_frame_free(&in);
+ return ff_filter_frame(outlink, out);
+}
+
+#define CHECK_ODD_FIELD(field, name) do { \
+ if (!(s->field & 1)) { \
+ s->field |= 1; \
+ av_log(ctx, AV_LOG_WARNING, name " size must be odd, " \
+ "setting it to %d\n", s->field); \
+ } \
+} while (0)
+
+static av_cold int init(AVFilterContext *ctx)
+{
+ int i;
+ NLMeansContext *s = ctx->priv;
+ const double h = s->sigma * 10.;
+
+ s->pdiff_scale = 1. / (h * h);
+ s->max_meaningful_diff = -log(1/255.) / s->pdiff_scale;
+ s->pdiff_lut_scale = 1./s->max_meaningful_diff * WEIGHT_LUT_SIZE;
+ av_assert0((s->max_meaningful_diff - 1) * s->pdiff_lut_scale < FF_ARRAY_ELEMS(s->weight_lut));
+ for (i = 0; i < WEIGHT_LUT_SIZE; i++)
+ s->weight_lut[i] = exp(-i / s->pdiff_lut_scale * s->pdiff_scale);
+
+ CHECK_ODD_FIELD(research_size, "Luma research window");
+ CHECK_ODD_FIELD(patch_size, "Luma patch");
+
+ if (!s->research_size_uv) s->research_size_uv = s->research_size;
+ if (!s->patch_size_uv) s->patch_size_uv = s->patch_size;
+
+ CHECK_ODD_FIELD(research_size_uv, "Chroma research window");
+ CHECK_ODD_FIELD(patch_size_uv, "Chroma patch");
+
+ s->research_hsize = s->research_size / 2;
+ s->research_hsize_uv = s->research_size_uv / 2;
+ s->patch_hsize = s->patch_size / 2;
+ s->patch_hsize_uv = s->patch_size_uv / 2;
+
+ av_log(ctx, AV_LOG_INFO, "Research window: %dx%d / %dx%d, patch size: %dx%d / %dx%d\n",
+ s->research_size, s->research_size, s->research_size_uv, s->research_size_uv,
+ s->patch_size, s->patch_size, s->patch_size_uv, s->patch_size_uv);
+
+ return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ NLMeansContext *s = ctx->priv;
+ av_freep(&s->ii_orig);
+ av_freep(&s->wa);
+}
+
+static const AVFilterPad nlmeans_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_input,
+ .filter_frame = filter_frame,
+ },
+ { NULL }
+};
+
+static const AVFilterPad nlmeans_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ },
+ { NULL }
+};
+
+AVFilter ff_vf_nlmeans = {
+ .name = "nlmeans",
+ .description = NULL_IF_CONFIG_SMALL("Non-local means denoiser."),
+ .priv_size = sizeof(NLMeansContext),
+ .init = init,
+ .uninit = uninit,
+ .query_formats = query_formats,
+ .inputs = nlmeans_inputs,
+ .outputs = nlmeans_outputs,
+ .priv_class = &nlmeans_class,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+};
1
0