[FFmpeg-devel] [PATCH] lavu/hwcontext_opencl.h: fix build on macOS

2017-11-27 Thread Rodger Combs
---
 libavutil/hwcontext_opencl.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavutil/hwcontext_opencl.h b/libavutil/hwcontext_opencl.h
index 8e34df44cd..ef54486c95 100644
--- a/libavutil/hwcontext_opencl.h
+++ b/libavutil/hwcontext_opencl.h
@@ -19,7 +19,11 @@
 #ifndef AVUTIL_HWCONTEXT_OPENCL_H
 #define AVUTIL_HWCONTEXT_OPENCL_H
 
+#ifdef __APPLE__
+#include 
+#else
 #include 
+#endif
 
 #include "frame.h"
 
-- 
2.14.3

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-11-21 Thread Rodger Combs


> On Nov 21, 2017, at 19:03, Rostislav Pehlivanov  wrote:
> 
> On 2 August 2017 at 00:35, Rodger Combs  <mailto:rodger.co...@gmail.com>> wrote:
> 
>> 
>>> On Aug 1, 2017, at 18:25, James Almer  wrote:
>>> 
>>> On 8/1/2017 3:33 AM, Rodger Combs wrote:
>>>> ---
>>>> libavformat/flacenc.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>> 
>>>> diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
>>>> index 9768b6a..1906aee 100644
>>>> --- a/libavformat/flacenc.c
>>>> +++ b/libavformat/flacenc.c
>>>> @@ -322,7 +322,7 @@ static int flac_write_trailer(struct
>> AVFormatContext *s)
>>>>if (!c->write_header || !streaminfo)
>>>>return 0;
>>>> 
>>>> -if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
>>>> +if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo ||
>> s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
>>> 
>>> In what situation would stream extradata or c->streaminfo be smaller
>>> than FLAC_STREAMINFO_SIZE? Nothing changes par->extradata anywhere, and
>>> c->streaminfo is always allocated with FLAC_STREAMINFO_SIZE bytes of
>> memory.
>>> I have the feeling i already asked this before, but not sure if you
>>> answered it. Apologies if you did.
>> 
>> It shouldn't happen in normal cases, but you could imagine a case with
>> remuxing a corrupted input file.
>> 
> 
> Shouldn't the demuxer handle this?

Even in e.g. MKV?

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v4 14/14] avcodec/videotoolbox: fix whitespace

2017-11-10 Thread Rodger Combs
Patchset LGTM.

> On Nov 10, 2017, at 15:40, Aman Gupta  wrote:
> 
> From: Aman Gupta 
> 
> ---
> libavcodec/videotoolbox.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> index 9eb06e619f..04c558935d 100644
> --- a/libavcodec/videotoolbox.c
> +++ b/libavcodec/videotoolbox.c
> @@ -88,7 +88,7 @@ int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, 
> AVFrame *frame)
> 
> CFDataRef ff_videotoolbox_avcc_extradata_create(AVCodecContext *avctx)
> {
> -H264Context *h = avctx->priv_data;
> +H264Context *h = avctx->priv_data;
> CFDataRef data = NULL;
> uint8_t *p;
> int vt_extradata_size = 6 + 2 + h->ps.sps->data_size + 3 + 
> h->ps.pps->data_size;
> @@ -897,7 +897,7 @@ static int videotoolbox_start(AVCodecContext *avctx)
> case kVTVideoDecoderMalfunctionErr:
> av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox malfunction.\n");
> return AVERROR(EINVAL);
> -case kVTVideoDecoderBadDataErr :
> +case kVTVideoDecoderBadDataErr:
> av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox reported invalid 
> data.\n");
> return AVERROR_INVALIDDATA;
> case 0:
> -- 
> 2.14.2
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/4] lavf: identify MP1 and MP2 as distinct containers from MP3

2017-10-19 Thread Rodger Combs
This allows us to report the correct codec ID here
---
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  4 +--
 libavformat/mp3dec.c | 66 +++-
 libavformat/utils.c  |  3 +--
 libavformat/version.h|  4 +--
 5 files changed, 50 insertions(+), 29 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2522a3e768..a978482211 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -296,7 +296,9 @@ OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o 
mov_chan.o replaygain.o
 OBJS-$(CONFIG_MOV_MUXER) += movenc.o avc.o hevc.o vpcc.o \
 movenchint.o mov_chan.o rtp.o \
 movenccenc.o rawutils.o
+OBJS-$(CONFIG_MP1_DEMUXER)   += mp3dec.o replaygain.o
 OBJS-$(CONFIG_MP1_MUXER) += rawenc.o
+OBJS-$(CONFIG_MP2_DEMUXER)   += mp3dec.o replaygain.o
 OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
 OBJS-$(CONFIG_MP3_DEMUXER)   += mp3dec.o replaygain.o
 OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 32e9a979bc..c02cdacb7b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -189,8 +189,8 @@ static void register_all(void)
 REGISTER_DEMUXER (MM,   mm);
 REGISTER_MUXDEMUX(MMF,  mmf);
 REGISTER_MUXDEMUX(MOV,  mov);
-REGISTER_MUXER   (MP1,  mp1);
-REGISTER_MUXER   (MP2,  mp2);
+REGISTER_MUXDEMUX(MP1,  mp1);
+REGISTER_MUXDEMUX(MP2,  mp2);
 REGISTER_MUXDEMUX(MP3,  mp3);
 REGISTER_MUXER   (MP4,  mp4);
 REGISTER_DEMUXER (MPC,  mpc);
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index a5c4f2ea12..d405a98d7b 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -66,7 +66,7 @@ static int check(AVIOContext *pb, int64_t pos, uint32_t 
*header);
 
 /* mp3 read */
 
-static int mp3_read_probe(AVProbeData *p)
+static int mpa_read_probe(AVProbeData *p, int layer)
 {
 int max_frames, first_frames = 0;
 int whole_used = 0;
@@ -89,7 +89,7 @@ static int mp3_read_probe(AVProbeData *p)
 
 header = AV_RB32(buf2);
 ret = avpriv_mpegaudio_decode_header(&h, header);
-if (ret != 0)
+if (ret != 0 || h.layer != layer)
 break;
 buf2 += h.frame_size;
 }
@@ -105,7 +105,8 @@ static int mp3_read_probe(AVProbeData *p)
 if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
 else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
 else if(max_frames>=4 && max_frames >= p->buf_size/1) return 
AVPROBE_SCORE_EXTENSION / 2;
-else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
+else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size &&
+(p->buf_size < PROBE_BUF_MAX || layer == 3))
return p->buf_size < PROBE_BUF_MAX ? 
AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
 else if(first_frames > 1 && whole_used) return 5;
 else if(max_frames>=1 && max_frames >= p->buf_size/1) return 1;
@@ -113,6 +114,12 @@ static int mp3_read_probe(AVProbeData *p)
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
 
+#define READ_PROBE(l) \
+static int mp##l##_read_probe(AVProbeData *p) \
+{ \
+return mpa_read_probe(p, l); \
+}
+
 static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t 
duration)
 {
 int i;
@@ -341,7 +348,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream 
*st, int64_t base)
 return 0;
 }
 
-static int mp3_read_header(AVFormatContext *s)
+static int mpa_read_header(AVFormatContext *s, enum AVCodecID id)
 {
 MP3DecContext *mp3 = s->priv_data;
 AVStream *st;
@@ -357,7 +364,7 @@ static int mp3_read_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_MP3;
+st->codecpar->codec_id = id;
 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
 st->start_time = 0;
 
@@ -422,6 +429,12 @@ static int mp3_read_header(AVFormatContext *s)
 return 0;
 }
 
+#define READ_HEADER(l) \
+static int mp##l##_read_header(AVFormatContext *s) \
+{ \
+return mpa_read_header(s, AV_CODEC_ID_MP##l); \
+}
+
 #define MP3_PACKET_SIZE 1024
 
 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -582,23 +595,30 @@ static const AVOption options[] = {
 { NULL },
 };
 
-static const AVClass demuxer_class = {
-.class_name = "mp3",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-.category   = AV_CLASS_CATEGORY_DEMUXER,
+#define DECLARE_LAYER(l, ext) \
+READ_PROBE

[FFmpeg-devel] [PATCH 4/4] lavf/movdec: request probing for an ambiguous codec tag

2017-10-19 Thread Rodger Combs
---
 libavformat/isom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 77983c5eaa..8b3f88ce74 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -519,6 +519,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);
 if (codec_id)
 st->codecpar->codec_id = codec_id;
+if (object_type_id == 0x6B) // This can be either MP3 or MP2; let 
probe_codec decide
+st->request_probe = 5;
 av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id);
 len = ff_mp4_read_descr(fc, pb, &tag);
 if (tag == MP4DecSpecificDescrTag) {
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/4] lavf: add MP1 muxer

2017-10-19 Thread Rodger Combs
---
 libavformat/Makefile |  1 +
 libavformat/allformats.c |  1 +
 libavformat/rawenc.c | 13 +
 3 files changed, 15 insertions(+)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index d955a8b12a..2522a3e768 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -296,6 +296,7 @@ OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o 
mov_chan.o replaygain.o
 OBJS-$(CONFIG_MOV_MUXER) += movenc.o avc.o hevc.o vpcc.o \
 movenchint.o mov_chan.o rtp.o \
 movenccenc.o rawutils.o
+OBJS-$(CONFIG_MP1_MUXER) += rawenc.o
 OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
 OBJS-$(CONFIG_MP3_DEMUXER)   += mp3dec.o replaygain.o
 OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 405ddb5ad9..32e9a979bc 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -189,6 +189,7 @@ static void register_all(void)
 REGISTER_DEMUXER (MM,   mm);
 REGISTER_MUXDEMUX(MMF,  mmf);
 REGISTER_MUXDEMUX(MOV,  mov);
+REGISTER_MUXER   (MP1,  mp1);
 REGISTER_MUXER   (MP2,  mp2);
 REGISTER_MUXDEMUX(MP3,  mp3);
 REGISTER_MUXER   (MP4,  mp4);
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index f640121cb4..1a30ba6c05 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -361,6 +361,19 @@ AVOutputFormat ff_mlp_muxer = {
 };
 #endif
 
+#if CONFIG_MP1_MUXER
+AVOutputFormat ff_mp1_muxer = {
+.name  = "mp1",
+.long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
+.mime_type = "audio/mpeg",
+.extensions= "mp1,m1a",
+.audio_codec   = AV_CODEC_ID_MP1,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_MP2_MUXER
 AVOutputFormat ff_mp2_muxer = {
 .name  = "mp2",
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/4] lavf/utils: add MP2 to the probing list

2017-10-19 Thread Rodger Combs
---
 libavformat/utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index a54687d239..416152eb39 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -329,6 +329,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "loas",  AV_CODEC_ID_AAC_LATM,   AVMEDIA_TYPE_AUDIO },
 { "m4v",   AV_CODEC_ID_MPEG4,  AVMEDIA_TYPE_VIDEO },
 { "mjpeg_2000",AV_CODEC_ID_JPEG2000,   AVMEDIA_TYPE_VIDEO },
+{ "mp2",   AV_CODEC_ID_MP2,AVMEDIA_TYPE_AUDIO },
 { "mp3",   AV_CODEC_ID_MP3,AVMEDIA_TYPE_AUDIO },
 { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
 { "truehd",AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO },
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] tools/libav-merge-next-commit: run properly on a branch that isn't master

2017-09-26 Thread Rodger Combs
---
 tools/libav-merge-next-commit | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libav-merge-next-commit b/tools/libav-merge-next-commit
index 9bd03fabf8..e2674008f6 100755
--- a/tools/libav-merge-next-commit
+++ b/tools/libav-merge-next-commit
@@ -7,7 +7,7 @@ fi
 
 [ "$1" = "noop" ] && merge_opts="-s ours"
 
-nextrev=$(git rev-list libav/master --not master --no-merges | tail -n1)
+nextrev=$(git rev-list libav/master --not HEAD --no-merges | tail -n1)
 if [ -z "$nextrev" ]; then
 printf "Nothing to merge..\n"
 exit 0
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/3] lavf/dashenc: unset codec_tag when it doesn't match the underlying muxer

2017-09-26 Thread Rodger Combs
---
 libavformat/dashenc.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 7ed48905f5..3a4b6478d1 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -763,6 +763,11 @@ static int dash_init(AVFormatContext *s)
 ctx->avoid_negative_ts = s->avoid_negative_ts;
 ctx->flags = s->flags;
 
+if (ctx->oformat->codec_tag &&
+av_codec_get_id (ctx->oformat->codec_tag, st->codecpar->codec_tag) 
!= st->codecpar->codec_id &&
+av_codec_get_tag(ctx->oformat->codec_tag, st->codecpar->codec_id) 
!= 0)
+st->codecpar->codec_tag = 0;
+
 if ((ret = avio_open_dyn_buf(&ctx->pb)) < 0)
 return ret;
 
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/3] lavf/dashenc: add format_options option, mirroring segment.c

2017-09-26 Thread Rodger Combs
---
 libavformat/dashenc.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 92d398ab50..7ed48905f5 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -100,6 +100,7 @@ typedef struct DASHContext {
 AVRational min_frame_rate, max_frame_rate;
 int ambiguous_frame_rate;
 const char *utc_timing_url;
+const char *format_options_str;
 } DASHContext;
 
 static struct codec_string {
@@ -785,6 +786,17 @@ static int dash_init(AVFormatContext *s)
 dict_set_int(&opts, "cluster_time_limit", c->min_seg_duration / 
1000, 0);
 dict_set_int(&opts, "cluster_size_limit", 5 * 1024 * 1024, 0); // 
set a large cluster size limit
 }
+
+if (c->format_options_str) {
+ret = av_dict_parse_string(&opts, c->format_options_str, "=", ":", 
0);
+if (ret < 0) {
+av_log(s, AV_LOG_ERROR, "Could not parse format options list 
'%s'\n",
+   c->format_options_str);
+av_dict_free(&opts);
+return ret;
+}
+}
+
 if ((ret = avformat_init_output(ctx, &opts)) < 0)
 return ret;
 os->ctx_inited = 1;
@@ -1190,6 +1202,7 @@ static const AVOption options[] = {
 { "init_seg_name", "DASH-templated name to used for the initialization 
segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = 
"init-stream$RepresentationID$.m4s"}, 0, 0, E },
 { "media_seg_name", "DASH-templated name to used for the media segments", 
OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = 
"chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
 { "utc_timing_url", "URL of the page that will return the UTC timestamp in 
ISO format", OFFSET(utc_timing_url), AV_OPT_TYPE_STRING, { 0 }, 0, 0, E },
+{ "format_options", "set list of options for the underlying mp4 muxer", 
OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
 { NULL },
 };
 
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/3] lavf/dashenc: fix merge error (write_header vs init_output)

2017-09-26 Thread Rodger Combs
---
 libavformat/dashenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 240ff41380..92d398ab50 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -785,7 +785,7 @@ static int dash_init(AVFormatContext *s)
 dict_set_int(&opts, "cluster_time_limit", c->min_seg_duration / 
1000, 0);
 dict_set_int(&opts, "cluster_size_limit", 5 * 1024 * 1024, 0); // 
set a large cluster size limit
 }
-if ((ret = avformat_write_header(ctx, &opts)) < 0)
+if ((ret = avformat_init_output(ctx, &opts)) < 0)
 return ret;
 os->ctx_inited = 1;
 avio_flush(ctx->pb);
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/file: fix build on Android NDK with unified headers

2017-09-26 Thread Rodger Combs
I used this rather absurd configure invocation:

