From b804eb4323a01f55727ac48475a9e3c257532ab5 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Mon, 21 Apr 2014 11:01:10 +0200 Subject: lavu/hash: add hash_final helpers. The helpers use local memory to compute the final hash, making AV_HASH_MAX_SIZE safe to use. --- doc/APIchanges | 3 +++ 1 file changed, 3 insertions(+) (limited to 'doc') diff --git a/doc/APIchanges b/doc/APIchanges index 8fe5ff2e7c..8d001cd6c4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2012-10-22 API changes, most recent first: +2014-04-29 - xxxxxxx - lavu 52.80.0 - hash.h + Add av_hash_final_bin(), av_hash_final_hex() and av_hash_final_b64(). + 2014-03-07 - 8b2a130 - lavc 55.50.0 / 55.53.100 - dxva2.h Add FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO for old Intel GPUs. -- cgit v1.2.3 From 70beebe35764f4dbf7623683326675bf5d8ee2e6 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Thu, 17 Apr 2014 09:36:44 +0200 Subject: lavc: minor bump and APIchanges for AVCodecDescriptor.mime_types. The minor bump also covers AV_CODEC_ID_BIN_DATA. --- doc/APIchanges | 3 +++ libavcodec/version.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/APIchanges b/doc/APIchanges index 8d001cd6c4..a35501a2bd 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2012-10-22 API changes, most recent first: +2014-04-29 - 1bf6396 - lavc 55.60.100 - avcodec.h + Add AVCodecDescriptor.mime_types field. + 2014-04-29 - xxxxxxx - lavu 52.80.0 - hash.h Add av_hash_final_bin(), av_hash_final_hex() and av_hash_final_b64(). diff --git a/libavcodec/version.h b/libavcodec/version.h index 43a4cc4946..44ec052198 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,8 +29,8 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 55 -#define LIBAVCODEC_VERSION_MINOR 59 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MINOR 60 +#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- cgit v1.2.3 From 50ed6e3ce635e47898c0cb9e3d57f3b7e0a67ff4 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Mon, 14 Apr 2014 13:49:12 +0200 Subject: lavf/concatdec: implement automatic conversions. --- doc/demuxers.texi | 8 +++++ libavformat/concatdec.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 23cec5a386..d51b9d0748 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -128,6 +128,14 @@ If set to 0, any file name is accepted. The default is -1, it is equivalent to 1 if the format was automatically probed and 0 otherwise. +@item auto_convert +If set to 1, try to perform automatic conversions on packet data to make the +streams concatenable. + +Currently, the only conversion is adding the h264_mp4toannexb bitstream +filter to H.264 streams in MP4 format. This is necessary in particular if +there are resolution changes. + @end table @section flv diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 5751d0c726..4590dc5923 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -18,7 +18,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavutil/avstring.h" +#include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "avformat.h" @@ -31,6 +33,7 @@ typedef enum ConcatMatchMode { } ConcatMatchMode; typedef struct ConcatStream { + AVBitStreamFilterContext *bsf; int out_stream_index; } ConcatStream; @@ -51,6 +54,7 @@ typedef struct { int safe; int seekable; ConcatMatchMode stream_match_mode; + unsigned auto_convert; } ConcatContext; static int concat_probe(AVProbeData *probe) @@ -150,8 +154,17 @@ static int copy_stream_props(AVStream *st, AVStream *source_st) { int ret; - if (st->codec->codec_id || !source_st->codec->codec_id) + if (st->codec->codec_id || !source_st->codec->codec_id) { + if (st->codec->extradata_size < source_st->codec->extradata_size) { + ret = ff_alloc_extradata(st->codec, + source_st->codec->extradata_size); + if (ret < 0) + return ret; + } + memcpy(st->codec->extradata, source_st->codec->extradata, + source_st->codec->extradata_size); return 0; + } if ((ret = avcodec_copy_context(st->codec, source_st->codec)) < 0) return ret; st->r_frame_rate = source_st->r_frame_rate; @@ -161,6 +174,27 @@ static int copy_stream_props(AVStream *st, AVStream *source_st) return 0; } +static int detect_stream_specific(AVFormatContext *avf, int idx) +{ + ConcatContext *cat = avf->priv_data; + AVStream *st = cat->avf->streams[idx]; + ConcatStream *cs = &cat->cur_file->streams[idx]; + AVBitStreamFilterContext *bsf; + + if (cat->auto_convert && st->codec->codec_id == AV_CODEC_ID_H264 && + (st->codec->extradata_size < 4 || AV_RB32(st->codec->extradata) != 1)) { + av_log(cat->avf, AV_LOG_INFO, + "Auto-inserting h264_mp4toannexb bitstream filter\n"); + if (!(bsf = av_bitstream_filter_init("h264_mp4toannexb"))) { + av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb bitstream filter " + "required for H.264 streams\n"); + return AVERROR_BSF_NOT_FOUND; + } + cs->bsf = bsf; + } + return 0; +} + static int match_streams_one_to_one(AVFormatContext *avf) { ConcatContext *cat = avf->priv_data; @@ -216,6 +250,8 @@ static int match_streams(AVFormatContext *avf) if (!map) return AVERROR(ENOMEM); cat->cur_file->streams = map; + memset(map + cat->cur_file->nb_streams, 0, + (cat->avf->nb_streams - cat->cur_file->nb_streams) * sizeof(*map)); for (i = cat->cur_file->nb_streams; i < cat->avf->nb_streams; i++) map[i].out_stream_index = -1; @@ -231,6 +267,9 @@ static int match_streams(AVFormatContext *avf) } if (ret < 0) return ret; + for (i = cat->cur_file->nb_streams; i < cat->avf->nb_streams; i++) + if ((ret = detect_stream_specific(avf, i)) < 0) + return ret; cat->cur_file->nb_streams = cat->avf->nb_streams; return 0; } @@ -390,6 +429,46 @@ static int open_next_file(AVFormatContext *avf) return open_file(avf, fileno); } +static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) +{ + AVStream *st = avf->streams[cs->out_stream_index]; + AVBitStreamFilterContext *bsf; + AVPacket pkt2; + int ret; + + av_assert0(cs->out_stream_index >= 0); + for (bsf = cs->bsf; bsf; bsf = bsf->next) { + pkt2 = *pkt; + ret = av_bitstream_filter_filter(bsf, st->codec, NULL, + &pkt2.data, &pkt2.size, + pkt->data, pkt->size, + !!(pkt->flags & AV_PKT_FLAG_KEY)); + if (ret < 0) { + av_packet_unref(pkt); + return ret; + } + av_assert0(pkt2.buf); + if (ret == 0 && pkt2.data != pkt->data) { + if ((ret = av_copy_packet(&pkt2, pkt)) < 0) { + av_free(pkt2.data); + return ret; + } + ret = 1; + } + if (ret > 0) { + av_free_packet(pkt); + pkt2.buf = av_buffer_create(pkt2.data, pkt2.size, + av_buffer_default_free, NULL, 0); + if (!pkt2.buf) { + av_free(pkt2.data); + return AVERROR(ENOMEM); + } + } + *pkt = pkt2; + } + return 0; +} + static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) { ConcatContext *cat = avf->priv_data; @@ -418,6 +497,8 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) pkt->stream_index = cs->out_stream_index; break; } + if ((ret = filter_packet(avf, cs, pkt))) + return ret; delta = av_rescale_q(cat->cur_file->start_time - cat->avf->start_time, AV_TIME_BASE_Q, @@ -524,6 +605,8 @@ static int concat_seek(AVFormatContext *avf, int stream, static const AVOption options[] = { { "safe", "enable safe mode", OFFSET(safe), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DEC }, + { "auto_convert", "automatically convert bitstream format", + OFFSET(auto_convert), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC }, { NULL } }; -- cgit v1.2.3 From 41334fcab41fee1a5a869c9f87c4a1d59a627b57 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Fri, 25 Apr 2014 14:01:43 +0200 Subject: lavfi/drawtext: allow to format pts as HH:MM:SS.mmm. --- doc/filters.texi | 9 ++++++++- libavfilter/vf_drawtext.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/filters.texi b/doc/filters.texi index e943923e00..a8b2668889 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -3850,7 +3850,14 @@ The frame number, starting from 0. A 1 character description of the current picture type. @item pts -The timestamp of the current frame, in seconds, with microsecond accuracy. +The timestamp of the current frame. +It can take up to two arguments. + +The first argument is the format of the timestamp; it defaults to @code{flt} +for seconds as a decimal number with microsecond accuracy; @code{hms} stands +for a formatted @var{[-]HH:MM:SS.mmm} timestamp with millisecond accuracy. + +The second argument is an offset added to the timestamp. @end table diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index f7486c9c6e..995a3e2ca3 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -699,8 +699,41 @@ static int func_pts(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { DrawTextContext *s = ctx->priv; + const char *fmt; + double pts = s->var_values[VAR_T]; + int ret; - av_bprintf(bp, "%.6f", s->var_values[VAR_T]); + fmt = argc >= 1 ? argv[0] : "flt"; + if (argc >= 2) { + int64_t delta; + if ((ret = av_parse_time(&delta, argv[1], 1)) < 0) { + av_log(ctx, AV_LOG_ERROR, "Invalid delta '%s'\n", argv[1]); + return ret; + } + pts += (double)delta / AV_TIME_BASE; + } + if (!strcmp(fmt, "flt")) { + av_bprintf(bp, "%.6f", s->var_values[VAR_T]); + } else if (!strcmp(fmt, "hms")) { + if (isnan(pts)) { + av_bprintf(bp, " ??:??:??.???"); + } else { + int64_t ms = round(pts * 1000); + char sign = ' '; + if (ms < 0) { + sign = '-'; + ms = -ms; + } + av_bprintf(bp, "%c%02d:%02d:%02d.%03d", sign, + (int)(ms / (60 * 60 * 1000)), + (int)(ms / (60 * 1000)) % 60, + (int)(ms / 1000) % 60, + (int)ms % 1000); + } + } else { + av_log(ctx, AV_LOG_ERROR, "Invalid format '%s'\n", fmt); + return AVERROR(EINVAL); + } return 0; } @@ -776,7 +809,7 @@ static const struct drawtext_function { { "expr", 1, 1, 0, func_eval_expr }, { "e", 1, 1, 0, func_eval_expr }, { "pict_type", 0, 0, 0, func_pict_type }, - { "pts", 0, 0, 0, func_pts }, + { "pts", 0, 2, 0, func_pts }, { "gmtime", 0, 1, 'G', func_strftime }, { "localtime", 0, 1, 'L', func_strftime }, { "frame_num", 0, 0, 0, func_frame_num }, -- cgit v1.2.3