BINDIR=$(realpath $(dirname $(ndk-which gcc)))
NDKDIR=$(dirname $(dirname $(dirname $(dirname $(dirname $BINDIR)
TARGET=16
ARCH=arm
TRIPLE=arm-linux-androideabi
SUFFIX=-4.9
PLATARCH=arm

../configure \
--enable-cross-compile \
--arch=$ARCH \
--cross_prefix="$NDKDIR/toolchains/$TRIPLE$SUFFIX/prebuilt/darwin-x86_64/bin/$TRIPLE-"
 \
--extra-cflags=-D__ANDROID_API__=$TARGET \
--extra-cflags="--sysroot=$NDKDIR/sysroot" \
--extra-cflags="-isystem $NDKDIR/sysroot/usr/include/$TRIPLE" \
--extra-cflags="-mfloat-abi=softfp" \
--extra-ldflags="--sysroot=$NDKDIR/platforms/android-$TARGET/arch-$PLATARCH" \
--extra-ldexeflags=-pie \
--enable-debug \
--target-os=android

The issue is that the unified headers don't declare mmap() on target API 
versions before 21 on 32-bit platforms when 
__USE_FILE_OFFSET64/_FILE_OFFSET_BITS=64 is set, because this sets off_t to be 
off64_t, and mmap64 isn't available until API 21. This doesn't matter for 
ffmpeg, since we never use the offset arg anyway, so we can just declare the 
function ourselves.

I'm not sure what one would do about this in configure.

> On Sep 26, 2017, at 06:27, Carl Eugen Hoyos  wrote:
> 
> 2017-09-26 3:52 GMT+02:00 Rodger Combs :
> 
>> +#  if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 && 
>> !defined(__LP64__)
>> +#   ifdef mmap
>> +#undef mmap
>> +#   endif
>> +void* mmap(void*, size_t, int, int, int, __kernel_off_t);
> 
> How can this issue be reproduced?
> 
> Shouldn't this be checked in configure?
> 
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/movdec: flag chapter streams as such, even when not reading them

2017-09-25 Thread Rodger Combs
This allows the use of the `ignore_chapters` option to avoid performing
extra seeks at startup without producing "subtitle" chapter streams.
---
 libavformat/mov.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2519707345..5b40408d62 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5780,6 +5780,7 @@ static void mov_read_chapters(AVFormatContext *s)
 int64_t cur_pos;
 int i, j;
 int chapter_track;
+int read_contents = (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && 
!mov->ignore_chapters;
 
 for (j = 0; j < mov->nb_chapter_tracks; j++) {
 chapter_track = mov->chapter_tracks[j];
@@ -5799,7 +5800,7 @@ static void mov_read_chapters(AVFormatContext *s)
 
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 st->disposition |= AV_DISPOSITION_ATTACHED_PIC | 
AV_DISPOSITION_TIMED_THUMBNAILS;
-if (st->nb_index_entries) {
+if (st->nb_index_entries && read_contents) {
 // Retrieve the first frame, if possible
 AVPacket pkt;
 AVIndexEntry *sample = &st->index_entries[0];
@@ -5819,6 +5820,10 @@ static void mov_read_chapters(AVFormatContext *s)
 st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
 st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA;
 st->discard = AVDISCARD_ALL;
+
+if (!read_contents)
+continue;
+
 for (i = 0; i < st->nb_index_entries; i++) {
 AVIndexEntry *sample = &st->index_entries[i];
 int64_t end = i+1 < st->nb_index_entries ? 
st->index_entries[i+1].timestamp : st->duration;
@@ -5869,7 +5874,8 @@ static void mov_read_chapters(AVFormatContext *s)
 }
 }
 finish:
-avio_seek(sc->pb, cur_pos, SEEK_SET);
+if (read_contents)
+avio_seek(sc->pb, cur_pos, SEEK_SET);
 }
 }
 
@@ -6206,9 +6212,11 @@ static int mov_read_header(AVFormatContext *s)
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
+
+if (mov->nb_chapter_tracks > 0)
+mov_read_chapters(s);
+
 if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
-if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters)
-mov_read_chapters(s);
 for (i = 0; i < s->nb_streams; i++)
 if (s->streams[i]->codecpar->codec_tag == AV_RL32("tmcd")) {
 mov_read_timecode_track(s, s->streams[i]);
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/dashenc: add format_options option, mirroring segment.c

2017-09-25 Thread Rodger Combs
---
 libavformat/dashenc.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 6471649eb7..5e5bea54c4 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -90,6 +90,7 @@ typedef struct DASHContext {
 AVRational min_frame_rate, max_frame_rate;
 int ambiguous_frame_rate;
 const char *utc_timing_url;
+const char *format_options_str;
 } DASHContext;
 
 static int dash_write(void *opaque, uint8_t *buf, int buf_size)
@@ -551,6 +552,17 @@ static int dash_init(AVFormatContext *s)
 os->init_start_pos = 0;
 
 av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
+
+if (c->format_options_str) {
+ret = av_dict_parse_string(&opts, c->format_options_str, "=", ":", 
0);
+if (ret < 0) {
+av_log(s, AV_LOG_ERROR, "Could not parse format options list 
'%s'\n",
+   c->format_options_str);
+av_dict_free(&opts);
+return ret;
+}
+}
+
 if ((ret = avformat_init_output(ctx, &opts)) < 0)
 return ret;
 os->ctx_inited = 1;
@@ -945,6 +957,7 @@ static const AVOption options[] = {
 { "init_seg_name", "DASH-templated name to used for the initialization 
segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = 
"init-stream$RepresentationID$.m4s"}, 0, 0, E },
 { "media_seg_name", "DASH-templated name to used for the media segments", 
OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = 
"chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
 { "utc_timing_url", "URL of the page that will return the UTC timestamp in 
ISO format", OFFSET(utc_timing_url), AV_OPT_TYPE_STRING, { 0 }, 0, 0, E },
+{ "format_options", "set list of options for the underlying mp4 muxer", 
OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
 { NULL },
 };
 
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavu/file: fix build on Android NDK with unified headers

2017-09-25 Thread Rodger Combs
---
 libavdevice/fbdev_enc.c  | 1 +
 libavformat/os_support.h | 6 ++
 libavutil/file.c | 1 +
 3 files changed, 8 insertions(+)

diff --git a/libavdevice/fbdev_enc.c b/libavdevice/fbdev_enc.c
index b4e5f84975..a9be608383 100644
--- a/libavdevice/fbdev_enc.c
+++ b/libavdevice/fbdev_enc.c
@@ -28,6 +28,7 @@
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include "libavformat/avformat.h"
+#include "libavformat/os_support.h"
 #include "fbdev_common.h"
 #include "avdevice.h"
 
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 91220e9716..54324603c9 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -65,6 +65,12 @@
 #   undef lseek
 #  endif
 #  define lseek(f,p,w) lseek64((f), (p), (w))
+#  if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 && 
!defined(__LP64__)
+#   ifdef mmap
+#undef mmap
+#   endif
+void* mmap(void*, size_t, int, int, int, __kernel_off_t);
+#  endif
 #endif
 
 static inline int is_dos_path(const char *path)
diff --git a/libavutil/file.c b/libavutil/file.c
index 7bdf6cde84..c4b22539d0 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -21,6 +21,7 @@
 #include "internal.h"
 #include "log.h"
 #include "mem.h"
+#include "libavformat/os_support.h"
 #include 
 #include 
 #if HAVE_UNISTD_H
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v15] avformat/dashdec: add dash demuxer base version

2017-08-30 Thread Rodger Combs
format add log here
> +goto finish;
> +}
> +}
> format_len = end - start - marker_len - 1 + strlen(PRId64);
> *o_format = av_mallocz(format_len+1);
> strncpy(*o_format, start + marker_len, end - start - marker_len -1);
> strcat(*o_format, PRId64);
> …
> }
> maybe more complex than this way, for example:
> %d
> %lld
> %04lld
> %PRId64
> %PRId32
> %PRId16
> 
> and think about the safety :
> %02c%lld
> %s%d%d%d%d
> 
> and so on,blablabla.
> 
> maybe we need to think a perfect solution.
> 
> 
> 
> 
> Dnia 28 sierpnia 2017 11:30 Rodger Combs  napisał(a):
> 
> I would expect parsing the number internally and using the additional arg to 
> be simpler and easier to verify than format string validation.
> 
> On Aug 28, 2017, at 04:28, samsamsam  wrote:
> 
> OK. I will.
> What about adding validation of format instead of adding "something like 
> `"%0*"PRId64`"?
> 
> Dnia 28 sierpnia 2017 03:30 Rodger Combs  napisał(a):
> 
> If you know of such a vulnerability, report it to ffmpeg-secur...@ffmpeg.org. 
> New code with known vulnerabilities will not be accepted.
> 
> Sent from my iPhone
> 
> On Aug 27, 2017, at 14:04, samsamsam  wrote:
> get_repl_pattern_and_format, you should have a fixed value of something like 
> `"%0*"PRId64`
> 
> If you afraid about safety then the only thing which need to be added to 
> get_repl_pattern_and_format is validation of format.
> Simple loop to validate format will be enough. Do you agree?
> 
> Anyway we are talking about safety but parser for mp4 atoms missing checking 
> and there is quite easy to make segfault of the libavformat when try to 
> prepared mp4 file.
> 
> I understand that you want to have maximum safety with new code but I hope 
> you know that ffmpeg at all is not safety.
> 
> Regards,
> SSS
> 
> Dnia 27 sierpnia 2017 16:34 Rodger Combs  napisał(a):
> 
> You're still calling snprintf with a string derived from the XML, which is 
> still not safe. Rather than having a format copied from the source in 
> get_repl_pattern_and_format, you should have a fixed value of something like 
> `"%0*"PRId64`, and specify an additional "precision" argument you parse from 
> the XML yourself. I can't reiterate this enough: _never pass data from the 
> XML into the format-string arg of a printf-family function_.
> 
> Also, rather than calling snprintf() twice with an av_malloc() in between, 
> you can just call av_asprintf(). That's what it does internally anyway.
> 
> On Aug 27, 2017, at 09:19, Steven Liu  wrote:
> 
> ffmpeg need a dash demuxer for demux the dash formats base on
> https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch
>  
> <https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch>
> 
> TODO:
> 1. support multi bitrate dash
> 
> v2 fixed:
> 1. from autodetect to disabled
> 2. from camelCase code style to ffmpeg code style
> 3. from RepType to AVMediaType
> 4. fix variable typo
> 5. change time value from uint32_t to uint64_t
> 6. removed be used once API
> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and 
> av_timegm
> 8. merge complex free operation to free_fragment
> 9. use API from snprintf to av_asprintf
> 
> v3 fixed:
> 1. fix typo from --enabled-xml2 to --enable-xml2
> 
> v4 fixed:
> 1. from --enable-xml2 to --enable-libxml2
> 2. move system includes to top
> 3. remove nouse includes
> 4. rename enum name
> 5. add a trailing comma for the last entry enum
> 6. fix comment typo
> 7. add const to DASHContext class front
> 8. check sscanf if return arguments and give warning message when error
> 9. check validity before free seg->url and seg
> 10. check if the val is null, before use atoll
> 
> v5 fixed:
> 1. fix typo from mainifest to manifest
> 
> v6 fixed:
> 1. from realloc to av_realloc
> 2. from free to av_free
> 
> v7 fixed:
> 1. remove the -lxml2 from configure when require_pkg_config
> 
> v8 fixed:
> 1. fix replace filename template by av_asprintf secure problem
> 
> v9 modified:
> 1. make manifest parser clearly
> 
> v10 fixed:
> 1. fix function API name code style
> 2. remove redundant strreplace call
> 3. remove redundant memory operation and check return value from 
> get_content_url()
> 4. add space between ) and {
> 5. remove no need to log the value for print
> 
> v11 fixed:
> 1. from atoll to strtoll
> 
> v12 fixed:
> 1. remove strreplace and instead by av_st

Re: [FFmpeg-devel] [PATCH v15] avformat/dashdec: add dash demuxer base version

2017-08-28 Thread Rodger Combs
I would expect parsing the number internally and using the additional arg to be 
simpler and easier to verify than format string validation.

> On Aug 28, 2017, at 04:28, samsamsam  wrote:
> 
> OK. I will.
> What about adding validation of format instead of adding "something like 
> `"%0*"PRId64`"?
> 
> Dnia 28 sierpnia 2017 03:30 Rodger Combs  napisał(a):
> 
> If you know of such a vulnerability, report it to  
> <mailto:ffmpeg-secur...@ffmpeg.org>ffmpeg-secur...@ffmpeg.org 
> <mailto:ffmpeg-secur...@ffmpeg.org>. New code with known vulnerabilities will 
> not be accepted.
> 
> Sent from my iPhone
> 
> On Aug 27, 2017, at 14:04, samsamsam < 
> <mailto:samsam...@o2.pl>samsam...@o2.pl <mailto:samsam...@o2.pl>> wrote:
>> get_repl_pattern_and_format, you should have a fixed value of something like 
>> `"%0*"PRId64`
>> 
>> If you afraid about safety then the only thing which need to be added to 
>> get_repl_pattern_and_format is validation of format.
>> Simple loop to validate format will be enough. Do you agree? 
>> 
>> Anyway we are talking about safety but parser for mp4 atoms missing checking 
>> and there is quite easy to make segfault of the libavformat when try to 
>> prepared mp4 file.
>> 
>> I understand that you want to have maximum safety with new code but I hope 
>> you know that ffmpeg at all is not safety.
>> 
>> Regards,
>> SSS
>> 
>> Dnia 27 sierpnia 2017 16:34 Rodger Combs < 
>> <mailto:rodger.co...@gmail.com>rodger.co...@gmail.com 
>> <mailto:rodger.co...@gmail.com>> napisał(a):
>> 
>> You're still calling snprintf with a string derived from the XML, which is 
>> still not safe. Rather than having a format copied from the source in 
>> get_repl_pattern_and_format, you should have a fixed value of something like 
>> `"%0*"PRId64`, and specify an additional "precision" argument you parse from 
>> the XML yourself. I can't reiterate this enough: _never pass data from the 
>> XML into the format-string arg of a printf-family function_.
>> 
>> Also, rather than calling snprintf() twice with an av_malloc() in between, 
>> you can just call av_asprintf(). That's what it does internally anyway.
>> 
>> On Aug 27, 2017, at 09:19, Steven Liu < 
>> <mailto:l...@chinaffmpeg.org>l...@chinaffmpeg.org 
>> <mailto:l...@chinaffmpeg.org>> wrote:
>> 
>> ffmpeg need a dash demuxer for demux the dash formats base on
>> https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch
>>  
>> <https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch>
>> 
>> TODO:
>> 1. support multi bitrate dash
>> 
>> v2 fixed:
>> 1. from autodetect to disabled
>> 2. from camelCase code style to ffmpeg code style
>> 3. from RepType to AVMediaType
>> 4. fix variable typo
>> 5. change time value from uint32_t to uint64_t
>> 6. removed be used once API
>> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and 
>> av_timegm
>> 8. merge complex free operation to free_fragment
>> 9. use API from snprintf to av_asprintf
>> 
>> v3 fixed:
>> 1. fix typo from --enabled-xml2 to --enable-xml2
>> 
>> v4 fixed:
>> 1. from --enable-xml2 to --enable-libxml2
>> 2. move system includes to top
>> 3. remove nouse includes
>> 4. rename enum name
>> 5. add a trailing comma for the last entry enum
>> 6. fix comment typo
>> 7. add const to DASHContext class front
>> 8. check sscanf if return arguments and give warning message when error
>> 9. check validity before free seg->url and seg
>> 10. check if the val is null, before use atoll
>> 
>> v5 fixed:
>> 1. fix typo from mainifest to manifest
>> 
>> v6 fixed:
>> 1. from realloc to av_realloc
>> 2. from free to av_free
>> 
>> v7 fixed:
>> 1. remove the -lxml2 from configure when require_pkg_config
>> 
>> v8 fixed:
>> 1. fix replace filename template by av_asprintf secure problem
>> 
>> v9 modified:
>> 1. make manifest parser clearly
>> 
>> v10 fixed:
>> 1. fix function API name code style
>> 2. remove redundant strreplace call
>> 3. remove redundant memory operation and check return value from 
>> get_content_url()
>> 4. add space between ) and {
>> 5. remove no need to log the value for print
>> 
>> v11 fixed:
>>

Re: [FFmpeg-devel] Odp: Re: [PATCH v15] avformat/dashdec: add dash demuxer base version

2017-08-27 Thread Rodger Combs
If you know of such a vulnerability, report it to ffmpeg-secur...@ffmpeg.org. 
New code with known vulnerabilities will not be accepted.

Sent from my iPhone

> On Aug 27, 2017, at 14:04, samsamsam  wrote:
> 
> get_repl_pattern_and_format, you should have a fixed value of something like 
> `"%0*"PRId64`
> 
> If you afraid about safety then the only thing which need to be added to 
> get_repl_pattern_and_format is validation of format.
> Simple loop to validate format will be enough. Do you agree? 
> 
> Anyway we are talking about safety but parser for mp4 atoms missing checking 
> and there is quite easy to make segfault of the libavformat when try to 
> prepared mp4 file.
> 
> I understand that you want to have maximum safety with new code but I hope 
> you know that ffmpeg at all is not safety.
> 
> Regards,
> SSS
> 
> Dnia 27 sierpnia 2017 16:34 Rodger Combs  napisał(a):
> 
> You're still calling snprintf with a string derived from the XML, which is 
> still not safe. Rather than having a format copied from the source in 
> get_repl_pattern_and_format, you should have a fixed value of something like 
> `"%0*"PRId64`, and specify an additional "precision" argument you parse from 
> the XML yourself. I can't reiterate this enough: _never pass data from the 
> XML into the format-string arg of a printf-family function_.
> 
> Also, rather than calling snprintf() twice with an av_malloc() in between, 
> you can just call av_asprintf(). That's what it does internally anyway.
> 
> On Aug 27, 2017, at 09:19, Steven Liu  wrote:
> 
> ffmpeg need a dash demuxer for demux the dash formats base on
> https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch
> 
> TODO:
> 1. support multi bitrate dash
> 
> v2 fixed:
> 1. from autodetect to disabled
> 2. from camelCase code style to ffmpeg code style
> 3. from RepType to AVMediaType
> 4. fix variable typo
> 5. change time value from uint32_t to uint64_t
> 6. removed be used once API
> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and 
> av_timegm
> 8. merge complex free operation to free_fragment
> 9. use API from snprintf to av_asprintf
> 
> v3 fixed:
> 1. fix typo from --enabled-xml2 to --enable-xml2
> 
> v4 fixed:
> 1. from --enable-xml2 to --enable-libxml2
> 2. move system includes to top
> 3. remove nouse includes
> 4. rename enum name
> 5. add a trailing comma for the last entry enum
> 6. fix comment typo
> 7. add const to DASHContext class front
> 8. check sscanf if return arguments and give warning message when error
> 9. check validity before free seg->url and seg
> 10. check if the val is null, before use atoll
> 
> v5 fixed:
> 1. fix typo from mainifest to manifest
> 
> v6 fixed:
> 1. from realloc to av_realloc
> 2. from free to av_free
> 
> v7 fixed:
> 1. remove the -lxml2 from configure when require_pkg_config
> 
> v8 fixed:
> 1. fix replace filename template by av_asprintf secure problem
> 
> v9 modified:
> 1. make manifest parser clearly
> 
> v10 fixed:
> 1. fix function API name code style
> 2. remove redundant strreplace call
> 3. remove redundant memory operation and check return value from 
> get_content_url()
> 4. add space between ) and {
> 5. remove no need to log the value for print
> 
> v11 fixed:
> 1. from atoll to strtoll
> 
> v12 fixed:
> 1. remove strreplace and instead by av_strreplace
> 
> v13 fixed:
> 1. fix bug: cannot play:
> http://dash.edgesuite.net/akamai/bbb_30fps/bbb_30fps.mpd
> 
> v14 fixed:
> 1. fix bug: TLS connection was non-properly terminated
> 2. fix bug: No trailing CRLF found in HTTP header
> 
> v15 fixed:
> 1. play youtube link: ffmpeg -i $(youtube-dl -J 
> "https://www.youtube.com/watch?v=XmL19DOP_Ls"; | jq -r 
> ".requested_formats[0].manifest_url")
> 2. code refine for timeline living stream
> 
> Reviewed-by: Clément Bœsch 
> Reviewed-by: Michael Niedermayer 
> Reviewed-by: Carl Eugen Hoyos 
> Reviewed-by: Rodger Combs 
> Reviewed-by: Moritz Barsnick 
> Reviewed-by: Nicolas George 
> Reviewed-by: Ricardo Constantino 
> Reviewed-by: wm4 
> Tested-by: Andy Furniss 
> Reported-by: Andy Furniss 
> Signed-off-by: Steven Liu 
> Signed-off-by: samsamsam 
> ---
> configure|4 +
> libavformat/Makefile |1 +
> libavformat/allformats.c |2 +-
> libavformat/dashdec.c| 1981 ++
> 4 files changed, 1987 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/dashdec.c
> 
> diff --git a/configure b/configure
&g

Re: [FFmpeg-devel] [PATCH v15] avformat/dashdec: add dash demuxer base version

2017-08-27 Thread Rodger Combs
You're still calling snprintf with a string derived from the XML, which is 
still not safe. Rather than having a format copied from the source in 
get_repl_pattern_and_format, you should have a fixed value of something like 
`"%0*"PRId64`, and specify an additional "precision" argument you parse from 
the XML yourself. I can't reiterate this enough: _never pass data from the XML 
into the format-string arg of a printf-family function_.

Also, rather than calling snprintf() twice with an av_malloc() in between, you 
can just call av_asprintf(). That's what it does internally anyway.

> On Aug 27, 2017, at 09:19, Steven Liu  wrote:
> 
> ffmpeg need a dash demuxer for demux the dash formats base on
> https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch
> 
> TODO:
> 1. support multi bitrate dash
> 
> v2 fixed:
> 1. from autodetect to disabled
> 2. from camelCase code style to ffmpeg code style
> 3. from RepType to AVMediaType
> 4. fix variable typo
> 5. change time value from uint32_t to uint64_t
> 6. removed be used once API
> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and 
> av_timegm
> 8. merge complex free operation to free_fragment
> 9. use API from snprintf to av_asprintf
> 
> v3 fixed:
> 1. fix typo from --enabled-xml2 to --enable-xml2
> 
> v4 fixed:
> 1. from --enable-xml2 to --enable-libxml2
> 2. move system includes to top
> 3. remove nouse includes
> 4. rename enum name
> 5. add a trailing comma for the last entry enum
> 6. fix comment typo
> 7. add const to DASHContext class front
> 8. check sscanf if return arguments and give warning message when error
> 9. check validity before free seg->url and seg
> 10. check if the val is null, before use atoll
> 
> v5 fixed:
> 1. fix typo from mainifest to manifest
> 
> v6 fixed:
> 1. from realloc to av_realloc
> 2. from free to av_free
> 
> v7 fixed:
> 1. remove the -lxml2 from configure when require_pkg_config
> 
> v8 fixed:
> 1. fix replace filename template by av_asprintf secure problem
> 
> v9 modified:
> 1. make manifest parser clearly
> 
> v10 fixed:
> 1. fix function API name code style
> 2. remove redundant strreplace call
> 3. remove redundant memory operation and check return value from 
> get_content_url()
> 4. add space between ) and {
> 5. remove no need to log the value for print
> 
> v11 fixed:
> 1. from atoll to strtoll
> 
> v12 fixed:
> 1. remove strreplace and instead by av_strreplace
> 
> v13 fixed:
> 1. fix bug: cannot play:
> http://dash.edgesuite.net/akamai/bbb_30fps/bbb_30fps.mpd
> 
> v14 fixed:
> 1. fix bug: TLS connection was non-properly terminated
> 2. fix bug: No trailing CRLF found in HTTP header
> 
> v15 fixed:
> 1. play youtube link: ffmpeg -i $(youtube-dl -J 
> "https://www.youtube.com/watch?v=XmL19DOP_Ls"; | jq -r 
> ".requested_formats[0].manifest_url")
> 2. code refine for timeline living stream
> 
> Reviewed-by: Clément Bœsch 
> Reviewed-by: Michael Niedermayer 
> Reviewed-by: Carl Eugen Hoyos 
> Reviewed-by: Rodger Combs 
> Reviewed-by: Moritz Barsnick 
> Reviewed-by: Nicolas George 
> Reviewed-by: Ricardo Constantino 
> Reviewed-by: wm4 
> Tested-by: Andy Furniss 
> Reported-by: Andy Furniss 
> Signed-off-by: Steven Liu 
> Signed-off-by: samsamsam 
> ---
> configure|4 +
> libavformat/Makefile |1 +
> libavformat/allformats.c |2 +-
> libavformat/dashdec.c| 1981 ++
> 4 files changed, 1987 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/dashdec.c
> 
> diff --git a/configure b/configure
> index 05f6dcc99a..7a7d61fa13 100755
> --- a/configure
> +++ b/configure
> @@ -272,6 +272,7 @@ External library support:
>   --enable-libxcb-shapeenable X11 grabbing shape rendering [autodetect]
>   --enable-libxvid enable Xvid encoding via xvidcore,
>native MPEG-4/Xvid encoder exists [no]
> +  --enable-libxml2 enable XML parsing using the C library libxml2 
> [no]
>   --enable-libzimg enable z.lib, needed for zscale filter [no]
>   --enable-libzmq  enable message passing via libzmq [no]
>   --enable-libzvbi enable teletext support via libzvbi [no]
> @@ -1576,6 +1577,7 @@ EXTERNAL_LIBRARY_LIST="
> libvpx
> libwavpack
> libwebp
> +libxml2
> libzimg
> libzmq
> libzvbi
> @@ -2937,6 +2939,7 @@ avi_muxer_select="riffenc"
> caf_demuxer_select="iso_media riffdec"
> caf_muxer_select="iso_media"
> dash_muxer

[FFmpeg-devel] [PATCH] lavf/mov: initial support for reading HEIF images

2017-08-19 Thread Rodger Combs
There's a decent chance this doesn't work on [pretty much anything other than
the samples I tested it with], but I haven't found very many samples, and don't
want to implement the rest of the features blind with nothing but a spec, and
most of it's pretty over-the-top anyway.

For some reason my phone running iOS 11 doesn't actually export HEIFs; it just
gives me JPEGs with a .HEIC extension.

HEIF is basically just an overengineered new mechanism for attaching still
pictures to MP4 files. Its atoms can exist along with a moov, or without one.

This can probably seek-thrash pretty badly in some cases, so if it becomes
common to use this to attach pictures to audio or video files, it'd probably
be worth adding an "ignore_attached_pics" option, a la "ignore_chapters". It'd
be possible to optimize some of the seeks out by adding some more internal
state (this is a naive implementation of a very implementer-unfriendly format),
but some are inherent to the design, like with "chap" chapters.

Short rant: this whole format is crazy. There are a bunch of variable-size
fields ("in case you ever need more than 2^16 pictures in a file!", and also
"in case you want to save space by using 3 bytes for the size instead of 4!"),
and everything has extra cruft at every opportunity in the name of future
extensibility. If somebody wants to explain why an 8-byte atom containing a
width and a height needs another 4 bytes for version and flags fields, I'm
all ears. There are also some count fields that serve no purpose within their
parent atom.

For some reason the format supports splitting a picture into multiple byte
ranges, which can be in separate mdats, or separate positions in the same
mdat, and there are 3 different ways to address them (I've only implemented
the one used in the samples I had). If anyone knows why anyone would ever
want to do that, please inform me.

This will definitely completely fall apart if any of the metadata atoms come
after the iloc. Hopefully that never happens, because it would be a pain to
work around.

TL;DR this format is bad, but at least we're finally moving past JPEG.
---
 libavformat/isom.h |   2 +
 libavformat/mov.c  | 331 +++--
 2 files changed, 326 insertions(+), 7 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index ff009b0896..a3ba10bf76 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -223,7 +223,9 @@ typedef struct MOVContext {
 int found_moov;   ///< 'moov' atom has been found
 int found_mdat;   ///< 'mdat' atom has been found
 int found_hdlr_mdta;  ///< 'hdlr' atom with type 'mdta' has been found
+int found_iloc;   ///< 'iloc' atom has been found
 int trak_index;   ///< Index of the current 'trak'
+int cur_stream_index; ///< Stream currently being populated
 char **meta_keys;
 unsigned meta_keys_count;
 DVDemuxContext *dv_demux;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 522ce60c2d..87dbc83d6f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1678,9 +1678,9 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 AVStream *st;
 int ret;
 
-if (c->fc->nb_streams < 1)
+if (c->cur_stream_index < 0)
 return 0;
-st = c->fc->streams[c->fc->nb_streams-1];
+st = c->fc->streams[c->cur_stream_index];
 
 if ((uint64_t)atom.size > (1<<30))
 return AVERROR_INVALIDDATA;
@@ -3742,6 +3742,8 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 sc = av_mallocz(sizeof(MOVStreamContext));
 if (!sc) return AVERROR(ENOMEM);
 
+c->cur_stream_index = st->index;
+
 st->priv_data = sc;
 st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
 sc->ffindex = st->index;
@@ -3976,6 +3978,10 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 
 static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
+// Skip version and flags
+avio_skip(pb, 4);
+atom.size -= 4;
+
 while (atom.size > 8) {
 uint32_t tag = avio_rl32(pb);
 atom.size -= 4;
@@ -5470,6 +5476,310 @@ static int mov_read_dops(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return 0;
 }
 
+static uint64_t read_length(AVIOContext *pb, unsigned len)
+{
+uint64_t ret = 0, i = 0;
+for (i = 0; i < len; i++)
+ret = (ret << 8) | avio_r8(pb);
+return ret;
+}
+
+enum HEIFOffsetType {
+HEIF_OFFSET_FILE = 0,
+HEIF_OFFSET_MDAT = 1,
+HEIF_OFFSET_ITEM = 2
+};
+
+static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+int version = avio_r8(pb);
+avio_rb24(pb); // flags
+int ret = 0;
+
+unsigned item_count, i, j;
+
+int offset_size = avio_r8(pb);
+int length_size = offset_size & 0xf;
+int base_offset_size = avio_r8(pb);
+int index_size = base_offset_size & 0xf;
+offset_size >>= 4;
+base_offset_size >>= 4;
+
+if (version > 2) {
+avpriv_reque

Re: [FFmpeg-devel] [PATCH 3/3] lavf/tls: verify TLS connections by default whenever possible

2017-08-18 Thread Rodger Combs


> On Aug 16, 2017, at 06:29, wm4  wrote:
> 
> On Wed, 16 Aug 2017 02:19:18 -0500
> Rodger Combs mailto:rodger.co...@gmail.com>> wrote:
> 
>> This makes a reasonable effort to set the default configuration to behave
>> securely, while maintaining the ability for consumers to produce builds using
>> the old behavior without making changes to their runtime code.
>> 
>> On Secure Transport and Secure Channel, we use a system-provided trust store,
>> so we don't have to worry about providing our own. On OpenSSL and GNUTLS, we
>> search for a default CA bundle path in the same locations as curl does in 
>> their
>> configure script. If this fails (or the user disabled it by setting the path
>> to an empty string), we turn off verification by default.
>> 
>> The user can also set an explicit default CA path (which applies on any TLS
>> engine), and explicitly enable or disable the new verify-by-default behavior.
>> 
>> When verification is turned off at compile-time (as opposed to runtime), we
>> log a warning indicating that this is the case, and informing the user of how
>> they can turn on verification.
>> 
>> Other options that were considered, but deemed too complex (for now) include:
>> - Including a default trust store for OpenSSL and GNUTLS within the 
>> libavformat
>>  library, to be read from the build machine or fetched online at compile-time
>>  (a la nodejs).
>> - Installing a library in the ffmpeg data directory, to be either copied from
>>  the build machine or fetched online at compile-time (a la curl).
>> - Providing an "rpath"-style mechanism to set the default CA bundle path
>>  relative to the running executable.
>> ---
>> configure | 29 +
>> libavformat/tls.c | 15 +++
>> libavformat/tls.h |  6 +++---
>> 3 files changed, 47 insertions(+), 3 deletions(-)
>> 
>> diff --git a/configure b/configure
>> index 7201941c36..aff5bf3bc7 100755
>> --- a/configure
>> +++ b/configure
>> @@ -374,6 +374,8 @@ Advanced options (experts only):
>>disable buffer boundary checking in bitreaders
>>(faster, but may crash)
>>   --sws-max-filter-size=N  the max filter size swscale uses 
>> [$sws_max_filter_size_default]
>> +  --disable-tls-verify disable verifying TLS certificates by default 
>> [autodetect]
>> +  --ca-bundle-path=PATHpath to the default trusted certificate 
>> authority list in PEM format [autodetect]
>> 
>> Optimization options (experts only):
>>   --disable-asmdisable all assembly optimizations
>> @@ -1631,6 +1633,7 @@ FEATURE_LIST="
>> small
>> static
>> swscale_alpha
>> +tls_verify
>> "
>> 
>> LIBRARY_LIST="
>> @@ -2200,6 +2203,7 @@ CMDLINE_SET="
>> build_suffix
>> cc
>> objcc
>> +ca_bundle_path
>> cpu
>> cross_prefix
>> custom_allocator
>> @@ -6593,6 +6597,25 @@ enabled lavfi_indev && prepend avdevice_deps 
>> "avfilter"
>> 
>> enabled opus_decoder&& prepend avcodec_deps "swresample"
>> 
>> +enabled_any tls_securetransport_protocol tls_schannel_protocol && 
>> enable_weak tls_verify
>> +enabled_any tls_openssl_protocol tls_gnutls_protocol && test -z 
>> ${ca_bundle_path+x} && {
>> +for file in /etc/ssl/certs/ca-certificates.crt \
>> +/etc/pki/tls/certs/ca-bundle.crt \
>> +/usr/share/ssl/certs/ca-bundle.crt \
>> +/usr/local/share/certs/ca-root-nss.crt \
>> +${prefix}/share/certs/ca-root-nss.crt \
>> +/etc/ssl/cert.pem \
>> +${prefix}/share/curl/curl-ca-bundle.crt \
>> +/usr/share/curl/curl-ca-bundle.crt \
>> +/usr/local/share/curl/curl-ca-bundle.crt; do
>> +if test -f "$file"; then
>> +ca_bundle_path="$file"
>> +break
>> +fi
>> +done;
>> +}
>> +enabled_any tls_openssl_protocol tls_gnutls_protocol && test -n 
>> "${ca_bundle_path}" && enable_weak tls_verify
>> +
> 
> Wouldn't it be better to search these at runtime? Doing it at compile
> time probably _will_ break cross compiles by default, unless the person
> building it knows about --ca-bundle-path and actually sets it correctly.

Hmm, I could search at runtime by default,

[FFmpeg-devel] [PATCH 3/3] lavf/tls: verify TLS connections by default whenever possible

2017-08-16 Thread Rodger Combs
This makes a reasonable effort to set the default configuration to behave
securely, while maintaining the ability for consumers to produce builds using
the old behavior without making changes to their runtime code.

On Secure Transport and Secure Channel, we use a system-provided trust store,
so we don't have to worry about providing our own. On OpenSSL and GNUTLS, we
search for a default CA bundle path in the same locations as curl does in their
configure script. If this fails (or the user disabled it by setting the path
to an empty string), we turn off verification by default.

The user can also set an explicit default CA path (which applies on any TLS
engine), and explicitly enable or disable the new verify-by-default behavior.

When verification is turned off at compile-time (as opposed to runtime), we
log a warning indicating that this is the case, and informing the user of how
they can turn on verification.

Other options that were considered, but deemed too complex (for now) include:
- Including a default trust store for OpenSSL and GNUTLS within the libavformat
  library, to be read from the build machine or fetched online at compile-time
  (a la nodejs).
- Installing a library in the ffmpeg data directory, to be either copied from
  the build machine or fetched online at compile-time (a la curl).
- Providing an "rpath"-style mechanism to set the default CA bundle path
  relative to the running executable.
---
 configure | 29 +
 libavformat/tls.c | 15 +++
 libavformat/tls.h |  6 +++---
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 7201941c36..aff5bf3bc7 100755
--- a/configure
+++ b/configure
@@ -374,6 +374,8 @@ Advanced options (experts only):
disable buffer boundary checking in bitreaders
(faster, but may crash)
   --sws-max-filter-size=N  the max filter size swscale uses 
[$sws_max_filter_size_default]
+  --disable-tls-verify disable verifying TLS certificates by default 
[autodetect]
+  --ca-bundle-path=PATHpath to the default trusted certificate authority 
list in PEM format [autodetect]
 
 Optimization options (experts only):
   --disable-asmdisable all assembly optimizations
@@ -1631,6 +1633,7 @@ FEATURE_LIST="
 small
 static
 swscale_alpha
+tls_verify
 "
 
 LIBRARY_LIST="
@@ -2200,6 +2203,7 @@ CMDLINE_SET="
 build_suffix
 cc
 objcc
+ca_bundle_path
 cpu
 cross_prefix
 custom_allocator
@@ -6593,6 +6597,25 @@ enabled lavfi_indev && prepend avdevice_deps 
"avfilter"
 
 enabled opus_decoder&& prepend avcodec_deps "swresample"
 
+enabled_any tls_securetransport_protocol tls_schannel_protocol && enable_weak 
tls_verify
+enabled_any tls_openssl_protocol tls_gnutls_protocol && test -z 
${ca_bundle_path+x} && {
+for file in /etc/ssl/certs/ca-certificates.crt \
+/etc/pki/tls/certs/ca-bundle.crt \
+/usr/share/ssl/certs/ca-bundle.crt \
+/usr/local/share/certs/ca-root-nss.crt \
+${prefix}/share/certs/ca-root-nss.crt \
+/etc/ssl/cert.pem \
+${prefix}/share/curl/curl-ca-bundle.crt \
+/usr/share/curl/curl-ca-bundle.crt \
+/usr/local/share/curl/curl-ca-bundle.crt; do
+if test -f "$file"; then
+ca_bundle_path="$file"
+break
+fi
+done;
+}
+enabled_any tls_openssl_protocol tls_gnutls_protocol && test -n 
"${ca_bundle_path}" && enable_weak tls_verify
+
 expand_deps(){
 lib_deps=${1}_deps
 eval "deps=\$$lib_deps"
@@ -6693,6 +6716,8 @@ echo "postprocessing support${postproc-no}"
 echo "network support   ${network-no}"
 echo "threading support ${thread_type-no}"
 echo "safe bitstream reader ${safe_bitstream_reader-no}"
+echo "TLS cert verification ${tls_verify-no}"
+echo "CA bundle path${ca_bundle_path-none}"
 echo "texi2html enabled ${texi2html-no}"
 echo "perl enabled  ${perl-no}"
 echo "pod2man enabled   ${pod2man-no}"
@@ -6909,6 +6934,10 @@ cat > $TMPH <>$TMPH ||
+echo "#define CA_BUNDLE_PATH NULL" >>$TMPH
+
 test -n "$assert_level" &&
 echo "#define ASSERT_LEVEL $assert_level" >>$TMPH
 
diff --git a/libavformat/tls.c b/libavformat/tls.c
index 10e0792e29..b1ce6529c8 100644
--- a/libavformat/tls.c
+++ b/libavformat/tls.c
@@ -64,6 +64,21 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, 
const char *uri, AV
 
 set_options(c, uri);
 
+if (c->verify < 0) {
+c->verify = CONFIG_TLS_VERIFY;
+#if CONFIG_TLS_VERIFY == 0
+av_log(parent, AV_LOG_WARNING, "ffmpeg was configured without TLS 
verification enabled,\n"
+   "so this connection will be made 
insecurely.\n"
+   "To make this connection securely, 
enable the 'tls_verify' option%s"

[FFmpeg-devel] [PATCH 1/3] lavf/tls_openssl: add support for verifying the server hostname on >=1.1.0

2017-08-16 Thread Rodger Combs
---
 libavformat/tls_openssl.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 38af8a21c0..50361d30e2 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -256,8 +256,6 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
 ret = AVERROR(EIO);
 goto fail;
 }
-// Note, this doesn't check that the peer certificate actually matches
-// the requested hostname.
 if (c->verify)
 SSL_CTX_set_verify(p->ctx, 
SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
 p->ssl = SSL_new(p->ctx);
@@ -281,8 +279,18 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
 bio->ptr = c->tcp;
 #endif
 SSL_set_bio(p->ssl, bio, bio);
-if (!c->listen && !c->numerichost)
+if (!c->listen && !c->numerichost) {
 SSL_set_tlsext_host_name(p->ssl, c->host);
+if (c->verify)
+#if OPENSSL_VERSION_NUMBER >= 0x101fL
+SSL_set1_host(p->ssl, c->host);
+#else
+av_log(h, AV_LOG_WARNING, "ffmpeg was built against an old version 
of OpenSSL\n"
+  "which doesn't provide peer name 
verification, so this connection\n"
+  "will be made insecurely. To make this 
connection securely,\n"
+  "upgrade to a newer OpenSSL version, or 
use GNUTLS instead.\n");
+#endif
+}
 ret = c->listen ? SSL_accept(p->ssl) : SSL_connect(p->ssl);
 if (ret == 0) {
 av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/3] lavf/tls: use AV_OPT_TYPE_BOOL

2017-08-16 Thread Rodger Combs
---
 libavformat/tls.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/tls.h b/libavformat/tls.h
index 0326ef7924..53d0634f49 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -47,10 +47,10 @@ typedef struct TLSShared {
 #define TLS_COMMON_OPTIONS(pstruct, options_field) \
 {"ca_file","Certificate Authority database file", offsetof(pstruct, 
options_field . ca_file),   AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"cafile", "Certificate Authority database file", offsetof(pstruct, 
options_field . ca_file),   AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
-{"tls_verify", "Verify the peer certificate", offsetof(pstruct, 
options_field . verify),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
+{"tls_verify", "Verify the peer certificate", offsetof(pstruct, 
options_field . verify),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
 {"cert_file",  "Certificate file",offsetof(pstruct, 
options_field . cert_file), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"key_file",   "Private key file",offsetof(pstruct, 
options_field . key_file),  AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
-{"listen", "Listen for incoming connections", offsetof(pstruct, 
options_field . listen),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
+{"listen", "Listen for incoming connections", offsetof(pstruct, 
options_field . listen),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
 {"verifyhost", "Verify against a specific hostname",  offsetof(pstruct, 
options_field . host),  AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }
 
 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, 
AVDictionary **options);
-- 
2.14.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/movdec: flag chapter streams as such, even when not reading them

2017-08-11 Thread Rodger Combs
This allows the use of the `ignore_chapters` option to avoid performing
extra seeks at startup without producing "subtitle" chapter streams.
---
 libavformat/mov.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 63f84be782..5f83c695e6 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5762,6 +5762,7 @@ static void mov_read_chapters(AVFormatContext *s)
 int64_t cur_pos;
 int i, j;
 int chapter_track;
+int read_contents = (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && 
!mov->ignore_chapters;
 
 for (j = 0; j < mov->nb_chapter_tracks; j++) {
 chapter_track = mov->chapter_tracks[j];
@@ -5781,7 +5782,7 @@ static void mov_read_chapters(AVFormatContext *s)
 
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 st->disposition |= AV_DISPOSITION_ATTACHED_PIC | 
AV_DISPOSITION_TIMED_THUMBNAILS;
-if (st->nb_index_entries) {
+if (st->nb_index_entries && read_contents) {
 // Retrieve the first frame, if possible
 AVPacket pkt;
 AVIndexEntry *sample = &st->index_entries[0];
@@ -5801,6 +5802,10 @@ static void mov_read_chapters(AVFormatContext *s)
 st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
 st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA;
 st->discard = AVDISCARD_ALL;
+
+if (!read_contents)
+continue;
+
 for (i = 0; i < st->nb_index_entries; i++) {
 AVIndexEntry *sample = &st->index_entries[i];
 int64_t end = i+1 < st->nb_index_entries ? 
st->index_entries[i+1].timestamp : st->duration;
@@ -5851,7 +5856,8 @@ static void mov_read_chapters(AVFormatContext *s)
 }
 }
 finish:
-avio_seek(sc->pb, cur_pos, SEEK_SET);
+if (read_contents)
+avio_seek(sc->pb, cur_pos, SEEK_SET);
 }
 }
 
@@ -6181,9 +6187,11 @@ static int mov_read_header(AVFormatContext *s)
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
+
+if (mov->nb_chapter_tracks > 0)
+mov_read_chapters(s);
+
 if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
-if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters)
-mov_read_chapters(s);
 for (i = 0; i < s->nb_streams; i++)
 if (s->streams[i]->codecpar->codec_tag == AV_RL32("tmcd")) {
 mov_read_timecode_track(s, s->streams[i]);
-- 
2.14.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [mov] Fix trampling of ctts during seeks when sidx support is enabled.

2017-08-04 Thread Rodger Combs
+sc->ctts_data = av_fast_realloc(sc->ctts_data, 
&sc->ctts_allocated_size, request_size);
^ this line is incorrect; setting realloc's first arg to its return value leaks 
the existing allocation in the OOM case. Since you're doing your own 
calculation for the desired new size here, you may want to use av_reallocp 
(which frees the original allocation on failure).

When reading a trun that requires this sort of realloc, is it common for there 
to be any existing entries in the range we're writing? Would it be safe to 
remove+replace them? Could we do a single realloc + single memmove, and then 
fill the newly-opened space, rather than repeating the memmove for each entry?

> On Aug 4, 2017, at 18:02, Dale Curtis  wrote:
> 
> Any comments here? +rodger who wrote the original sidx processing for review.
> 
> - dale
> 
> On Mon, Jul 31, 2017 at 3:01 PM, Dale Curtis  > wrote:
> Whoops, that patch accidentally reverted to an earlier version. Here's the 
> fixed one that works with the mpg sample mentioned above.
> 
> - dale
> 
> On Mon, Jul 31, 2017 at 2:29 PM, Dale Curtis  > wrote:
> Here's an updated patch with a fate test attached. You'll need to add 
> http://storage.googleapis.com/dalecurtis/buck480p30_na.mp4 
>  to the 
> fate-suite/mov for this test. This is licensed under creative commons 
> attribution, so it should be fine for tests: https://peach.blender.org/about/ 
>  I tried to use the existing samples, but 
> you need a clip long enough that the entire index isn't generated from the 
> start.
> 
> - dale
> 
> On Tue, Jul 25, 2017 at 1:03 PM, Michael Niedermayer  > wrote:
> On Mon, Jul 24, 2017 at 02:32:41PM -0700, Dale Curtis wrote:
> > On Thu, Jul 20, 2017 at 5:00 AM, Michael Niedermayer  > > wrote:
> >
> > > Hi
> > >
> > > On Wed, Jul 19, 2017 at 07:30:01PM -0700, Dale Curtis wrote:
> > > > Thanks will take a look. Is this test not part of fate? make fate passed
> > >
> > > no, we should have tests for all (fixed) tickets in fate ideally
> > > but in reality most tickets lack a corresponding test
> > > I tried both in outreachy and as well in GSoC to improve this situation
> > > with student projects but both only moved this forward by a small
> > > step. Its a large amount of work to create robust, portable and
> > > practical tests for "all" tickets and everything else.
> > > The way out to get this actually done would be to pay a developer to
> > > create tests for "all" tickets in fate. I belive carl would be the
> > > ideal one to do this work as he has since a very long time always tested
> > > and kept track of all our tickets.
> > > I did suggest a while ago to someone at google that funding such
> > > project would make sense but IIRC i never heared back.
> > > if some company would fund something like this, i belive this would be
> > > very usefull in the long run for code quality
> > >
> >
> > I think it'd be pretty hard to get someone to go through and create tests
> > for every issue ever seen. Even Chromium has trouble with this, but making
> 
> yes, unless theres someone who enjoys doing this kind of work.
> 
> 
> > it part of the culture helps. I.e. reviewers should ask for every change to
> > include a test.
> 
> yes though theres already
> 1.8 patch submission checklist
> ...
> 26. Consider adding a regression test for your code.
> on http://ffmpeg.org/developer.html 
> 
> 
> > I'm happy to add one to fate for this change. Or can do so
> > in a followup patch if you prefer.
> 
> please do (any variant is fine)
> 
> thx
> 
> >
> > Does anyone have comments on this change specifically? We've already rolled
> > this into Chrome and it's working fine and passing all regression tests.
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org 
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> > 
> 
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Breaking DRM is a little like attempting to break through a door even
> though the window is wide open and the only thing in the house is a bunch
> of things you dont want and which you would get tomorrow for free anyway
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org 
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> 
> 
> 
> 
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 7/7] lavf/flacenc: generate timestamps internally

2017-08-02 Thread Rodger Combs
---
 libavformat/flacenc.c| 87 ++--
 tests/ref/acodec/flac|  4 +-
 tests/ref/acodec/flac-exact-rice |  4 +-
 tests/ref/seek/acodec-flac   | 36 -
 4 files changed, 106 insertions(+), 25 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 1906aee..39e5e2c 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -30,6 +30,7 @@
 #include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
+#include "libavutil/crc.h"
 
 
 typedef struct FlacMuxerContext {
@@ -46,6 +47,8 @@ typedef struct FlacMuxerContext {
 uint8_t *streaminfo;
 
 unsigned attached_types;
+
+uint64_t samples;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -263,11 +266,17 @@ static int flac_write_header(struct AVFormatContext *s)
 return ret;
 }
 
+static const int32_t blocksize_table[16] = {
+ 0,192, 576<<0, 576<<1, 576<<2, 576<<3,  0,  0,
+256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
+};
+
 static int flac_write_audio_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
 FlacMuxerContext *c = s->priv_data;
 uint8_t *streaminfo;
 int streaminfo_size;
+char header[16];
 
 /* check for updated streaminfo */
 streaminfo = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
@@ -281,8 +290,77 @@ static int flac_write_audio_packet(struct AVFormatContext 
*s, AVPacket *pkt)
 memcpy(c->streaminfo, streaminfo, FLAC_STREAMINFO_SIZE);
 }
 
-if (pkt->size)
-avio_write(s->pb, pkt->data, pkt->size);
+if (pkt->size) {
+uint8_t tmp;
+uint64_t pts = c->samples;
+int offset = 5;
+int headerlen = 4;
+int bscode, bs;
+int crc;
+if (pkt->size < FLAC_MIN_FRAME_SIZE)
+return AVERROR_INVALIDDATA;
+memcpy(header, pkt->data, 4);
+if (pkt->pts == AV_NOPTS_VALUE)
+pts = 0;
+if ((pkt->data[4] & 0xC0) == 0xC0)
+offset += ff_clz((unsigned char)~pkt->data[4]) - 25;
+else if (pkt->data[4] & 0x80)
+return AVERROR_INVALIDDATA;
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+
+// Forcing use of sample counts instead of block counts to avoid bs
+// mismatch issues
+header[1] |= 1;
+
+bscode = (unsigned char)header[2] >> 4;
+bs = blocksize_table[bscode];
+if (bscode == 0)
+return AVERROR_INVALIDDATA;
+if (bscode == 6) {
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+bs = pkt->data[offset] + 1;
+} else if (bscode == 7) {
+if (pkt->size <= offset + 2)
+return AVERROR_INVALIDDATA;
+bs = AV_RB16(&pkt->data[offset]) + 1;
+}
+
+c->samples += bs;
+
+PUT_UTF8(pts, tmp, header[headerlen++] = tmp;)
+if (headerlen > 11)
+return AVERROR_INVALIDDATA;
+if ((bscode & 0xE) == 0x6)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if (bscode == 0x7)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0xC) == 0xC) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0x3) == 0x3)
+return AVERROR_INVALIDDATA;
+else if (header[2] & 0x3) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+}
+}
+header[headerlen] = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, header, 
headerlen);
+headerlen++; offset++;
+crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, header, headerlen);
+if (pkt->size < offset + 3)
+return AVERROR_INVALIDDATA;
+avio_write(s->pb, header, headerlen);
+avio_write(s->pb, pkt->data + offset, pkt->size - offset - 2);
+avio_wl16(s->pb, av_crc(av_crc_get_table(AV_CRC_16_ANSI), crc, 
pkt->data + offset, pkt->size - offset - 2));
+}
 return 0;
 }
 
@@ -326,7 +404,10 @@ static int flac_write_trailer(struct AVFormatContext *s)
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
+avio_write(pb, streaminfo, 13);
+avio_w8(pb, (streaminfo[13] & 0xF0) | ((c->samples >> 32) & 0xF));
+avio_wb32(pb, c->samples);
+avio_write(pb, streaminfo + 18, FLAC_STREAMINFO_SIZE - 18);
 avio_seek(pb, file_size, SEEK_SE

[FFmpeg-devel] [PATCH 5/7] lavf/flacenc: support writing attached pictures

2017-08-02 Thread Rodger Combs
---
 libavformat/flacenc.c | 285 +++---
 1 file changed, 250 insertions(+), 35 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b894f9e..9768b6a 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -21,10 +21,13 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "flacenc.h"
+#include "id3v2.h"
+#include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
 
@@ -33,8 +36,16 @@ typedef struct FlacMuxerContext {
 const AVClass *class;
 int write_header;
 
+int audio_stream_idx;
+AVPacket *pics;
+int nb_pics, waiting_pics;
+/* audio packets are queued here until we get all the attached pictures */
+AVPacketList *queue, *queue_end;
+
 /* updated streaminfo sent by the encoder at the end */
 uint8_t *streaminfo;
+
+unsigned attached_types;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -74,31 +85,156 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_write_picture(struct AVFormatContext *s, AVPacket *pkt)
 {
-int ret;
-int padding = s->metadata_header_padding;
-AVCodecParameters *par = s->streams[0]->codecpar;
-FlacMuxerContext *c   = s->priv_data;
-
-if (!c->write_header)
+FlacMuxerContext *c = s->priv_data;
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0;
+
+if (!pkt->data)
 return 0;
 
-if (s->nb_streams > 1) {
-av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
 return AVERROR(EINVAL);
 }
-if (par->codec_id != AV_CODEC_ID_FLAC) {
-av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if ((c->attached_types & (1 << type)) & 0x6) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
+return AVERROR(EINVAL);
+}
+
+if (type == 1 && (st->codecpar->codec_id != AV_CODEC_ID_PNG ||
+  st->codecpar->width != 32 ||
+  st->codecpar->height != 32)) {
+av_log(s, AV_LOG_ERROR, "File icon attachment must be a 32x32 PNG");
 return AVERROR(EINVAL);
 }
 
+c->attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+avio_w8(pb, 0x06);
+avio_wb24(pb, 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + 
pkt->size);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+return 0;
+}
+
+static int flac_finish_header(struct AVFormatContext *s)
+{
+FlacMuxerContext *c = s->priv_data;
+int i, ret, padding = s->metadata_header_padding;
 if (padding < 0)
 padding = 8192;
 /* The FLAC specification states that 24 bits are used to represent the
  * size of a metadata block so we must clip this value to 2^24-1. */
 padding = av_clip_uintp2(padding, 24);
 
+for (i = 0; i < c->nb_pics; i++) {
+ret = flac_write_picture(s, &c->pics[i]);
+if (ret)
+return ret;
+}
+
+ret = flac_write_block_comment(s->pb, &s->metadata, !padding,
+   s->flags & AVFMT_FLAG_BITEXACT);
+if (ret)
+return ret;
+
+/* The command line flac encoder defaults to placing a seekpoint
+ * every 10s.  So one

[FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-08-02 Thread Rodger Combs
---
 libavformat/flacenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 9768b6a..1906aee 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -322,7 +322,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
 if (!c->write_header || !streaminfo)
 return 0;
 
-if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
+if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-08-02 Thread Rodger Combs
---
 doc/muxers.texi   |  6 +
 libavformat/segment.c | 65 +++
 libavformat/version.h |  2 +-
 3 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 94472ce..23ef2e7 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1538,6 +1538,12 @@ This option specifies to start a new segment whenever a 
reference
 stream key frame is found and the sequential number (starting from 0)
 of the frame is greater or equal to the next value in the list.
 
+@item segment_chapters @var{1|0}
+Split each chapter into its own segment. Metadata from the chapters
+will be written to the corresponding segments. If this option is selected
+and the filename contains tokens in the format @code{$varname$}, they
+will be replaced by the corresponding metadata values.
+
 @item segment_wrap @var{limit}
 Wrap around segment index once it reaches @var{limit}.
 
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 0e8bcdd..590f62b 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -106,6 +106,8 @@ typedef struct SegmentContext {
 int frame_count;   ///< total number of reference frames
 int segment_frame_count; ///< number of reference frames in the segment
 
+int split_chapters;///< split on chapter markers
+
 int64_t time_delta;
 int  individual_header_trailer; /**< Set by a private option. */
 int  write_header_trailer; /**< Set by a private option. */
@@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
 return 0;
 }
 
+static int replace_variables(AVFormatContext *oc)
+{
+char name[sizeof(oc->filename)];
+char *p = name;
+char *out = oc->filename;
+strncpy(name, oc->filename, sizeof(name));
+while (*p) {
+char c = *p++;
+if (c == '$') {
+if (*p == '$') {
+p++;
+goto append;
+} else {
+int len;
+const char *val;
+const AVDictionaryEntry *e;
+int end = strcspn(p, "$");
+if (p[end] == '\0')
+continue;
+p[end] = '\0';
+e = av_dict_get(oc->metadata, p, NULL, 0);
+val = e ? e->value : "(unknown)";
+len = strlen(val);
+strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
out);
+out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
len);
+p += end + 1;
+}
+} else {
+append:
+if (out - oc->filename < sizeof(oc->filename) - 1)
+*out++ = c;
+}
+}
+*out = '\0';
+return 0;
+}
+
 static int set_segment_filename(AVFormatContext *s)
 {
 SegmentContext *seg = s->priv_data;
@@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
+if (seg->split_chapters)
+replace_variables(oc);
+
 /* copy modified name in list entry */
 size = strlen(av_basename(oc->filename)) + 1;
 if (seg->entry_prefix)
@@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 if ((err = segment_mux_init(s)) < 0)
 return err;
 oc = seg->avf;
+if (seg->split_chapters && seg->segment_count < s->nb_chapters && (err 
= av_dict_copy(&oc->metadata, s->chapters[seg->segment_count]->metadata, 0)) < 
0)
+return err;
 }
 
 seg->segment_idx++;
@@ -659,10 +703,14 @@ static int seg_init(AVFormatContext *s)
"you can use output_ts_offset instead of it\n");
 }
 
-if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
+if (seg->segment_idx < 0)
+seg->segment_idx = seg->split_chapters;
+
+if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
!!seg->split_chapters > 1) {
 av_log(s, AV_LOG_ERROR,
-   "segment_time, segment_times, and segment_frames options "
-   "are mutually exclusive, select just one of them\n");
+   "segment_time, segment_times, segment_frames, and "
+   "segment_chapters options are mutually exclusive; "
+   "select just one of them\n");
 return AVERROR(EINVAL);
 }
 
@@ -672,7 +720,7 @@ static int seg_init(AVFormatContext *s)
 } else if (seg->frames_str) {
 if ((ret = parse_frames(s, &seg->frames, &seg->nb_frames, 
seg->frames_str)) < 0)
 return ret;
-} else {
+} else if (!seg->split_chapters) {
 /* set default value if not specified */
 if (!seg->time_str)
 seg->time_str = av_strdup("2");
@@ -739,6 +787,9 @@ static int seg_init(AVFormatContext *s)
 if ((ret = segment_mux_init(s)) < 0)
 return ret;
 
+if (seg->split_chapters && s->nb_chapters && (ret = 
av_dict_copy(&seg->avf->metadata, s->chapters[0]->metadata, 0)) < 0)
+return ret;
+
  

[FFmpeg-devel] [PATCH 3/7] lavf/segment: copy stream dispositions in output

2017-08-02 Thread Rodger Combs
---
 libavformat/segment.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 590f62b..ef0a915 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -182,6 +182,7 @@ static int segment_mux_init(AVFormatContext *s)
 }
 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
 st->time_base = s->streams[i]->time_base;
+st->disposition = s->streams[i]->disposition;
 av_dict_copy(&st->metadata, s->streams[i]->metadata, 0);
 }
 
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-02 Thread Rodger Combs
---
 doc/muxers.texi   |  4 
 libavformat/segment.c | 40 +---
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 23ef2e7..93147e1 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
defaults to 0.
 If enabled, write an empty segment if there are no packets during the period a
 segment would usually span. Otherwise, the segment will be filled with the next
 packet written. Defaults to @code{0}.
+
+@item dup_attached_pics @var{1|0}
+If enabled, attached-picture packets will be written to all segments, rather
+than only the first. Defaults to @code{1}.
 @end table
 
 @subsection Examples
diff --git a/libavformat/segment.c b/libavformat/segment.c
index ef0a915..632476e 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -119,6 +119,7 @@ typedef struct SegmentContext {
 int   reference_stream_index;
 int   break_non_keyframes;
 int   write_empty;
+int   dup_attached_pics;
 
 int use_rename;
 char temp_list_filename[1024];
@@ -126,6 +127,8 @@ typedef struct SegmentContext {
 SegmentListEntry cur_entry;
 SegmentListEntry *segment_list_entries;
 SegmentListEntry *segment_list_entries_end;
+
+AVPacket *attached_pics;
 } SegmentContext;
 
 static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
@@ -193,16 +196,15 @@ static int replace_variables(AVFormatContext *oc)
 {
 char name[sizeof(oc->filename)];
 char *p = name;
-char *out = oc->filename;
+AVBPrint bprint;
 strncpy(name, oc->filename, sizeof(name));
+av_bprint_init_for_buffer(&bprint, oc->filename, sizeof(oc->filename));
 while (*p) {
 char c = *p++;
 if (c == '$') {
 if (*p == '$') {
-p++;
-goto append;
+av_bprint_chars(&bprint, c, 1);
 } else {
-int len;
 const char *val;
 const AVDictionaryEntry *e;
 int end = strcspn(p, "$");
@@ -211,18 +213,13 @@ static int replace_variables(AVFormatContext *oc)
 p[end] = '\0';
 e = av_dict_get(oc->metadata, p, NULL, 0);
 val = e ? e->value : "(unknown)";
-len = strlen(val);
-strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
out);
-out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
len);
+av_bprint_append_data(&bprint, val, strlen(val));
 p += end + 1;
 }
 } else {
-append:
-if (out - oc->filename < sizeof(oc->filename) - 1)
-*out++ = c;
+av_bprint_chars(&bprint, c, 1);
 }
 }
-*out = '\0';
 return 0;
 }
 
@@ -301,6 +298,7 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
 
 if (write_header) {
+int i;
 AVDictionary *options = NULL;
 av_dict_copy(&options, seg->format_options, 0);
 av_dict_set(&options, "fflags", "-autobsf", 0);
@@ -308,6 +306,13 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_dict_free(&options);
 if (err < 0)
 return err;
+for (i = 0; i < s->nb_streams; i++) {
+if (seg->dup_attached_pics &&
+s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
+seg->attached_pics[i].data) {
+av_write_frame(oc, &seg->attached_pics[i]);
+}
+}
 }
 
 seg->segment_frame_count = 0;
@@ -680,6 +685,12 @@ static void seg_free(AVFormatContext *s)
 ff_format_io_close(seg->avf, &seg->list_pb);
 avformat_free_context(seg->avf);
 seg->avf = NULL;
+if (seg->attached_pics) {
+int i;
+for (i = 0; i < s->nb_streams; i++)
+av_packet_unref(&seg->attached_pics[i]);
+av_freep(&seg->attached_pics);
+}
 }
 
 static int seg_init(AVFormatContext *s)
@@ -840,6 +851,9 @@ static int seg_init(AVFormatContext *s)
 avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
inner_st->time_base.num, inner_st->time_base.den);
 }
 
+if (seg->dup_attached_pics && !(seg->attached_pics = 
av_calloc(s->nb_streams, sizeof(AVPacket
+return AVERROR(ENOMEM);
+
 if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
 s->avoid_negative_ts = 1;
 
@@ -905,6 +919,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (!seg->avf || !seg->avf->pb)
 return AVERROR(EINVAL);
 
+if (seg->dup_attached_pics && st->disposition & 
AV_DISPOSITION_ATTACHED_PIC)
+av_copy_packet(&seg->attached_pics[pkt->stream_index], pkt);
+
 calc_times:
 if (seg->times) {
 end_pts = seg->segment_count < seg->nb_times ?
@@ -,6 +1128,7

[FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-08-02 Thread Rodger Combs
---
 Changelog|   2 +
 doc/demuxers.texi|  17 
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/cuedec.c | 246 +++
 libavformat/version.h|   2 +-
 6 files changed, 268 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/cuedec.c

diff --git a/Changelog b/Changelog
index 187ae79..6701d30 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,8 @@ version :
 - limiter video filter
 - libvmaf video filter
 - Dolby E decoder and SMPTE 337M demuxer
+- Cue sheet demuxer
+
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 29a23d4..04eaf27 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -244,6 +244,23 @@ file subdir/file-2.wav
 @end example
 @end itemize
 
+@section cue
+
+Cue sheet demuxer.
+
+This demuxer reads a cue sheet (text file) and exports its track listing in
+the form of AVChapters. Packet data is read from the file listed in the sheet,
+which must be in the same directory. To override the path the packet data is
+read from, use the @code{url} option.
+
+This demuxer currently only supports cue sheets with a single audio file.
+
+This demuxer can be used along with the segment muxer to split a cue+audio pair
+into individual files for the different tracks:
+@example
+ffmpeg -i input.cue -f segment -segment_chapters 1 '%02d $artist$ - 
$title$.flac'
+@end example
+
 @section flv, live_flv
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index b0ef82c..4381c42 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER)  += cdxl.o
 OBJS-$(CONFIG_CINE_DEMUXER)  += cinedec.o
 OBJS-$(CONFIG_CONCAT_DEMUXER)+= concatdec.o
 OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
+OBJS-$(CONFIG_CUE_DEMUXER)   += cuedec.o
 OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
 OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
 OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1ebc142..25afa8b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -96,6 +96,7 @@ static void register_all(void)
 REGISTER_DEMUXER (CINE, cine);
 REGISTER_DEMUXER (CONCAT,   concat);
 REGISTER_MUXER   (CRC,  crc);
+REGISTER_DEMUXER (CUE,  cue);
 REGISTER_MUXER   (DASH, dash);
 REGISTER_MUXDEMUX(DATA, data);
 REGISTER_MUXDEMUX(DAUD, daud);
diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c
new file mode 100644
index 000..11b256d
--- /dev/null
+++ b/libavformat/cuedec.c
@@ -0,0 +1,246 @@
+/*
+ * Cue sheet demuxer
+ * Copyright (c) 2016 The FFmpeg Project
+ *
+ * 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
+ * Cue sheet demuxer
+ * @author Rodger Combs 
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "subtitles.h"
+#include "url.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+
+typedef struct CueDemuxContext {
+AVClass *class;
+char *url;
+AVFormatContext *avf;
+} CueDemuxContext;
+
+static int cue_probe(AVProbeData *p)
+{
+const unsigned char *ptr = p->buf;
+int has_file = 0, has_track = 0;
+
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr && (!has_file || !has_track)) {
+while (*ptr == ' ' || *ptr == '\t')
+ptr++;
+if (!strncmp(ptr, "FILE ", 5)) {
+ptr += 5;
+while (*ptr == ' ' || *ptr == '\t')
+ptr++;
+if (*ptr == '"')
+has_file = 1;
+} else if (!strncmp(ptr, "TRACK ", 6)) {
+ptr += 6;
+while (*ptr == ' ' || *ptr == '\t')
+ptr++;
+if (!av_isdigit(*ptr))
+return 0;
+while

Re: [FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-08-01 Thread Rodger Combs

> On Aug 1, 2017, at 02:58, Nicolas George  wrote:
> 
> Le quartidi 14 thermidor, an CCXXV, Rodger Combs a écrit :
>> ---
>> Changelog|   2 +
>> doc/demuxers.texi|   8 ++
>> libavformat/Makefile |   1 +
>> libavformat/allformats.c |   1 +
>> libavformat/cuedec.c | 215 
>> +++
>> libavformat/version.h|   2 +-
>> 6 files changed, 228 insertions(+), 1 deletion(-)
>> create mode 100644 libavformat/cuedec.c
>> 
>> diff --git a/Changelog b/Changelog
>> index 187ae79..6701d30 100644
>> --- a/Changelog
>> +++ b/Changelog
>> @@ -29,6 +29,8 @@ version :
>> - limiter video filter
>> - libvmaf video filter
>> - Dolby E decoder and SMPTE 337M demuxer
>> +- Cue sheet demuxer
>> +
>> 
>> version 3.3:
>> - CrystalHD decoder moved to new decode API
>> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
>> index 29a23d4..7ea4f27 100644
>> --- a/doc/demuxers.texi
>> +++ b/doc/demuxers.texi
>> @@ -244,6 +244,14 @@ file subdir/file-2.wav
>> @end example
>> @end itemize
>> 
>> +@section cue
>> +
>> +Cue sheet demuxer.
>> +
>> +This demuxer reads a cue sheet (text file) and exports its track listing in
>> +the form of AVChapters. Packet data is read from the file listed in the 
>> sheet.
>> +To override the path the packet data is read from, use the @code{url} 
>> option.
>> +
>> @section flv, live_flv
>> 
>> Adobe Flash Video Format demuxer.
>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>> index b0ef82c..4381c42 100644
>> --- a/libavformat/Makefile
>> +++ b/libavformat/Makefile
>> @@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER)  += cdxl.o
>> OBJS-$(CONFIG_CINE_DEMUXER)  += cinedec.o
>> OBJS-$(CONFIG_CONCAT_DEMUXER)+= concatdec.o
>> OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
>> +OBJS-$(CONFIG_CUE_DEMUXER)   += cuedec.o
>> OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
>> OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
>> OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>> index 1ebc142..25afa8b 100644
>> --- a/libavformat/allformats.c
>> +++ b/libavformat/allformats.c
>> @@ -96,6 +96,7 @@ static void register_all(void)
>> REGISTER_DEMUXER (CINE, cine);
>> REGISTER_DEMUXER (CONCAT,   concat);
>> REGISTER_MUXER   (CRC,  crc);
>> +REGISTER_DEMUXER (CUE,  cue);
>> REGISTER_MUXER   (DASH, dash);
>> REGISTER_MUXDEMUX(DATA, data);
>> REGISTER_MUXDEMUX(DAUD, daud);
>> diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c
>> new file mode 100644
>> index 000..d0dcac4
>> --- /dev/null
>> +++ b/libavformat/cuedec.c
>> @@ -0,0 +1,215 @@
>> +/*
>> + * Cue sheet demuxer
>> + * Copyright (c) 2016 The FFmpeg Project
>> + *
>> + * 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
>> + * Cue sheet demuxer
>> + * @author Rodger Combs 
>> + */
>> +
>> +#include "avformat.h"
>> +#include "internal.h"
>> +#include "subtitles.h"
>> +#include "url.h"
>> +#include "libavutil/intreadwrite.h"
>> +#include "libavutil/avstring.h"
>> +#include "libavutil/opt.h"
>> +
>> +typedef struct CueDemuxContext {
>> +AVClass *class;
>> +char *url;
>> +AVFormatContext *avf;
>> +} CueDemuxContext;
>> +
>> +static int cue_probe(AVProbeData *p)
>> +{
>

Re: [FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-08-01 Thread Rodger Combs

> On Aug 1, 2017, at 18:25, James Almer  wrote:
> 
> On 8/1/2017 3:33 AM, Rodger Combs wrote:
>> ---
>> libavformat/flacenc.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
>> index 9768b6a..1906aee 100644
>> --- a/libavformat/flacenc.c
>> +++ b/libavformat/flacenc.c
>> @@ -322,7 +322,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
>> if (!c->write_header || !streaminfo)
>> return 0;
>> 
>> -if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
>> +if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
>> s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
> 
> In what situation would stream extradata or c->streaminfo be smaller
> than FLAC_STREAMINFO_SIZE? Nothing changes par->extradata anywhere, and
> c->streaminfo is always allocated with FLAC_STREAMINFO_SIZE bytes of memory.
> I have the feeling i already asked this before, but not sure if you
> answered it. Apologies if you did.

It shouldn't happen in normal cases, but you could imagine a case with remuxing 
a corrupted input file.

> 
> You can also simplify this by just rewriting the STREAMINFO header only
> if c->streaminfo is allocated, meaning updated extradata showed up in a
> packet. Otherwise, you'd be rewriting the same STREAMINFO header you
> already wrote at the beginning.

Ah, good idea! Done.

> You could also even use ff_flac_write_header(), which already does a
> buffer size check.

I don't think this is necessary when coupled with your previous suggestion?

> 
> diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
> index b894f9ef61..7392cf13c1 100644
> --- a/libavformat/flacenc.c
> +++ b/libavformat/flacenc.c
> @@ -141,17 +141,15 @@ static int flac_write_trailer(struct
> AVFormatContext *s)
> AVIOContext *pb = s->pb;
> int64_t file_size;
> FlacMuxerContext *c = s->priv_data;
> -uint8_t *streaminfo = c->streaminfo ? c->streaminfo :
> -
> s->streams[0]->codecpar->extradata;
> 
> -if (!c->write_header || !streaminfo)
> +if (!c->write_header || !c->streaminfo)
> return 0;
> 
> if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
> /* rewrite the STREAMINFO header block data */
> file_size = avio_tell(pb);
> -avio_seek(pb, 8, SEEK_SET);
> -avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
> +avio_seek(pb, 0, SEEK_SET);
> +ff_flac_write_header(pb, c->streaminfo, FLAC_STREAMINFO_SIZE, 0);
> avio_seek(pb, file_size, SEEK_SET);
> avio_flush(pb);
> } else {
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Rodger Combs
Variables may be declared at the top of a scope block in ffmpeg.

> On Aug 1, 2017, at 01:50, Steven Liu  wrote:
> 
> 2017-08-01 14:33 GMT+08:00 Rodger Combs  <mailto:rodger.co...@gmail.com>>:
>> ---
>> doc/muxers.texi   |  4 
>> libavformat/segment.c | 24 
>> 2 files changed, 28 insertions(+)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 23ef2e7..93147e1 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
>> defaults to 0.
>> If enabled, write an empty segment if there are no packets during the period 
>> a
>> segment would usually span. Otherwise, the segment will be filled with the 
>> next
>> packet written. Defaults to @code{0}.
>> +
>> +@item dup_attached_pics @var{1|0}
>> +If enabled, attached-picture packets will be written to all segments, rather
>> +than only the first. Defaults to @code{1}.
>> @end table
>> 
>> @subsection Examples
>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>> index ef0a915..8e82030 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -119,6 +119,7 @@ typedef struct SegmentContext {
>> int   reference_stream_index;
>> int   break_non_keyframes;
>> int   write_empty;
>> +int   dup_attached_pics;
>> 
>> int use_rename;
>> char temp_list_filename[1024];
>> @@ -126,6 +127,8 @@ typedef struct SegmentContext {
>> SegmentListEntry cur_entry;
>> SegmentListEntry *segment_list_entries;
>> SegmentListEntry *segment_list_entries_end;
>> +
>> +AVPacket *attached_pics;
>> } SegmentContext;
>> 
>> static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
>> @@ -301,6 +304,7 @@ static int segment_start(AVFormatContext *s, int 
>> write_header)
>> av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
>> 
>> if (write_header) {
>> +int i;
> move to the top of the function,
>> AVDictionary *options = NULL;
>> av_dict_copy(&options, seg->format_options, 0);
>> av_dict_set(&options, "fflags", "-autobsf", 0);
>> @@ -308,6 +312,13 @@ static int segment_start(AVFormatContext *s, int 
>> write_header)
>> av_dict_free(&options);
>> if (err < 0)
>> return err;
>> +for (i = 0; i < s->nb_streams; i++) {
>> +if (seg->dup_attached_pics &&
>> +s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
>> +seg->attached_pics[i].data) {
>> +av_write_frame(oc, &seg->attached_pics[i]);
>> +}
>> +}
>> }
>> 
>> seg->segment_frame_count = 0;
>> @@ -680,6 +691,12 @@ static void seg_free(AVFormatContext *s)
>> ff_format_io_close(seg->avf, &seg->list_pb);
>> avformat_free_context(seg->avf);
>> seg->avf = NULL;
>> +if (seg->attached_pics) {
>> +int i;
> move to the top of the function,
>> +for (i = 0; i < s->nb_streams; i++)
>> +av_packet_unref(&seg->attached_pics[i]);
>> +av_freep(&seg->attached_pics);
>> +}
>> }
>> 
>> static int seg_init(AVFormatContext *s)
>> @@ -840,6 +857,9 @@ static int seg_init(AVFormatContext *s)
>> avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
>> inner_st->time_base.num, inner_st->time_base.den);
>> }
>> 
>> +if (seg->dup_attached_pics && !(seg->attached_pics = 
>> av_calloc(s->nb_streams, sizeof(AVPacket
>> +return AVERROR(ENOMEM);
>> +
>> if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
>> s->avoid_negative_ts = 1;
>> 
>> @@ -905,6 +925,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
>> *pkt)
>> if (!seg->avf || !seg->avf->pb)
>> return AVERROR(EINVAL);
>> 
>> +if (seg->dup_attached_pics && st->disposition & 
>> AV_DISPOSITION_ATTACHED_PIC)
>> +av_copy_packet(&seg->attached_pics[pkt->stream_index], pkt);
>> +
>> calc_times:
>> if (seg->times) {
>> end_pts = seg->segment_count < seg->nb_times ?
>> @@ -,6 +1134,7 @@ static c

Re: [FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-08-01 Thread Rodger Combs
This was pretty confusing whether it uses strlcpy or strncpy, so I'm switching 
it to AVBPrintf.

> On Aug 1, 2017, at 01:54, Steven Liu  wrote:
> 
> 2017-08-01 14:33 GMT+08:00 Rodger Combs  <mailto:rodger.co...@gmail.com>>:
>> ---
>> doc/muxers.texi   |  6 +
>> libavformat/segment.c | 65 
>> +++
>> libavformat/version.h |  2 +-
>> 3 files changed, 67 insertions(+), 6 deletions(-)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 94472ce..23ef2e7 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -1538,6 +1538,12 @@ This option specifies to start a new segment whenever 
>> a reference
>> stream key frame is found and the sequential number (starting from 0)
>> of the frame is greater or equal to the next value in the list.
>> 
>> +@item segment_chapters @var{1|0}
>> +Split each chapter into its own segment. Metadata from the chapters
>> +will be written to the corresponding segments. If this option is selected
>> +and the filename contains tokens in the format @code{$varname$}, they
>> +will be replaced by the corresponding metadata values.
>> +
>> @item segment_wrap @var{limit}
>> Wrap around segment index once it reaches @var{limit}.
>> 
>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>> index 0e8bcdd..590f62b 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -106,6 +106,8 @@ typedef struct SegmentContext {
>> int frame_count;   ///< total number of reference frames
>> int segment_frame_count; ///< number of reference frames in the segment
>> 
>> +int split_chapters;///< split on chapter markers
>> +
>> int64_t time_delta;
>> int  individual_header_trailer; /**< Set by a private option. */
>> int  write_header_trailer; /**< Set by a private option. */
>> @@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
>> return 0;
>> }
>> 
>> +static int replace_variables(AVFormatContext *oc)
>> +{
>> +char name[sizeof(oc->filename)];
>> +char *p = name;
>> +char *out = oc->filename;
>> +strncpy(name, oc->filename, sizeof(name));
>> +while (*p) {
>> +char c = *p++;
>> +if (c == '$') {
>> +if (*p == '$') {
>> +p++;
>> +goto append;
>> +} else {
>> +int len;
>> +const char *val;
>> +const AVDictionaryEntry *e;
>> +int end = strcspn(p, "$");
>> +if (p[end] == '\0')
>> +continue;
>> +p[end] = '\0';
>> +e = av_dict_get(oc->metadata, p, NULL, 0);
>> +val = e ? e->value : "(unknown)";
>> +len = strlen(val);
>> +strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
>> out);
> why not av_strlcpy?
>> +out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
>> len);
>> +p += end + 1;
>> +}
>> +} else {
>> +append:
>> +if (out - oc->filename < sizeof(oc->filename) - 1)
>> +*out++ = c;
>> +}
>> +}
>> +*out = '\0';
>> +return 0;
>> +}
>> +
>> static int set_segment_filename(AVFormatContext *s)
>> {
>> SegmentContext *seg = s->priv_data;
>> @@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
>> return AVERROR(EINVAL);
>> }
>> 
>> +if (seg->split_chapters)
>> +replace_variables(oc);
>> +
>> /* copy modified name in list entry */
>> size = strlen(av_basename(oc->filename)) + 1;
>> if (seg->entry_prefix)
>> @@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
>> write_header)
>> if ((err = segment_mux_init(s)) < 0)
>> return err;
>> oc = seg->avf;
>> +if (seg->split_chapters && seg->segment_count < s->nb_chapters && 
>> (err = av_dict_copy(&oc->metadata, 
>> s->chapters[seg->segment_count]->metadata, 0)) < 0)
>> +return err;
>> }
>> 
>> seg->segment_idx++;
>> @@ -659,10 +703,14 @@ static int seg_init(AVFormatContex

[FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-07-31 Thread Rodger Combs
---
 Changelog|   2 +
 doc/demuxers.texi|   8 ++
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/cuedec.c | 215 +++
 libavformat/version.h|   2 +-
 6 files changed, 228 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/cuedec.c

diff --git a/Changelog b/Changelog
index 187ae79..6701d30 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,8 @@ version :
 - limiter video filter
 - libvmaf video filter
 - Dolby E decoder and SMPTE 337M demuxer
+- Cue sheet demuxer
+
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 29a23d4..7ea4f27 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -244,6 +244,14 @@ file subdir/file-2.wav
 @end example
 @end itemize
 
+@section cue
+
+Cue sheet demuxer.
+
+This demuxer reads a cue sheet (text file) and exports its track listing in
+the form of AVChapters. Packet data is read from the file listed in the sheet.
+To override the path the packet data is read from, use the @code{url} option.
+
 @section flv, live_flv
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index b0ef82c..4381c42 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER)  += cdxl.o
 OBJS-$(CONFIG_CINE_DEMUXER)  += cinedec.o
 OBJS-$(CONFIG_CONCAT_DEMUXER)+= concatdec.o
 OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
+OBJS-$(CONFIG_CUE_DEMUXER)   += cuedec.o
 OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
 OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
 OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1ebc142..25afa8b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -96,6 +96,7 @@ static void register_all(void)
 REGISTER_DEMUXER (CINE, cine);
 REGISTER_DEMUXER (CONCAT,   concat);
 REGISTER_MUXER   (CRC,  crc);
+REGISTER_DEMUXER (CUE,  cue);
 REGISTER_MUXER   (DASH, dash);
 REGISTER_MUXDEMUX(DATA, data);
 REGISTER_MUXDEMUX(DAUD, daud);
diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c
new file mode 100644
index 000..d0dcac4
--- /dev/null
+++ b/libavformat/cuedec.c
@@ -0,0 +1,215 @@
+/*
+ * Cue sheet demuxer
+ * Copyright (c) 2016 The FFmpeg Project
+ *
+ * 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
+ * Cue sheet demuxer
+ * @author Rodger Combs 
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "subtitles.h"
+#include "url.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+
+typedef struct CueDemuxContext {
+AVClass *class;
+char *url;
+AVFormatContext *avf;
+} CueDemuxContext;
+
+static int cue_probe(AVProbeData *p)
+{
+const unsigned char *ptr = p->buf;
+
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr && strncmp(ptr, "FILE ", 5))
+ptr += ff_subtitles_next_line(ptr);
+if (!strncmp(ptr, "FILE ", 5))
+return AVPROBE_SCORE_MAX - 5;
+return 0;
+}
+
+static char *get_token(char *in)
+{
+char *end;
+while (av_isspace(*in))
+in++;
+if (*in == '"') {
+in++;
+end = in + strcspn(in, "\"\n\t\r");
+} else {
+end = in + strcspn(in, " \n\t\r");
+}
+*end = '\0';
+return in;
+}
+
+static int cue_read_header(AVFormatContext *s)
+{
+int ret, i;
+CueDemuxContext *cue = s->priv_data;
+char line[4096], *ptr;
+AVDictionary **meta = &s->metadata;
+AVChapter *chap = NULL;
+while (ff_get_line(s->pb, line, sizeof(line))) {
+ptr = line;
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr == ' ' || *ptr == '\t')
+ptr++;
+if (!strncmp(ptr, "RE

[FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-07-31 Thread Rodger Combs
---
 doc/muxers.texi   |  6 +
 libavformat/segment.c | 65 +++
 libavformat/version.h |  2 +-
 3 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 94472ce..23ef2e7 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1538,6 +1538,12 @@ This option specifies to start a new segment whenever a 
reference
 stream key frame is found and the sequential number (starting from 0)
 of the frame is greater or equal to the next value in the list.
 
+@item segment_chapters @var{1|0}
+Split each chapter into its own segment. Metadata from the chapters
+will be written to the corresponding segments. If this option is selected
+and the filename contains tokens in the format @code{$varname$}, they
+will be replaced by the corresponding metadata values.
+
 @item segment_wrap @var{limit}
 Wrap around segment index once it reaches @var{limit}.
 
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 0e8bcdd..590f62b 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -106,6 +106,8 @@ typedef struct SegmentContext {
 int frame_count;   ///< total number of reference frames
 int segment_frame_count; ///< number of reference frames in the segment
 
+int split_chapters;///< split on chapter markers
+
 int64_t time_delta;
 int  individual_header_trailer; /**< Set by a private option. */
 int  write_header_trailer; /**< Set by a private option. */
@@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
 return 0;
 }
 
+static int replace_variables(AVFormatContext *oc)
+{
+char name[sizeof(oc->filename)];
+char *p = name;
+char *out = oc->filename;
+strncpy(name, oc->filename, sizeof(name));
+while (*p) {
+char c = *p++;
+if (c == '$') {
+if (*p == '$') {
+p++;
+goto append;
+} else {
+int len;
+const char *val;
+const AVDictionaryEntry *e;
+int end = strcspn(p, "$");
+if (p[end] == '\0')
+continue;
+p[end] = '\0';
+e = av_dict_get(oc->metadata, p, NULL, 0);
+val = e ? e->value : "(unknown)";
+len = strlen(val);
+strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
out);
+out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
len);
+p += end + 1;
+}
+} else {
+append:
+if (out - oc->filename < sizeof(oc->filename) - 1)
+*out++ = c;
+}
+}
+*out = '\0';
+return 0;
+}
+
 static int set_segment_filename(AVFormatContext *s)
 {
 SegmentContext *seg = s->priv_data;
@@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
+if (seg->split_chapters)
+replace_variables(oc);
+
 /* copy modified name in list entry */
 size = strlen(av_basename(oc->filename)) + 1;
 if (seg->entry_prefix)
@@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 if ((err = segment_mux_init(s)) < 0)
 return err;
 oc = seg->avf;
+if (seg->split_chapters && seg->segment_count < s->nb_chapters && (err 
= av_dict_copy(&oc->metadata, s->chapters[seg->segment_count]->metadata, 0)) < 
0)
+return err;
 }
 
 seg->segment_idx++;
@@ -659,10 +703,14 @@ static int seg_init(AVFormatContext *s)
"you can use output_ts_offset instead of it\n");
 }
 
-if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
+if (seg->segment_idx < 0)
+seg->segment_idx = seg->split_chapters;
+
+if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
!!seg->split_chapters > 1) {
 av_log(s, AV_LOG_ERROR,
-   "segment_time, segment_times, and segment_frames options "
-   "are mutually exclusive, select just one of them\n");
+   "segment_time, segment_times, segment_frames, and "
+   "segment_chapters options are mutually exclusive; "
+   "select just one of them\n");
 return AVERROR(EINVAL);
 }
 
@@ -672,7 +720,7 @@ static int seg_init(AVFormatContext *s)
 } else if (seg->frames_str) {
 if ((ret = parse_frames(s, &seg->frames, &seg->nb_frames, 
seg->frames_str)) < 0)
 return ret;
-} else {
+} else if (!seg->split_chapters) {
 /* set default value if not specified */
 if (!seg->time_str)
 seg->time_str = av_strdup("2");
@@ -739,6 +787,9 @@ static int seg_init(AVFormatContext *s)
 if ((ret = segment_mux_init(s)) < 0)
 return ret;
 
+if (seg->split_chapters && s->nb_chapters && (ret = 
av_dict_copy(&seg->avf->metadata, s->chapters[0]->metadata, 0)) < 0)
+return ret;
+
  

[FFmpeg-devel] [PATCH 5/7] lavf/flacenc: support writing attached pictures

2017-07-31 Thread Rodger Combs
---
 libavformat/flacenc.c | 285 +++---
 1 file changed, 250 insertions(+), 35 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b894f9e..9768b6a 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -21,10 +21,13 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "flacenc.h"
+#include "id3v2.h"
+#include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
 
@@ -33,8 +36,16 @@ typedef struct FlacMuxerContext {
 const AVClass *class;
 int write_header;
 
+int audio_stream_idx;
+AVPacket *pics;
+int nb_pics, waiting_pics;
+/* audio packets are queued here until we get all the attached pictures */
+AVPacketList *queue, *queue_end;
+
 /* updated streaminfo sent by the encoder at the end */
 uint8_t *streaminfo;
+
+unsigned attached_types;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -74,31 +85,156 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_write_picture(struct AVFormatContext *s, AVPacket *pkt)
 {
-int ret;
-int padding = s->metadata_header_padding;
-AVCodecParameters *par = s->streams[0]->codecpar;
-FlacMuxerContext *c   = s->priv_data;
-
-if (!c->write_header)
+FlacMuxerContext *c = s->priv_data;
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0;
+
+if (!pkt->data)
 return 0;
 
-if (s->nb_streams > 1) {
-av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
 return AVERROR(EINVAL);
 }
-if (par->codec_id != AV_CODEC_ID_FLAC) {
-av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if ((c->attached_types & (1 << type)) & 0x6) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
+return AVERROR(EINVAL);
+}
+
+if (type == 1 && (st->codecpar->codec_id != AV_CODEC_ID_PNG ||
+  st->codecpar->width != 32 ||
+  st->codecpar->height != 32)) {
+av_log(s, AV_LOG_ERROR, "File icon attachment must be a 32x32 PNG");
 return AVERROR(EINVAL);
 }
 
+c->attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+avio_w8(pb, 0x06);
+avio_wb24(pb, 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + 
pkt->size);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+return 0;
+}
+
+static int flac_finish_header(struct AVFormatContext *s)
+{
+FlacMuxerContext *c = s->priv_data;
+int i, ret, padding = s->metadata_header_padding;
 if (padding < 0)
 padding = 8192;
 /* The FLAC specification states that 24 bits are used to represent the
  * size of a metadata block so we must clip this value to 2^24-1. */
 padding = av_clip_uintp2(padding, 24);
 
+for (i = 0; i < c->nb_pics; i++) {
+ret = flac_write_picture(s, &c->pics[i]);
+if (ret)
+return ret;
+}
+
+ret = flac_write_block_comment(s->pb, &s->metadata, !padding,
+   s->flags & AVFMT_FLAG_BITEXACT);
+if (ret)
+return ret;
+
+/* The command line flac encoder defaults to placing a seekpoint
+ * every 10s.  So one

[FFmpeg-devel] [PATCH 3/7] lavf/segment: copy stream dispositions in output

2017-07-31 Thread Rodger Combs
---
 libavformat/segment.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 590f62b..ef0a915 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -182,6 +182,7 @@ static int segment_mux_init(AVFormatContext *s)
 }
 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
 st->time_base = s->streams[i]->time_base;
+st->disposition = s->streams[i]->disposition;
 av_dict_copy(&st->metadata, s->streams[i]->metadata, 0);
 }
 
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-07-31 Thread Rodger Combs
---
 doc/muxers.texi   |  4 
 libavformat/segment.c | 24 
 2 files changed, 28 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 23ef2e7..93147e1 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
defaults to 0.
 If enabled, write an empty segment if there are no packets during the period a
 segment would usually span. Otherwise, the segment will be filled with the next
 packet written. Defaults to @code{0}.
+
+@item dup_attached_pics @var{1|0}
+If enabled, attached-picture packets will be written to all segments, rather
+than only the first. Defaults to @code{1}.
 @end table
 
 @subsection Examples
diff --git a/libavformat/segment.c b/libavformat/segment.c
index ef0a915..8e82030 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -119,6 +119,7 @@ typedef struct SegmentContext {
 int   reference_stream_index;
 int   break_non_keyframes;
 int   write_empty;
+int   dup_attached_pics;
 
 int use_rename;
 char temp_list_filename[1024];
@@ -126,6 +127,8 @@ typedef struct SegmentContext {
 SegmentListEntry cur_entry;
 SegmentListEntry *segment_list_entries;
 SegmentListEntry *segment_list_entries_end;
+
+AVPacket *attached_pics;
 } SegmentContext;
 
 static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
@@ -301,6 +304,7 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
 
 if (write_header) {
+int i;
 AVDictionary *options = NULL;
 av_dict_copy(&options, seg->format_options, 0);
 av_dict_set(&options, "fflags", "-autobsf", 0);
@@ -308,6 +312,13 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_dict_free(&options);
 if (err < 0)
 return err;
+for (i = 0; i < s->nb_streams; i++) {
+if (seg->dup_attached_pics &&
+s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
+seg->attached_pics[i].data) {
+av_write_frame(oc, &seg->attached_pics[i]);
+}
+}
 }
 
 seg->segment_frame_count = 0;
@@ -680,6 +691,12 @@ static void seg_free(AVFormatContext *s)
 ff_format_io_close(seg->avf, &seg->list_pb);
 avformat_free_context(seg->avf);
 seg->avf = NULL;
+if (seg->attached_pics) {
+int i;
+for (i = 0; i < s->nb_streams; i++)
+av_packet_unref(&seg->attached_pics[i]);
+av_freep(&seg->attached_pics);
+}
 }
 
 static int seg_init(AVFormatContext *s)
@@ -840,6 +857,9 @@ static int seg_init(AVFormatContext *s)
 avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
inner_st->time_base.num, inner_st->time_base.den);
 }
 
+if (seg->dup_attached_pics && !(seg->attached_pics = 
av_calloc(s->nb_streams, sizeof(AVPacket
+return AVERROR(ENOMEM);
+
 if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
 s->avoid_negative_ts = 1;
 
@@ -905,6 +925,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (!seg->avf || !seg->avf->pb)
 return AVERROR(EINVAL);
 
+if (seg->dup_attached_pics && st->disposition & 
AV_DISPOSITION_ATTACHED_PIC)
+av_copy_packet(&seg->attached_pics[pkt->stream_index], pkt);
+
 calc_times:
 if (seg->times) {
 end_pts = seg->segment_count < seg->nb_times ?
@@ -,6 +1134,7 @@ static const AVOption options[] = {
 { "reset_timestamps", "reset timestamps at the begin of each segment", 
OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
 { "initial_offset", "set initial timestamp offset", 
OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, 
INT64_MAX, E },
 { "write_empty_segments", "allow writing empty 'filler' segments", 
OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
+{ "dup_attached_pics",  "write attached pictures to all segments", 
OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
 { NULL },
 };
 
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 7/7] lavf/flacenc: generate timestamps internally

2017-07-31 Thread Rodger Combs
---
 libavformat/flacenc.c | 88 +--
 1 file changed, 85 insertions(+), 3 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 1906aee..f569c14 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -30,6 +30,7 @@
 #include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
+#include "libavutil/crc.h"
 
 
 typedef struct FlacMuxerContext {
@@ -46,6 +47,9 @@ typedef struct FlacMuxerContext {
 uint8_t *streaminfo;
 
 unsigned attached_types;
+
+uint64_t samples;
+unsigned last_bs;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -263,11 +267,17 @@ static int flac_write_header(struct AVFormatContext *s)
 return ret;
 }
 
+static const int32_t blocksize_table[16] = {
+ 0,192, 576<<0, 576<<1, 576<<2, 576<<3,  0,  0,
+256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
+};
+
 static int flac_write_audio_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
 FlacMuxerContext *c = s->priv_data;
 uint8_t *streaminfo;
 int streaminfo_size;
+char header[16];
 
 /* check for updated streaminfo */
 streaminfo = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
@@ -281,8 +291,77 @@ static int flac_write_audio_packet(struct AVFormatContext 
*s, AVPacket *pkt)
 memcpy(c->streaminfo, streaminfo, FLAC_STREAMINFO_SIZE);
 }
 
-if (pkt->size)
-avio_write(s->pb, pkt->data, pkt->size);
+if (pkt->size) {
+uint8_t tmp;
+uint64_t pts = c->samples;
+int offset = 5;
+int headerlen = 4;
+int bscode, bs;
+int crc;
+if (pkt->size < FLAC_MIN_FRAME_SIZE)
+return AVERROR_INVALIDDATA;
+memcpy(header, pkt->data, 4);
+if (pkt->pts == AV_NOPTS_VALUE)
+pts = 0;
+if ((pkt->data[4] & 0xC0) == 0xC0)
+offset += ff_clz((unsigned char)~pkt->data[4]) - 25;
+else if (pkt->data[4] & 0x80)
+return AVERROR_INVALIDDATA;
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+
+bscode = (unsigned char)header[2] >> 4;
+bs = blocksize_table[bscode];
+if (bscode == 0)
+return AVERROR_INVALIDDATA;
+if (bscode == 6) {
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+bs = pkt->data[offset] + 1;
+} else if (bscode == 7) {
+if (pkt->size <= offset + 2)
+return AVERROR_INVALIDDATA;
+bs = AV_RB16(&pkt->data[offset]) + 1;
+}
+if ((header[1] & 1) == 0)
+pts /= c->last_bs ? c->last_bs : bs;
+
+c->last_bs = bs;
+
+c->samples += bs;
+
+PUT_UTF8(pts, tmp, header[headerlen++] = tmp;)
+if (headerlen > 11)
+return AVERROR_INVALIDDATA;
+if ((bscode & 0xE) == 0x6)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if (bscode == 0x7)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0xC) == 0xC) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0x3) == 0x3)
+return AVERROR_INVALIDDATA;
+else if (header[2] & 0x3) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+}
+}
+header[headerlen] = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, header, 
headerlen);
+headerlen++; offset++;
+crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, header, headerlen);
+if (pkt->size < offset + 3)
+return AVERROR_INVALIDDATA;
+avio_write(s->pb, header, headerlen);
+avio_write(s->pb, pkt->data + offset, pkt->size - offset - 2);
+avio_wl16(s->pb, av_crc(av_crc_get_table(AV_CRC_16_ANSI), crc, 
pkt->data + offset, pkt->size - offset - 2));
+}
 return 0;
 }
 
@@ -326,7 +405,10 @@ static int flac_write_trailer(struct AVFormatContext *s)
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
+avio_write(pb, streaminfo, 13);
+avio_w8(pb, (streaminfo[13] & 0xF0) | ((c->samples >> 32) & 0xF));
+avio_wb32(pb, c->samples);
+avio_write(pb, streaminfo + 18, FLAC_STREAMINFO_SIZE - 18);
 avio_seek(pb, file_size, SEEK_SET);
 avio_flush(pb);
 } else {
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel

[FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-07-31 Thread Rodger Combs
---
 libavformat/flacenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 9768b6a..1906aee 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -322,7 +322,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
 if (!c->write_header || !streaminfo)
 return 0;
 
-if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
+if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-05-07 Thread Rodger Combs
---
 Changelog|   2 +
 doc/demuxers.texi|   8 ++
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/cuedec.c | 207 +++
 libavformat/version.h|   4 +-
 6 files changed, 221 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/cuedec.c

diff --git a/Changelog b/Changelog
index 0787bea..3e2776d 100644
--- a/Changelog
+++ b/Changelog
@@ -8,6 +8,8 @@ version :
 - pixscope video filter
 - oscilloscope video filter
 - config.log and other configuration files moved into ffbuild/ directory
+- Cue sheet demuxer
+
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 29a23d4..7ea4f27 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -244,6 +244,14 @@ file subdir/file-2.wav
 @end example
 @end itemize
 
+@section cue
+
+Cue sheet demuxer.
+
+This demuxer reads a cue sheet (text file) and exports its track listing in
+the form of AVChapters. Packet data is read from the file listed in the sheet.
+To override the path the packet data is read from, use the @code{url} option.
+
 @section flv, live_flv
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 4e169fd..d4c8b3b 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER)  += cdxl.o
 OBJS-$(CONFIG_CINE_DEMUXER)  += cinedec.o
 OBJS-$(CONFIG_CONCAT_DEMUXER)+= concatdec.o
 OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
+OBJS-$(CONFIG_CUE_DEMUXER)   += cuedec.o
 OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
 OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
 OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 09e62c3..ad29a8c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -96,6 +96,7 @@ static void register_all(void)
 REGISTER_DEMUXER (CINE, cine);
 REGISTER_DEMUXER (CONCAT,   concat);
 REGISTER_MUXER   (CRC,  crc);
+REGISTER_DEMUXER (CUE,  cue);
 REGISTER_MUXER   (DASH, dash);
 REGISTER_MUXDEMUX(DATA, data);
 REGISTER_MUXDEMUX(DAUD, daud);
diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c
new file mode 100644
index 000..b177a26
--- /dev/null
+++ b/libavformat/cuedec.c
@@ -0,0 +1,207 @@
+/*
+ * Cue sheet demuxer
+ * Copyright (c) 2016 The FFmpeg Project
+ *
+ * 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
+ * Cue sheet demuxer
+ * @author Rodger Combs 
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "subtitles.h"
+#include "url.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+
+typedef struct CueDemuxContext {
+AVClass *class;
+char *url;
+AVFormatContext *avf;
+} CueDemuxContext;
+
+static int cue_probe(AVProbeData *p)
+{
+const unsigned char *ptr = p->buf;
+
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr && strncmp(ptr, "FILE ", 5))
+ptr += ff_subtitles_next_line(ptr);
+if (!strncmp(ptr, "FILE ", 5))
+return AVPROBE_SCORE_MAX - 5;
+return 0;
+}
+
+static char *get_token(char *in)
+{
+char *end;
+while (av_isspace(*in))
+in++;
+if (*in == '"') {
+in++;
+end = in + strcspn(in, "\"\n\t\r");
+} else {
+end = in + strcspn(in, " \n\t\r");
+}
+*end = '\0';
+return in;
+}
+
+static int cue_read_header(AVFormatContext *s)
+{
+int ret, i;
+CueDemuxContext *cue = s->priv_data;
+char line[4096], *ptr;
+AVDictionary **meta = &s->metadata;
+AVChapter *chap = NULL;
+while (ff_get_line(s->pb, line, sizeof(line))) {
+ptr = line;
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr == ' ' || *ptr == '\t')
+ptr++;

[FFmpeg-devel] [PATCH 7/7] lavf/flacenc: generate timestamps internally

2017-05-07 Thread Rodger Combs
---
 libavformat/flacenc.c | 88 +--
 1 file changed, 85 insertions(+), 3 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b8800cc..0e948ac 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -30,6 +30,7 @@
 #include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
+#include "libavutil/crc.h"
 
 
 typedef struct FlacMuxerContext {
@@ -46,6 +47,9 @@ typedef struct FlacMuxerContext {
 uint8_t *streaminfo;
 
 unsigned attached_types;
+
+uint64_t samples;
+unsigned last_bs;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -256,11 +260,17 @@ static int flac_write_header(struct AVFormatContext *s)
 return ret;
 }
 
+static const int32_t blocksize_table[16] = {
+ 0,192, 576<<0, 576<<1, 576<<2, 576<<3,  0,  0,
+256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
+};
+
 static int flac_write_audio_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
 FlacMuxerContext *c = s->priv_data;
 uint8_t *streaminfo;
 int streaminfo_size;
+char header[16];
 
 /* check for updated streaminfo */
 streaminfo = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
@@ -274,8 +284,77 @@ static int flac_write_audio_packet(struct AVFormatContext 
*s, AVPacket *pkt)
 memcpy(c->streaminfo, streaminfo, FLAC_STREAMINFO_SIZE);
 }
 
-if (pkt->size)
-avio_write(s->pb, pkt->data, pkt->size);
+if (pkt->size) {
+uint8_t tmp;
+uint64_t pts = c->samples;
+int offset = 5;
+int headerlen = 4;
+int bscode, bs;
+int crc;
+if (pkt->size < FLAC_MIN_FRAME_SIZE)
+return AVERROR_INVALIDDATA;
+memcpy(header, pkt->data, 4);
+if (pkt->pts == AV_NOPTS_VALUE)
+pts = 0;
+if ((pkt->data[4] & 0xC0) == 0xC0)
+offset += ff_clz((unsigned char)~pkt->data[4]) - 25;
+else if (pkt->data[4] & 0x80)
+return AVERROR_INVALIDDATA;
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+
+bscode = (unsigned char)header[2] >> 4;
+bs = blocksize_table[bscode];
+if (bscode == 0)
+return AVERROR_INVALIDDATA;
+if (bscode == 6) {
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+bs = pkt->data[offset] + 1;
+} else if (bscode == 7) {
+if (pkt->size <= offset + 2)
+return AVERROR_INVALIDDATA;
+bs = AV_RB16(&pkt->data[offset]) + 1;
+}
+if ((header[1] & 1) == 0)
+pts /= c->last_bs ? c->last_bs : bs;
+
+c->last_bs = bs;
+
+c->samples += bs;
+
+PUT_UTF8(pts, tmp, header[headerlen++] = tmp;)
+if (headerlen > 11)
+return AVERROR_INVALIDDATA;
+if ((bscode & 0xE) == 0x6)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if (bscode == 0x7)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0xC) == 0xC) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0x3) == 0x3)
+return AVERROR_INVALIDDATA;
+else if (header[2] & 0x3) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+}
+}
+header[headerlen] = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, header, 
headerlen);
+headerlen++; offset++;
+crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, header, headerlen);
+if (pkt->size < offset + 3)
+return AVERROR_INVALIDDATA;
+avio_write(s->pb, header, headerlen);
+avio_write(s->pb, pkt->data + offset, pkt->size - offset - 2);
+avio_wl16(s->pb, av_crc(av_crc_get_table(AV_CRC_16_ANSI), crc, 
pkt->data + offset, pkt->size - offset - 2));
+}
 return 0;
 }
 
@@ -319,7 +398,10 @@ static int flac_write_trailer(struct AVFormatContext *s)
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
+avio_write(pb, streaminfo, 13);
+avio_w8(pb, (streaminfo[13] & 0xF0) | ((c->samples >> 32) & 0xF));
+avio_wb32(pb, c->samples);
+avio_write(pb, streaminfo + 18, FLAC_STREAMINFO_SIZE - 18);
 avio_seek(pb, file_size, SEEK_SET);
 avio_flush(pb);
 } else {
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel

[FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-05-07 Thread Rodger Combs
---
 libavformat/flacenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 9bb4947..b8800cc 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -315,7 +315,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
 if (!c->write_header || !streaminfo)
 return 0;
 
-if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
+if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-05-07 Thread Rodger Combs
---
 doc/muxers.texi   |  4 
 libavformat/segment.c | 24 
 libavformat/version.h |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index b80bc68..3707d05 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1559,6 +1559,10 @@ argument must be a time duration specification, and 
defaults to 0.
 If enabled, write an empty segment if there are no packets during the period a
 segment would usually span. Otherwise, the segment will be filled with the next
 packet written. Defaults to @code{0}.
+
+@item dup_attached_pics @var{1|0}
+If enabled, attached-picture packets will be written to all segments, rather
+than only the first. Defaults to @code{1}.
 @end table
 
 @subsection Examples
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 9c6ce73..0b9089c 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -121,6 +121,7 @@ typedef struct SegmentContext {
 int   reference_stream_index;
 int   break_non_keyframes;
 int   write_empty;
+int   dup_attached_pics;
 
 int use_rename;
 char temp_list_filename[1024];
@@ -128,6 +129,8 @@ typedef struct SegmentContext {
 SegmentListEntry cur_entry;
 SegmentListEntry *segment_list_entries;
 SegmentListEntry *segment_list_entries_end;
+
+AVPacket *attached_pics;
 } SegmentContext;
 
 static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
@@ -303,6 +306,7 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
 
 if (write_header) {
+int i;
 AVDictionary *options = NULL;
 av_dict_copy(&options, seg->format_options, 0);
 av_dict_set(&options, "fflags", "-autobsf", 0);
@@ -310,6 +314,13 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_dict_free(&options);
 if (err < 0)
 return err;
+for (i = 0; i < s->nb_streams; i++) {
+if (seg->dup_attached_pics &&
+s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
+seg->attached_pics[i].data) {
+av_write_frame(oc, &seg->attached_pics[i]);
+}
+}
 }
 
 seg->segment_frame_count = 0;
@@ -682,6 +693,12 @@ static void seg_free(AVFormatContext *s)
 ff_format_io_close(seg->avf, &seg->list_pb);
 avformat_free_context(seg->avf);
 seg->avf = NULL;
+if (seg->attached_pics) {
+int i;
+for (i = 0; i < s->nb_streams; i++)
+av_packet_unref(&seg->attached_pics[i]);
+av_freep(&seg->attached_pics);
+}
 }
 
 static int seg_init(AVFormatContext *s)
@@ -842,6 +859,9 @@ static int seg_init(AVFormatContext *s)
 avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
inner_st->time_base.num, inner_st->time_base.den);
 }
 
+if (seg->dup_attached_pics && !(seg->attached_pics = 
av_calloc(s->nb_streams, sizeof(AVPacket
+return AVERROR(ENOMEM);
+
 if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
 s->avoid_negative_ts = 1;
 
@@ -907,6 +927,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (!seg->avf || !seg->avf->pb)
 return AVERROR(EINVAL);
 
+if (seg->dup_attached_pics && st->disposition & 
AV_DISPOSITION_ATTACHED_PIC)
+av_copy_packet(&seg->attached_pics[pkt->stream_index], pkt);
+
 calc_times:
 if (seg->times) {
 end_pts = seg->segment_count < seg->nb_times ?
@@ -1113,6 +1136,7 @@ static const AVOption options[] = {
 { "reset_timestamps", "reset timestamps at the begin of each segment", 
OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
 { "initial_offset", "set initial timestamp offset", 
OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, 
INT64_MAX, E },
 { "write_empty_segments", "allow writing empty 'filler' segments", 
OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
+{ "dup_attached_pics",  "write attached pictures to all segments", 
OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
 { NULL },
 };
 
diff --git a/libavformat/version.h b/libavformat/version.h
index 645a226..910e348 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
 #define LIBAVFORMAT_VERSION_MINOR  73
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MICRO 102
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/7] lavf/segment: copy stream dispositions in output

2017-05-07 Thread Rodger Combs
---
 libavformat/segment.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 8575d32..9c6ce73 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -184,6 +184,7 @@ static int segment_mux_init(AVFormatContext *s)
 }
 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
 st->time_base = s->streams[i]->time_base;
+st->disposition = s->streams[i]->disposition;
 av_dict_copy(&st->metadata, s->streams[i]->metadata, 0);
 }
 
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/7] lavf/flacenc: support writing attached pictures

2017-05-07 Thread Rodger Combs
---
 libavformat/flacenc.c | 271 +++---
 1 file changed, 236 insertions(+), 35 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b894f9e..9bb4947 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -21,10 +21,13 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "flacenc.h"
+#include "id3v2.h"
+#include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
 
@@ -33,8 +36,16 @@ typedef struct FlacMuxerContext {
 const AVClass *class;
 int write_header;
 
+int audio_stream_idx;
+AVPacket *pics;
+int nb_pics, waiting_pics;
+/* audio packets are queued here until we get all the attached pictures */
+AVPacketList *queue, *queue_end;
+
 /* updated streaminfo sent by the encoder at the end */
 uint8_t *streaminfo;
+
+unsigned attached_types;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -74,31 +85,149 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_write_picture(struct AVFormatContext *s, AVPacket *pkt)
 {
-int ret;
-int padding = s->metadata_header_padding;
-AVCodecParameters *par = s->streams[0]->codecpar;
-FlacMuxerContext *c   = s->priv_data;
-
-if (!c->write_header)
+FlacMuxerContext *c = s->priv_data;
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0;
+
+if (!pkt->data)
 return 0;
 
-if (s->nb_streams > 1) {
-av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
 return AVERROR(EINVAL);
 }
-if (par->codec_id != AV_CODEC_ID_FLAC) {
-av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if (c->attached_types & (1 << type)) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
 return AVERROR(EINVAL);
 }
 
+c->attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+avio_w8(pb, 0x06);
+avio_wb24(pb, 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + 
pkt->size);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+return 0;
+}
+
+static int flac_finish_header(struct AVFormatContext *s)
+{
+FlacMuxerContext *c = s->priv_data;
+int i, ret, padding = s->metadata_header_padding;
 if (padding < 0)
 padding = 8192;
 /* The FLAC specification states that 24 bits are used to represent the
  * size of a metadata block so we must clip this value to 2^24-1. */
 padding = av_clip_uintp2(padding, 24);
 
+for (i = 0; i < c->nb_pics; i++) {
+ret = flac_write_picture(s, &c->pics[i]);
+if (ret)
+return ret;
+}
+
+ret = flac_write_block_comment(s->pb, &s->metadata, !padding,
+   s->flags & AVFMT_FLAG_BITEXACT);
+if (ret)
+return ret;
+
+/* The command line flac encoder defaults to placing a seekpoint
+ * every 10s.  So one might add padding to allow that later
+ * but there seems to be no simple way to get the duration here.
+ * So just add the amount requested by the user. */
+if (padding)
+flac_write_block_padding(s->pb, padding, 1);
+
+return 0;
+}
+
+static int flac_write_header(struct AVFor

[FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-05-07 Thread Rodger Combs
---
 doc/muxers.texi   |  6 +
 libavformat/segment.c | 65 +++
 libavformat/version.h |  2 +-
 3 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 0866142..b80bc68 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1521,6 +1521,12 @@ This option specifies to start a new segment whenever a 
reference
 stream key frame is found and the sequential number (starting from 0)
 of the frame is greater or equal to the next value in the list.
 
+@item segment_chapters @var{1|0}
+Split each chapter into its own segment. Metadata from the chapters
+will be written to the corresponding segments. If this option is selected
+and the filename contains tokens in the format @code{$varname$}, they
+will be replaced by the corresponding metadata values.
+
 @item segment_wrap @var{limit}
 Wrap around segment index once it reaches @var{limit}.
 
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 8ec3653..8575d32 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -108,6 +108,8 @@ typedef struct SegmentContext {
 int frame_count;   ///< total number of reference frames
 int segment_frame_count; ///< number of reference frames in the segment
 
+int split_chapters;///< split on chapter markers
+
 int64_t time_delta;
 int  individual_header_trailer; /**< Set by a private option. */
 int  write_header_trailer; /**< Set by a private option. */
@@ -188,6 +190,43 @@ static int segment_mux_init(AVFormatContext *s)
 return 0;
 }
 
+static int replace_variables(AVFormatContext *oc)
+{
+char name[sizeof(oc->filename)];
+char *p = name;
+char *out = oc->filename;
+strncpy(name, oc->filename, sizeof(name));
+while (*p) {
+char c = *p++;
+if (c == '$') {
+if (*p == '$') {
+p++;
+goto append;
+} else {
+int len;
+const char *val;
+const AVDictionaryEntry *e;
+int end = strcspn(p, "$");
+if (p[end] == '\0')
+continue;
+p[end] = '\0';
+e = av_dict_get(oc->metadata, p, NULL, 0);
+val = e ? e->value : "(unknown)";
+len = strlen(val);
+strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
out);
+out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
len);
+p += end + 1;
+}
+} else {
+append:
+if (out - oc->filename < sizeof(oc->filename) - 1)
+*out++ = c;
+}
+}
+*out = '\0';
+return 0;
+}
+
 static int set_segment_filename(AVFormatContext *s)
 {
 SegmentContext *seg = s->priv_data;
@@ -212,6 +251,9 @@ static int set_segment_filename(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
+if (seg->split_chapters)
+replace_variables(oc);
+
 /* copy modified name in list entry */
 size = strlen(av_basename(oc->filename)) + 1;
 if (seg->entry_prefix)
@@ -238,6 +280,8 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 if ((err = segment_mux_init(s)) < 0)
 return err;
 oc = seg->avf;
+if (seg->split_chapters && seg->segment_count < s->nb_chapters && (err 
= av_dict_copy(&oc->metadata, s->chapters[seg->segment_count]->metadata, 0)) < 
0)
+return err;
 }
 
 seg->segment_idx++;
@@ -661,10 +705,14 @@ static int seg_init(AVFormatContext *s)
"you can use output_ts_offset instead of it\n");
 }
 
-if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
+if (seg->segment_idx < 0)
+seg->segment_idx = seg->split_chapters;
+
+if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
!!seg->split_chapters > 1) {
 av_log(s, AV_LOG_ERROR,
-   "segment_time, segment_times, and segment_frames options "
-   "are mutually exclusive, select just one of them\n");
+   "segment_time, segment_times, segment_frames, and "
+   "segment_chapters options are mutually exclusive; "
+   "select just one of them\n");
 return AVERROR(EINVAL);
 }
 
@@ -674,7 +722,7 @@ static int seg_init(AVFormatContext *s)
 } else if (seg->frames_str) {
 if ((ret = parse_frames(s, &seg->frames, &seg->nb_frames, 
seg->frames_str)) < 0)
 return ret;
-} else {
+} else if (!seg->split_chapters) {
 /* set default value if not specified */
 if (!seg->time_str)
 seg->time_str = av_strdup("2");
@@ -741,6 +789,9 @@ static int seg_init(AVFormatContext *s)
 if ((ret = segment_mux_init(s)) < 0)
 return ret;
 
+if (seg->split_chapters && s->nb_chapters && (ret = 
av_dict_copy(&seg->avf->metadata, s->chapters[0]->metadata, 0)) < 0)
+return ret;
+
  

[FFmpeg-devel] [PATCH] lavf/utils: bail early if we don't see any packets in an MPEGTS stream

2017-05-02 Thread Rodger Combs
---
 libavformat/utils.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index ba82a766dc..80895b31f0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3505,6 +3505,8 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 int64_t max_analyze_duration = ic->max_analyze_duration;
 int64_t max_stream_analyze_duration;
 int64_t max_subtitle_analyze_duration;
+int64_t max_empty_analyze_duration;
+int skip_empty_streams = 0;
 int64_t probesize = ic->probesize;
 int eof_reached = 0;
 int *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, 
"missing_streams");
@@ -3515,14 +3517,20 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 
 max_stream_analyze_duration = max_analyze_duration;
 max_subtitle_analyze_duration = max_analyze_duration;
+max_empty_analyze_duration = max_analyze_duration;
 if (!max_analyze_duration) {
+max_empty_analyze_duration =
 max_stream_analyze_duration =
 max_analyze_duration= 5*AV_TIME_BASE;
 max_subtitle_analyze_duration = 30*AV_TIME_BASE;
-if (!strcmp(ic->iformat->name, "flv"))
+if (!strcmp(ic->iformat->name, "flv")) {
+max_empty_analyze_duration =
 max_stream_analyze_duration = 90*AV_TIME_BASE;
-if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, 
"mpegts"))
+}
+if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, 
"mpegts")) {
 max_stream_analyze_duration = 7*AV_TIME_BASE;
+max_empty_analyze_duration = 2*AV_TIME_BASE;
+}
 }
 
 if (ic->pb)
@@ -3628,6 +3636,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 int fps_analyze_framecount = 20;
 
 st = ic->streams[i];
+
+if (st->codec_info_nb_frames == 0 &&
+st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE &&
+skip_empty_streams)
+continue;
+
 if (!has_codec_parameters(st, NULL))
 break;
 /* If the timebase is coarse (like the usual millisecond precision
@@ -3791,6 +3805,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_packet_unref(pkt);
 break;
 }
+
+if (t >= max_empty_analyze_duration)
+skip_empty_streams = 1;
+
 if (pkt->duration) {
 if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != 
AV_NOPTS_VALUE && pkt->pts >= st->start_time) {
 st->info->codec_info_duration = FFMIN(pkt->pts - 
st->start_time, st->info->codec_info_duration + pkt->duration);
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavf/utils: bail early if we don't see any packets in an MPEGTS stream

2017-05-02 Thread Rodger Combs

> On May 2, 2017, at 03:59, Matthias Hunstock  wrote:
> 
> Am 02.05.2017 um 03:42 schrieb Rodger Combs:
>> +max_empty_analyze_duration = max_analyze_duration;
>> if (!max_analyze_duration) {
>> +max_empty_analyze_duration =
>> max_stream_analyze_duration =
>> max_analyze_duration= 5*AV_TIME_BASE;
>> max_subtitle_analyze_duration = 30*AV_TIME_BASE;
>> if (!strcmp(ic->iformat->name, "flv"))
>> max_stream_analyze_duration = 90*AV_TIME_BASE;
>> -if (!strcmp(ic->iformat->name, "mpeg") || 
>> !strcmp(ic->iformat->name, "mpegts"))
>> +if (!strcmp(ic->iformat->name, "mpeg") || 
>> !strcmp(ic->iformat->name, "mpegts")) {
>> max_stream_analyze_duration = 7*AV_TIME_BASE;
>> +max_empty_analyze_duration = 2*AV_TIME_BASE;
>> +}
>> }
> 
> What's the origin of "max_empty_analyze_duration = 2*AV_TIME_BASE;", I
> mean why 2*timebase and not 1 or 3 or 10 ?

Same as any of the other constants here, I'd imagine: seemed about right and 
worked. I'm actually considering changing it to 1, though.
This doesn't apply to subtitle streams, and audio or video streams generally 
have at least several packets per second, so streams that are actually active 
_shouldn't_ be affected even with the smaller value.

> 
> Matthias
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] lavf/utils: bail early if we don't see any packets in an MPEGTS stream

2017-05-01 Thread Rodger Combs
---
 libavformat/utils.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index ba82a766dc..4028d8dbcb 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3505,6 +3505,8 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 int64_t max_analyze_duration = ic->max_analyze_duration;
 int64_t max_stream_analyze_duration;
 int64_t max_subtitle_analyze_duration;
+int64_t max_empty_analyze_duration;
+int skip_empty_streams = 0;
 int64_t probesize = ic->probesize;
 int eof_reached = 0;
 int *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, 
"missing_streams");
@@ -3515,14 +3517,18 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 
 max_stream_analyze_duration = max_analyze_duration;
 max_subtitle_analyze_duration = max_analyze_duration;
+max_empty_analyze_duration = max_analyze_duration;
 if (!max_analyze_duration) {
+max_empty_analyze_duration =
 max_stream_analyze_duration =
 max_analyze_duration= 5*AV_TIME_BASE;
 max_subtitle_analyze_duration = 30*AV_TIME_BASE;
 if (!strcmp(ic->iformat->name, "flv"))
 max_stream_analyze_duration = 90*AV_TIME_BASE;
-if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, 
"mpegts"))
+if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, 
"mpegts")) {
 max_stream_analyze_duration = 7*AV_TIME_BASE;
+max_empty_analyze_duration = 2*AV_TIME_BASE;
+}
 }
 
 if (ic->pb)
@@ -3628,6 +3634,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 int fps_analyze_framecount = 20;
 
 st = ic->streams[i];
+
+if (st->codec_info_nb_frames == 0 &&
+st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE &&
+skip_empty_streams)
+continue;
+
 if (!has_codec_parameters(st, NULL))
 break;
 /* If the timebase is coarse (like the usual millisecond precision
@@ -3791,6 +3803,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_packet_unref(pkt);
 break;
 }
+
+if (t >= max_empty_analyze_duration)
+skip_empty_streams = 1;
+
 if (pkt->duration) {
 if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != 
AV_NOPTS_VALUE && pkt->pts >= st->start_time) {
 st->info->codec_info_duration = FFMIN(pkt->pts - 
st->start_time, st->info->codec_info_duration + pkt->duration);
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] ffmpeg: treat audio streams with no parsed packets like unknown streams

2017-05-01 Thread Rodger Combs
---
 ffmpeg_opt.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index d1fe8742ff..5ed29d717e 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -2255,6 +2255,14 @@ loop_end:
 if(o->data_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_DATA)
 continue;
 
+if (ignore_unknown_streams &&
+ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ist->st->codecpar->sample_rate <= 0) {
+av_log(NULL, AV_LOG_WARNING, "Skipping stream #%d:%d - not 
parsed.\n",
+   map->file_index, map->stream_index);
+continue;
+}
+
 ost = NULL;
 switch (ist->st->codecpar->codec_type) {
 case AVMEDIA_TYPE_VIDEO:  ost = new_video_stream (o, 
oc, src_idx); break;
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CID 1405135

2017-04-25 Thread Rodger Combs

> On Apr 25, 2017, at 18:47, Steven Liu  wrote:
> 
> CID: 1405135

I have no idea what this message is supposed to mean.

> Signed-off-by: Steven Liu 
> ---
> libavformat/hlsenc.c | 8 
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 3ec0f330fb..b7aafb73da 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -394,11 +394,11 @@ static int do_encrypt(AVFormatContext *s)
> av_strlcat(hls->key_basename, ".key", len);
> 
> if (hls->key_url) {
> -strncpy(hls->key_file, hls->key_url, sizeof(hls->key_file));
> -strncpy(hls->key_uri, hls->key_url, sizeof(hls->key_uri));
> +av_strlcpy(hls->key_file, hls->key_url, strlen(hls->key_url));
> +av_strlcpy(hls->key_uri, hls->key_url, strlen(hls->key_url));

Changing this to av_strlcpy makes sense, but using strlen() here replaces a DoS 
vulnerability with a memory-corruption one. Use sizeof() like the original code 
in all 4 cases.

> } else {
> -strncpy(hls->key_file, hls->key_basename, sizeof(hls->key_file));
> -strncpy(hls->key_uri, hls->key_basename, sizeof(hls->key_uri));
> +av_strlcpy(hls->key_file, hls->key_basename, 
> strlen(hls->key_basename));
> +av_strlcpy(hls->key_uri, hls->key_basename, 
> strlen(hls->key_basename));
> }
> 
> if (!*hls->iv_string) {
> -- 
> 2.11.0 (Apple Git-81)
> 
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/5] ffprobe: switch xml_escape_str to use av_bprint_escape

2017-04-12 Thread Rodger Combs
This now escapes single-quotes, so the test reference is updated.
---
 ffprobe.c  | 25 ++---
 tests/ref/fate/ffprobe_xml |  2 +-
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index 0a9ba14d8d..5c5bdaf3b1 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -1658,21 +1658,10 @@ static av_cold int xml_init(WriterContext *wctx)
 return 0;
 }
 
-static const char *xml_escape_str(AVBPrint *dst, const char *src, void 
*log_ctx)
+static const char *xml_escape_str(AVBPrint *dst, const char *src)
 {
-const char *p;
-
-for (p = src; *p; p++) {
-switch (*p) {
-case '&' : av_bprintf(dst, "%s", "&");  break;
-case '<' : av_bprintf(dst, "%s", "<");   break;
-case '>' : av_bprintf(dst, "%s", ">");   break;
-case '"' : av_bprintf(dst, "%s", """); break;
-case '\'': av_bprintf(dst, "%s", "'"); break;
-default: av_bprint_chars(dst, *p, 1);
-}
-}
-
+av_bprint_clear(dst);
+av_bprint_escape(dst, src, NULL, AV_ESCAPE_MODE_XML, 
AV_ESCAPE_FLAG_ESCAPE_DOUBLE_QUOTE);
 return dst->str;
 }
 
@@ -1747,14 +1736,12 @@ static void xml_print_str(WriterContext *wctx, const 
char *key, const char *valu
 
 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
 XML_INDENT();
-printf("<%s key=\"%s\"",
-   section->element_name, xml_escape_str(&buf, key, wctx));
-av_bprint_clear(&buf);
-printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
+printf("<%s key=\"%s\"", section->element_name, xml_escape_str(&buf, 
key));
+printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value));
 } else {
 if (wctx->nb_item[wctx->level])
 printf(" ");
-printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
+printf("%s=\"%s\"", key, xml_escape_str(&buf, value));
 }
 
 av_bprint_finalize(&buf, NULL);
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index d2c5ecdf73..8abac000c9 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -51,7 +51,7 @@
 
 
 
-
+
 
 
 
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/5] lavu/bprint: add URL escaping

2017-04-12 Thread Rodger Combs
---
 libavutil/avstring.h |  1 +
 libavutil/bprint.c   | 11 +++
 libavutil/version.h  |  2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 68b753a569..cce210 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -315,6 +315,7 @@ enum AVEscapeMode {
 AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
 AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
 AV_ESCAPE_MODE_XML,   ///< Use XML ampersand-escaping; requires UTF-8 
input.
+AV_ESCAPE_MODE_URL,   ///< Use URL percent-escaping
 };
 
 /**
diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 8e44c57346..7335acf3c9 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -345,5 +345,16 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 }
 }
 break;
+
+case AV_ESCAPE_MODE_URL:
+for (; *src; src++) {
+int is_strictly_special = special_chars && strchr(special_chars, 
*src);
+if (is_strictly_special ||
+(!(flags & AV_ESCAPE_FLAG_STRICT) && 
!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", 
*src)))
+av_bprintf(dstbuf, "%%%02X", *src);
+else
+av_bprint_chars(dstbuf, *src, 1);
+}
+break;
 }
 }
diff --git a/libavutil/version.h b/libavutil/version.h
index bba39e0180..90d9137e08 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  55
-#define LIBAVUTIL_VERSION_MINOR  61
+#define LIBAVUTIL_VERSION_MINOR  62
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/5] lavc/webvttenc: XML-escape text output

2017-04-12 Thread Rodger Combs
The test output was previously incorrect, so the reference is updated.
---
 libavcodec/webvttenc.c   |  7 ++-
 tests/ref/fate/sub-webvttenc | 20 ++--
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index c84bbf4b4e..0f51e73012 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -112,7 +112,12 @@ static void webvtt_style_apply(WebVTTContext *s, const 
char *style)
 static void webvtt_text_cb(void *priv, const char *text, int len)
 {
 WebVTTContext *s = priv;
-av_bprint_append_data(&s->buffer, text, len);
+char *buf = av_strndup(text, len);
+if (!buf)
+return;
+
+av_bprint_escape(&s->buffer, buf, NULL, AV_ESCAPE_MODE_XML, 0);
+av_free(buf);
 }
 
 static void webvtt_new_line_cb(void *priv, int forced)
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index ba567c33f6..08903e3a9d 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -36,18 +36,18 @@ This line should be strikethrough
 should be underline
 
 00:14.501 --> 00:17.500
->
+>
 It would be a good thing to
 hide invalid html tags that are closed and show the text in them
-but show un-closed invalid html tags
-Show not opened tags
-<
+but show un-closed invalid html tags
+Show not opened tags
+<
 
 00:17.501 --> 00:20.500
 and also
 hide invalid html tags with parameters that are closed and show the text in 
them
-but show un-closed invalid html tags
-This text should be showed underlined without problems also: 2<3,5>1,4<6
+but show un-closed invalid html tags
+This text should be showed underlined without problems also: 
2<3,5>1,4<6
 This shouldn't be underlined
 
 00:20.501 --> 00:21.500
@@ -164,14 +164,14 @@ should be hidden.
 
 01:02.501 --> 01:04.500
 It shouldn't be strikethrough,
-not opened tag showed as text.
-Not opened tag showed as text.
+not opened tag showed as text.
+Not opened tag showed as text.
 
 01:04.501 --> 01:06.500
 Three lines should be strikethrough,
 yes.
-Not closed tags showed as text
+<>Not closed tags showed as text
 
 01:06.501 --> 01:08.500
 Both line should be strikethrough but
-the wrong closing tag should be showed
+the wrong closing tag should be showed
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/5] lavu/bprint: add XML escaping

2017-04-12 Thread Rodger Combs
---
 libavutil/avstring.h | 28 
 libavutil/bprint.c   | 43 +++
 2 files changed, 71 insertions(+)

diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 04d2695640..68b753a569 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -314,6 +314,7 @@ enum AVEscapeMode {
 AV_ESCAPE_MODE_AUTO,  ///< Use auto-selected escaping mode.
 AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
 AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
+AV_ESCAPE_MODE_XML,   ///< Use XML ampersand-escaping; requires UTF-8 
input.
 };
 
 /**
@@ -334,6 +335,33 @@ enum AVEscapeMode {
 #define AV_ESCAPE_FLAG_STRICT (1 << 1)
 
 /**
+ * In addition to the provided list, escape all characters outside the range of
+ * U+0020 to U+007E.
+ * This only applies to XML-escaping.
+ */
+#define AV_ESCAPE_FLAG_NON_ASCII (1 << 2)
+
+/**
+ * In addition to the provided list, escape single or double quotes.
+ * This only applies to XML-escaping.
+ */
+#define AV_ESCAPE_FLAG_ESCAPE_SINGLE_QUOTE (1 << 3)
+#define AV_ESCAPE_FLAG_ESCAPE_DOUBLE_QUOTE (1 << 4)
+
+/**
+ * Replace invalid UTF-8 characters with a U+FFFD REPLACEMENT CHARACTER, 
escaped
+ * if AV_ESCAPE_FLAG_NON_ASCII is set.
+ * This only applies to XML-escaping.
+ */
+#define AV_ESCAPE_FLAG_REPLACE_INVALID_SEQUENCES (1 << 5)
+
+/**
+ * Replace invalid UTF-8 characters with a '?', overriding the previous flag.
+ * This only applies to XML-escaping.
+ */
+#define AV_ESCAPE_FLAG_REPLACE_INVALID_ASCII (1 << 6)
+
+/**
  * Escape string in src, and put the escaped string in an allocated
  * string in *dst, which must be freed with av_free().
  *
diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 652775bef9..8e44c57346 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -302,5 +302,48 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 }
 av_bprint_chars(dstbuf, '\'', 1);
 break;
+
+case AV_ESCAPE_MODE_XML:
+/* &;-escape characters */
+while (*src) {
+uint8_t tmp;
+uint32_t cp;
+const char *src1 = src;
+GET_UTF8(cp, (uint8_t)*src++, goto err;);
+
+if ((cp < 0xFF &&
+ ((special_chars && strchr(special_chars, cp)) ||
+  (flags & AV_ESCAPE_FLAG_WHITESPACE) && strchr(WHITESPACES, 
cp))) ||
+(!(flags & AV_ESCAPE_FLAG_STRICT) &&
+ (cp == '&' || cp == '<' || cp == '>')) ||
+((flags & AV_ESCAPE_FLAG_ESCAPE_SINGLE_QUOTE) && cp == '\'') ||
+((flags & AV_ESCAPE_FLAG_ESCAPE_DOUBLE_QUOTE) && cp == '"') ||
+((flags & AV_ESCAPE_FLAG_NON_ASCII) && (cp < 0x20 || cp > 
0x7e))) {
+switch (cp) {
+case '&' : av_bprintf(dstbuf, "&");  break;
+case '<' : av_bprintf(dstbuf, "<");   break;
+case '>' : av_bprintf(dstbuf, ">");   break;
+case '"' : av_bprintf(dstbuf, """); break;
+case '\'': av_bprintf(dstbuf, "'"); break;
+default:   av_bprintf(dstbuf, "&#x%"PRIx32";", cp); break;
+}
+} else {
+PUT_UTF8(cp, tmp, av_bprint_chars(dstbuf, tmp, 1);)
+}
+continue;
+err:
+if (flags & AV_ESCAPE_FLAG_REPLACE_INVALID_ASCII) {
+av_bprint_chars(dstbuf, '?', 1);
+} else if (flags & AV_ESCAPE_FLAG_REPLACE_INVALID_SEQUENCES) {
+if (flags & AV_ESCAPE_FLAG_NON_ASCII)
+av_bprintf(dstbuf, "\xEF\xBF\xBD");
+else
+av_bprintf(dstbuf, "�");
+} else {
+while (src1 < src)
+av_bprint_chars(dstbuf, *src1++, 1);
+}
+}
+break;
 }
 }
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/5] lavu/bprint: reorder cases to match enum order

2017-04-12 Thread Rodger Combs
---
 libavutil/bprint.c | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 2f059c5ba6..652775bef9 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -271,19 +271,8 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 mode = AV_ESCAPE_MODE_BACKSLASH; /* TODO: implement a heuristic */
 
 switch (mode) {
-case AV_ESCAPE_MODE_QUOTE:
-/* enclose the string between '' */
-av_bprint_chars(dstbuf, '\'', 1);
-for (; *src; src++) {
-if (*src == '\'')
-av_bprintf(dstbuf, "'\\''");
-else
-av_bprint_chars(dstbuf, *src, 1);
-}
-av_bprint_chars(dstbuf, '\'', 1);
-break;
-
 /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */
+case AV_ESCAPE_MODE_BACKSLASH:
 default:
 /* \-escape characters */
 for (; *src; src++) {
@@ -301,5 +290,17 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 av_bprint_chars(dstbuf, *src, 1);
 }
 break;
+
+case AV_ESCAPE_MODE_QUOTE:
+/* enclose the string between '' */
+av_bprint_chars(dstbuf, '\'', 1);
+for (; *src; src++) {
+if (*src == '\'')
+av_bprintf(dstbuf, "'\\''");
+else
+av_bprint_chars(dstbuf, *src, 1);
+}
+av_bprint_chars(dstbuf, '\'', 1);
+break;
 }
 }
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/5] lavu/bprint: reorder cases to match enum order

2017-04-12 Thread Rodger Combs
---
 libavutil/bprint.c | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 2f059c5ba6..652775bef9 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -271,19 +271,8 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 mode = AV_ESCAPE_MODE_BACKSLASH; /* TODO: implement a heuristic */
 
 switch (mode) {
-case AV_ESCAPE_MODE_QUOTE:
-/* enclose the string between '' */
-av_bprint_chars(dstbuf, '\'', 1);
-for (; *src; src++) {
-if (*src == '\'')
-av_bprintf(dstbuf, "'\\''");
-else
-av_bprint_chars(dstbuf, *src, 1);
-}
-av_bprint_chars(dstbuf, '\'', 1);
-break;
-
 /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */
+case AV_ESCAPE_MODE_BACKSLASH:
 default:
 /* \-escape characters */
 for (; *src; src++) {
@@ -301,5 +290,17 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 av_bprint_chars(dstbuf, *src, 1);
 }
 break;
+
+case AV_ESCAPE_MODE_QUOTE:
+/* enclose the string between '' */
+av_bprint_chars(dstbuf, '\'', 1);
+for (; *src; src++) {
+if (*src == '\'')
+av_bprintf(dstbuf, "'\\''");
+else
+av_bprint_chars(dstbuf, *src, 1);
+}
+av_bprint_chars(dstbuf, '\'', 1);
+break;
 }
 }
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v14] avformat/dashdec: add dash demuxer base version

2017-04-11 Thread Rodger Combs

> On Apr 9, 2017, at 09:08, Steven Liu  wrote:
> 
> ffmpeg need a dash demuxer for demux the dash formats
> base on
> https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch
> 
> TODO:
> 1. support multi bitrate dash
> 
> v2 fixed:
> 1. from autodetect to disabled
> 2. from camelCase code style to ffmpeg code style
> 3. from RepType to AVMediaType
> 4. fix variable typo
> 5. change time value from uint32_t to uint64_t
> 6. removed be used once API
> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and 
> av_timegm
> 8. merge complex free operation to free_fragment
> 9. use API from snprintf to av_asprintf
> 
> v3 fixed:
> 1. fix typo from --enabled-xml2 to --enable-xml2
> 
> v4 fixed:
> 1. from --enable-xml2 to --enable-libxml2
> 2. move system includes to top
> 3. remove nouse includes
> 4. rename enum name
> 5. add a trailing comma for the last entry enum
> 6. fix comment typo
> 7. add const to DASHContext class front
> 8. check sscanf if return arguments and give warning message when error
> 9. check validity before free seg->url and seg
> 10. check if the val is null, before use atoll
> 
> v5 fixed:
> 1. fix typo from mainifest to manifest
> 
> v6 fixed:
> 1. from realloc to av_realloc
> 2. from free to av_free
> 
> v7 fixed:
> 1. remove the -lxml2 from configure when require_pkg_config
> 
> v8 fixed:
> 1. fix replace filename template by av_asprintf secure problem
> 
> v9 modified:
> 1. make manifest parser clearly
> 
> v10 fixed:
> 1. fix function API name code style
> 2. remove redundant strreplace call
> 3. remove redundant memory operation and check return value from 
> get_content_url()
> 4. add space between ) and {
> 5. remove no need to log the value for print
> 
> v11 fixed:
> 1. from atoll to strtoll
> 
> v12 fixed:
> 1. remove strreplace and instead by av_strreplace
> 
> v13 fixed:
> 1. fix bug: cannot play:
> http://dash.edgesuite.net/akamai/bbb_30fps/bbb_30fps.mpd
> 
> v14 fixed:
> 1. fix bug: TLS connection was non-properly terminated
> 2. fix bug: No trailing CRLF found in HTTP header
> 
> Reviewed-by: Clément Bœsch 
> Reviewed-by: Michael Niedermayer 
> Reviewed-by: Carl Eugen Hoyos 
> Reviewed-by: Rodger Combs 
> Reviewed-by: Moritz Barsnick 
> Reviewed-by: Nicolas George 
> Reviewed-by: Ricardo Constantino 
> Reviewed-by: wm4 
> Tested-by: Andy Furniss 
> Reported-by: Andy Furniss 
> Signed-off-by: Steven Liu 
> ---
> configure|4 +
> libavformat/Makefile |1 +
> libavformat/allformats.c |2 +-
> libavformat/dashdec.c| 1800 ++
> 4 files changed, 1806 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/dashdec.c
> 
> diff --git a/configure b/configure
> index 6dc0b7aad3..5a63240096 100755
> --- a/configure
> +++ b/configure
> @@ -274,6 +274,7 @@ External library support:
>   --enable-libxcb-shapeenable X11 grabbing shape rendering [autodetect]
>   --enable-libxvid enable Xvid encoding via xvidcore,
>native MPEG-4/Xvid encoder exists [no]
> +  --enable-libxml2enable XML parsing using the C library libxml2 
> [no]

Misaligned.

>   --enable-libzimg enable z.lib, needed for zscale filter [no]
>   --enable-libzmq  enable message passing via libzmq [no]
>   --enable-libzvbi enable teletext support via libzvbi [no]
> @@ -1581,6 +1582,7 @@ EXTERNAL_LIBRARY_LIST="
> libvpx
> libwavpack
> libwebp
> +libxml2
> libzimg
> libzmq
> libzvbi
> @@ -2916,6 +2918,7 @@ avi_muxer_select="riffenc"
> caf_demuxer_select="iso_media riffdec"
> caf_muxer_select="iso_media"
> dash_muxer_select="mp4_muxer"
> +dash_demuxer_deps="libxml2"
> dirac_demuxer_select="dirac_parser"
> dts_demuxer_select="dca_parser"
> dtshd_demuxer_select="dca_parser"
> @@ -5921,6 +5924,7 @@ enabled openssl   && { use_pkg_config openssl 
> openssl/ssl.h OPENSSL_init
>check_lib openssl/ssl.h SSL_library_init -lssl 
> -lcrypto -lws2_32 -lgdi32 ||
>die "ERROR: openssl not found"; }
> enabled qtkit_indev  && { check_header_objcc QTKit/QTKit.h || disable 
> qtkit_indev; }
> +enabled libxml2 && require_pkg_config libxml-2.0 
> libxml2/libxml/xmlversion.h xmlCheckVersion

Misaligned (though the previous line also is).

> 
> # libdc1394 check
> if enabl

Re: [FFmpeg-devel] [PATCH v9] avformat/dashdec: add dash demuxer base version

2017-03-27 Thread Rodger Combs

> On Mar 27, 2017, at 01:52, Steven Liu  wrote:
> 
> 2017-03-27 8:39 GMT+08:00 Rodger Combs  <mailto:rodger.co...@gmail.com>>:
> 
>> 
>>> On Mar 26, 2017, at 19:10, Steven Liu  wrote:
>>> 
>>> v2 fixed:
>>> 1. from autodetect to disabled
>>> 2. from camelCase code style to ffmpeg code style
>>> 3. from RepType to AVMediaType
>>> 4. fix variable typo
>>> 5. change time value from uint32_t to uint64_t
>>> 6. removed be used once API
>>> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and
>>> av_timegm
>>> 8. merge complex free operation to free_fragment
>>> 9. use API from snprintf to av_asprintf
>>> 
>>> v3 fixed:
>>> 1. fix typo from --enabled-xml2 to --enable-xml2
>>> 
>>> v4 fixed:
>>> 1. from --enable-xml2 to --enable-libxml2
>>> 2. move system includes to top
>>> 3. remove nouse includes
>>> 4. rename enum name
>>> 5. add a trailing comma for the last entry enum
>>> 6. fix comment typo
>>> 7. add const to DASHContext class front
>>> 8. check sscanf if return arguments and give warning message when error
>>> 9. check validity before free seg->url and seg
>>> 10. check if the val is null, before use atoll
>>> 
>>> v5 fixed:
>>> 1. fix typo from mainifest to manifest
>>> 
>>> v6 fixed:
>>> 1. from realloc to av_realloc
>>> 2. from free to av_free
>>> 
>>> v7 fixed:
>>> 1. remove the -lxml2 from configure when require_pkg_config
>>> 
>>> v8 fixed:
>>> 1. fix replace filename template by av_asprintf secure problem
>>> 
>>> v9 modified:
>>> 1. make manifest parser clearly
>>> 
>>> Reviewed-by: Clément Bœsch 
>>> Reviewed-by: Michael Niedermayer 
>>> Reviewed-by: Carl Eugen Hoyos 
>>> Reviewed-by: Rodger Combs 
>>> Reviewed-by: Moritz Barsnick 
>>> Reviewed-by: Nicolas George 
>>> Reviewed-by: Ricardo Constantino 
>>> Signed-off-by: Steven Liu 
>>> ---
>>> configure|4 +
>>> libavformat/Makefile |1 +
>>> libavformat/allformats.c |2 +-
>>> libavformat/dashdec.c| 1842 ++
>> 
>>> 4 files changed, 1848 insertions(+), 1 deletion(-)
>>> create mode 100644 libavformat/dashdec.c
>>> 
>>> diff --git a/configure b/configure
>>> index 9cc7e7d..4a6fe8a 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -273,6 +273,7 @@ External library support:
>>>  --enable-libxcb-shapeenable X11 grabbing shape rendering
>> [autodetect]
>>>  --enable-libxvid enable Xvid encoding via xvidcore,
>>>   native MPEG-4/Xvid encoder exists [no]
>>> +  --enable-libxml2enable XML parsing using the C library
>> libxml2 [no]
>>>  --enable-libzimg enable z.lib, needed for zscale filter [no]
>>>  --enable-libzmq  enable message passing via libzmq [no]
>>>  --enable-libzvbi enable teletext support via libzvbi [no]
>>> @@ -1574,6 +1575,7 @@ EXTERNAL_LIBRARY_LIST="
>>>libvpx
>>>libwavpack
>>>libwebp
>>> +libxml2
>>>libzimg
>>>libzmq
>>>libzvbi
>>> @@ -2906,6 +2908,7 @@ avi_muxer_select="riffenc"
>>> caf_demuxer_select="iso_media riffdec"
>>> caf_muxer_select="iso_media"
>>> dash_muxer_select="mp4_muxer"
>>> +dash_demuxer_deps="libxml2"
>>> dirac_demuxer_select="dirac_parser"
>>> dts_demuxer_select="dca_parser"
>>> dtshd_demuxer_select="dca_parser"
>>> @@ -5908,6 +5911,7 @@ enabled openssl   && { use_pkg_config
>> openssl openssl/ssl.h OPENSSL_init
>>>   check_lib openssl/ssl.h SSL_library_init
>> -lssl -lcrypto -lws2_32 -lgdi32 ||
>>>   die "ERROR: openssl not found"; }
>>> enabled qtkit_indev  && { check_header_objcc QTKit/QTKit.h ||
>> disable qtkit_indev; }
>>> +enabled libxml2 && require_pkg_config libxml-2.0
>> libxml2/libxml/xmlversion.h xmlCheckVersion
>>> 
>>> # libdc1394 check
>>> if enabled libdc1394; then
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index f5

Re: [FFmpeg-devel] [PATCH v9] avformat/dashdec: add dash demuxer base version

2017-03-26 Thread Rodger Combs

> On Mar 26, 2017, at 19:10, Steven Liu  wrote:
> 
> v2 fixed:
> 1. from autodetect to disabled
> 2. from camelCase code style to ffmpeg code style
> 3. from RepType to AVMediaType
> 4. fix variable typo
> 5. change time value from uint32_t to uint64_t
> 6. removed be used once API
> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and
> av_timegm
> 8. merge complex free operation to free_fragment
> 9. use API from snprintf to av_asprintf
> 
> v3 fixed:
> 1. fix typo from --enabled-xml2 to --enable-xml2
> 
> v4 fixed:
> 1. from --enable-xml2 to --enable-libxml2
> 2. move system includes to top
> 3. remove nouse includes
> 4. rename enum name
> 5. add a trailing comma for the last entry enum
> 6. fix comment typo
> 7. add const to DASHContext class front
> 8. check sscanf if return arguments and give warning message when error
> 9. check validity before free seg->url and seg
> 10. check if the val is null, before use atoll
> 
> v5 fixed:
> 1. fix typo from mainifest to manifest
> 
> v6 fixed:
> 1. from realloc to av_realloc
> 2. from free to av_free
> 
> v7 fixed:
> 1. remove the -lxml2 from configure when require_pkg_config
> 
> v8 fixed:
> 1. fix replace filename template by av_asprintf secure problem
> 
> v9 modified:
> 1. make manifest parser clearly
> 
> Reviewed-by: Clément Bœsch 
> Reviewed-by: Michael Niedermayer 
> Reviewed-by: Carl Eugen Hoyos 
> Reviewed-by: Rodger Combs 
> Reviewed-by: Moritz Barsnick 
> Reviewed-by: Nicolas George 
> Reviewed-by: Ricardo Constantino 
> Signed-off-by: Steven Liu 
> ---
> configure|4 +
> libavformat/Makefile |1 +
> libavformat/allformats.c |2 +-
> libavformat/dashdec.c| 1842 ++
> 4 files changed, 1848 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/dashdec.c
> 
> diff --git a/configure b/configure
> index 9cc7e7d..4a6fe8a 100755
> --- a/configure
> +++ b/configure
> @@ -273,6 +273,7 @@ External library support:
>   --enable-libxcb-shapeenable X11 grabbing shape rendering [autodetect]
>   --enable-libxvid enable Xvid encoding via xvidcore,
>native MPEG-4/Xvid encoder exists [no]
> +  --enable-libxml2enable XML parsing using the C library libxml2 
> [no]
>   --enable-libzimg enable z.lib, needed for zscale filter [no]
>   --enable-libzmq  enable message passing via libzmq [no]
>   --enable-libzvbi enable teletext support via libzvbi [no]
> @@ -1574,6 +1575,7 @@ EXTERNAL_LIBRARY_LIST="
> libvpx
> libwavpack
> libwebp
> +libxml2
> libzimg
> libzmq
> libzvbi
> @@ -2906,6 +2908,7 @@ avi_muxer_select="riffenc"
> caf_demuxer_select="iso_media riffdec"
> caf_muxer_select="iso_media"
> dash_muxer_select="mp4_muxer"
> +dash_demuxer_deps="libxml2"
> dirac_demuxer_select="dirac_parser"
> dts_demuxer_select="dca_parser"
> dtshd_demuxer_select="dca_parser"
> @@ -5908,6 +5911,7 @@ enabled openssl   && { use_pkg_config openssl 
> openssl/ssl.h OPENSSL_init
>check_lib openssl/ssl.h SSL_library_init -lssl 
> -lcrypto -lws2_32 -lgdi32 ||
>die "ERROR: openssl not found"; }
> enabled qtkit_indev  && { check_header_objcc QTKit/QTKit.h || disable 
> qtkit_indev; }
> +enabled libxml2 && require_pkg_config libxml-2.0 
> libxml2/libxml/xmlversion.h xmlCheckVersion
> 
> # libdc1394 check
> if enabled libdc1394; then
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index f56ef16..d77ffaa 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -134,6 +134,7 @@ OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
> OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
> OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
> OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
> +OBJS-$(CONFIG_DASH_DEMUXER)  += dashdec.o
> OBJS-$(CONFIG_DAUD_DEMUXER)  += dauddec.o
> OBJS-$(CONFIG_DAUD_MUXER)+= daudenc.o
> OBJS-$(CONFIG_DCSTR_DEMUXER) += dcstr.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 09e62c3..d57314b 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -96,7 +96,7 @@ static void register_all(void)
> REGISTER_DEMUXER (CINE, cine);
> REGISTER_DEMUXER (CONCAT,   concat);
> REGISTER_MUXER   (CRC,  crc);
> -REGISTER_MUXER   

Re: [FFmpeg-devel] [PATCH v6] avformat/dashdec: add dash demuxer base version

2017-03-22 Thread Rodger Combs

> On Mar 22, 2017, at 09:31, Steven Liu  wrote:
> 
> 2017-03-22 22:01 GMT+08:00 Rodger Combs  <mailto:rodger.co...@gmail.com>>:
> 
>> 
>>> On Mar 21, 2017, at 08:16, Steven Liu  wrote:
>>> 
>>> v2 fixed:
>>> 1. from autodetect to disabled
>>> 2. from camelCase code style to ffmpeg code style
>>> 3. from RepType to AVMediaType
>>> 4. fix variable typo
>>> 5. change time value from uint32_t to uint64_t
>>> 6. removed be used once API
>>> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and
>> av_timegm
>>> 8. merge complex free operation to free_fragment
>>> 9. use API from snprintf to av_asprintf
>>> 
>>> v3 fixed:
>>> 1. fix typo from --enabled-xml2 to --enable-xml2
>>> 
>>> v4 fixed:
>>> 1. from --enable-xml2 to --enable-libxml2
>>> 2. move system includes to top
>>> 3. remove nouse includes
>>> 4. rename enum name
>>> 5. add a trailing comma for the last entry enum
>>> 6. fix comment typo
>>> 7. add const to DASHContext class front
>>> 8. check sscanf if return arguments and give warning message when error
>>> 9. check validity before free seg->url and seg
>>> 10. check if the val is null, before use atoll
>>> 
>>> v5 fixed:
>>> 1. fix typo from mainifest to manifest
>>> 
>>> v6 fixed:
>>> 1. from realloc to av_realloc
>>> 2. from free to av_free
>>> 
>>> Reviewed-by: Clément Bœsch 
>>> Reviewed-by: Michael Niedermayer 
>>> Reviewed-by: Carl Eugen Hoyos 
>>> Reviewed-by: Rodger Combs 
>>> Reviewed-by: Moritz Barsnick 
>>> Reviewed-by: Nicolas George 
>>> Reviewed-by: Ricardo Constantino 
>>> Signed-off-by: Steven Liu 
>>> ---
>>> configure|4 +
>>> libavformat/Makefile |1 +
>>> libavformat/allformats.c |2 +-
>>> libavformat/dashdec.c| 1841 ++
>> 
>>> 4 files changed, 1847 insertions(+), 1 deletion(-)
>>> create mode 100644 libavformat/dashdec.c
>>> 
>>> diff --git a/configure b/configure
>>> index 4eb116b..86d16a8 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -273,6 +273,7 @@ External library support:
>>>  --enable-libxcb-shapeenable X11 grabbing shape rendering
>> [autodetect]
>>>  --enable-libxvid enable Xvid encoding via xvidcore,
>>>   native MPEG-4/Xvid encoder exists [no]
>>> +  --enable-libxml2enable XML parsing using the C library
>> libxml2 [no]
>>>  --enable-libzimg enable z.lib, needed for zscale filter [no]
>>>  --enable-libzmq  enable message passing via libzmq [no]
>>>  --enable-libzvbi enable teletext support via libzvbi [no]
>>> @@ -1590,6 +1591,7 @@ EXTERNAL_LIBRARY_LIST="
>>>libvpx
>>>libwavpack
>>>libwebp
>>> +libxml2
>>>libzimg
>>>libzmq
>>>libzvbi
>>> @@ -2920,6 +2922,7 @@ avi_muxer_select="riffenc"
>>> caf_demuxer_select="iso_media riffdec"
>>> caf_muxer_select="iso_media"
>>> dash_muxer_select="mp4_muxer"
>>> +dash_demuxer_deps="libxml2"
>>> dirac_demuxer_select="dirac_parser"
>>> dts_demuxer_select="dca_parser"
>>> dtshd_demuxer_select="dca_parser"
>>> @@ -5920,6 +5923,7 @@ enabled openssl   && { use_pkg_config
>> openssl openssl/ssl.h OPENSSL_init
>>>   check_lib openssl/ssl.h SSL_library_init
>> -lssl -lcrypto -lws2_32 -lgdi32 ||
>>>   die "ERROR: openssl not found"; }
>>> enabled qtkit_indev  && { check_header_objcc QTKit/QTKit.h ||
>> disable qtkit_indev; }
>>> +enabled libxml2 && require_pkg_config libxml-2.0
>> libxml2/libxml/xmlversion.h xmlCheckVersion -lxml2
>>> 
>>> # libdc1394 check
>>> if enabled libdc1394; then
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index f56ef16..d77ffaa 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -134,6 +134,7 @@ OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
>>> OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
>>> OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o

Re: [FFmpeg-devel] [PATCH v6] avformat/dashdec: add dash demuxer base version

2017-03-22 Thread Rodger Combs

> On Mar 21, 2017, at 08:16, Steven Liu  wrote:
> 
> v2 fixed:
> 1. from autodetect to disabled
> 2. from camelCase code style to ffmpeg code style
> 3. from RepType to AVMediaType
> 4. fix variable typo
> 5. change time value from uint32_t to uint64_t
> 6. removed be used once API
> 7. change 'time(NULL)`, except it is not 2038-safe.' to av_gettime and 
> av_timegm
> 8. merge complex free operation to free_fragment
> 9. use API from snprintf to av_asprintf
> 
> v3 fixed:
> 1. fix typo from --enabled-xml2 to --enable-xml2
> 
> v4 fixed:
> 1. from --enable-xml2 to --enable-libxml2
> 2. move system includes to top
> 3. remove nouse includes
> 4. rename enum name
> 5. add a trailing comma for the last entry enum
> 6. fix comment typo
> 7. add const to DASHContext class front
> 8. check sscanf if return arguments and give warning message when error
> 9. check validity before free seg->url and seg
> 10. check if the val is null, before use atoll
> 
> v5 fixed:
> 1. fix typo from mainifest to manifest
> 
> v6 fixed:
> 1. from realloc to av_realloc
> 2. from free to av_free
> 
> Reviewed-by: Clément Bœsch 
> Reviewed-by: Michael Niedermayer 
> Reviewed-by: Carl Eugen Hoyos 
> Reviewed-by: Rodger Combs 
> Reviewed-by: Moritz Barsnick 
> Reviewed-by: Nicolas George 
> Reviewed-by: Ricardo Constantino 
> Signed-off-by: Steven Liu 
> ---
> configure|4 +
> libavformat/Makefile |1 +
> libavformat/allformats.c |2 +-
> libavformat/dashdec.c| 1841 ++
> 4 files changed, 1847 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/dashdec.c
> 
> diff --git a/configure b/configure
> index 4eb116b..86d16a8 100755
> --- a/configure
> +++ b/configure
> @@ -273,6 +273,7 @@ External library support:
>   --enable-libxcb-shapeenable X11 grabbing shape rendering [autodetect]
>   --enable-libxvid enable Xvid encoding via xvidcore,
>native MPEG-4/Xvid encoder exists [no]
> +  --enable-libxml2enable XML parsing using the C library libxml2 
> [no]
>   --enable-libzimg enable z.lib, needed for zscale filter [no]
>   --enable-libzmq  enable message passing via libzmq [no]
>   --enable-libzvbi enable teletext support via libzvbi [no]
> @@ -1590,6 +1591,7 @@ EXTERNAL_LIBRARY_LIST="
> libvpx
> libwavpack
> libwebp
> +libxml2
> libzimg
> libzmq
> libzvbi
> @@ -2920,6 +2922,7 @@ avi_muxer_select="riffenc"
> caf_demuxer_select="iso_media riffdec"
> caf_muxer_select="iso_media"
> dash_muxer_select="mp4_muxer"
> +dash_demuxer_deps="libxml2"
> dirac_demuxer_select="dirac_parser"
> dts_demuxer_select="dca_parser"
> dtshd_demuxer_select="dca_parser"
> @@ -5920,6 +5923,7 @@ enabled openssl   && { use_pkg_config openssl 
> openssl/ssl.h OPENSSL_init
>check_lib openssl/ssl.h SSL_library_init -lssl 
> -lcrypto -lws2_32 -lgdi32 ||
>die "ERROR: openssl not found"; }
> enabled qtkit_indev  && { check_header_objcc QTKit/QTKit.h || disable 
> qtkit_indev; }
> +enabled libxml2 && require_pkg_config libxml-2.0 
> libxml2/libxml/xmlversion.h xmlCheckVersion -lxml2
> 
> # libdc1394 check
> if enabled libdc1394; then
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index f56ef16..d77ffaa 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -134,6 +134,7 @@ OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
> OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
> OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
> OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
> +OBJS-$(CONFIG_DASH_DEMUXER)  += dashdec.o
> OBJS-$(CONFIG_DAUD_DEMUXER)  += dauddec.o
> OBJS-$(CONFIG_DAUD_MUXER)+= daudenc.o
> OBJS-$(CONFIG_DCSTR_DEMUXER) += dcstr.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 09e62c3..d57314b 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -96,7 +96,7 @@ static void register_all(void)
> REGISTER_DEMUXER (CINE, cine);
> REGISTER_DEMUXER (CONCAT,   concat);
> REGISTER_MUXER   (CRC,  crc);
> -REGISTER_MUXER   (DASH, dash);
> +REGISTER_MUXDEMUX(DASH, dash);
> REGISTER_MUXDEMUX(DATA, data);
> REGISTER_MUXDEMUX(DAUD, daud);
> REGISTER_DEMUXER (DCSTR,

Re: [FFmpeg-devel] [PATCH] avformat/dashdec: add dash demuxer base version

2017-03-19 Thread Rodger Combs
A few initial comments inline:

> On Mar 19, 2017, at 04:05, Steven Liu  wrote:
> 
> ffmpeg need a dash demuxer for demux the dash formats
> base on 
> https://github.com/samsamsam-iptvplayer/exteplayer3/blob/master/tmp/ffmpeg/patches/3.2.2/01_add_dash_demux.patch
> 
> Signed-off-by: Steven Liu 
> ---
> configure|4 +
> libavformat/Makefile |1 +
> libavformat/allformats.c |2 +-
> libavformat/dashdec.c| 1845 ++
> 4 files changed, 1851 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/dashdec.c
> 
> diff --git a/configure b/configure
> index 1e2e774..4850cfa 100755
> --- a/configure
> +++ b/configure
> @@ -292,6 +292,7 @@ External library support:
>on OSX if openssl and gnutls are not used 
> [autodetect]
>   --enable-x11grab enable X11 grabbing (legacy) [no]
>   --disable-xlib   disable xlib [autodetect]
> +  --disable-xml2   disable XML parsing using the C library libxml2 
> [autodetect]
>   --disable-zlib   disable zlib [autodetect]
> 
>   The following libraries provide various hardware acceleration features:
> @@ -1508,6 +1509,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
> sdl2
> securetransport
> xlib
> +xml2
> zlib
> "
> 
> @@ -2902,6 +2904,7 @@ avi_muxer_select="riffenc"
> caf_demuxer_select="iso_media riffdec"
> caf_muxer_select="iso_media"
> dash_muxer_select="mp4_muxer"
> +dash_demuxer_select="xml2"
> dirac_demuxer_select="dirac_parser"
> dts_demuxer_select="dca_parser"
> dtshd_demuxer_select="dca_parser"
> @@ -5710,6 +5713,7 @@ enabled pthreads &&
> disabled  zlib || check_lib   zlib.h  zlibVersion -lz   || disable  zlib
> disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
> disabled  lzma || check_lib2  lzma.h lzma_version_number -llzma || disable 
> lzma
> +disabled  xml2 || { add_cflags -I/usr/include/libxml2 && check_lib 
> libxml/xmlversion.h xmlCheckVersion -lxml2; } || disable xml2
> 
> check_lib math.h sin -lm && LIBM="-lm"
> disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h 
> DtsCrystalHDVersion -lcrystalhd || disable crystalhd
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index f56ef16..d77ffaa 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -134,6 +134,7 @@ OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
> OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
> OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
> OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
> +OBJS-$(CONFIG_DASH_DEMUXER)  += dashdec.o
> OBJS-$(CONFIG_DAUD_DEMUXER)  += dauddec.o
> OBJS-$(CONFIG_DAUD_MUXER)+= daudenc.o
> OBJS-$(CONFIG_DCSTR_DEMUXER) += dcstr.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 09e62c3..d57314b 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -96,7 +96,7 @@ static void register_all(void)
> REGISTER_DEMUXER (CINE, cine);
> REGISTER_DEMUXER (CONCAT,   concat);
> REGISTER_MUXER   (CRC,  crc);
> -REGISTER_MUXER   (DASH, dash);
> +REGISTER_MUXDEMUX(DASH, dash);
> REGISTER_MUXDEMUX(DATA, data);
> REGISTER_MUXDEMUX(DAUD, daud);
> REGISTER_DEMUXER (DCSTR,dcstr);
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> new file mode 100644
> index 000..4c347f3
> --- /dev/null
> +++ b/libavformat/dashdec.c
> @@ -0,0 +1,1845 @@
> +/*
> + * Dynamic Adaptive Streaming over HTTP demux
> + * Copyright (c) 2017 samsam...@o2.pl based on HLS demux
> + * Copyright (c) 2017 Steven Liu
> + *
> + * 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 "libavutil/avstring.h"
> +#include "libavutil/avassert.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/mathematics.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/dict.h"
> +#include "libavutil/time.h"
> +#include "avformat.h"
> +#include "internal.h"
> +#include "avio_internal.h"
> +#include "url.h"
> +#include "id3v2.h"
> +
> +#define INITIAL_BUFFER_SIZE 32768
> +
> +#include 
> +#include 
> +

[FFmpeg-devel] [PATCH 1/3] lavf: identify MP1 and MP2 as distinct containers from MP3

2017-03-18 Thread Rodger Combs
This allows us to report the correct codec ID here
---
 libavformat/allformats.c |  3 ++-
 libavformat/mp3dec.c | 66 +++-
 libavformat/rawenc.c | 13 ++
 libavformat/utils.c  |  4 +--
 libavformat/version.h|  4 +--
 5 files changed, 62 insertions(+), 28 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 09e62c3cfc..b9caeb3737 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -185,7 +185,8 @@ static void register_all(void)
 REGISTER_DEMUXER (MM,   mm);
 REGISTER_MUXDEMUX(MMF,  mmf);
 REGISTER_MUXDEMUX(MOV,  mov);
-REGISTER_MUXER   (MP2,  mp2);
+REGISTER_MUXDEMUX(MP1,  mp1);
+REGISTER_MUXDEMUX(MP2,  mp2);
 REGISTER_MUXDEMUX(MP3,  mp3);
 REGISTER_MUXER   (MP4,  mp4);
 REGISTER_DEMUXER (MPC,  mpc);
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index b45a066686..8773a55f80 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -66,7 +66,7 @@ static int check(AVIOContext *pb, int64_t pos, uint32_t 
*header);
 
 /* mp3 read */
 
-static int mp3_read_probe(AVProbeData *p)
+static int mpa_read_probe(AVProbeData *p, int layer)
 {
 int max_frames, first_frames = 0;
 int whole_used = 0;
@@ -89,7 +89,7 @@ static int mp3_read_probe(AVProbeData *p)
 
 header = AV_RB32(buf2);
 ret = avpriv_mpegaudio_decode_header(&h, header);
-if (ret != 0)
+if (ret != 0 || h.layer != layer)
 break;
 buf2 += h.frame_size;
 }
@@ -105,7 +105,8 @@ static int mp3_read_probe(AVProbeData *p)
 if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
 else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
 else if(max_frames>=4 && max_frames >= p->buf_size/1) return 
AVPROBE_SCORE_EXTENSION / 2;
-else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
+else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size &&
+(p->buf_size < PROBE_BUF_MAX || layer == 3))
return p->buf_size < PROBE_BUF_MAX ? 
AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
 else if(first_frames > 1 && whole_used) return 5;
 else if(max_frames>=1 && max_frames >= p->buf_size/1) return 1;
@@ -113,6 +114,12 @@ static int mp3_read_probe(AVProbeData *p)
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
 
+#define READ_PROBE(l) \
+static int mp##l##_read_probe(AVProbeData *p) \
+{ \
+return mpa_read_probe(p, l); \
+}
+
 static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t 
duration)
 {
 int i;
@@ -341,7 +348,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream 
*st, int64_t base)
 return 0;
 }
 
-static int mp3_read_header(AVFormatContext *s)
+static int mpa_read_header(AVFormatContext *s, enum AVCodecID id)
 {
 MP3DecContext *mp3 = s->priv_data;
 AVStream *st;
@@ -357,7 +364,7 @@ static int mp3_read_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_MP3;
+st->codecpar->codec_id = id;
 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
 st->start_time = 0;
 
@@ -422,6 +429,12 @@ static int mp3_read_header(AVFormatContext *s)
 return 0;
 }
 
+#define READ_HEADER(l) \
+static int mp##l##_read_header(AVFormatContext *s) \
+{ \
+return mpa_read_header(s, AV_CODEC_ID_MP##l); \
+}
+
 #define MP3_PACKET_SIZE 1024
 
 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -582,23 +595,30 @@ static const AVOption options[] = {
 { NULL },
 };
 
-static const AVClass demuxer_class = {
-.class_name = "mp3",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-.category   = AV_CLASS_CATEGORY_DEMUXER,
+#define DECLARE_LAYER(l, ext) \
+READ_PROBE(l) \
+READ_HEADER(l) \
+static const AVClass demuxer_class_##l = { \
+.class_name = "mp" #l, \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+.category   = AV_CLASS_CATEGORY_DEMUXER, \
+}; \
+\
+AVInputFormat ff_mp##l##_demuxer = { \
+.name   = "mp" #l, \
+.long_name  = NULL_IF_CONFIG_SMALL("MP" #l " (MPEG audio layer " #l 
")"), \
+.read_probe = mp##l##_read_probe, \
+.read_header= mp##l##_read_header, \
+.read_packet= mp3_read_packet, \
+.read_seek  = mp3_seek, \
+.priv_data_size = sizeof(MP3DecContext), \
+.flags  = AVFMT_GENERIC_INDEX, \
+.extensions = ext, /* XXX: use probe */ \
+.priv_class = &demuxer_class_##l, \
 };
 
-AVInputFormat ff_mp3_demuxer = {
-.name   = "mp3",
-.long_name  = N

[FFmpeg-devel] [PATCH 2/3] lavf/utils: add MP2 to the probing list

2017-03-18 Thread Rodger Combs
---
 libavformat/utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 84acb9c795..8bf34e8f6f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -329,6 +329,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "loas",  AV_CODEC_ID_AAC_LATM,   AVMEDIA_TYPE_AUDIO },
 { "m4v",   AV_CODEC_ID_MPEG4,  AVMEDIA_TYPE_VIDEO },
 { "mjpeg_2000",AV_CODEC_ID_JPEG2000,   AVMEDIA_TYPE_VIDEO },
+{ "mp2",   AV_CODEC_ID_MP2,AVMEDIA_TYPE_AUDIO },
 { "mp3",   AV_CODEC_ID_MP3,AVMEDIA_TYPE_AUDIO },
 { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
 { "truehd",AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO },
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/3] lavf/movdec: request probing for an ambiguous codec tag

2017-03-18 Thread Rodger Combs
---
 libavformat/isom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 7da2700842..9589f42741 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -514,6 +514,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);
 if (codec_id)
 st->codecpar->codec_id = codec_id;
+if (object_type_id == 0x6B) // This can be either MP3 or MP2; let 
probe_codec decide
+st->request_probe = 5;
 av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id);
 len = ff_mp4_read_descr(fc, pb, &tag);
 if (tag == MP4DecSpecificDescrTag) {
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/movdec: downgrade "shifted frame pts" log line to trace

2017-03-08 Thread Rodger Combs
This gets pretty chatty in files that use edit lists, so it fits
a bit better at the trace level with similar messages.
---
 libavformat/mov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d5c3949050..06f84f9f8e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3175,7 +3175,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 curr_cts = current->timestamp + msc->dts_shift;
 
 if (ctts_data_old && ctts_index_old < ctts_count_old) {
-av_log(mov->fc, AV_LOG_DEBUG, "shifted frame pts, curr_cts: 
%"PRId64" @ %"PRId64", ctts: %d, ctts_count: %"PRId64"\n",
+av_log(mov->fc, AV_LOG_TRACE, "shifted frame pts, curr_cts: 
%"PRId64" @ %"PRId64", ctts: %d, ctts_count: %"PRId64"\n",
curr_cts, ctts_index_old, 
ctts_data_old[ctts_index_old].duration, ctts_count_old);
 curr_cts += ctts_data_old[ctts_index_old].duration;
 ctts_sample_old++;
-- 
2.11.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/segment: fix crash when failing to open segment list

2017-01-20 Thread Rodger Combs
This happens because segment_end() returns an error, so seg_write_packet
never proceeds to segment_start(), and seg->avf->pb is never re-set,
so we crash with a null pb when av_write_trailer flushes the packet
queue.

This doesn't seem to be clearly recoverable, so I'm just failing more
gracefully.

Repro:
ffmpeg -i input.ts -f segment -c copy -segment_list /noaxx.m3u8 test-%05d.ts

(assuming you don't have write access to /)
---
 libavformat/segment.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 9b3dc178eb..9d471483b3 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -354,6 +354,9 @@ static int segment_end(AVFormatContext *s, int 
write_trailer, int is_last)
 int i;
 int err;
 
+if (!oc || !oc->pb)
+return AVERROR(EINVAL);
+
 av_write_frame(oc, NULL); /* Flush any buffered data (fragmented mp4) */
 if (write_trailer)
 ret = av_write_trailer(oc);
@@ -850,7 +853,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 int64_t usecs;
 int64_t wrapped_val;
 
-if (!seg->avf)
+if (!seg->avf || !seg->avf->pb)
 return AVERROR(EINVAL);
 
 calc_times:
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/9] avutil: add FF_RETURN_ON_OVERFLOW

2017-01-07 Thread Rodger Combs

> On Jan 7, 2017, at 02:36, Paul B Mahol  wrote:
> 
> On 1/7/17, Michael Niedermayer  <mailto:mich...@niedermayer.cc>> wrote:
>> On Fri, Jan 06, 2017 at 09:11:10PM -0300, James Almer wrote:
>>> On 1/6/2017 4:46 PM, Andreas Cadhalpun wrote:
>>>> Suggested-by: Rodger Combs 
>>>> Signed-off-by: Andreas Cadhalpun 
>>>> ---
>>>> 
>>>> Changed the name as suggested by wm4 and the return value as suggested
>>>> by Muhammad Faiz.
>>>> There are also two new overflow checks at the end of the series.
>>> 
>>> This is a good chance to introduce the gcc overflow check builtins.
>>> See https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html,
>>> they
>>> use hardware instructions when possible, like x86's Jump on Overflow.
>>> 
>>> The idea would be to use __builtin_mul_overflow_p(). For example
>>> (untested):
>>> 
>>> #if AV_GCC_VERSION_AT_LEAST(5,1)
>>> #define av_builtin_mul_overflow_p(a, b) __builtin_mul_overflow_p(a, b,
>>> (int) 0)
>>> #else
>>> #define av_builtin_mul_overflow_p(a, b) ((a) > INT_MAX / (b)))
>>> #endif
>>> 
>>> It can also be used all across the codebase, not just for these checks.
>>> 
>> 
>>>> 
>>>> ---
>>>> libavutil/common.h | 2 ++
>>>> 1 file changed, 2 insertions(+)
>>>> 
>>>> diff --git a/libavutil/common.h b/libavutil/common.h
>>>> index 8142b31fdb..6d795a353a 100644
>>>> --- a/libavutil/common.h
>>>> +++ b/libavutil/common.h
>>>> @@ -99,6 +99,8 @@
>>>> #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a=
>>>> SWAP_tmp;}while(0)
>>>> #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
>>>> 
>>>> +#define FF_RETURN_ON_OVERFLOW(ctx, x) if (x) {av_log(ctx, AV_LOG_ERROR,
>>>> "Overflow check failed: " #x"\n"); return AVERROR(ERANGE);}
>>> 
>>> Printing an error unconditionally seems like log bloat. We do all kinds
>>> of
>>> sanity checks on demuxers and simply return INVALIDDATA without printing
>>> anything if they fail.
>>> Maybe we should do the same here and let the demuxer choose to print an
>>> error or not.
>> 
>> error messages help debuging and thus maintaining code.
>> 
> 
> Not really. Expecially in this case.

Eh, I generally prefer a print-and-return over just returning an error code in 
cases where the source is ambiguous. There are a lot of cases currently where 
in e.g. ffmpeg CLI, the code just gets bubbled up and printed, potentially with 
the name of the codec it came from, but no further information about the 
source, so it can be difficult to track down exactly where the failure 
occurred. Printing a message can be a fair bit more clear.
This seems like something it would be worth talking about and deciding on in 
general, though: as a rule, should we try to print errors about specific 
failures like this?

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf: identify MP1 and MP2 as distinct containers from MP3

2016-12-22 Thread Rodger Combs
This allows us to report the correct codec ID here
---
 libavformat/allformats.c |  3 ++-
 libavformat/mp3dec.c | 66 +++-
 libavformat/rawenc.c | 13 ++
 libavformat/utils.c  |  4 +--
 libavformat/version.h|  2 +-
 5 files changed, 61 insertions(+), 27 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a79b75d78..3f105f8b31 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -189,7 +189,8 @@ void av_register_all(void)
 REGISTER_DEMUXER (MM,   mm);
 REGISTER_MUXDEMUX(MMF,  mmf);
 REGISTER_MUXDEMUX(MOV,  mov);
-REGISTER_MUXER   (MP2,  mp2);
+REGISTER_MUXDEMUX(MP1,  mp1);
+REGISTER_MUXDEMUX(MP2,  mp2);
 REGISTER_MUXDEMUX(MP3,  mp3);
 REGISTER_MUXER   (MP4,  mp4);
 REGISTER_DEMUXER (MPC,  mpc);
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 099ca57d24..f530d69ee8 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -66,7 +66,7 @@ static int check(AVIOContext *pb, int64_t pos, uint32_t 
*header);
 
 /* mp3 read */
 
-static int mp3_read_probe(AVProbeData *p)
+static int mpa_read_probe(AVProbeData *p, int layer)
 {
 int max_frames, first_frames = 0;
 int whole_used = 0;
@@ -89,7 +89,7 @@ static int mp3_read_probe(AVProbeData *p)
 
 header = AV_RB32(buf2);
 ret = avpriv_mpegaudio_decode_header(&h, header);
-if (ret != 0)
+if (ret != 0 || h.layer != layer)
 break;
 buf2 += h.frame_size;
 }
@@ -105,7 +105,8 @@ static int mp3_read_probe(AVProbeData *p)
 if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
 else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
 else if(max_frames>=4 && max_frames >= p->buf_size/1) return 
AVPROBE_SCORE_EXTENSION / 2;
-else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
+else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size &&
+(p->buf_size < PROBE_BUF_MAX || layer == 3))
return p->buf_size < PROBE_BUF_MAX ? 
AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
 else if(first_frames > 1 && whole_used) return 5;
 else if(max_frames>=1 && max_frames >= p->buf_size/1) return 1;
@@ -113,6 +114,12 @@ static int mp3_read_probe(AVProbeData *p)
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
 
+#define READ_PROBE(l) \
+static int mp##l##_read_probe(AVProbeData *p) \
+{ \
+return mpa_read_probe(p, l); \
+}
+
 static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t 
duration)
 {
 int i;
@@ -341,7 +348,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream 
*st, int64_t base)
 return 0;
 }
 
-static int mp3_read_header(AVFormatContext *s)
+static int mpa_read_header(AVFormatContext *s, enum AVCodecID id)
 {
 MP3DecContext *mp3 = s->priv_data;
 AVStream *st;
@@ -354,7 +361,7 @@ static int mp3_read_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_MP3;
+st->codecpar->codec_id = id;
 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
 st->start_time = 0;
 
@@ -419,6 +426,12 @@ static int mp3_read_header(AVFormatContext *s)
 return 0;
 }
 
+#define READ_HEADER(l) \
+static int mp##l##_read_header(AVFormatContext *s) \
+{ \
+return mpa_read_header(s, AV_CODEC_ID_MP##l); \
+}
+
 #define MP3_PACKET_SIZE 1024
 
 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -579,23 +592,30 @@ static const AVOption options[] = {
 { NULL },
 };
 
-static const AVClass demuxer_class = {
-.class_name = "mp3",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-.category   = AV_CLASS_CATEGORY_DEMUXER,
+#define DECLARE_LAYER(l, ext) \
+READ_PROBE(l) \
+READ_HEADER(l) \
+static const AVClass demuxer_class_##l = { \
+.class_name = "mp" #l, \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+.category   = AV_CLASS_CATEGORY_DEMUXER, \
+}; \
+\
+AVInputFormat ff_mp##l##_demuxer = { \
+.name   = "mp" #l, \
+.long_name  = NULL_IF_CONFIG_SMALL("MP" #l " (MPEG audio layer " #l 
")"), \
+.read_probe = mp##l##_read_probe, \
+.read_header= mp##l##_read_header, \
+.read_packet= mp3_read_packet, \
+.read_seek  = mp3_seek, \
+.priv_data_size = sizeof(MP3DecContext), \
+.flags  = AVFMT_GENERIC_INDEX, \
+.extensions = ext, /* XXX: use probe */ \
+.priv_class = &demuxer_class_##l, \
 };
 
-AVInputFormat ff_mp3_demuxer = {
-.name   = "mp3",
-.long_name  = NULL_I

Re: [FFmpeg-devel] [PATCH 1/3] lavf: identify MP2 as a distinct container from MP3

2016-12-21 Thread Rodger Combs

> On Dec 21, 2016, at 13:50, compn  wrote:
> 
> On Wed, 21 Dec 2016 12:51:18 -0600
> Rodger Combs  wrote:
> 
>> 
>>> On Dec 21, 2016, at 02:27, Carl Eugen Hoyos 
>>> wrote:
>>> 
>>> 2016-12-21 5:48 GMT+01:00 Rodger Combs :
>>>> This allows us to report the correct codec ID here
>>> 
>>> Just curious: What does this fix?
>> 
>> Reporting in ffprobe, or when using lavf as a library. Some devices
>> and decoders either refuse to decode MP2, or need to be told that the
>> input is MP2 as opposed to MP3 ahead of time. This also means we'll
>> write the correct ID when remuxing.
> 
> if mp2 is a problem, i would rather make it more difficult for the user
> to encode mp2. by defaulting to mp3 and / or printing a warning message
> about mp2. honestly i cant remember any good coming from someone using
> mp2.
> 
> mp2 is dead, long live mp3.
> 
> also please share your mp2 sample, if you have not already done so, if
> possible.

Here's the sample provided by a user: http://www.ste.no/jens/sample.mp4 
<http://www.ste.no/jens/sample.mp4>
They said they're using MP2 because of some audio desync issue they get when 
using VLC to stream-dump ("well there's your problem"), but I don't think the 
reasoning behind this particular sample is relevant to the legitimacy of the 
issue.

> 
> -compn
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/3] lavf: identify MP2 as a distinct container from MP3

2016-12-21 Thread Rodger Combs

> On Dec 21, 2016, at 02:27, Carl Eugen Hoyos  wrote:
> 
> 2016-12-21 5:48 GMT+01:00 Rodger Combs :
>> This allows us to report the correct codec ID here
> 
> Just curious: What does this fix?

Reporting in ffprobe, or when using lavf as a library. Some devices and 
decoders either refuse to decode MP2, or need to be told that the input is MP2 
as opposed to MP3 ahead of time. This also means we'll write the correct ID 
when remuxing.

> 
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/3] lavf/movdec: request probing for an ambiguous codec tag

2016-12-20 Thread Rodger Combs
---
 libavformat/isom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index ae10cb7d3f..37bfd5af30 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -509,6 +509,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);
 if (codec_id)
 st->codecpar->codec_id = codec_id;
+if (object_type_id == 0x6B) // This can be either MP3 or MP2; let 
probe_codec decide
+st->request_probe = 5;
 av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id);
 len = ff_mp4_read_descr(fc, pb, &tag);
 if (tag == MP4DecSpecificDescrTag) {
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/3] lavf/utils: add MP2 to the probing list

2016-12-20 Thread Rodger Combs
---
 libavformat/utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 50a30f6942..738211dd54 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -329,6 +329,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "loas",  AV_CODEC_ID_AAC_LATM,   AVMEDIA_TYPE_AUDIO },
 { "m4v",   AV_CODEC_ID_MPEG4,  AVMEDIA_TYPE_VIDEO },
 { "mjpeg_2000",AV_CODEC_ID_JPEG2000,   AVMEDIA_TYPE_VIDEO },
+{ "mp2",   AV_CODEC_ID_MP2,AVMEDIA_TYPE_AUDIO },
 { "mp3",   AV_CODEC_ID_MP3,AVMEDIA_TYPE_AUDIO },
 { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
 { "truehd",AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO },
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/3] lavf: identify MP2 as a distinct container from MP3

2016-12-20 Thread Rodger Combs
This allows us to report the correct codec ID here
---
 libavformat/allformats.c |  2 +-
 libavformat/mp3dec.c | 62 +++-
 libavformat/version.h|  2 +-
 3 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a79b75d78..6fd8aa609b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -189,7 +189,7 @@ void av_register_all(void)
 REGISTER_DEMUXER (MM,   mm);
 REGISTER_MUXDEMUX(MMF,  mmf);
 REGISTER_MUXDEMUX(MOV,  mov);
-REGISTER_MUXER   (MP2,  mp2);
+REGISTER_MUXDEMUX(MP2,  mp2);
 REGISTER_MUXDEMUX(MP3,  mp3);
 REGISTER_MUXER   (MP4,  mp4);
 REGISTER_DEMUXER (MPC,  mpc);
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 099ca57d24..499aa45fd4 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -66,7 +66,7 @@ static int check(AVIOContext *pb, int64_t pos, uint32_t 
*header);
 
 /* mp3 read */
 
-static int mp3_read_probe(AVProbeData *p)
+static int mpa_read_probe(AVProbeData *p, int layer)
 {
 int max_frames, first_frames = 0;
 int whole_used = 0;
@@ -89,7 +89,7 @@ static int mp3_read_probe(AVProbeData *p)
 
 header = AV_RB32(buf2);
 ret = avpriv_mpegaudio_decode_header(&h, header);
-if (ret != 0)
+if (ret != 0 || h.layer != layer)
 break;
 buf2 += h.frame_size;
 }
@@ -113,6 +113,12 @@ static int mp3_read_probe(AVProbeData *p)
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
 
+#define READ_PROBE(l) \
+static int mp##l##_read_probe(AVProbeData *p) \
+{ \
+return mpa_read_probe(p, l); \
+}
+
 static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t 
duration)
 {
 int i;
@@ -341,7 +347,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream 
*st, int64_t base)
 return 0;
 }
 
-static int mp3_read_header(AVFormatContext *s)
+static int mpa_read_header(AVFormatContext *s, enum AVCodecID id)
 {
 MP3DecContext *mp3 = s->priv_data;
 AVStream *st;
@@ -354,7 +360,7 @@ static int mp3_read_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_MP3;
+st->codecpar->codec_id = id;
 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
 st->start_time = 0;
 
@@ -419,6 +425,12 @@ static int mp3_read_header(AVFormatContext *s)
 return 0;
 }
 
+#define READ_HEADER(l) \
+static int mp##l##_read_header(AVFormatContext *s) \
+{ \
+return mpa_read_header(s, AV_CODEC_ID_MP##l); \
+}
+
 #define MP3_PACKET_SIZE 1024
 
 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -579,23 +591,29 @@ static const AVOption options[] = {
 { NULL },
 };
 
-static const AVClass demuxer_class = {
-.class_name = "mp3",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-.category   = AV_CLASS_CATEGORY_DEMUXER,
+#define DECLARE_LAYER(l, ext) \
+READ_PROBE(l) \
+READ_HEADER(l) \
+static const AVClass demuxer_class_##l = { \
+.class_name = "mp" #l, \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+.category   = AV_CLASS_CATEGORY_DEMUXER, \
+}; \
+\
+AVInputFormat ff_mp##l##_demuxer = { \
+.name   = "mp" #l, \
+.long_name  = NULL_IF_CONFIG_SMALL("MP" #l " (MPEG audio layer " #l 
")"), \
+.read_probe = mp##l##_read_probe, \
+.read_header= mp##l##_read_header, \
+.read_packet= mp3_read_packet, \
+.read_seek  = mp3_seek, \
+.priv_data_size = sizeof(MP3DecContext), \
+.flags  = AVFMT_GENERIC_INDEX, \
+.extensions = ext, /* XXX: use probe */ \
+.priv_class = &demuxer_class_##l, \
 };
 
-AVInputFormat ff_mp3_demuxer = {
-.name   = "mp3",
-.long_name  = NULL_IF_CONFIG_SMALL("MP2/3 (MPEG audio layer 2/3)"),
-.read_probe = mp3_read_probe,
-.read_header= mp3_read_header,
-.read_packet= mp3_read_packet,
-.read_seek  = mp3_seek,
-.priv_data_size = sizeof(MP3DecContext),
-.flags  = AVFMT_GENERIC_INDEX,
-.extensions = "mp2,mp3,m2a,mpa", /* XXX: use probe */
-.priv_class = &demuxer_class,
-};
+DECLARE_LAYER(2, "mp2,m2a,mpa")
+DECLARE_LAYER(3, "mp3,mpa")
diff --git a/libavformat/version.h b/libavformat/version.h
index 65e6a4ccb7..21cc8a99c7 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
-#define LIBAVFORMAT_VERSION_MINOR  61
+#define LIBAVFORMAT_VERSION_MINOR  62
 #define LIBAVFORMAT

Re: [FFmpeg-devel] [PATCH 2/7] 4xm: prevent overflow during block alignment calculation

2016-12-15 Thread Rodger Combs

> On Dec 15, 2016, at 20:32, Andreas Cadhalpun 
>  wrote:
> 
> Signed-off-by: Andreas Cadhalpun 
> ---
> libavformat/4xm.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/libavformat/4xm.c b/libavformat/4xm.c
> index 2758b69..9332f78 100644
> --- a/libavformat/4xm.c
> +++ b/libavformat/4xm.c
> @@ -187,6 +187,7 @@ static int parse_strk(AVFormatContext *s,
> st->codecpar->bit_rate  = (int64_t)st->codecpar->channels *
>   st->codecpar->sample_rate *
>   st->codecpar->bits_per_coded_sample;
> +FF_BAIL_ON_OVERFLOW(s, st->codecpar->channels && 
> st->codecpar->bits_per_coded_sample > INT_MAX / st->codecpar->channels)

Shouldn't this go before the actual (potentially-overflowing) calculation is 
done?

> st->codecpar->block_align   = st->codecpar->channels *
>   st->codecpar->bits_per_coded_sample;
> 
> -- 
> 2.10.2
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/3] 4xm: prevent overflow during bit rate calculation

2016-12-15 Thread Rodger Combs

> On Dec 15, 2016, at 19:21, Andreas Cadhalpun 
>  wrote:
> 
> On 15.12.2016 14:02, Ronald S. Bultje wrote:
>> On Wed, Dec 14, 2016 at 7:11 PM, Andreas Cadhalpun <
>> andreas.cadhal...@googlemail.com> wrote:
>>> On 14.12.2016 02:46, Ronald S. Bultje wrote:
 Not wanting to discourage you, but I wonder if there's really a point to
 this...?
>>> 
>>> These patches are prerequisites for enforcing the validity of codec
>>> parameters [1].
>>> 
 I don't see how the user experience changes.
>>> 
>>> Users won't see ffmpeg claiming nonsense bit rates like -1184293205235990
>>> kb/s
>>> anymore.
>> 
>> 
>> I don't think you understand my question.
> 
> Maybe you just didn't understand my answer.
> 
>> - does this belong in 4xm.c? (Or in generic code? Or in the app?)
> 
> I think it belongs both in 4xm.c and generic code, as I have explained
> in detail [1] in the discussion back then.
> 
>> - should it return an error? (Or just clip parameters? Or ignore the
>> invalid value?)
> 
> This was also already discussed [2].
> 
> On 15.12.2016 21:57, Ronald S. Bultje wrote:
>> So, I asked on IRC, here's 3 suggestions from Roger Combs:
>> 
>> - in case we want to be pedantic (I personally don't care, but I understand
>> other people are), it might make sense to just make these members
>> (channels, block_align, bitrate) unsigned. That removes the UB of the
>> overflow, and it fixes the negative number reporting in client apps for
>> bitrate, but you can still have positive crazy numbers and it doesn't
>> return an error.
> 
> These are public fields, so changing them is not easy and more importantly
> changing them from signed to unsigned is a very bad idea, as it will most
> probably cause all kinds of subtle bugs for API users, e.g. when comparing,
> subtracting, etc. and not expecting unsigned behavior.
> 

Fair enough.

>> - if for whatever reason some things cannot be done in generic code or by
>> changing the type (this should really cover most cases), and we want
>> specific overflow checks, then maybe we want to have some generic helper
>> macros that make them one-liners in decoders. This would return an error
>> along with fixing the UB.
> 
> I don't think the number of overflow checks added justifies the additional
> complexity of factoring things out. These checks are also subtly different,
> so it's not easy to write a generic helper for that.
> However, I plan to do this for the actually common cases when validating
> codec parameters, like checking that a parameter is not negative.
> 

My proposal was for something like:
#define BAIL_ON_OVERFLOW(x) if (x) {av_log(avctx, AV_LOG_ERROR, "Overflow check 
failed: " #x); return AVERROR_INVALIDDATA;}
Which basically reduces the code overhead down to a simple one-liner. It's hard 
to get detailed error prints out of this, but if we're saying these cases are 
so unlikely (fuzzer-only?) that we're comfortable outright failing on them, the 
level of precision in the message probably doesn't matter much?

>> - have overflow-safe multiplication functions instead of checking each
>> argument before doing a multiply, like __builtin_mul_overflow, and then
>> return INT64_MAX if it would overflow inside that function. This fixes
>> display of numbers in client applications and the UB, but without returning
>> an error.
> 
> I think that would be over-engineered.
> 
>> What I want most - and this comment applies to all patches of this sort -
>> is to have something that we can all agree is OK for pretty much any
>> decoder out there without significant overhead in code (source - not
>> binary) size. This way, you have a template to work from and fix specific
>> instances without us having to argue over every single time you do a next
>> run with ubsan.
> 
> UBSan is not only about overflows, undefined shifts are also quite common.
> But I haven't really looked into these cases yet, so I don't know what kind
> of template, if any, would make sense for them.
> 
> Best regards,
> Andreas
> 
> 
> 1: https://ffmpeg.org/pipermail/ffmpeg-devel/2016-October/201742.html
> 2: https://ffmpeg.org/pipermail/ffmpeg-devel/2016-November/203257.html
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc: report frame field order in avctx

2016-11-18 Thread Rodger Combs

> On Nov 17, 2016, at 18:47, Michael Niedermayer  wrote:
> 
> On Thu, Nov 17, 2016 at 04:48:07AM -0600, Rodger Combs wrote:
>> 
>>> On Nov 15, 2016, at 03:43, Michael Niedermayer  
>>> wrote:
>>> 
>>> On Mon, Nov 14, 2016 at 05:19:25PM -0600, Rodger Combs wrote:
>>>> ---
>>>> libavcodec/utils.c   | 13 +
>>>> tests/api/api-codec-param-test.c |  3 +++
>>>> tests/fate/matroska.mak  |  2 +-
>>>> tests/ref/fate/api-mjpeg-codec-param |  2 +-
>>>> tests/ref/fate/api-png-codec-param   |  2 +-
>>>> tests/ref/fate/mov-zombie|  2 +-
>>>> 6 files changed, 20 insertions(+), 4 deletions(-)
>>>> 
>>>> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
>>>> index d6dca18..b9af880 100644
>>>> --- a/libavcodec/utils.c
>>>> +++ b/libavcodec/utils.c
>>>> @@ -2296,6 +2296,12 @@ fail:
>>>>   guess_correct_pts(avctx,
>>>> 
>>>> picture->pts,
>>>> 
>>>> picture->pkt_dts));
>>>> +
>>>> +if (avctx->field_order == AV_FIELD_UNKNOWN) {
>>>> +avctx->field_order = picture->interlaced_frame
>>>> +   ? (picture->top_field_first ? 
>>>> AV_FIELD_TT : AV_FIELD_BB)
>>>> +   : AV_FIELD_PROGRESSIVE;
>>>> +}
>>>>} else
>>>>av_frame_unref(picture);
>>>>} else
>>>> @@ -2895,6 +2901,13 @@ int attribute_align_arg 
>>>> avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
>>>>av_frame_set_best_effort_timestamp(frame,
>>>>guess_correct_pts(avctx, frame->pts, frame->pkt_dts));
>>>>}
>>>> +
>>>> +if (avctx->field_order == AV_FIELD_UNKNOWN &&
>>>> +avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
>>>> +avctx->field_order = frame->interlaced_frame
>>>> +   ? (frame->top_field_first ? 
>>>> AV_FIELD_TT : AV_FIELD_BB)
>>>> +   : AV_FIELD_PROGRESSIVE;
>>>> +}
>>>>}
>>>>return ret;
>>>>}
>>> 
>>> This doesnt leave any "unknown" option left.
>>> What should a decoder do that knows the field order is unknown
>> 
>> Is this a real case?
> 
> any codec that doesnt have a interlaced flag couldnt set this
> rawvideo and various lossless codecs can store interlaced material
> without problems but lack such flags.

Eugh, but OK.

> 
> 
>> 
>> What I really need here is a stream-level "is interlaced" indicator; I've 
>> considered adding an AV_FIELD_INTERLACED_UNKNOWN value to indicate "This is 
>> interlaced, but I don't know the field order".
>> Thoughts?
> 
> I think AVFrame lacks a unknown between progressive and interlaced

Sorry, I meant "interlaced, but with unknown field order". I'd set that when 
`interlaced_frame` is set, and otherwise leave it as AV_FIELD_UNKNOWN. Does 
that sound reasonable?

> 
> If you want a video filter to fill in only unknown ones that distinction
> would be important
> 
> 
> [...]
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Breaking DRM is a little like attempting to break through a door even
> though the window is wide open and the only thing in the house is a bunch
> of things you dont want and which you would get tomorrow for free anyway
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc: report frame field order in avctx

2016-11-17 Thread Rodger Combs

> On Nov 15, 2016, at 03:43, Michael Niedermayer  wrote:
> 
> On Mon, Nov 14, 2016 at 05:19:25PM -0600, Rodger Combs wrote:
>> ---
>> libavcodec/utils.c   | 13 +
>> tests/api/api-codec-param-test.c |  3 +++
>> tests/fate/matroska.mak  |  2 +-
>> tests/ref/fate/api-mjpeg-codec-param |  2 +-
>> tests/ref/fate/api-png-codec-param   |  2 +-
>> tests/ref/fate/mov-zombie|  2 +-
>> 6 files changed, 20 insertions(+), 4 deletions(-)
>> 
>> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
>> index d6dca18..b9af880 100644
>> --- a/libavcodec/utils.c
>> +++ b/libavcodec/utils.c
>> @@ -2296,6 +2296,12 @@ fail:
>>guess_correct_pts(avctx,
>>  
>> picture->pts,
>>  
>> picture->pkt_dts));
>> +
>> +if (avctx->field_order == AV_FIELD_UNKNOWN) {
>> +avctx->field_order = picture->interlaced_frame
>> +   ? (picture->top_field_first ? 
>> AV_FIELD_TT : AV_FIELD_BB)
>> +   : AV_FIELD_PROGRESSIVE;
>> +}
>> } else
>> av_frame_unref(picture);
>> } else
>> @@ -2895,6 +2901,13 @@ int attribute_align_arg 
>> avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
>> av_frame_set_best_effort_timestamp(frame,
>> guess_correct_pts(avctx, frame->pts, frame->pkt_dts));
>> }
>> +
>> +if (avctx->field_order == AV_FIELD_UNKNOWN &&
>> +avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
>> +avctx->field_order = frame->interlaced_frame
>> +   ? (frame->top_field_first ? AV_FIELD_TT 
>> : AV_FIELD_BB)
>> +   : AV_FIELD_PROGRESSIVE;
>> +}
>> }
>> return ret;
>> }
> 
> This doesnt leave any "unknown" option left.
> What should a decoder do that knows the field order is unknown

Is this a real case?

What I really need here is a stream-level "is interlaced" indicator; I've 
considered adding an AV_FIELD_INTERLACED_UNKNOWN value to indicate "This is 
interlaced, but I don't know the field order".
Thoughts?

> 
> [...]
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> What does censorship reveal? It reveals fear. -- Julian Assange
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc: report frame field order in avctx

2016-11-14 Thread Rodger Combs
---
 libavcodec/utils.c   | 13 +
 tests/api/api-codec-param-test.c |  3 +++
 tests/fate/matroska.mak  |  2 +-
 tests/ref/fate/api-mjpeg-codec-param |  2 +-
 tests/ref/fate/api-png-codec-param   |  2 +-
 tests/ref/fate/mov-zombie|  2 +-
 6 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index d6dca18..b9af880 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2296,6 +2296,12 @@ fail:
guess_correct_pts(avctx,
  picture->pts,
  
picture->pkt_dts));
+
+if (avctx->field_order == AV_FIELD_UNKNOWN) {
+avctx->field_order = picture->interlaced_frame
+   ? (picture->top_field_first ? AV_FIELD_TT : 
AV_FIELD_BB)
+   : AV_FIELD_PROGRESSIVE;
+}
 } else
 av_frame_unref(picture);
 } else
@@ -2895,6 +2901,13 @@ int attribute_align_arg 
avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
 av_frame_set_best_effort_timestamp(frame,
 guess_correct_pts(avctx, frame->pts, frame->pkt_dts));
 }
+
+if (avctx->field_order == AV_FIELD_UNKNOWN &&
+avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+avctx->field_order = frame->interlaced_frame
+   ? (frame->top_field_first ? AV_FIELD_TT : 
AV_FIELD_BB)
+   : AV_FIELD_PROGRESSIVE;
+}
 }
 return ret;
 }
diff --git a/tests/api/api-codec-param-test.c b/tests/api/api-codec-param-test.c
index 377a5e9..16ba8c6 100644
--- a/tests/api/api-codec-param-test.c
+++ b/tests/api/api-codec-param-test.c
@@ -211,6 +211,9 @@ static int check_video_streams(const AVFormatContext 
*fmt_ctx1, const AVFormatCo
 if (!strcmp(opt->name, "frame_number"))
 continue;
 
+if (!strcmp(opt->name, "field_order"))
+continue;
+
 av_assert0(av_opt_get(codec_ctx1, opt->name, 0, &str1) >= 0);
 av_assert0(av_opt_get(codec_ctx2, opt->name, 0, &str2) >= 0);
 if (strcmp(str1, str2)) {
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 35ed41f..16397b5 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -4,6 +4,6 @@
 FATE_MATROSKA-$(call DEMMUX, MATROSKA, MATROSKA) += fate-matroska-remux
 fate-matroska-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-2pass-akiyo.webm -color_trc 4 -c:v 
copy -fflags +bitexact -strict -2 -f matroska
 fate-matroska-remux: CMP = oneline
-fate-matroska-remux: REF = 9b8398b42804ba12c39d2f47299a0996
+fate-matroska-remux: REF = cb6cc1cb581e31c98dd77173c7b4d221
 
 FATE_SAMPLES_AVCONV += $(FATE_MATROSKA-yes)
diff --git a/tests/ref/fate/api-mjpeg-codec-param 
b/tests/ref/fate/api-mjpeg-codec-param
index c67d1b1..c7e8da2 100644
--- a/tests/ref/fate/api-mjpeg-codec-param
+++ b/tests/ref/fate/api-mjpeg-codec-param
@@ -307,7 +307,7 @@ stream=0, decode=1
 refcounted_frames=false
 side_data_only_packets=true
 skip_alpha=false
-field_order=0
+field_order=1
 dump_separator=
 codec_whitelist=
 pixel_format=yuvj422p
diff --git a/tests/ref/fate/api-png-codec-param 
b/tests/ref/fate/api-png-codec-param
index bd53441..cba634e 100644
--- a/tests/ref/fate/api-png-codec-param
+++ b/tests/ref/fate/api-png-codec-param
@@ -307,7 +307,7 @@ stream=0, decode=1
 refcounted_frames=false
 side_data_only_packets=true
 skip_alpha=false
-field_order=0
+field_order=1
 dump_separator=
 codec_whitelist=
 pixel_format=rgba
diff --git a/tests/ref/fate/mov-zombie b/tests/ref/fate/mov-zombie
index 42e3a6f..c9cf7db 100644
--- a/tests/ref/fate/mov-zombie
+++ b/tests/ref/fate/mov-zombie
@@ -129,5 +129,5 @@ 
packet|codec_type=video|stream_index=0|pts=188623|pts_time=2.095811|dts=188622|d
 
frame|media_type=video|stream_index=0|key_frame=0|pkt_pts=188623|pkt_pts_time=2.095811|pkt_dts=188622|pkt_dts_time=2.095800|best_effort_timestamp=188623|best_effort_timestamp_time=2.095811|pkt_duration=3003|pkt_duration_time=0.033367|pkt_pos=100846|pkt_size=974|width=160|height=240|pix_fmt=yuv420p|sample_aspect_ratio=2:1|pict_type=B|coded_picture_number=64|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0
 
packet|codec_type=video|stream_index=0|pts=197632|pts_time=2.195911|dts=191625|dts_time=2.129167|duration=3003|duration_time=0.033367|convergence_duration=N/A|convergence_duration_time=N/A|size=580|pos=101820|flags=__
 
frame|media_type=video|stream_index=0|key_frame=0|pkt_pts=191626|pkt_pts_time=2.129178|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=191626|best_effort_timestamp_time=2.129178|pkt_duration=3003|pkt_duration_tim

[FFmpeg-devel] [PATCH] lavf/mux: don't warn about missing timestamps on attached pictures

2016-11-12 Thread Rodger Combs
---
 libavformat/mux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 77823a4..963d006 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -575,6 +575,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, 
AVStream *st, AVPacket *
 
 if (!s->internal->missing_ts_warning &&
 !(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
+(!(st->disposition & AV_DISPOSITION_ATTACHED_PIC) || (st->disposition 
& AV_DISPOSITION_TIMED_THUMBNAILS)) &&
 (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) {
 av_log(s, AV_LOG_WARNING,
"Timestamps are unset in a packet for stream %d. "
-- 
2.10.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] tests/fate/avformat: add segment.c tests

2016-10-29 Thread Rodger Combs
---
 tests/fate/avformat.mak   |  56 +++
 tests/ref/fate/segment-adts-to-mkv-header-000 |  21 
 tests/ref/fate/segment-adts-to-mkv-header-001 |  22 +
 tests/ref/fate/segment-adts-to-mkv-header-002 |   9 ++
 tests/ref/fate/segment-adts-to-mkv-header-all |  40 
 tests/ref/fate/segment-mp4-to-ts  | 132 ++
 6 files changed, 280 insertions(+)
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-000
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-001
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-002
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-all
 create mode 100644 tests/ref/fate/segment-mp4-to-ts

diff --git a/tests/fate/avformat.mak b/tests/fate/avformat.mak
index 3760e41..cdea970 100644
--- a/tests/fate/avformat.mak
+++ b/tests/fate/avformat.mak
@@ -80,3 +80,59 @@ $(FATE_LAVF_FATE): CMD = lavffatetest
 
 FATE_SAMPLES_FFMPEG += $(FATE_LAVF_FATE)
 fate-lavf-fate:$(FATE_LAVF_FATE)
+
+tests/data/mp4-to-ts.m3u8: TAG = GEN
+tests/data/mp4-to-ts.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+-i $(TARGET_SAMPLES)/h264/interlaced_crop.mp4 \
+-f ssegment -segment_time 1 -map 0 -flags +bitexact -codec copy \
+-segment_list $(TARGET_PATH)/$@ -y 
$(TARGET_PATH)/tests/data/mp4-to-ts-%03d.ts 2>/dev/null
+
+tests/data/adts-to-mkv.m3u8: TAG = GEN
+tests/data/adts-to-mkv.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+-i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts 
\
+-f segment -segment_time 1 -map 0 -flags +bitexact -codec copy 
-segment_format_options live=1 \
+-segment_list $(TARGET_PATH)/$@ -y 
$(TARGET_PATH)/tests/data/adts-to-mkv-%03d.mkv 2>/dev/null
+
+tests/data/adts-to-mkv-header.mkv: TAG = GEN
+tests/data/adts-to-mkv-header.mkv: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+-i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts 
\
+-f segment -segment_time 1 -map 0 -flags +bitexact -codec copy 
-segment_format_options live=1 \
+-segment_header_filename 
$(TARGET_PATH)/tests/data/adts-to-mkv-header.mkv \
+-y $(TARGET_PATH)/tests/data/adts-to-mkv-header-%03d.mkv 2>/dev/null
+
+tests/data/adts-to-mkv-header-%.mkv: tests/data/adts-to-mkv-header.mkv ;
+
+FATE_SEGMENT_PARTS += 000 001 002
+
+tests/data/adts-to-mkv-cated-all.mkv: TAG = GEN
+tests/data/adts-to-mkv-cated-all.mkv: tests/data/adts-to-mkv-header.mkv 
$(FATE_SEGMENT_PARTS:%=tests/data/adts-to-mkv-header-%.mkv) | tests/data
+   $(M)cat $^ >$@
+
+tests/data/adts-to-mkv-cated-%.mkv: TAG = GEN
+tests/data/adts-to-mkv-cated-%.mkv: tests/data/adts-to-mkv-header.mkv 
tests/data/adts-to-mkv-header-%.mkv | tests/data
+   $(M)cat $^ >$@
+
+FATE_SEGMENT += fate-segment-mp4-to-ts
+fate-segment-mp4-to-ts: tests/data/mp4-to-ts.m3u8
+fate-segment-mp4-to-ts: CMD = framecrc -flags +bitexact -i 
$(TARGET_PATH)/tests/data/mp4-to-ts.m3u8 -c copy
+FATE_SEGMENT-$(call ALLYES, MOV_DEMUXER H264_MP4TOANNEXB_BSF MPEGTS_MUXER 
MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += fate-segment-mp4-to-ts
+
+FATE_SEGMENT += fate-segment-adts-to-mkv
+fate-segment-adts-to-mkv: tests/data/adts-to-mkv.m3u8
+fate-segment-adts-to-mkv: CMD = framecrc -flags +bitexact -i 
$(TARGET_PATH)/tests/data/adts-to-mkv.m3u8 -c copy
+fate-segment-adts-to-mkv: REF = 
$(SRC_PATH)/tests/ref/fate/segment-adts-to-mkv-header-all
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER 
MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += fate-segment-adts-to-mkv
+
+FATE_SEGMENT_ALLPARTS = $(FATE_SEGMENT_PARTS)
+FATE_SEGMENT_ALLPARTS += all
+FATE_SEGMENT_SPLIT += 
$(FATE_SEGMENT_ALLPARTS:%=fate-segment-adts-to-mkv-header-%)
+$(foreach N,$(FATE_SEGMENT_ALLPARTS),$(eval 
$(N:%=fate-segment-adts-to-mkv-header-%): 
tests/data/adts-to-mkv-cated-$(N).mkv))
+fate-segment-adts-to-mkv-header-%: CMD = framecrc -flags +bitexact -i 
$(TARGET_PATH)/tests/data/$(@:fate-segment-adts-to-mkv-header-%=adts-to-mkv-cated-%).mkv
 -c copy
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER 
MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += $(FATE_SEGMENT_SPLIT)
+
+FATE_SAMPLES_FFMPEG += $(FATE_SEGMENT-yes)
+
+fate-segment: $(FATE_SEGMENT-yes)
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-000 
b/tests/ref/fate/segment-adts-to-mkv-header-000
new file mode 100644
index 000..d00e886
--- /dev/null
+++ b/tests/ref/fate/segment-adts-to-mkv-header-000
@@ -0,0 +1,21 @@
+#extradata 0:2, 0x0030001c
+#tb 0: 1/1000
+#media_type 0: audio
+#codec_id 0: aac
+#sample_rate 0: 16000
+#channel_layout 0: 4
+0,  0,  0,   64,4, 0x02f70117
+0, 64, 64,   64,  163, 0xd5f85007
+0,128,128,   64,  127, 0x66484065
+0,192,192,   6

Re: [FFmpeg-devel] [PATCH 1/4] lavf/segment: fix autobsf

2016-10-27 Thread Rodger Combs

> On Oct 27, 2016, at 02:07, Steven Liu  wrote:
> 
> 2016-10-27 15:01 GMT+08:00 Steven Liu  <mailto:lingjiujia...@gmail.com>>:
> 
>> 
>> 
>> 2016-10-27 14:52 GMT+08:00 Rodger Combs :
>> 
>>> 
>>>> On Oct 27, 2016, at 01:41, Steven Liu  wrote:
>>>> 
>>>> 2016-10-27 14:16 GMT+08:00 Rodger Combs :
>>>> 
>>>>> ---
>>>>> libavformat/segment.c | 40 +++-
>>>>> 1 file changed, 39 insertions(+), 1 deletion(-)
>>>>> 
>>>>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>>>>> index 868f0a8..9b3dc17 100644
>>>>> --- a/libavformat/segment.c
>>>>> +++ b/libavformat/segment.c
>>>>> @@ -798,9 +798,26 @@ static int seg_write_header(AVFormatContext *s)
>>>>> {
>>>>>SegmentContext *seg = s->priv_data;
>>>>>AVFormatContext *oc = seg->avf;
>>>>> -int ret;
>>>>> +int ret, i;
>>>>> 
>>>>>if (!seg->header_written) {
>>>>> +for (i = 0; i < s->nb_streams; i++) {
>>>>> +AVStream *st = oc->streams[i];
>>>>> +AVCodecParameters *ipar, *opar;
>>>>> +
>>>>> +ipar = s->streams[i]->codecpar;
>>>>> +opar = oc->streams[i]->codecpar;
>>>>> +avcodec_parameters_copy(opar, ipar);
>>>>> +if (!oc->oformat->codec_tag ||
>>>>> +av_codec_get_id (oc->oformat->codec_tag,
>>> ipar->codec_tag)
>>>>> == opar->codec_id ||
>>>>> +av_codec_get_tag(oc->oformat->codec_tag,
>>> ipar->codec_id)
>>>>> <= 0) {
>>>>> +opar->codec_tag = ipar->codec_tag;
>>>>> +} else {
>>>>> +opar->codec_tag = 0;
>>>>> +}
>>>>> +st->sample_aspect_ratio = s->streams[i]->sample_aspect_r
>>> atio;
>>>>> +st->time_base = s->streams[i]->time_base;
>>>>> +}
>>>>>ret = avformat_write_header(oc, NULL);
>>>>>if (ret < 0)
>>>>>return ret;
>>>>> @@ -978,6 +995,25 @@ fail:
>>>>>return ret;
>>>>> }
>>>>> 
>>>>> +static int seg_check_bitstream(struct AVFormatContext *s, const
>>> AVPacket
>>>>> *pkt)
>>>>> +{
>>>>> +SegmentContext *seg = s->priv_data;
>>>>> +AVFormatContext *oc = seg->avf;
>>>>> +if (oc->oformat->check_bitstream) {
>>>>> +int ret = oc->oformat->check_bitstream(oc, pkt);
>>>>> +if (ret == 1) {
>>>>> +AVStream *st = s->streams[pkt->stream_index];
>>>>> +AVStream *ost = oc->streams[pkt->stream_index];
>>>>> +st->internal->bsfcs = ost->internal->bsfcs;
>>>>> +st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
>>>>> +ost->internal->bsfcs = NULL;
>>>>> +ost->internal->nb_bsfcs = 0;
>>>>> +}
>>>>> +return ret;
>>>>> +}
>>>>> +return 1;
>>>>> +}
>>>>> +
>>>>> #define OFFSET(x) offsetof(SegmentContext, x)
>>>>> #define E AV_OPT_FLAG_ENCODING_PARAM
>>>>> static const AVOption options[] = {
>>>>> @@ -1041,6 +1077,7 @@ AVOutputFormat ff_segment_muxer = {
>>>>>.write_packet   = seg_write_packet,
>>>>>.write_trailer  = seg_write_trailer,
>>>>>.deinit = seg_free,
>>>>> +.check_bitstream = seg_check_bitstream,
>>>>>.priv_class = &seg_class,
>>>>> };
>>>>> 
>>>>> @@ -1061,5 +1098,6 @@ AVOutputFormat ff_stream_segment_muxer = {
>>>>>.write_packet   = seg_write_packet,
>>>>>.write_trailer  = seg_write_trailer,
>>>>>.deinit = seg_free,
>>>>> +.check_bitstream = seg_check_bitstream,
>>>>>.priv_class = &sseg_class,
>>>>> };
>>>>> --

Re: [FFmpeg-devel] [PATCH 1/4] lavf/segment: fix autobsf

2016-10-26 Thread Rodger Combs

> On Oct 27, 2016, at 01:41, Steven Liu  wrote:
> 
> 2016-10-27 14:16 GMT+08:00 Rodger Combs :
> 
>> ---
>> libavformat/segment.c | 40 +++-
>> 1 file changed, 39 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>> index 868f0a8..9b3dc17 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -798,9 +798,26 @@ static int seg_write_header(AVFormatContext *s)
>> {
>> SegmentContext *seg = s->priv_data;
>> AVFormatContext *oc = seg->avf;
>> -int ret;
>> +int ret, i;
>> 
>> if (!seg->header_written) {
>> +for (i = 0; i < s->nb_streams; i++) {
>> +AVStream *st = oc->streams[i];
>> +AVCodecParameters *ipar, *opar;
>> +
>> +ipar = s->streams[i]->codecpar;
>> +opar = oc->streams[i]->codecpar;
>> +avcodec_parameters_copy(opar, ipar);
>> +if (!oc->oformat->codec_tag ||
>> +av_codec_get_id (oc->oformat->codec_tag, ipar->codec_tag)
>> == opar->codec_id ||
>> +av_codec_get_tag(oc->oformat->codec_tag, ipar->codec_id)
>> <= 0) {
>> +opar->codec_tag = ipar->codec_tag;
>> +} else {
>> +opar->codec_tag = 0;
>> +}
>> +st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
>> +st->time_base = s->streams[i]->time_base;
>> +}
>> ret = avformat_write_header(oc, NULL);
>> if (ret < 0)
>> return ret;
>> @@ -978,6 +995,25 @@ fail:
>> return ret;
>> }
>> 
>> +static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket
>> *pkt)
>> +{
>> +SegmentContext *seg = s->priv_data;
>> +AVFormatContext *oc = seg->avf;
>> +if (oc->oformat->check_bitstream) {
>> +int ret = oc->oformat->check_bitstream(oc, pkt);
>> +if (ret == 1) {
>> +AVStream *st = s->streams[pkt->stream_index];
>> +AVStream *ost = oc->streams[pkt->stream_index];
>> +st->internal->bsfcs = ost->internal->bsfcs;
>> +st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
>> +ost->internal->bsfcs = NULL;
>> +ost->internal->nb_bsfcs = 0;
>> +}
>> +return ret;
>> +}
>> +return 1;
>> +}
>> +
>> #define OFFSET(x) offsetof(SegmentContext, x)
>> #define E AV_OPT_FLAG_ENCODING_PARAM
>> static const AVOption options[] = {
>> @@ -1041,6 +1077,7 @@ AVOutputFormat ff_segment_muxer = {
>> .write_packet   = seg_write_packet,
>> .write_trailer  = seg_write_trailer,
>> .deinit = seg_free,
>> +.check_bitstream = seg_check_bitstream,
>> .priv_class = &seg_class,
>> };
>> 
>> @@ -1061,5 +1098,6 @@ AVOutputFormat ff_stream_segment_muxer = {
>> .write_packet   = seg_write_packet,
>> .write_trailer  = seg_write_trailer,
>> .deinit = seg_free,
>> +.check_bitstream = seg_check_bitstream,
>> .priv_class = &sseg_class,
>> };
>> --
>> 2.10.0
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> 
> This is move to usual area by Michael
> you can refer to  commit id: e29d2d9c92e19b0caf05a2064d132ccdecdfc3d5
> and
> de9674c5eacc076894bd0f94bee0001ba6ab8344

See 45f5c5573203a48acb2dd6fbf18f4b0c25b7aff0 (which accidentally breaks autobsf 
for segment [patch was written before 
e29d2d9c92e19b0caf05a2064d132ccdecdfc3d5]).
This is necessary for the separate-header-file functionality to work.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/4] tests/fate/avformat: add segment.c tests

2016-10-26 Thread Rodger Combs
---
 tests/fate/avformat.mak   |  56 +++
 tests/ref/fate/segment-adts-to-mkv-header-000 |  20 
 tests/ref/fate/segment-adts-to-mkv-header-001 |  21 +
 tests/ref/fate/segment-adts-to-mkv-header-002 |   8 ++
 tests/ref/fate/segment-adts-to-mkv-header-all |  39 
 tests/ref/fate/segment-mp4-to-ts  | 131 ++
 6 files changed, 275 insertions(+)
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-000
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-001
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-002
 create mode 100644 tests/ref/fate/segment-adts-to-mkv-header-all
 create mode 100644 tests/ref/fate/segment-mp4-to-ts

diff --git a/tests/fate/avformat.mak b/tests/fate/avformat.mak
index 3760e41..3d0d52b 100644
--- a/tests/fate/avformat.mak
+++ b/tests/fate/avformat.mak
@@ -80,3 +80,59 @@ $(FATE_LAVF_FATE): CMD = lavffatetest
 
 FATE_SAMPLES_FFMPEG += $(FATE_LAVF_FATE)
 fate-lavf-fate:$(FATE_LAVF_FATE)
+
+tests/data/mp4-to-ts.m3u8: TAG = GEN
+tests/data/mp4-to-ts.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+-i $(TARGET_SAMPLES)/h264/interlaced_crop.mp4 \
+-f ssegment -segment_time 1 -map 0 -flags +bitexact -codec copy \
+-segment_list $(TARGET_PATH)/$@ -y 
$(TARGET_PATH)/tests/data/mp4-to-ts-%03d.ts 2>/dev/null
+
+tests/data/adts-to-mkv.m3u8: TAG = GEN
+tests/data/adts-to-mkv.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+-i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts 
\
+-f segment -segment_time 1 -map 0 -flags +bitexact -codec copy 
-segment_format_options live=1 \
+-segment_list $(TARGET_PATH)/$@ -y 
$(TARGET_PATH)/tests/data/adts-to-mkv-%03d.mkv 2>/dev/null
+
+tests/data/adts-to-mkv-header.mkv: TAG = GEN
+tests/data/adts-to-mkv-header.mkv: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+-i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts 
\
+-f segment -segment_time 1 -map 0 -flags +bitexact -codec copy 
-segment_format_options live=1 \
+-segment_header_filename 
$(TARGET_PATH)/tests/data/adts-to-mkv-header.mkv \
+-y $(TARGET_PATH)/tests/data/adts-to-mkv-header-%03d.mkv 2>/dev/null
+
+tests/data/adts-to-mkv-header-%.mkv: tests/data/adts-to-mkv-header.mkv ;
+
+FATE_SEGMENT_PARTS += 000 001 002
+
+tests/data/adts-to-mkv-cated-all.mkv: TAG = GEN
+tests/data/adts-to-mkv-cated-all.mkv: tests/data/adts-to-mkv-header.mkv 
$(FATE_SEGMENT_PARTS:%=tests/data/adts-to-mkv-header-%.mkv) | tests/data
+   $(M)cat $^ >$@
+
+tests/data/adts-to-mkv-cated-%.mkv: TAG = GEN
+tests/data/adts-to-mkv-cated-%.mkv: tests/data/adts-to-mkv-header.mkv 
tests/data/adts-to-mkv-header-%.mkv | tests/data
+   $(M)cat $^ >$@
+
+FATE_SEGMENT += fate-segment-mp4-to-ts
+fate-segment-mp4-to-ts: tests/data/mp4-to-ts.m3u8
+fate-segment-mp4-to-ts: CMD = framecrc -flags +bitexact -i 
$(TARGET_PATH)/tests/data/mp4-to-ts.m3u8
+FATE_SEGMENT-$(call ALLYES, MOV_DEMUXER H264_MP4TOANNEXB_BSF MPEGTS_MUXER 
MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += fate-segment-mp4-to-ts
+
+FATE_SEGMENT += fate-segment-adts-to-mkv
+fate-segment-adts-to-mkv: tests/data/adts-to-mkv.m3u8
+fate-segment-adts-to-mkv: CMD = framecrc -flags +bitexact -i 
$(TARGET_PATH)/tests/data/adts-to-mkv.m3u8
+fate-segment-adts-to-mkv: REF = tests/ref/fate/segment-adts-to-mkv-header-all
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER 
MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += fate-segment-adts-to-mkv
+
+FATE_SEGMENT_ALLPARTS = $(FATE_SEGMENT_PARTS)
+FATE_SEGMENT_ALLPARTS += all
+FATE_SEGMENT_SPLIT += 
$(FATE_SEGMENT_ALLPARTS:%=fate-segment-adts-to-mkv-header-%)
+$(foreach N,$(FATE_SEGMENT_ALLPARTS),$(eval 
$(N:%=fate-segment-adts-to-mkv-header-%): 
tests/data/adts-to-mkv-cated-$(N).mkv))
+fate-segment-adts-to-mkv-header-%: CMD = framecrc -flags +bitexact -i 
$(TARGET_PATH)/tests/data/$(@:fate-segment-adts-to-mkv-header-%=adts-to-mkv-cated-%).mkv
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER 
MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += $(FATE_SEGMENT_SPLIT)
+
+FATE_SAMPLES_FFMPEG += $(FATE_SEGMENT-yes)
+
+fate-segment: $(FATE_SEGMENT-yes)
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-000 
b/tests/ref/fate/segment-adts-to-mkv-header-000
new file mode 100644
index 000..cc38a08
--- /dev/null
+++ b/tests/ref/fate/segment-adts-to-mkv-header-000
@@ -0,0 +1,20 @@
+#tb 0: 1/16000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 16000
+#channel_layout 0: 4
+0,  0,  0, 1024, 2048, 0x
+0,   1024,   1024, 1024, 2048, 0xae1f3a0a
+0,   2048,   2048, 1024, 2048, 0x5179fe36
+0,   3072,   3072, 1024, 2048, 0xd079fcb2
+0,   4096,   4096, 1024, 2

[FFmpeg-devel] [PATCH 2/4] lavf/matroskaenc: fix uninitialized read

2016-10-26 Thread Rodger Combs
---
 libavformat/matroskaenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d91055f..c94a490 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1547,7 +1547,7 @@ static int mkv_write_attachments(AVFormatContext *s)
 
 mkv->attachments = av_mallocz(sizeof(*mkv->attachments));
 if (!mkv->attachments)
-return ret;
+return AVERROR(ENOMEM);
 
 av_lfg_init(&c, av_get_random_seed());
 
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/4] lavf/segment: fix autobsf

2016-10-26 Thread Rodger Combs
---
 libavformat/segment.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 868f0a8..9b3dc17 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -798,9 +798,26 @@ static int seg_write_header(AVFormatContext *s)
 {
 SegmentContext *seg = s->priv_data;
 AVFormatContext *oc = seg->avf;
-int ret;
+int ret, i;
 
 if (!seg->header_written) {
+for (i = 0; i < s->nb_streams; i++) {
+AVStream *st = oc->streams[i];
+AVCodecParameters *ipar, *opar;
+
+ipar = s->streams[i]->codecpar;
+opar = oc->streams[i]->codecpar;
+avcodec_parameters_copy(opar, ipar);
+if (!oc->oformat->codec_tag ||
+av_codec_get_id (oc->oformat->codec_tag, ipar->codec_tag) == 
opar->codec_id ||
+av_codec_get_tag(oc->oformat->codec_tag, ipar->codec_id) <= 0) 
{
+opar->codec_tag = ipar->codec_tag;
+} else {
+opar->codec_tag = 0;
+}
+st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
+st->time_base = s->streams[i]->time_base;
+}
 ret = avformat_write_header(oc, NULL);
 if (ret < 0)
 return ret;
@@ -978,6 +995,25 @@ fail:
 return ret;
 }
 
+static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
+{
+SegmentContext *seg = s->priv_data;
+AVFormatContext *oc = seg->avf;
+if (oc->oformat->check_bitstream) {
+int ret = oc->oformat->check_bitstream(oc, pkt);
+if (ret == 1) {
+AVStream *st = s->streams[pkt->stream_index];
+AVStream *ost = oc->streams[pkt->stream_index];
+st->internal->bsfcs = ost->internal->bsfcs;
+st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
+ost->internal->bsfcs = NULL;
+ost->internal->nb_bsfcs = 0;
+}
+return ret;
+}
+return 1;
+}
+
 #define OFFSET(x) offsetof(SegmentContext, x)
 #define E AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -1041,6 +1077,7 @@ AVOutputFormat ff_segment_muxer = {
 .write_packet   = seg_write_packet,
 .write_trailer  = seg_write_trailer,
 .deinit = seg_free,
+.check_bitstream = seg_check_bitstream,
 .priv_class = &seg_class,
 };
 
@@ -1061,5 +1098,6 @@ AVOutputFormat ff_stream_segment_muxer = {
 .write_packet   = seg_write_packet,
 .write_trailer  = seg_write_trailer,
 .deinit = seg_free,
+.check_bitstream = seg_check_bitstream,
 .priv_class = &sseg_class,
 };
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/4] lavf/matroskaenc: don't try to modify the header when live-streaming

2016-10-26 Thread Rodger Combs
---
 libavformat/matroskaenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index c94a490..4f5948d 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1783,7 +1783,7 @@ static int mkv_write_header(AVFormatContext *s)
 put_ebml_void(pb, 11);  // assumes double-precision 
float to be written
 }
 }
-if (s->pb->seekable)
+if (s->pb->seekable && !mkv->is_live)
 put_ebml_void(s->pb, avio_tell(pb));
 else
 end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, mkv->info);
@@ -2274,7 +2274,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 return ret;
 }
 
-if (pb->seekable) {
+if (pb->seekable && !mkv->is_live) {
 if (mkv->cues->num_entries) {
 if (mkv->reserve_cues_space) {
 int64_t cues_end;
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavfi/vf_overlay: support NV12 and NV21

2016-10-25 Thread Rodger Combs
---
 libavfilter/vf_overlay.c| 22 +-
 tests/fate/filter-video.mak | 10 ++
 tests/filtergraphs/overlay_nv12 |  5 +
 tests/filtergraphs/overlay_nv21 |  5 +
 4 files changed, 37 insertions(+), 5 deletions(-)
 create mode 100644 tests/filtergraphs/overlay_nv12
 create mode 100644 tests/filtergraphs/overlay_nv21

diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index c592dca..b249ad7 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -125,6 +125,7 @@ typedef struct OverlayContext {
 int main_pix_step[4];   ///< steps per pixel for each plane of the 
main output
 int overlay_pix_step[4];///< steps per pixel for each plane of the 
overlay
 int hsub, vsub; ///< chroma subsampling values
+const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input
 
 double var_values[VAR_VARS_NB];
 char *x_expr, *y_expr;
@@ -215,7 +216,9 @@ static int query_formats(AVFilterContext *ctx)
 
 /* overlay formats contains alpha, for avoiding conversion with alpha 
information loss */
 static const enum AVPixelFormat main_pix_fmts_yuv420[] = {
-AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P, 
AV_PIX_FMT_NONE
+AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
+AV_PIX_FMT_NV12, AV_PIX_FMT_NV21,
+AV_PIX_FMT_NONE
 };
 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
 AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE
@@ -470,6 +473,7 @@ static av_always_inline void blend_plane(AVFilterContext 
*ctx,
  int x, int y,
  int main_has_alpha)
 {
+OverlayContext *ol = ctx->priv;
 int src_wp = AV_CEIL_RSHIFT(src_w, hsub);
 int src_hp = AV_CEIL_RSHIFT(src_h, vsub);
 int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub);
@@ -479,14 +483,20 @@ static av_always_inline void blend_plane(AVFilterContext 
*ctx,
 uint8_t *s, *sp, *d, *dp, *a, *ap;
 int jmax, j, k, kmax;
 
+int dst_plane  = ol->main_desc->comp[i].plane;
+int dst_offset = ol->main_desc->comp[i].offset;
+int dst_step   = ol->main_desc->comp[i].step;
+
 j = FFMAX(-yp, 0);
 sp = src->data[i] + j * src->linesize[i];
-dp = dst->data[i] + (yp+j)* dst->linesize[i];
+dp = dst->data[dst_plane]
+  + (yp+j)* dst->linesize[dst_plane]
+  + dst_offset;
 ap = src->data[3] + (jlinesize[dst_plane];
 sp += src->linesize[i];
 ap += (1 << vsub) * src->linesize[3];
 }
@@ -626,6 +636,8 @@ static int config_input_main(AVFilterLink *inlink)
 s->hsub = pix_desc->log2_chroma_w;
 s->vsub = pix_desc->log2_chroma_h;
 
+s->main_desc = pix_desc;
+
 s->main_is_packed_rgb =
 ff_fill_rgba_map(s->main_rgba_map, inlink->format) >= 0;
 s->main_has_alpha = ff_fmt_is_in(inlink->format, alpha_pix_fmts);
diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index e2513f5..ec22d25 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -172,6 +172,16 @@ FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER 
SCALE_FILTER PAD_FILTER OVERLAY_F
 fate-filter-overlay_yuv420: tests/data/filtergraphs/overlay_yuv420
 fate-filter-overlay_yuv420: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_yuv420
 
+FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER 
OVERLAY_FILTER) += fate-filter-overlay_nv12
+fate-filter-overlay_nv12: tests/data/filtergraphs/overlay_nv12
+fate-filter-overlay_nv12: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_nv12
+fate-filter-overlay_nv12: REF = 
$(SRC_PATH)/tests/ref/fate/filter-overlay_yuv420
+
+FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER 
OVERLAY_FILTER) += fate-filter-overlay_nv21
+fate-filter-overlay_nv21: tests/data/filtergraphs/overlay_nv21
+fate-filter-overlay_nv21: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_nv21
+fate-filter-overlay_nv21: REF = 
$(SRC_PATH)/tests/ref/fate/filter-overlay_yuv420
+
 FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER 
OVERLAY_FILTER) += fate-filter-overlay_yuv422
 fate-filter-overlay_yuv422: tests/data/filtergraphs/overlay_yuv422
 fate-filter-overlay_yuv422: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_yuv422
diff --git a/tests/filtergraphs/overlay_nv12 b/tests/filtergraphs/overlay_nv12
new file mode 100644
index 000..ec82cbe
--- /dev/null
+++ b/tests/fil

[FFmpeg-devel] [PATCH] lavfi/vf_overlay: support NV12 and NV21

2016-10-25 Thread Rodger Combs
---
 libavfilter/vf_overlay.c| 22 +-
 tests/fate/filter-video.mak | 10 ++
 tests/filtergraphs/overlay_nv12 |  5 +
 tests/filtergraphs/overlay_nv21 |  5 +
 4 files changed, 37 insertions(+), 5 deletions(-)
 create mode 100644 tests/filtergraphs/overlay_nv12
 create mode 100644 tests/filtergraphs/overlay_nv21

diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index c592dca..b249ad7 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -125,6 +125,7 @@ typedef struct OverlayContext {
 int main_pix_step[4];   ///< steps per pixel for each plane of the 
main output
 int overlay_pix_step[4];///< steps per pixel for each plane of the 
overlay
 int hsub, vsub; ///< chroma subsampling values
+const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input
 
 double var_values[VAR_VARS_NB];
 char *x_expr, *y_expr;
@@ -215,7 +216,9 @@ static int query_formats(AVFilterContext *ctx)
 
 /* overlay formats contains alpha, for avoiding conversion with alpha 
information loss */
 static const enum AVPixelFormat main_pix_fmts_yuv420[] = {
-AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P, 
AV_PIX_FMT_NONE
+AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
+AV_PIX_FMT_NV12, AV_PIX_FMT_NV21,
+AV_PIX_FMT_NONE
 };
 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
 AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE
@@ -470,6 +473,7 @@ static av_always_inline void blend_plane(AVFilterContext 
*ctx,
  int x, int y,
  int main_has_alpha)
 {
+OverlayContext *ol = ctx->priv;
 int src_wp = AV_CEIL_RSHIFT(src_w, hsub);
 int src_hp = AV_CEIL_RSHIFT(src_h, vsub);
 int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub);
@@ -479,14 +483,20 @@ static av_always_inline void blend_plane(AVFilterContext 
*ctx,
 uint8_t *s, *sp, *d, *dp, *a, *ap;
 int jmax, j, k, kmax;
 
+int dst_plane  = ol->main_desc->comp[i].plane;
+int dst_offset = ol->main_desc->comp[i].offset;
+int dst_step   = ol->main_desc->comp[i].step;
+
 j = FFMAX(-yp, 0);
 sp = src->data[i] + j * src->linesize[i];
-dp = dst->data[i] + (yp+j)* dst->linesize[i];
+dp = dst->data[dst_plane]
+  + (yp+j)* dst->linesize[dst_plane]
+  + dst_offset;
 ap = src->data[3] + (jlinesize[dst_plane];
 sp += src->linesize[i];
 ap += (1 << vsub) * src->linesize[3];
 }
@@ -626,6 +636,8 @@ static int config_input_main(AVFilterLink *inlink)
 s->hsub = pix_desc->log2_chroma_w;
 s->vsub = pix_desc->log2_chroma_h;
 
+s->main_desc = pix_desc;
+
 s->main_is_packed_rgb =
 ff_fill_rgba_map(s->main_rgba_map, inlink->format) >= 0;
 s->main_has_alpha = ff_fmt_is_in(inlink->format, alpha_pix_fmts);
diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index e2513f5..81c50f7 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -172,6 +172,16 @@ FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER 
SCALE_FILTER PAD_FILTER OVERLAY_F
 fate-filter-overlay_yuv420: tests/data/filtergraphs/overlay_yuv420
 fate-filter-overlay_yuv420: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_yuv420
 
+FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER 
OVERLAY_FILTER) += fate-filter-overlay_nv12
+fate-filter-overlay_nv12: tests/data/filtergraphs/overlay_nv12
+fate-filter-overlay_nv12: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_nv12
+fate-filter-overlay_nv12: REF = tests/ref/fate/filter-overlay_yuv420
+
+FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER 
OVERLAY_FILTER) += fate-filter-overlay_nv21
+fate-filter-overlay_nv21: tests/data/filtergraphs/overlay_nv21
+fate-filter-overlay_nv21: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_nv21
+fate-filter-overlay_nv21: REF = tests/ref/fate/filter-overlay_yuv420
+
 FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER 
OVERLAY_FILTER) += fate-filter-overlay_yuv422
 fate-filter-overlay_yuv422: tests/data/filtergraphs/overlay_yuv422
 fate-filter-overlay_yuv422: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_yuv422
diff --git a/tests/filtergraphs/overlay_nv12 b/tests/filtergraphs/overlay_nv12
new file mode 100644
index 000..ec82cbe
--- /dev/null
+++ b/tests/filtergraphs/overlay_nv12
@@ 

[FFmpeg-devel] [PATCH] lavf/segment: decide whether to rename based on list URI

2016-10-06 Thread Rodger Combs
This fixes the case of writing segments to local files, but the list
over a network protocol.
---
 libavformat/segment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 33a5cf0..55dcaf0 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -709,7 +709,7 @@ static int seg_init(AVFormatContext *s)
 if ((ret = segment_list_open(s)) < 0)
 goto fail;
 } else {
-const char *proto = avio_find_protocol_name(s->filename);
+const char *proto = avio_find_protocol_name(seg->list);
 seg->use_rename = proto && !strcmp(proto, "file");
 }
 }
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] lavf/utils: avoid using programs for duration when there's only one

2016-10-05 Thread Rodger Combs
This allows us to be more selective about the streams we derive durations from
(specifically, ignoring text streams with outlier end times) in the common case
---
 libavformat/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index d19cc5e..1aa3b50 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2582,7 +2582,7 @@ static void update_stream_timings(AVFormatContext *ic)
 if (start_time != INT64_MAX) {
 ic->start_time = start_time;
 if (end_time != INT64_MIN) {
-if (ic->nb_programs) {
+if (ic->nb_programs > 1) {
 for (i = 0; i < ic->nb_programs; i++) {
 p = ic->programs[i];
 if (p->start_time != AV_NOPTS_VALUE && p->end_time > 
p->start_time)
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] lavf/utils: ignore outlier subtitle and data stream end times as well

2016-10-05 Thread Rodger Combs
---
 libavformat/utils.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3acb260..d19cc5e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2524,7 +2524,7 @@ static int has_duration(AVFormatContext *ic)
  */
 static void update_stream_timings(AVFormatContext *ic)
 {
-int64_t start_time, start_time1, start_time_text, end_time, end_time1;
+int64_t start_time, start_time1, start_time_text, end_time, end_time1, 
end_time_text;
 int64_t duration, duration1, filesize;
 int i;
 AVStream *st;
@@ -2533,6 +2533,7 @@ static void update_stream_timings(AVFormatContext *ic)
 start_time = INT64_MAX;
 start_time_text = INT64_MAX;
 end_time   = INT64_MIN;
+end_time_text   = INT64_MIN;
 duration   = INT64_MIN;
 for (i = 0; i < ic->nb_streams; i++) {
 st = ic->streams[i];
@@ -2549,7 +2550,10 @@ static void update_stream_timings(AVFormatContext *ic)
  
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= 
INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
 end_time1 += start_time1;
-end_time = FFMAX(end_time, end_time1);
+if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
+end_time_text = FFMAX(end_time_text, end_time1);
+else
+end_time = FFMAX(end_time, end_time1);
 }
 for (p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) {
 if (p->start_time == AV_NOPTS_VALUE || p->start_time > 
start_time1)
@@ -2569,6 +2573,12 @@ static void update_stream_timings(AVFormatContext *ic)
 else if (start_time > start_time_text)
 av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream 
starttime %f\n", start_time_text / (float)AV_TIME_BASE);
 
+if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - 
end_time < AV_TIME_BASE)) {
+end_time = end_time_text;
+} else if (end_time < end_time_text) {
+av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream 
endtime %f\n", end_time_text / (float)AV_TIME_BASE);
+}
+
 if (start_time != INT64_MAX) {
 ic->start_time = start_time;
 if (end_time != INT64_MIN) {
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/segment: provide a virtual AVIOContext representing all the segments

2016-10-04 Thread Rodger Combs
This allows the use of muxers like matroska, which attempt to seek even
when an AVIOContext doesn't set `seekable`, without concern for a rouge
seek leading the muxer to overwrite the wrong data in a later segment.
---
 doc/muxers.texi   |  17 
 libavformat/segment.c | 276 +-
 libavformat/version.h |   2 +-
 3 files changed, 223 insertions(+), 72 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 9ec2e31..2cfa1ec 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1390,6 +1390,23 @@ argument must be a time duration specification, and 
defaults to 0.
 If enabled, write an empty segment if there are no packets during the period a
 segment would usually span. Otherwise, the segment will be filled with the next
 packet written. Defaults to @code{0}.
+
+@item individual_header_trailer @var{1|0}
+Write each segment as an individual distinct file in the underlying format.
+When this is set to @code{0}, the segments are treated as a single continuous
+stream. When set to @code{1} (the default), each individual segment receives
+a header and trailer, so they can be played independently.
+
+@item segment_header_filename @var{name}
+Write the global header to a separate file. Requires
+@var{individual_header_trailer} to be @code{0}. If not set, the global header
+will be written to the first file along with actual segment data.
+
+@item segment_seekback @var{1|0}
+Allow the muxer to seek back and overwrite data from previous segments. 
Requires
+@var{individual_header_trailer} to be @code{0}. If set to @code{0} (the 
default),
+the underlying muxer will be unable to seek back into previous segments, so 
they
+can be relied upon not to change once written.
 @end table
 
 @subsection Examples
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 33a5cf0..4858e9c 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -51,8 +51,10 @@ typedef struct SegmentListEntry {
 int64_t start_pts;
 int64_t offset_pts;
 char *filename;
+char *full_filename;
 struct SegmentListEntry *next;
 int64_t last_duration;
+size_t start_offset;
 } SegmentListEntry;
 
 typedef enum {
@@ -125,7 +127,13 @@ typedef struct SegmentContext {
 
 SegmentListEntry cur_entry;
 SegmentListEntry *segment_list_entries;
+SegmentListEntry *segment_list_entries_all;
 SegmentListEntry *segment_list_entries_end;
+SegmentListEntry *segment_list_entry_writing;
+int seekback;  ///< allow seeking back to previous segments
+AVIOContext *cur_pb;   ///< current segment put-byte context
+size_t write_offset;
+size_t max_offset;
 } SegmentContext;
 
 static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
@@ -144,6 +152,123 @@ static void print_csv_escaped_str(AVIOContext *ctx, const 
char *str)
 avio_w8(ctx, '"');
 }
 
+static int64_t virtual_seek(void *priv, int64_t target, int whence)
+{
+AVFormatContext *s = priv;
+SegmentContext *seg = s->priv_data;
+SegmentListEntry *it, *current = NULL;
+int64_t offset = target;
+int64_t ret;
+
+if (whence != SEEK_SET)
+return AVERROR(EINVAL);
+if (offset < 0)
+return AVERROR(EINVAL);
+
+if (offset >= seg->max_offset) {
+ff_format_io_close(s, &seg->cur_pb);
+seg->write_offset = offset;
+return offset;
+}
+
+if (seg->cur_entry.start_offset <= offset) {
+current = &seg->cur_entry;
+} else {
+for (it = seg->segment_list_entries_all; it; it = it->next) {
+if (it->start_offset <= offset)
+current = it;
+else if (it->start_offset > offset)
+break;
+}
+}
+
+offset -= current->start_offset;
+
+if (current != seg->segment_list_entry_writing) {
+int is_seekback = (current != &seg->cur_entry) && 
seg->segment_list_entries;
+char *new_filename;
+AVIOContext *new_ctx = NULL;
+AVDictionary *options = NULL;
+
+if (!seg->seekback && is_seekback)
+return AVERROR(EINVAL);
+
+new_filename = current->full_filename;
+
+if (new_filename) {
+if (is_seekback)
+av_dict_set_int(&options, "truncate", 0, 0);
+if ((ret = s->io_open(s, &new_ctx, new_filename, AVIO_FLAG_WRITE, 
&options)) < 0) {
+av_log(s, AV_LOG_ERROR, "Failed to seek into segment '%s'\n", 
new_filename);
+return ret;
+}
+}
+
+ff_format_io_close(s, &seg->cur_pb);
+seg->cur_pb = new_ctx;
+seg->segment_list_entry_writing = current;
+}
+
+if (seg->cur_pb)
+if ((ret = avio_seek(seg->cur_pb, offset, SEEK_SET)) < 0)
+return ret;
+
+seg->write_offset = offset;
+
+return target;
+}
+
+static int virtual_write(void *priv, uint8_t *buf, int buf_size)
+{
+AVFormatContext *s = priv;
+SegmentContext *seg = s->priv_data;
+  

[FFmpeg-devel] [PATCH 2/3] lavf/mov: improve `tref/chap` chapter handling

2016-10-04 Thread Rodger Combs
3 parts:
- Supports multiple chapter streams
- Exports regular text chapter streams as opaque data. This prevents consumers
  from showing chapters as if they were regular subtitle streams.
- Exports video chapter streams as thumbnails, and provides the first one as
  an attached_pic.
---
 libavformat/isom.h |  3 ++-
 libavformat/mov.c  | 54 +++---
 2 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 2246fed..9038057 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -210,7 +210,8 @@ typedef struct MOVContext {
 unsigned trex_count;
 int itunes_metadata;  ///< metadata are itunes style
 int handbrake_version;
-int chapter_track;
+int *chapter_tracks;
+unsigned int nb_chapter_tracks;
 int use_absolute_path;
 int ignore_editlist;
 int ignore_chapters;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index a15c8d1..d0f1316 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3971,7 +3971,20 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
-c->chapter_track = avio_rb32(pb);
+unsigned i, num;
+void *new_tracks;
+
+num = atom.size / 4;
+if (!(new_tracks = av_malloc_array(num, sizeof(int
+return AVERROR(ENOMEM);
+
+av_free(c->chapter_tracks);
+c->chapter_tracks = new_tracks;
+c->nb_chapter_tracks = num;
+
+for (i = 0; i < num && !pb->eof_reached; i++)
+c->chapter_tracks[i] = avio_rb32(pb);
+
 return 0;
 }
 
@@ -5034,25 +5047,50 @@ static int mov_probe(AVProbeData *p)
 static void mov_read_chapters(AVFormatContext *s)
 {
 MOVContext *mov = s->priv_data;
-AVStream *st = NULL;
+AVStream *st;
 MOVStreamContext *sc;
 int64_t cur_pos;
-int i;
+int i, j;
+int chapter_track;
 
+for (j = 0; j < mov->nb_chapter_tracks; j++) {
+chapter_track = mov->chapter_tracks[j];
+st = NULL;
 for (i = 0; i < s->nb_streams; i++)
-if (s->streams[i]->id == mov->chapter_track) {
+if (s->streams[i]->id == chapter_track) {
 st = s->streams[i];
 break;
 }
 if (!st) {
 av_log(s, AV_LOG_ERROR, "Referenced QT chapter track not found\n");
-return;
+continue;
 }
 
-st->discard = AVDISCARD_ALL;
 sc = st->priv_data;
 cur_pos = avio_tell(sc->pb);
 
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+st->disposition |= AV_DISPOSITION_ATTACHED_PIC | 
AV_DISPOSITION_TIMED_THUMBNAILS;
+if (st->nb_index_entries) {
+// Retrieve the first frame, if possible
+AVPacket pkt;
+AVIndexEntry *sample = &st->index_entries[0];
+if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
+av_log(s, AV_LOG_ERROR, "Failed to retrieve first frame\n");
+goto finish;
+}
+
+if (av_get_packet(sc->pb, &pkt, sample->size) < 0)
+goto finish;
+
+st->attached_pic  = pkt;
+st->attached_pic.stream_index = st->index;
+st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
+}
+} else {
+st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA;
+st->discard = AVDISCARD_ALL;
 for (i = 0; i < st->nb_index_entries; i++) {
 AVIndexEntry *sample = &st->index_entries[i];
 int64_t end = i+1 < st->nb_index_entries ? 
st->index_entries[i+1].timestamp : st->duration;
@@ -5101,8 +5139,10 @@ static void mov_read_chapters(AVFormatContext *s)
 avpriv_new_chapter(s, i, st->time_base, sample->timestamp, end, title);
 av_freep(&title);
 }
+}
 finish:
 avio_seek(sc->pb, cur_pos, SEEK_SET);
+}
 }
 
 static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st,
@@ -5425,7 +5465,7 @@ static int mov_read_header(AVFormatContext *s)
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
 if (pb->seekable) {
-if (mov->chapter_track > 0 && !mov->ignore_chapters)
+if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters)
 mov_read_chapters(s);
 for (i = 0; i < s->nb_streams; i++)
 if (s->streams[i]->codecpar->codec_tag == AV_RL32("tmcd")) {
-- 
2.10.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


<    1   2   3   4   5   6   7   8   >