Re: [FFmpeg-devel] [GSOC] [PATCH] SRCNN filter

2018-03-28 Thread Sergey Lavrushkin
> [...]
> > +#define OFFSET(x) offsetof(SRCNNContext, x)
> > +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
> > +static const AVOption srcnn_options[] = {
> > +{ "config_file", "path to configuration file with network
> parameters", OFFSET(config_file_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0,
> 0, FLAGS },
> > +{ NULL }
> > +};
> > +
> > +AVFILTER_DEFINE_CLASS(srcnn);
> > +
> > +#define CHECK_FILE(file)if (ferror(file) || feof(file)){ \
> > +av_log(context, AV_LOG_ERROR, "error
> reading configuration file\n");\
> > +fclose(file); \
> > +return AVERROR(EIO); \
> > +}
> > +
> > +#define CHECK_ALLOCATION(conv, file)if
> (allocate_and_read_convolution_data(&conv, file)){ \
> > +av_log(context,
> AV_LOG_ERROR, "could not allocate memory for convolutions\n"); \
> > +fclose(file); \
> > +return AVERROR(ENOMEM); \
> > +}
> > +
>
> > +static int allocate_and_read_convolution_data(Convolution* conv, FILE*
> config_file)
> > +{
> > +int32_t kernel_size = conv->output_channels * conv->size *
> conv->size * conv->input_channels;
> > +conv->kernel = av_malloc(kernel_size * sizeof(double));
> > +if (!conv->kernel){
> > +return 1;
>
> this should return an AVERROR code for consistency with the rest of
> the codebase
>

Ok.


> > +}
>
> > +fread(conv->kernel, sizeof(double), kernel_size, config_file);
>
> directly reading data types is not portable, it would for example be
> endian specific
> and using avio for reading may be better, though fread is as far as iam
> concerned also ok
>

Ok, I understand the problem, but I have not really worked with it before,
so I need an advice of how to properly fix it. If I understand correctly,
for
int32_t I need to check endianness and reverse bytes if necessary. But with
doubles it is more complicated. Should I write a IEEE 754 converter from
binary
to double or maybe I can somehow check IEEE 754 doubles support and
depending
on it either stick to the default network weights, or just read bytes and
check
endianness, if IEEE 754 doubles are supported? Or maybe avio provide some
utility to deal with this problem?


> [...]
> > +/**
> > + * @file
> > + * Default cnn weights for x2 upsampling with srcnn filter.
> > + */
> > +
> > +/// First convolution kernel
>
> > +static double conv1_kernel[] = {
>
> static data should be also const, otherwise it may be changed and could
> cause
> thread saftey issues
>

Ok, I just wanted to not allocate additional memory in case of using
default weights.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add OpenCL scale filter

2018-03-28 Thread Song, Ruiling
> 
> No license, can't use it. Shadertoy has no explicit license.
> 
> 
> Moreover the whole filter is incorrectly designed. Take a look at what mpv
> does and how it has no explicit per-algorithm scaling functions.

Hi Rostislav,

It is just a coincidence that I am also working on the OpenCL version scale 
filter. So I am very interested in further discussion.
I just attached my patch. It still has some problem with aspect ratio, and I 
only add bilinear filter, but with NV12 support.
Basically it is something like scale_cuda. Based on your comments. Seems I also 
mis-designed the filter:(
So could you talk a little bit more about your idea? Why per-algorithm scaling 
function seems not so good?
For the mpv, do you mean something like pass_sample_bicubic_fast() @ 
$mpv/video/out/gpu/video_shaders.c?
I have not read mpv code before, please forgive me if I am wrong.
I am not sure if anybody else has idea on how we should implement the OpenCL 
version scaler?

Thanks!
Ruiling





0001-lavf-add-scale_opencl-filter.patch
Description: 0001-lavf-add-scale_opencl-filter.patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] movtextenc: fix handling of utf-8 subtitles

2018-03-28 Thread wm4
On Tue, 27 Mar 2018 20:07:05 -0700
Philip Langdale  wrote:

> See the earlier fix for movtextdec for details. The equivalent bug is
> present on the encoder side as well.
> 
> We need to track the text length in 'characters' (which seems to really
> mean codepoints) to ensure that styles are applied across the correct
> ranges.
> 
> Signed-off-by: Philip Langdale 
> ---
>  libavcodec/movtextenc.c | 24 +++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
> index d795e317c3..fd0743f752 100644
> --- a/libavcodec/movtextenc.c
> +++ b/libavcodec/movtextenc.c
> @@ -304,11 +304,33 @@ static void mov_text_color_cb(void *priv, unsigned int 
> color, unsigned int color
>   */
>  }
>  
> +static uint16_t utf8_strlen(const char *text, int len)
> +{
> +uint16_t i = 0, ret = 0;
> +while (i < len) {
> +char c = text[i];
> +if (c >= 0)
> +i += 1;
> +else if ((c & 0xE0) == 0xC0)
> +i += 2;
> +else if ((c & 0xF0) == 0xE0)
> +i += 3;
> +else if ((c & 0xF8) == 0xF0)
> +i += 4;
> +else
> +return 0;
> +ret++;
> +}
> +return ret;
> +}
> +
>  static void mov_text_text_cb(void *priv, const char *text, int len)
>  {
> +uint16_t utf8_len = utf8_strlen(text, len);
>  MovTextContext *s = priv;
>  av_bprint_append_data(&s->buffer, text, len);
> -s->text_pos += len;
> +// If it's not utf-8, just use the byte length
> +s->text_pos += utf8_len ? utf8_len : len;
>  }
>  
>  static void mov_text_new_line_cb(void *priv, int forced)

LGTM.

Maybe a later patch that adds the UTF-8 length as lavu function (or
macro for SPEEED?) eould be nice, since we seem to need that often.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/buffer: add a dynamic size buffer pool API

2018-03-28 Thread wm4
On Tue, 27 Mar 2018 23:11:27 -0300
James Almer  wrote:

> Signed-off-by: James Almer 
> ---
> Implemented as a completely separate API as suggested. Missing
> Changelog, APIChanges and version bump as usual.
> 
>  libavutil/buffer.c  | 159 
> 
>  libavutil/buffer.h  |  53 +++
>  libavutil/buffer_internal.h |  14 
>  3 files changed, 226 insertions(+)
> 
> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> index 8d1aa5fa84..c39a14c3c7 100644
> --- a/libavutil/buffer.c
> +++ b/libavutil/buffer.c
> @@ -24,6 +24,7 @@
>  #include "common.h"
>  #include "mem.h"
>  #include "thread.h"
> +#include "tree.h"
>  
>  AVBufferRef *av_buffer_create(uint8_t *data, int size,
>void (*free)(void *opaque, uint8_t *data),
> @@ -355,3 +356,161 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
>  
>  return ret;
>  }
> +
> +AVBufferDynPool *av_buffer_dyn_pool_init(AVBufferRef* (*alloc)(int size))
> +{
> +AVBufferDynPool *pool = av_mallocz(sizeof(*pool));
> +if (!pool)
> +return NULL;
> +
> +ff_mutex_init(&pool->mutex, NULL);
> +
> +pool->alloc = alloc ? alloc : av_buffer_alloc;
> +
> +atomic_init(&pool->refcount, 1);
> +
> +return pool;
> +}
> +
> +static int free_node(void *opaque, void *elem)
> +{
> +BufferPoolEntry *buf = elem;
> +
> +buf->free(buf->opaque, buf->data);
> +av_free(buf);
> +
> +return 0;
> +}
> +
> +static void buffer_dyn_pool_free(AVBufferDynPool *pool)
> +{
> +av_tree_enumerate(pool->root, NULL, NULL, free_node);
> +av_tree_destroy(pool->root);
> +
> +ff_mutex_destroy(&pool->mutex);
> +
> +av_freep(&pool);
> +}
> +
> +void av_buffer_dyn_pool_uninit(AVBufferDynPool **ppool)
> +{
> +AVBufferDynPool *pool;
> +
> +if (!ppool || !*ppool)
> +return;
> +pool   = *ppool;
> +*ppool = NULL;
> +
> +if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) 
> == 1)
> +buffer_dyn_pool_free(pool);
> +}
> +
> +static int cmp_insert(const void *key, const void *node)
> +{
> +int ret = ((const BufferPoolEntry *) key)->size - ((const 
> BufferPoolEntry *) node)->size;
> +
> +if (!ret)
> +ret = ((const BufferPoolEntry *) key)->data - ((const 
> BufferPoolEntry *) node)->data;
> +return ret;
> +}
> +
> +static void pool_release_dyn_buffer(void *opaque, uint8_t *data)
> +{
> +BufferPoolEntry *buf = opaque;
> +AVBufferDynPool *pool = buf->dynpool;
> +
> +if(CONFIG_MEMORY_POISONING)
> +memset(buf->data, FF_MEMORY_POISON, buf->size);
> +
> +ff_mutex_lock(&pool->mutex);
> +/* Add the buffer into the pool, using the preallocated
> + * AVTreeNode stored in buf->node */
> +av_tree_insert(&pool->root, buf, cmp_insert, &buf->node);
> +ff_mutex_unlock(&pool->mutex);
> +
> +if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) 
> == 1)
> +buffer_dyn_pool_free(pool);
> +}
> +
> +static AVBufferRef *pool_alloc_dyn_buffer(AVBufferDynPool *pool, int size)
> +{
> +BufferPoolEntry *buf;
> +AVBufferRef *ret;
> +
> +ret = pool->alloc(size);
> +if (!ret)
> +return NULL;
> +
> +buf = av_mallocz(sizeof(*buf));
> +if (!buf) {
> +av_buffer_unref(&ret);
> +return NULL;
> +}
> +
> +buf->node = av_tree_node_alloc();
> +if (!buf->node) {
> +av_free(buf);
> +av_buffer_unref(&ret);
> +return NULL;
> +}
> +
> +buf->data= ret->buffer->data;
> +buf->opaque  = ret->buffer->opaque;
> +buf->free= ret->buffer->free;
> +buf->size= size;
> +buf->dynpool = pool;
> +
> +ret->buffer->opaque = buf;
> +ret->buffer->free   = pool_release_dyn_buffer;
> +
> +return ret;
> +}
> +
> +static int cmp_find(const void *key, const void *node)
> +{
> +return *(const int *)key - ((const BufferPoolEntry *) node)->size;
> +}
> +
> +AVBufferRef *av_buffer_dyn_pool_get(AVBufferDynPool *pool, int size)
> +{
> +AVBufferRef *ret;
> +BufferPoolEntry *buf, *next[2] = { NULL, NULL };
> +
> +ff_mutex_lock(&pool->mutex);
> +/* Find a big enough buffer in the pool. */
> +buf = av_tree_find(pool->root, &size, cmp_find, (void **)next);
> +
> +if (!buf)
> +/* If none of the requested size exists, use a bigger one. */
> +buf = next[1];
> +if (!buf && (buf = next[0])) {
> +/* If the pool also doesn't have a bigger buffer, but does
> + * have a smaller one, then replace it with a new buffer of
> + * the requested size. */
> +av_tree_insert(&pool->root, buf, cmp_insert, &buf->node);
> +buf->free(buf->opaque, buf->data);
> +av_free(buf->node);
> +av_freep(&buf);
> +}
> +
> +if (buf) {
> +ret = av_buffer_create(buf->data, buf->size, pool_release_dyn_buffer,
> +   buf, 0);
> +if (ret) {
> + 

Re: [FFmpeg-devel] [RFC] Exporting virtual timelines as stream side data

2018-03-28 Thread wm4
On Tue, 27 Mar 2018 20:44:00 +0100
Derek Buitenhuis  wrote:

> So, I know we have edit list "support" in mov.c, but I am steadfast in my
> belief that it is incorrect to implement it at the demuxing layer. By the
> ISOBMFF spec, it is supposed to be applied at the presenattion layer. I'm
> aware we probably cannot remove the current implementation very easily
> (or at all?) because many will argue it is "removing a feature". Thus, for
> ISOBMFF and mov support, this will likely have to live under a movflag,
> I assume?
> 
> Anyway, this is my proposal for generic stream side data for virtual 
> timelines.
> This is also meant to cover Matroska ordered chapters and editions, though I
> am not entirely sure how segment linking would work into this, if I am honest.
> 
> If/once I have the side data structs and API (in the following RFC patch) 
> agreed
> upon, I am willing to write:
> 
> * Support for exporting MOV/ISOBMFF edit lists via side data
> * Support for exporting Matroska edit lists via side data
> * Porting the fftools to use it (if wanted)
> 
> As a side note, I would appreciate input from someone who unerstands Matroska
> better than I do on this. I haven't included e.g. the Hidden/Enabled flags in
> AVtimelineEntry since they don't seem to actually be useful to the actual
> timeline (they seem to be mostly related to displaying chapter names or not).
> 
> The side data structs and API are based off of the recently pushed encryption
> side data changes. The media rate is a rational, because exporting a float
> would change on different platforms, and would make adding regression tests
> problematic.
> 
> So, everyone, rev up your diesel powered bikesheds and drive them full steam
> into this thread's back yard, over my daffodils.
> 
> Derek Buitenhuis (1):
>   avcodec/avutil: Add timeline side data
> 
>  libavcodec/avcodec.h |   8 +++
>  libavutil/timeline.h | 160 
> +++
>  2 files changed, 168 insertions(+)
>  create mode 100644 libavutil/timeline.h
> 

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


Re: [FFmpeg-devel] [PATCH] movtextenc: fix handling of utf-8 subtitles

2018-03-28 Thread Andrey Turkin
I think first check (ascii case) should be explicit bit-test, or (if there
is some reason to use sign-bit approach) at least "c" should be signed char
instead of simply char.

2018-03-28 6:07 GMT+03:00 Philip Langdale :

> See the earlier fix for movtextdec for details. The equivalent bug is
> present on the encoder side as well.
>
> We need to track the text length in 'characters' (which seems to really
> mean codepoints) to ensure that styles are applied across the correct
> ranges.
>
> Signed-off-by: Philip Langdale 
> ---
>  libavcodec/movtextenc.c | 24 +++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
> index d795e317c3..fd0743f752 100644
> --- a/libavcodec/movtextenc.c
> +++ b/libavcodec/movtextenc.c
> @@ -304,11 +304,33 @@ static void mov_text_color_cb(void *priv, unsigned
> int color, unsigned int color
>   */
>  }
>
> +static uint16_t utf8_strlen(const char *text, int len)
> +{
> +uint16_t i = 0, ret = 0;
> +while (i < len) {
> +char c = text[i];
> +if (c >= 0)
> +i += 1;
> +else if ((c & 0xE0) == 0xC0)
> +i += 2;
> +else if ((c & 0xF0) == 0xE0)
> +i += 3;
> +else if ((c & 0xF8) == 0xF0)
> +i += 4;
> +else
> +return 0;
> +ret++;
> +}
> +return ret;
> +}
> +
>  static void mov_text_text_cb(void *priv, const char *text, int len)
>  {
> +uint16_t utf8_len = utf8_strlen(text, len);
>  MovTextContext *s = priv;
>  av_bprint_append_data(&s->buffer, text, len);
> -s->text_pos += len;
> +// If it's not utf-8, just use the byte length
> +s->text_pos += utf8_len ? utf8_len : len;
>  }
>
>  static void mov_text_new_line_cb(void *priv, int forced)
> --
> 2.14.1
>
> ___
> 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] movtextenc: fix handling of utf-8 subtitles

2018-03-28 Thread wm4
On Wed, 28 Mar 2018 14:02:04 +0300
Andrey Turkin  wrote:

> I think first check (ascii case) should be explicit bit-test, or (if there
> is some reason to use sign-bit approach) at least "c" should be signed char
> instead of simply char.

Good point actually. It relies on char signedness, which is not
guaranteed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3] libavformat/dashdec: Support signaling of last segment number

2018-03-28 Thread Steven Liu
2018-03-27 22:34 GMT+08:00 Steven Liu :
>
>
>> On 27 Mar 2018, at 9:28 PM, sanilraut  wrote:
>>
>> Last segment indicated by mpd is not parsed.
>> Example stream: 
>> http://dash.akamaized.net/dash264/TestCasesIOP41/LastSegmentNumber/1/manifest_last_segment_num.mpd
>>
>> This patch supports parsing of Supplemental Descriptor with @schemeIdUri set 
>> to http://dashif.org/guide-
>> lines/last-segment-number with the @value set to the last segment number.
>>
>> ---
>> libavformat/dashdec.c | 26 +++---
>> 1 file changed, 23 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
>> index 7b79b93..8bfde4d 100644
>> --- a/libavformat/dashdec.c
>> +++ b/libavformat/dashdec.c
>> @@ -805,7 +805,8 @@ static int parse_manifest_representation(AVFormatContext 
>> *s, const char *url,
>>  xmlNodePtr fragment_template_node,
>>  xmlNodePtr content_component_node,
>>  xmlNodePtr adaptionset_baseurl_node,
>> - xmlNodePtr 
>> adaptionset_segmentlist_node)
>> + xmlNodePtr 
>> adaptionset_segmentlist_node,
>> + xmlNodePtr 
>> adaptionset_supplementalproperty_node)
>> {
>> int32_t ret = 0;
>> int32_t audio_rep_idx = 0;
>> @@ -825,6 +826,7 @@ static int parse_manifest_representation(AVFormatContext 
>> *s, const char *url,
>> char *timescale_val = NULL;
>> char *initialization_val = NULL;
>> char *media_val = NULL;
>> +char *val = NULL;
>> xmlNodePtr baseurl_nodes[4];
>> xmlNodePtr representation_node = node;
>> char *rep_id_val = xmlGetProp(representation_node, "id");
>> @@ -920,6 +922,17 @@ static int 
>> parse_manifest_representation(AVFormatContext *s, const char *url,
>> rep->first_seq_no = (int64_t) strtoll(startnumber_val, NULL, 
>> 10);
>> xmlFree(startnumber_val);
>> }
>> +if (adaptionset_supplementalproperty_node) {
>> +if 
>> (!av_strcasecmp(xmlGetProp(adaptionset_supplementalproperty_node,"schemeIdUri"),
>>  "http://dashif.org/guidelines/last-segment-number";)) {
>> +val = 
>> xmlGetProp(adaptionset_supplementalproperty_node,"value");
>> +if (!val) {
>> +av_log(s, AV_LOG_ERROR, "Missing value attribute in 
>> adaptionset_supplementalproperty_node\n");
>> +} else {
>> +rep->last_seq_no =(int64_t) strtoll(val, NULL, 10) 
>> - 1;
>> +xmlFree(val);
>> +}
>> + }
>> +}
>>
>> fragment_timeline_node = 
>> find_child_node_by_name(representation_segmenttemplate_node, 
>> "SegmentTimeline");
>>
>> @@ -1054,6 +1067,7 @@ static int 
>> parse_manifest_adaptationset(AVFormatContext *s, const char *url,
>> xmlNodePtr content_component_node = NULL;
>> xmlNodePtr adaptionset_baseurl_node = NULL;
>> xmlNodePtr adaptionset_segmentlist_node = NULL;
>> +xmlNodePtr adaptionset_supplementalproperty_node = NULL;
>> xmlNodePtr node = NULL;
>>
>> node = xmlFirstElementChild(adaptionset_node);
>> @@ -1066,6 +1080,8 @@ static int 
>> parse_manifest_adaptationset(AVFormatContext *s, const char *url,
>> adaptionset_baseurl_node = node;
>> } else if (!av_strcasecmp(node->name, (const char *)"SegmentList")) {
>> adaptionset_segmentlist_node = node;
>> +} else if (!av_strcasecmp(node->name, (const char 
>> *)"SupplementalProperty")) {
>> +adaptionset_supplementalproperty_node = node;
>> } else if (!av_strcasecmp(node->name, (const char 
>> *)"Representation")) {
>> ret = parse_manifest_representation(s, url, node,
>> adaptionset_node,
>> @@ -1076,7 +1092,8 @@ static int 
>> parse_manifest_adaptationset(AVFormatContext *s, const char *url,
>> fragment_template_node,
>> content_component_node,
>> adaptionset_baseurl_node,
>> -
>> adaptionset_segmentlist_node);
>> +
>> adaptionset_segmentlist_node,
>> +
>> adaptionset_supplementalproperty_node);
>> if (ret < 0) {
>> return ret;
>> }
>> @@ -1819,7 +1836,10 @@ static int open_demux_for_component(AVFormatContext 
>> *s, struct representation *p
>>
>> pls->parent = s;
>> pls->cur_seq_no  = calc_cur_seg_no(s, pls);
>> -pls->last_seq_no = calc_max_seg_no(pls, s->priv_data);
>> +
>> +if (!pls->last_seq_no) {
>> +pls->last_seq_no = calc

[FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) is retained during the encoding process

2018-03-28 Thread Alexander Kravchenko
Hello.
I fixed couple of issues in previous patch.
So if it is possible to use newer one, could you please review the following 
patch.


Subject: amfenc: Retain a reference to D3D frames used as input during the 
encoding process
---
libavcodec/amfenc.c | 91 +
 1 file changed, 91 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..4a8385f9e2 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -443,6 +443,75 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
+{ \
+AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
+res = from->pVtbl->QueryInterface(from, &guid_##InterfaceTypeTo, 
(void**)&to); \
+}
+
+#define AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val) \
+{ \
+AMFInterface *amf_interface; \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+if (res == AMF_OK) { \
+AMF_AV_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
+} \
+if (res == AMF_OK) { \
+res = AMFVariantAssignInterface(&var, amf_interface); \
+amf_interface->pVtbl->Release(amf_interface); \
+} \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->SetProperty(pThis, name, var); \
+} \
+AMFVariantClear(&var); \
+}
+
+#define AMF_AV_GET_PROPERTY_INTERFACE(res, pThis, name, TargetType, val) \
+{ \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+res = pThis->pVtbl->GetProperty(pThis, name, &var); \
+if (res == AMF_OK) { \
+if (var.type == AMF_VARIANT_INTERFACE && 
AMFVariantInterface(&var)) { \
+AMF_AV_QUERY_INTERFACE(res, AMFVariantInterface(&var), 
TargetType, val); \
+} else { \
+res = AMF_INVALID_DATA_TYPE; \
+} \
+} \
+AMFVariantClear(&var); \
+}
+
+static AMFBuffer* amf_create_buffer_with_frame_ref(const AVFrame* frame, 
AMFContext *context)
+{
+AVFrame *frame_ref;
+AMFBuffer *frame_ref_storage_buffer = NULL;
+AMF_RESULT res;
+
+res = context->pVtbl->AllocBuffer(context, AMF_MEMORY_HOST, 
sizeof(frame_ref), &frame_ref_storage_buffer);
+if (res == AMF_OK) {
+frame_ref = av_frame_clone(frame);
+if (frame_ref) {
+
memcpy(frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
&frame_ref, sizeof(frame_ref));
+} else {
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+frame_ref_storage_buffer = NULL;
+}
+}
+return frame_ref_storage_buffer;
+}
+
+static void amf_release_buffer_with_frame_ref(AMFBuffer 
*frame_ref_storage_buffer)
+{
+AVFrame *av_frame_ref;
+memcpy(&av_frame_ref, 
frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
sizeof(av_frame_ref));
+av_frame_free(&av_frame_ref);
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+} 
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -484,6 +553,7 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 (ctx->hw_device_ctx && 
((AVHWFramesContext*)frame->hw_frames_ctx->data)->device_ctx ==
 (AVHWDeviceContext*)ctx->hw_device_ctx->data)
 )) {
+AMFBuffer *frame_ref_storage_buffer;
 #if CONFIG_D3D11VA
 static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 
0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
 ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // 
actual texture
@@ -496,6 +566,16 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 // input HW surfaces can be vertically aligned by 16; tell AMF the 
real size
 surface->pVtbl->SetCrop(surface, 0, 0, frame->width, 
frame->height);
 #endif
+
+frame_ref_storage_buffer = amf_create_buffer_with_frame_ref(frame, 
ctx->context);
+AMF_RETURN_IF_FALSE(ctx, frame_ref_storage_buffer != NULL, 
AVERROR(ENOMEM), "create_buffer_with_frame_ref() returned NULL\n");
+
+AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, surface, L"av_frame_ref", 
frame_ref_storage_buffer);
+if (res != AMF_OK) {
+surface->pVtbl->Release(surface);
+}
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"SetProperty failed for \"av_frame_ref\" with error %d\n", res);
 } else {
 res = ctx->context->pVtbl->AllocSurface(ctx->context, 
AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
 AMF_RETURN_IF_FAL

[FFmpeg-devel] Soft Subtitles (DVB) size problem on direct convert MPEG-TS video

2018-03-28 Thread Eleftherios Antoniades
Hi,
Here is my case:

I have a MPEG-TS video file  with one video and one audio stream and i am
trying to create a direct video convert with adding a  DVBSUB stream inside
it. My original subs file is a stl file.

After many workarounds i finally managed to add the DVBSUB stream, after
converting the stl file into a sub file with idx. I used the idx, so i get
the palette information correct.

So the command i used is:

ffmpeg -i testvideo.ts -i subtitles.idx -map 0:v -map 0:a  -map 1 -c:v copy
-c:a copy -c:s:0 dvbsub -metadata:s:s:0 language=ell -streamid 2:151
output.ts

The video and subtitles size is 1920x1080, but the output.ts file comes out
with wrong subtitles size. It looks like the dvbsub codec converts the
dvbsubs stream in 720 size by default, rather 1080??

Is there a way to force the subs into the correct size?
Or, is there another way to achive that?

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


Re: [FFmpeg-devel] [PATCH] avutil/buffer: add a dynamic size buffer pool API

2018-03-28 Thread James Almer
On 3/28/2018 6:59 AM, wm4 wrote:
> On Tue, 27 Mar 2018 23:11:27 -0300
> James Almer  wrote:
> 
>> Signed-off-by: James Almer 
>> ---
>> Implemented as a completely separate API as suggested. Missing
>> Changelog, APIChanges and version bump as usual.
>>
>>  libavutil/buffer.c  | 159 
>> 
>>  libavutil/buffer.h  |  53 +++
>>  libavutil/buffer_internal.h |  14 
>>  3 files changed, 226 insertions(+)
>>
>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>> index 8d1aa5fa84..c39a14c3c7 100644
>> --- a/libavutil/buffer.c
>> +++ b/libavutil/buffer.c
>> @@ -24,6 +24,7 @@
>>  #include "common.h"
>>  #include "mem.h"
>>  #include "thread.h"
>> +#include "tree.h"
>>  
>>  AVBufferRef *av_buffer_create(uint8_t *data, int size,
>>void (*free)(void *opaque, uint8_t *data),
>> @@ -355,3 +356,161 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
>>  
>>  return ret;
>>  }
>> +
>> +AVBufferDynPool *av_buffer_dyn_pool_init(AVBufferRef* (*alloc)(int size))
>> +{
>> +AVBufferDynPool *pool = av_mallocz(sizeof(*pool));
>> +if (!pool)
>> +return NULL;
>> +
>> +ff_mutex_init(&pool->mutex, NULL);
>> +
>> +pool->alloc = alloc ? alloc : av_buffer_alloc;
>> +
>> +atomic_init(&pool->refcount, 1);
>> +
>> +return pool;
>> +}
>> +
>> +static int free_node(void *opaque, void *elem)
>> +{
>> +BufferPoolEntry *buf = elem;
>> +
>> +buf->free(buf->opaque, buf->data);
>> +av_free(buf);
>> +
>> +return 0;
>> +}
>> +
>> +static void buffer_dyn_pool_free(AVBufferDynPool *pool)
>> +{
>> +av_tree_enumerate(pool->root, NULL, NULL, free_node);
>> +av_tree_destroy(pool->root);
>> +
>> +ff_mutex_destroy(&pool->mutex);
>> +
>> +av_freep(&pool);
>> +}
>> +
>> +void av_buffer_dyn_pool_uninit(AVBufferDynPool **ppool)
>> +{
>> +AVBufferDynPool *pool;
>> +
>> +if (!ppool || !*ppool)
>> +return;
>> +pool   = *ppool;
>> +*ppool = NULL;
>> +
>> +if (atomic_fetch_add_explicit(&pool->refcount, -1, 
>> memory_order_acq_rel) == 1)
>> +buffer_dyn_pool_free(pool);
>> +}
>> +
>> +static int cmp_insert(const void *key, const void *node)
>> +{
>> +int ret = ((const BufferPoolEntry *) key)->size - ((const 
>> BufferPoolEntry *) node)->size;
>> +
>> +if (!ret)
>> +ret = ((const BufferPoolEntry *) key)->data - ((const 
>> BufferPoolEntry *) node)->data;
>> +return ret;
>> +}
>> +
>> +static void pool_release_dyn_buffer(void *opaque, uint8_t *data)
>> +{
>> +BufferPoolEntry *buf = opaque;
>> +AVBufferDynPool *pool = buf->dynpool;
>> +
>> +if(CONFIG_MEMORY_POISONING)
>> +memset(buf->data, FF_MEMORY_POISON, buf->size);
>> +
>> +ff_mutex_lock(&pool->mutex);
>> +/* Add the buffer into the pool, using the preallocated
>> + * AVTreeNode stored in buf->node */
>> +av_tree_insert(&pool->root, buf, cmp_insert, &buf->node);
>> +ff_mutex_unlock(&pool->mutex);
>> +
>> +if (atomic_fetch_add_explicit(&pool->refcount, -1, 
>> memory_order_acq_rel) == 1)
>> +buffer_dyn_pool_free(pool);
>> +}
>> +
>> +static AVBufferRef *pool_alloc_dyn_buffer(AVBufferDynPool *pool, int size)
>> +{
>> +BufferPoolEntry *buf;
>> +AVBufferRef *ret;
>> +
>> +ret = pool->alloc(size);
>> +if (!ret)
>> +return NULL;
>> +
>> +buf = av_mallocz(sizeof(*buf));
>> +if (!buf) {
>> +av_buffer_unref(&ret);
>> +return NULL;
>> +}
>> +
>> +buf->node = av_tree_node_alloc();
>> +if (!buf->node) {
>> +av_free(buf);
>> +av_buffer_unref(&ret);
>> +return NULL;
>> +}
>> +
>> +buf->data= ret->buffer->data;
>> +buf->opaque  = ret->buffer->opaque;
>> +buf->free= ret->buffer->free;
>> +buf->size= size;
>> +buf->dynpool = pool;
>> +
>> +ret->buffer->opaque = buf;
>> +ret->buffer->free   = pool_release_dyn_buffer;
>> +
>> +return ret;
>> +}
>> +
>> +static int cmp_find(const void *key, const void *node)
>> +{
>> +return *(const int *)key - ((const BufferPoolEntry *) node)->size;
>> +}
>> +
>> +AVBufferRef *av_buffer_dyn_pool_get(AVBufferDynPool *pool, int size)
>> +{
>> +AVBufferRef *ret;
>> +BufferPoolEntry *buf, *next[2] = { NULL, NULL };
>> +
>> +ff_mutex_lock(&pool->mutex);
>> +/* Find a big enough buffer in the pool. */
>> +buf = av_tree_find(pool->root, &size, cmp_find, (void **)next);
>> +
>> +if (!buf)
>> +/* If none of the requested size exists, use a bigger one. */
>> +buf = next[1];
>> +if (!buf && (buf = next[0])) {
>> +/* If the pool also doesn't have a bigger buffer, but does
>> + * have a smaller one, then replace it with a new buffer of
>> + * the requested size. */
>> +av_tree_insert(&pool->root, buf, cmp_insert, &buf->node);
>> +buf->free(buf->opaque, buf->data);
>> +av_free(buf->node);
>> +av

[FFmpeg-devel] [PATCH v3 1/3] avutil/log: rename and initialize global log flags variable

2018-03-28 Thread Tobias Rapp
Rename global variable for symmetry with av_log_level.

Signed-off-by: Tobias Rapp 
---
 libavutil/log.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavutil/log.c b/libavutil/log.c
index 9b7d484..0a99d01 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -52,7 +52,7 @@ static AVMutex mutex = AV_MUTEX_INITIALIZER;
 #endif
 
 static int av_log_level = AV_LOG_INFO;
-static int flags;
+static int av_log_flags = 0;
 
 #define NB_LEVELS 8
 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE
@@ -268,7 +268,7 @@ static void format_line(void *avcl, int level, const char 
*fmt, va_list vl,
 if(type) type[1] = get_category(avcl);
 }
 
-if (*print_prefix && (level > AV_LOG_QUIET) && (flags & 
AV_LOG_PRINT_LEVEL))
+if (*print_prefix && (level > AV_LOG_QUIET) && (av_log_flags & 
AV_LOG_PRINT_LEVEL))
 av_bprintf(part+2, "[%s] ", get_level_str(level));
 
 av_vbprintf(part+3, fmt, vl);
@@ -325,7 +325,7 @@ void av_log_default_callback(void* ptr, int level, const 
char* fmt, va_list vl)
 is_atty = isatty(2) ? 1 : -1;
 #endif
 
-if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) 
&&
+if (print_prefix && (av_log_flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, 
prev) &&
 *line && line[strlen(line) - 1] != '\r'){
 count++;
 if (is_atty == 1)
@@ -389,12 +389,12 @@ void av_log_set_level(int level)
 
 void av_log_set_flags(int arg)
 {
-flags = arg;
+av_log_flags = arg;
 }
 
 int av_log_get_flags(void)
 {
-return flags;
+return av_log_flags;
 }
 
 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
-- 
2.7.4


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


[FFmpeg-devel] [PATCH v3 2/3] avutil/log: add av_log_set_opts function

2018-03-28 Thread Tobias Rapp
Allows to set log level and flag values from string.

Signed-off-by: Tobias Rapp 
---
 doc/APIchanges  |  3 +++
 libavutil/log.c | 76 +
 libavutil/log.h | 16 +++
 libavutil/version.h |  2 +-
 4 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 83c7a40..2d14452 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-03-xx - xxx - lavu 56.13.100 - log.h
+  Add av_log_set_opts().
+
 2018-03-xx - xxx - lavc 58.16.100 - avcodec.h
   Add FF_SUB_CHARENC_MODE_IGNORE.
 
diff --git a/libavutil/log.c b/libavutil/log.c
index 0a99d01..af32cd6 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -34,6 +34,7 @@
 #endif
 #include 
 #include 
+#include "avassert.h"
 #include "avutil.h"
 #include "bprint.h"
 #include "common.h"
@@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, 
const char*, va_list))
 av_log_callback = callback;
 }
 
+int av_log_set_opts(const char *arg)
+{
+const struct { const char *name; int level; } log_levels[] = {
+{ "quiet"  , AV_LOG_QUIET   },
+{ "panic"  , AV_LOG_PANIC   },
+{ "fatal"  , AV_LOG_FATAL   },
+{ "error"  , AV_LOG_ERROR   },
+{ "warning", AV_LOG_WARNING },
+{ "info"   , AV_LOG_INFO},
+{ "verbose", AV_LOG_VERBOSE },
+{ "debug"  , AV_LOG_DEBUG   },
+{ "trace"  , AV_LOG_TRACE   },
+};
+const char *token;
+char *tail;
+int flags = av_log_get_flags();
+int level = av_log_get_level();
+int cmd, i = 0;
+
+av_assert0(arg);
+while (*arg) {
+token = arg;
+if (*token == '+' || *token == '-') {
+cmd = *token++;
+} else {
+cmd = 0;
+}
+if (!i && !cmd) {
+flags = 0;  /* missing relative prefix, build absolute value */
+}
+if (!strncmp(token, "repeat", 6)) {
+if (cmd == '-') {
+flags |= AV_LOG_SKIP_REPEATED;
+} else {
+flags &= ~AV_LOG_SKIP_REPEATED;
+}
+arg = token + 6;
+} else if (!strncmp(token, "level", 5)) {
+if (cmd == '-') {
+flags &= ~AV_LOG_PRINT_LEVEL;
+} else {
+flags |= AV_LOG_PRINT_LEVEL;
+}
+arg = token + 5;
+} else {
+break;
+}
+i++;
+}
+if (!*arg) {
+goto end;
+} else if (*arg == '+') {
+arg++;
+} else if (!i) {
+flags = av_log_get_flags();  /* level value without prefix, reset 
flags */
+}
+
+for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
+if (!strcmp(arg, log_levels[i].name)) {
+level = log_levels[i].level;
+goto end;
+}
+}
+
+level = strtol(arg, &tail, 10);
+if (*tail) {
+return -1;
+}
+
+end:
+av_log_set_flags(flags);
+av_log_set_level(level);
+return 0;
+}
+
 static void missing_feature_sample(int sample, void *avc, const char *msg,
va_list argument_list)
 {
diff --git a/libavutil/log.h b/libavutil/log.h
index d9554e6..97010f7 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -356,6 +356,22 @@ void av_log_set_flags(int arg);
 int av_log_get_flags(void);
 
 /**
+ * Set log flags and level as an option string. Accepts "repeat" and "level"
+ * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL,
+ * followed by the log level specified either by name ("warning", "info",
+ * "verbose", etc.) or by number.
+ *
+ * When flags are prefixed with "+" or "-" the change is relative to the
+ * current flags value. When both flags and level are present a "+" separator
+ * is expected between last flag and before level.
+ *
+ * @param  arg  log option string
+ * @return Returns a negative value if parsing the option string failed,
+ * otherwise returns 0.
+ */
+int av_log_set_opts(const char *arg);
+
+/**
  * @}
  */
 
diff --git a/libavutil/version.h b/libavutil/version.h
index d3dd2df..296c24b 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  12
+#define LIBAVUTIL_VERSION_MINOR  13
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.7.4


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


[FFmpeg-devel] [PATCH v3 3/3] fftools/cmdutils: replace loglevel option parsing with av_log_set_opts

2018-03-28 Thread Tobias Rapp
Signed-off-by: Tobias Rapp 
---
 fftools/cmdutils.c | 48 +++-
 1 file changed, 7 insertions(+), 41 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index c0ddf0b..2a0a995 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -870,51 +870,17 @@ int opt_cpuflags(void *optctx, const char *opt, const 
char *arg)
 
 int opt_loglevel(void *optctx, const char *opt, const char *arg)
 {
-const struct { const char *name; int level; } log_levels[] = {
-{ "quiet"  , AV_LOG_QUIET   },
-{ "panic"  , AV_LOG_PANIC   },
-{ "fatal"  , AV_LOG_FATAL   },
-{ "error"  , AV_LOG_ERROR   },
-{ "warning", AV_LOG_WARNING },
-{ "info"   , AV_LOG_INFO},
-{ "verbose", AV_LOG_VERBOSE },
-{ "debug"  , AV_LOG_DEBUG   },
-{ "trace"  , AV_LOG_TRACE   },
-};
-char *tail;
-int level;
-int flags;
-int i;
-
-flags = av_log_get_flags();
-tail = strstr(arg, "repeat");
-if (tail)
-flags &= ~AV_LOG_SKIP_REPEATED;
-else
-flags |= AV_LOG_SKIP_REPEATED;
-
-av_log_set_flags(flags);
-if (tail == arg)
-arg += 6 + (arg[6]=='+');
-if(tail && !*arg)
-return 0;
-
-for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
-if (!strcmp(log_levels[i].name, arg)) {
-av_log_set_level(log_levels[i].level);
-return 0;
-}
-}
+int ret;
 
-level = strtol(arg, &tail, 10);
-if (*tail) {
+ret = av_log_set_opts(arg);
+if (ret < 0) {
 av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
-   "Possible levels are numbers or:\n", arg);
-for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
-av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
+   "Possible levels are numbers or:\n"
+   "\"quiet\", \"panic\", \"fatal\", \"error\", \"warning\", "
+   "\"info\", \"verbose\", \"debug\", \"trace\"\n"
+   "optionally prefixed by \"repeat\" or \"level\" flags\n", arg);
 exit_program(1);
 }
-av_log_set_level(level);
 return 0;
 }
 
-- 
2.7.4


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


Re: [FFmpeg-devel] [PATCH v3 2/3] avutil/log: add av_log_set_opts function

2018-03-28 Thread wm4
On Wed, 28 Mar 2018 17:03:39 +0200
Tobias Rapp  wrote:

> Allows to set log level and flag values from string.
> 
> Signed-off-by: Tobias Rapp 
> ---
>  doc/APIchanges  |  3 +++
>  libavutil/log.c | 76 
> +
>  libavutil/log.h | 16 +++
>  libavutil/version.h |  2 +-
>  4 files changed, 96 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 83c7a40..2d14452 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2018-03-xx - xxx - lavu 56.13.100 - log.h
> +  Add av_log_set_opts().
> +
>  2018-03-xx - xxx - lavc 58.16.100 - avcodec.h
>Add FF_SUB_CHARENC_MODE_IGNORE.
>  
> diff --git a/libavutil/log.c b/libavutil/log.c
> index 0a99d01..af32cd6 100644
> --- a/libavutil/log.c
> +++ b/libavutil/log.c
> @@ -34,6 +34,7 @@
>  #endif
>  #include 
>  #include 
> +#include "avassert.h"
>  #include "avutil.h"
>  #include "bprint.h"
>  #include "common.h"
> @@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, 
> const char*, va_list))
>  av_log_callback = callback;
>  }
>  
> +int av_log_set_opts(const char *arg)
> +{
> +const struct { const char *name; int level; } log_levels[] = {
> +{ "quiet"  , AV_LOG_QUIET   },
> +{ "panic"  , AV_LOG_PANIC   },
> +{ "fatal"  , AV_LOG_FATAL   },
> +{ "error"  , AV_LOG_ERROR   },
> +{ "warning", AV_LOG_WARNING },
> +{ "info"   , AV_LOG_INFO},
> +{ "verbose", AV_LOG_VERBOSE },
> +{ "debug"  , AV_LOG_DEBUG   },
> +{ "trace"  , AV_LOG_TRACE   },
> +};
> +const char *token;
> +char *tail;
> +int flags = av_log_get_flags();
> +int level = av_log_get_level();
> +int cmd, i = 0;
> +
> +av_assert0(arg);
> +while (*arg) {
> +token = arg;
> +if (*token == '+' || *token == '-') {
> +cmd = *token++;
> +} else {
> +cmd = 0;
> +}
> +if (!i && !cmd) {
> +flags = 0;  /* missing relative prefix, build absolute value */
> +}
> +if (!strncmp(token, "repeat", 6)) {
> +if (cmd == '-') {
> +flags |= AV_LOG_SKIP_REPEATED;
> +} else {
> +flags &= ~AV_LOG_SKIP_REPEATED;
> +}
> +arg = token + 6;
> +} else if (!strncmp(token, "level", 5)) {
> +if (cmd == '-') {
> +flags &= ~AV_LOG_PRINT_LEVEL;
> +} else {
> +flags |= AV_LOG_PRINT_LEVEL;
> +}
> +arg = token + 5;
> +} else {
> +break;
> +}
> +i++;
> +}
> +if (!*arg) {
> +goto end;
> +} else if (*arg == '+') {
> +arg++;
> +} else if (!i) {
> +flags = av_log_get_flags();  /* level value without prefix, reset 
> flags */
> +}
> +
> +for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
> +if (!strcmp(arg, log_levels[i].name)) {
> +level = log_levels[i].level;
> +goto end;
> +}
> +}
> +
> +level = strtol(arg, &tail, 10);
> +if (*tail) {
> +return -1;
> +}
> +
> +end:
> +av_log_set_flags(flags);
> +av_log_set_level(level);
> +return 0;
> +}
> +
>  static void missing_feature_sample(int sample, void *avc, const char *msg,
> va_list argument_list)
>  {
> diff --git a/libavutil/log.h b/libavutil/log.h
> index d9554e6..97010f7 100644
> --- a/libavutil/log.h
> +++ b/libavutil/log.h
> @@ -356,6 +356,22 @@ void av_log_set_flags(int arg);
>  int av_log_get_flags(void);
>  
>  /**
> + * Set log flags and level as an option string. Accepts "repeat" and "level"
> + * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL,
> + * followed by the log level specified either by name ("warning", "info",
> + * "verbose", etc.) or by number.
> + *
> + * When flags are prefixed with "+" or "-" the change is relative to the
> + * current flags value. When both flags and level are present a "+" separator
> + * is expected between last flag and before level.
> + *
> + * @param  arg  log option string
> + * @return Returns a negative value if parsing the option string failed,
> + * otherwise returns 0.
> + */
> +int av_log_set_opts(const char *arg);
> +
> +/**
>   * @}
>   */
>  
> diff --git a/libavutil/version.h b/libavutil/version.h
> index d3dd2df..296c24b 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  56
> -#define LIBAVUTIL_VERSION_MINOR  12
> +#define LIBAVUTIL_VERSION_MINOR  13
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Seems like a step backwards. Why can't it stay in the fftools thing?
___

[FFmpeg-devel] [PATCH] movtextenc: fix handling of utf-8 subtitles

2018-03-28 Thread Philip Langdale
See the earlier fix for movtextdec for details. The equivalent bug is
present on the encoder side as well.

We need to track the text length in 'characters' (which seems to really
mean codepoints) to ensure that styles are applied across the correct
ranges.

Signed-off-by: Philip Langdale 
---
 libavcodec/movtextenc.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
index d795e317c3..e1d2ae446c 100644
--- a/libavcodec/movtextenc.c
+++ b/libavcodec/movtextenc.c
@@ -304,11 +304,33 @@ static void mov_text_color_cb(void *priv, unsigned int 
color, unsigned int color
  */
 }
 
+static uint16_t utf8_strlen(const char *text, int len)
+{
+uint16_t i = 0, ret = 0;
+while (i < len) {
+char c = text[i];
+if ((c & 0x80) == 0)
+i += 1;
+else if ((c & 0xE0) == 0xC0)
+i += 2;
+else if ((c & 0xF0) == 0xE0)
+i += 3;
+else if ((c & 0xF8) == 0xF0)
+i += 4;
+else
+return 0;
+ret++;
+}
+return ret;
+}
+
 static void mov_text_text_cb(void *priv, const char *text, int len)
 {
+uint16_t utf8_len = utf8_strlen(text, len);
 MovTextContext *s = priv;
 av_bprint_append_data(&s->buffer, text, len);
-s->text_pos += len;
+// If it's not utf-8, just use the byte length
+s->text_pos += utf8_len ? utf8_len : len;
 }
 
 static void mov_text_new_line_cb(void *priv, int forced)
-- 
2.14.1

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


Re: [FFmpeg-devel] [PATCH] movtextenc: fix handling of utf-8 subtitles

2018-03-28 Thread Philip Langdale
On Wed, 28 Mar 2018 12:01:47 +0200
wm4  wrote:

> 
> LGTM.
> 
> Maybe a later patch that adds the UTF-8 length as lavu function (or
> macro for SPEEED?) eould be nice, since we seem to need that often.

I can do that.

Although, I'm not sure the SPEEED version is readable enough to justify
using it. :-)

http://www.daemonology.net/blog/2008-06-05-faster-utf8-strlen.html

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


Re: [FFmpeg-devel] [PATCH] movtextenc: fix handling of utf-8 subtitles

2018-03-28 Thread Philip Langdale
On Wed, 28 Mar 2018 13:14:57 +0200
wm4  wrote:

> On Wed, 28 Mar 2018 14:02:04 +0300
> Andrey Turkin  wrote:
> 
> > I think first check (ascii case) should be explicit bit-test, or
> > (if there is some reason to use sign-bit approach) at least "c"
> > should be signed char instead of simply char.  
> 
> Good point actually. It relies on char signedness, which is not
> guaranteed.

Fair point. I'm updating it.

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


[FFmpeg-devel] Writing iTunes cover images to mp4 files

2018-03-28 Thread Timo Teras
Hi ffmpeg-devel,

I am looking into and happy to write the code to write iTunes cover
images to mp4 files.

It seems there's a bug tracking this at:
https://trac.ffmpeg.org/ticket/2798

And apparently there was already patches posted some years ago. The
best patch around seems to be:
https://ffmpeg.org/pipermail/ffmpeg-devel/2013-July/146604.html

I would be happy to rebase / fix the above mentioned patch if the
approach looks good. Otherwise, suggestions on what approach to take
would be appreciated.

Thanks,
Timo

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


[FFmpeg-devel] [PATCH 1/1] avformat/movenc: use modern iTunes copyright atom

2018-03-28 Thread Timo Teräs
iTunes currently uses the 'cprt' atom to store the copyright notice
and this patch fixes compatibility with majority of software that
supports the 'ilst' atom. Other software and documentation using this:
 - AtomicParseley encodes and parses only 'cprt'
 - Most players recognize only 'cprt'
 - https://sno.phy.queensu.ca/~phil/exiftool/TagNames/QuickTime.html
   documents both tag types
 - http://mutagen.readthedocs.io/en/latest/api/mp4.html documents
   only 'cprt'

ffmpeg mov reader properly parses the 'cprt' tag inside 'ilst' tag
and functions correctly with streams produced with this commit.

Since 'cprt' seems to be the current correct atom, it is used by
default. "-movflags legacy_copyright" option is added to revert
back to the old atom type in case that is needed.

Signed-off-by: Timo Teräs 
---
If the legacy option is not needed, I'm happy to resend patch just
changing the atom types.

 libavformat/movenc.c | 6 +-
 libavformat/movenc.h | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index ef668eccd5..230aeb6a6d 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -79,6 +79,7 @@ static const AVOption options[] = {
 { "use_metadata_tags", "Use mdta atom for metadata.", 0, 
AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_USE_MDTA}, INT_MIN, INT_MAX, 
AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
 { "skip_trailer", "Skip writing the mfra/tfra/mfro trailer for fragmented 
files", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SKIP_TRAILER}, INT_MIN, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
 { "negative_cts_offsets", "Use negative CTS offsets (reducing the need for 
edit lists)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS}, 
INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+{ "legacy_copyright", "Use legacy iTunes (c)cpy copyright atom inside 
ilst", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_LEGACY_ILTS_CPRT}, INT_MIN, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
 FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
 { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, 
iods_skip), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
 { "iods_audio_profile", "iods audio profile atom.", 
offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
255, AV_OPT_FLAG_ENCODING_PARAM},
@@ -3432,7 +3433,10 @@ static int mov_write_ilst_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 }
 mov_write_string_metadata(s, pb, "\251cmt", "comment"  , 1);
 mov_write_string_metadata(s, pb, "\251gen", "genre", 1);
-mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1);
+if (mov->flags & FF_MOV_FLAG_LEGACY_ILTS_CPRT)
+  mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1);
+else
+  mov_write_string_metadata(s, pb, "cprt", "copyright", 1);
 mov_write_string_metadata(s, pb, "\251grp", "grouping" , 1);
 mov_write_string_metadata(s, pb, "\251lyr", "lyrics"   , 1);
 mov_write_string_metadata(s, pb, "desc","description",1);
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index ca2a9c9722..e83a29aea2 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -246,6 +246,7 @@ typedef struct MOVMuxContext {
 #define FF_MOV_FLAG_SKIP_TRAILER  (1 << 18)
 #define FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS  (1 << 19)
 #define FF_MOV_FLAG_FRAG_EVERY_FRAME  (1 << 20)
+#define FF_MOV_FLAG_LEGACY_ILTS_CPRT  (1 << 21)
 
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
 
-- 
2.16.2

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


Re: [FFmpeg-devel] [RFC] Exporting virtual timelines as stream side data

2018-03-28 Thread Dave Rice

> On Mar 27, 2018, at 5:16 PM, wm4  wrote:
> 
> On Tue, 27 Mar 2018 16:45:23 -0400
> Dave Rice mailto:d...@dericed.com>> wrote:
> 
>>> On Mar 27, 2018, at 4:33 PM, wm4  wrote:
>>> 
>>> On Tue, 27 Mar 2018 16:11:11 -0400
>>> Dave Rice  wrote:
>>> 
> On Mar 27, 2018, at 4:01 PM, Derek Buitenhuis 
>  wrote:
> 
> On 3/27/2018 8:52 PM, Rostislav Pehlivanov wrote:
>> I think we should drop the internal crap if the tools and the API support
>> it. Would also solve a lot of issues like ffmpeg.c not trimming the start
>> frame (so people complain all the time about longer files).
> 
> I personally agree, but I thought I'd be diplomatic about it, since it 
> would
> technically be losing a 'feature', since it would no longer Just Work(ish)
> and require user applications to apply timelines themselves - and I 
> figured
> some would argue that point.
 
 +1 I’m willing to contribute what information or samples would be needed 
 to help with Matroska support with virtual timelines. IMO, this would be a 
 valuable feature to have in ffmpeg.
 Dave Rice  
>>> 
>>> Some explanations how this interacts with editions would be good.  
>> 
>> I put an example with two editions at 
>> https://archive.org/download/chapters_test/chapters_test.mkv which mimics a 
>> digitized video 
> 
> Also this file lacks a chapter end time in the second edition. How is
> that valid?

You’re right. I moved this discussion to cellar, but when the Edition is 
Ordered then ChapterTimeEnd is required.
Dave Rice

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


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Michael Niedermayer
On Tue, Mar 27, 2018 at 08:44:01PM +0100, Derek Buitenhuis wrote:
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavcodec/avcodec.h |   8 +++
>  libavutil/timeline.h | 160 
> +++
>  2 files changed, 168 insertions(+)
>  create mode 100644 libavutil/timeline.h
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 50c34db..6f54495 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -1358,6 +1358,14 @@ enum AVPacketSideDataType {
>  AV_PKT_DATA_ENCRYPTION_INFO,
>  
>  /**
> + * This side data contains timeline entries for a given stream. This type
> + * will only apear as stream side data.
> + *
> + * The format is not part of the ABI, use av_timeline_* method to access.
> + */
> +AV_PKT_DATA_TIMELINE,
> +
> +/**
>   * The number of side data types.
>   * This is not part of the public API/ABI in the sense that it may
>   * change when new side data types are added.
> diff --git a/libavutil/timeline.h b/libavutil/timeline.h
> new file mode 100644
> index 000..f1f3e1b
> --- /dev/null
> +++ b/libavutil/timeline.h
> @@ -0,0 +1,160 @@
> +/*
> + * Copyright (C) 2018 Derek Buitenhuis
> + *
> + * 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
> + */
> +
> +#ifndef AVUTIL_TIMELINE_H
> +#define AVUTIL_TIMELINE_H
> +
> +#include 
> +#include 
> +
> +#include "rational.h"
> +
> +typedef struct AVTimelineEntry {
> +/**
> + * The start time of the given timeline entry, in stream timebase units.
> + * If this value is AV_NOPTS_VALUE, you must display black for the 
> duration
> + * of the entry. For audio, silence must be played.
> + */
> +int64_t start;
> +
> +/**
> + * The duration of the given timeline entry, in steam timebase units.
> + */
> +int64_t duration;
> +
> +/**
> + * The rate at which this entry should be played back. The value is a 
> multipier
> + * of the stream's rate, for example: 1.2 means play back this entry at 
> 1.2x speed.
> + * If this value is 0, then the first sample (located at 'start') must 
> be displayed
> + * for the duration of the entry.
> + */
> +AVRational media_rate;
> +} AVTimelineEntry;
> +
> +/**
> + * Describes a timeline for a stream in terms of edits/entries. Each entry 
> must be
> + * played back in order, according to the information in each. Each stream 
> may have
> + * multiple timelines which need to be correlated between different streams.
> + */
> +typedef struct AVTimeline {
> +/**
> + * The ID of a given timeline. Since each stream may have multiple 
> timelines
> + * defined, this value is used to correlated different streams' timelines
> + * which should be used together. For example, if one has two streams,
> + * one video, and one audio, with two timelines each, the timelines
> + * with matching IDs should be used in conjuction, to assure everything
> + * is in sync and matches. The concept is similar to that of EditionUID
> + * in Matroska.
> + */
> +uint32_t id;
> +
> +/**
> + * An in-order array of entries for the given timeline.
> + * Each entry contains information on which samples to display for a
> + * particular edit.
> + */
> +AVTimelineEntry *entries;

This is problematic as its non extensible. (unless iam missing something)
Consider that a field is added to AVTimelineEntry, the entries array would
have a larger element size and that would require all user apps to be rebuild

Also, if you want to support quicktime more fully theres more needed.
QT can for example switch even between codecs mid stream IIRC
not sure we want to support this

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Jan Ekström
On Wed, Mar 28, 2018 at 9:12 PM, Michael Niedermayer
 wrote:
>> +/**
>> + * An in-order array of entries for the given timeline.
>> + * Each entry contains information on which samples to display for a
>> + * particular edit.
>> + */
>> +AVTimelineEntry *entries;
>
> This is problematic as its non extensible. (unless iam missing something)
> Consider that a field is added to AVTimelineEntry, the entries array would
> have a larger element size and that would require all user apps to be rebuild
>

So you would prefer some sort of iterator? Or a size entry like with
some of the entries in AVEncryptionInfo? I have a feeling this was
based off of the following added into AVEncryptionInfo:
+AVSubsampleEncryptionInfo *subsamples;
+uint32_t subsample_count;

Which now would seem to be similarly not being extendable?

> Also, if you want to support quicktime more fully theres more needed.
> QT can for example switch even between codecs mid stream IIRC
> not sure we want to support this
>

Thankfully, that has little to do with virtual timelines (edit lists)
as far as I can tell?

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


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Derek Buitenhuis
On 3/28/2018 7:12 PM, Michael Niedermayer wrote:
> This is problematic as its non extensible. (unless iam missing something)
> Consider that a field is added to AVTimelineEntry, the entries array would
> have a larger element size and that would require all user apps to be rebuild

Do you have an actual suggest though? Afaict, this is exactly how the recently
pushed encryption support works with AVSubsampleEncryptionInfo entries in the
AVEncryptionInfo struct. is this now not acceptable, even though we pushed
that a few days ago after months of review?

I'm all ears to a solution...

> 
> Also, if you want to support quicktime more fully theres more needed.
> QT can for example switch even between codecs mid stream IIRC
> not sure we want to support this

Codec switching is not related to timelines at all. It's entirely separate...

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


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Nicolas George
Derek Buitenhuis (2018-03-28):
> Do you have an actual suggest though?

Maybe not using a badly designed API that requires everything to be
stored in a serialized uint8_t array.

>   Afaict, this is exactly how the recently
> pushed encryption support works with AVSubsampleEncryptionInfo entries in the
> AVEncryptionInfo struct. is this now not acceptable, even though we pushed
> that a few days ago after months of review?

It just means that these months of review failed to see that flaw. Let
us hope we will not need to extend AVSubsampleEncryptionInfo.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread wm4
On Wed, 28 Mar 2018 19:42:21 +0100
Derek Buitenhuis  wrote:

> On 3/28/2018 7:12 PM, Michael Niedermayer wrote:
> > This is problematic as its non extensible. (unless iam missing something)
> > Consider that a field is added to AVTimelineEntry, the entries array would
> > have a larger element size and that would require all user apps to be 
> > rebuild  
> 
> Do you have an actual suggest though? Afaict, this is exactly how the recently
> pushed encryption support works with AVSubsampleEncryptionInfo entries in the
> AVEncryptionInfo struct. is this now not acceptable, even though we pushed
> that a few days ago after months of review?
> 
> I'm all ears to a solution...

You just need to change * to **. Then the size of the struct doesn't
matter anymore for array access and can be excluded from the ABI.

> > 
> > Also, if you want to support quicktime more fully theres more needed.
> > QT can for example switch even between codecs mid stream IIRC
> > not sure we want to support this  
> 
> Codec switching is not related to timelines at all. It's entirely separate...
> 
> - Derek
> ___
> 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][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Derek Buitenhuis
On 3/28/2018 7:47 PM, Nicolas George wrote:
> Derek Buitenhuis (2018-03-28):
>> Do you have an actual suggest though?
> 
> Maybe not using a badly designed API that requires everything to be
> stored in a serialized uint8_t array.

Isn't this the same as saying "don't use the existing side data APIs at all"?

Do you expect me to design a whole new side data API first? 

>>  Afaict, this is exactly how the recently
>> pushed encryption support works with AVSubsampleEncryptionInfo entries in the
>> AVEncryptionInfo struct. is this now not acceptable, even though we pushed
>> that a few days ago after months of review?
> 
> It just means that these months of review failed to see that flaw. Let
> us hope we will not need to extend AVSubsampleEncryptionInfo.

I guess the only consistent thing about FFmpeg APIs is that they are
inconsistent.

I am still open to a different propose solution.

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


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Derek Buitenhuis
On 3/28/2018 7:49 PM, wm4 wrote:
> You just need to change * to **. Then the size of the struct doesn't
> matter anymore for array access and can be excluded from the ABI.

To be thorough: Does anyone else have opinions on this approach?

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


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread James Almer
On 3/28/2018 3:53 PM, Derek Buitenhuis wrote:
> On 3/28/2018 7:49 PM, wm4 wrote:
>> You just need to change * to **. Then the size of the struct doesn't
>> matter anymore for array access and can be excluded from the ABI.
> 
> To be thorough: Does anyone else have opinions on this approach?

It's what's being done in AVFrame side data, so i guess acceptable?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread James Almer
On 3/28/2018 3:47 PM, Nicolas George wrote:
> Derek Buitenhuis (2018-03-28):
>> Do you have an actual suggest though?
> 
> Maybe not using a badly designed API that requires everything to be
> stored in a serialized uint8_t array.
> 
>>  Afaict, this is exactly how the recently
>> pushed encryption support works with AVSubsampleEncryptionInfo entries in the
>> AVEncryptionInfo struct. is this now not acceptable, even though we pushed
>> that a few days ago after months of review?
> 
> It just means that these months of review failed to see that flaw. Let
> us hope we will not need to extend AVSubsampleEncryptionInfo.

We're very much in time to address it in AVSubsampleEncryptionInfo. It
was pushed only a few days ago.
There's no need to let it stay as is if a better solution is available.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] avcodec: add eac3_core bitstream filter

2018-03-28 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/bitstream_filters.texi |  4 +++
 libavcodec/Makefile|  1 +
 libavcodec/bitstream_filters.c |  1 +
 libavcodec/eac3_core_bsf.c | 80 ++
 4 files changed, 86 insertions(+)
 create mode 100644 libavcodec/eac3_core_bsf.c

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 982e3edac8..7322af6550 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -75,6 +75,10 @@ the header stored in extradata to the key packets:
 ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra 
out.ts
 @end example
 
+@section eac3_core
+
+Extract the core from a E-AC-3 stream, dropping extra channels.
+
 @section extract_extradata
 
 Extract the in-band extradata.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index aaef6c3ab8..8220ad855d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)  += 
aac_adtstoasc_bsf.o mpeg4audio.o
 OBJS-$(CONFIG_CHOMP_BSF)  += chomp_bsf.o
 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
+OBJS-$(CONFIG_EAC3_CORE_BSF)  += eac3_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  h2645_parse.o
 OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 12211225bb..18b698a85f 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -28,6 +28,7 @@ extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
 extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
+extern const AVBitStreamFilter ff_eac3_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_filter_units_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
diff --git a/libavcodec/eac3_core_bsf.c b/libavcodec/eac3_core_bsf.c
new file mode 100644
index 00..85feb2583b
--- /dev/null
+++ b/libavcodec/eac3_core_bsf.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * 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 "avcodec.h"
+#include "bsf.h"
+#include "get_bits.h"
+#include "libavutil/mem.h"
+#include "ac3_parser_internal.h"
+
+static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
+{
+AC3HeaderInfo hdr;
+GetBitContext gbc;
+int ret;
+
+ret = ff_bsf_get_packet_ref(ctx, pkt);
+if (ret < 0)
+return ret;
+ret = init_get_bits8(&gbc, pkt->data, pkt->size);
+if (ret < 0)
+return ret;
+
+ret = ff_ac3_parse_header(&gbc, &hdr);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
+
+if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
+hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
+pkt->size = hdr.frame_size;
+} else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size > 
hdr.frame_size) {
+AC3HeaderInfo hdr2;
+
+ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size - 
hdr.frame_size);
+if (ret < 0)
+return ret;
+
+ret = ff_ac3_parse_header(&gbc, &hdr2);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
+
+if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
+hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
+pkt->size -= hdr.frame_size;
+pkt->data += hdr.frame_size;
+} else {
+pkt->size = 0;
+}
+} else {
+pkt->size = 0;
+}
+
+return 0;
+}
+
+static const enum AVCodecID codec_ids[] = {
+AV_CODEC_ID_EAC3, AV_CODEC_ID_NONE,
+};
+
+const AVBitStreamFilter ff_eac3_core_bsf = {
+.name  = "eac3_core",
+.filter= eac3_core_filter,
+.codec_ids = codec_ids,
+};
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 1/2] avcodec/eac3: add support for dependent stream

2018-03-28 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/aac_ac3_parser.c |   9 ++-
 libavcodec/ac3_parser.c |   2 +-
 libavcodec/ac3dec.c | 177 +++-
 libavcodec/ac3dec.h |  10 ++-
 libavcodec/eac3dec.c|  11 +--
 tests/ref/fate/ts-demux |   2 +-
 tests/ref/seek/lavf-rm  |   6 +-
 7 files changed, 164 insertions(+), 53 deletions(-)

diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index 4e834b4424..019074b0dd 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -86,13 +86,16 @@ get_next:
the frame). */
 if (avctx->codec_id != AV_CODEC_ID_AAC) {
 avctx->sample_rate = s->sample_rate;
-avctx->channels = s->channels;
-avctx->channel_layout = s->channel_layout;
+if (avctx->codec_id != AV_CODEC_ID_EAC3) {
+avctx->channels = s->channels;
+avctx->channel_layout = s->channel_layout;
+}
 s1->duration = s->samples;
 avctx->audio_service_type = s->service_type;
 }
 
-avctx->bit_rate = s->bit_rate;
+if (avctx->codec_id != AV_CODEC_ID_EAC3)
+avctx->bit_rate = s->bit_rate;
 }
 
 return i;
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 1015245a90..f4618bf215 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -218,8 +218,8 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext 
*hdr_info,
 else if (hdr_info->codec_id == AV_CODEC_ID_NONE)
 hdr_info->codec_id = AV_CODEC_ID_AC3;
 
-*need_next_header = (hdr.frame_type != EAC3_FRAME_TYPE_AC3_CONVERT);
 *new_frame_start  = (hdr.frame_type != EAC3_FRAME_TYPE_DEPENDENT);
+*need_next_header = *new_frame_start || (hdr.frame_type != 
EAC3_FRAME_TYPE_AC3_CONVERT);
 return hdr.frame_size;
 }
 
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 244a18323f..554eae9218 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -106,6 +106,25 @@ static const uint8_t ac3_default_coeffs[8][5][2] = {
 { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
 };
 
+static const uint64_t custom_channel_map_locations[16][2] = {
+{ 1, AV_CH_FRONT_LEFT },
+{ 1, AV_CH_FRONT_CENTER },
+{ 1, AV_CH_FRONT_RIGHT },
+{ 1, AV_CH_SIDE_LEFT },
+{ 1, AV_CH_SIDE_RIGHT },
+{ 0, AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER },
+{ 0, AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT },
+{ 0, AV_CH_BACK_CENTER },
+{ 0, AV_CH_TOP_CENTER },
+{ 0, AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT },
+{ 0, AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT },
+{ 0, AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT},
+{ 0, AV_CH_TOP_FRONT_CENTER },
+{ 0, AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT },
+{ 0, AV_CH_LOW_FREQUENCY_2 },
+{ 1, AV_CH_LOW_FREQUENCY },
+};
+
 /**
  * Symmetrical Dequantization
  * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization
@@ -317,6 +336,7 @@ static int parse_frame_header(AC3DecodeContext *s)
 s->fbw_channels = s->channels - s->lfe_on;
 s->lfe_ch   = s->fbw_channels + 1;
 s->frame_size   = hdr.frame_size;
+s->superframe_size += hdr.frame_size;
 s->preferred_downmix= AC3_DMIXMOD_NOTINDICATED;
 s->center_mix_level = hdr.center_mix_level;
 s->center_mix_level_ltrt= 4; // -3.0dB
@@ -683,7 +703,7 @@ static void do_rematrixing(AC3DecodeContext *s)
  * Convert frequency domain coefficients to time-domain audio samples.
  * reference: Section 7.9.4 Transformation Equations
  */
-static inline void do_imdct(AC3DecodeContext *s, int channels)
+static inline void do_imdct(AC3DecodeContext *s, int channels, int offset)
 {
 int ch;
 
@@ -695,25 +715,25 @@ static inline void do_imdct(AC3DecodeContext *s, int 
channels)
 x[i] = s->transform_coeffs[ch][2 * i];
 s->imdct_256.imdct_half(&s->imdct_256, s->tmp_output, x);
 #if USE_FIXED
-s->fdsp->vector_fmul_window_scaled(s->outptr[ch - 1], s->delay[ch 
- 1],
+s->fdsp->vector_fmul_window_scaled(s->outptr[ch - 1], s->delay[ch 
- 1 + offset],
s->tmp_output, s->window, 128, 8);
 #else
-s->fdsp->vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1],
+s->fdsp->vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1 + 
offset],
s->tmp_output, s->window, 128);
 #endif
 for (i = 0; i < 128; i++)
 x[i] = s->transform_coeffs[ch][2 * i + 1];
-s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1], x);
+s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1 + offset], 
x);
 } else {
 s->imdct_512.imdct_half(&s->imdct_512, s->tmp_output, 
s->transform_coeffs[ch]);
 #if USE_FIXED
-

Re: [FFmpeg-devel] [PATCH 2/2] avcodec: add eac3_core bitstream filter

2018-03-28 Thread James Almer
On 3/28/2018 4:00 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/bitstream_filters.texi |  4 +++
>  libavcodec/Makefile|  1 +
>  libavcodec/bitstream_filters.c |  1 +
>  libavcodec/eac3_core_bsf.c | 80 
> ++
>  4 files changed, 86 insertions(+)
>  create mode 100644 libavcodec/eac3_core_bsf.c
> 
> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> index 982e3edac8..7322af6550 100644
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -75,6 +75,10 @@ the header stored in extradata to the key packets:
>  ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v 
> dump_extra out.ts
>  @end example
>  
> +@section eac3_core
> +
> +Extract the core from a E-AC-3 stream, dropping extra channels.
> +
>  @section extract_extradata
>  
>  Extract the in-band extradata.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index aaef6c3ab8..8220ad855d 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)  += 
> aac_adtstoasc_bsf.o mpeg4audio.o
>  OBJS-$(CONFIG_CHOMP_BSF)  += chomp_bsf.o
>  OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
>  OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
> +OBJS-$(CONFIG_EAC3_CORE_BSF)  += eac3_core_bsf.o
>  OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
>   h2645_parse.o
>  OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
> diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
> index 12211225bb..18b698a85f 100644
> --- a/libavcodec/bitstream_filters.c
> +++ b/libavcodec/bitstream_filters.c
> @@ -28,6 +28,7 @@ extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
>  extern const AVBitStreamFilter ff_chomp_bsf;
>  extern const AVBitStreamFilter ff_dump_extradata_bsf;
>  extern const AVBitStreamFilter ff_dca_core_bsf;
> +extern const AVBitStreamFilter ff_eac3_core_bsf;
>  extern const AVBitStreamFilter ff_extract_extradata_bsf;
>  extern const AVBitStreamFilter ff_filter_units_bsf;
>  extern const AVBitStreamFilter ff_h264_metadata_bsf;
> diff --git a/libavcodec/eac3_core_bsf.c b/libavcodec/eac3_core_bsf.c
> new file mode 100644
> index 00..85feb2583b
> --- /dev/null
> +++ b/libavcodec/eac3_core_bsf.c
> @@ -0,0 +1,80 @@
> +/*
> + * Copyright (c) 2018 Paul B Mahol
> + *
> + * 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 "avcodec.h"
> +#include "bsf.h"
> +#include "get_bits.h"
> +#include "libavutil/mem.h"

Why?

> +#include "ac3_parser_internal.h"
> +
> +static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
> +{
> +AC3HeaderInfo hdr;
> +GetBitContext gbc;
> +int ret;
> +
> +ret = ff_bsf_get_packet_ref(ctx, pkt);
> +if (ret < 0)
> +return ret;
> +ret = init_get_bits8(&gbc, pkt->data, pkt->size);
> +if (ret < 0)
> +return ret;

av_packet_unref(pkt);

Same with every other failure below, so maybe doing a goto fail would be
easier.

> +
> +ret = ff_ac3_parse_header(&gbc, &hdr);
> +if (ret < 0)
> +return AVERROR_INVALIDDATA;
> +
> +if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
> +hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
> +pkt->size = hdr.frame_size;
> +} else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size > 
> hdr.frame_size) {
> +AC3HeaderInfo hdr2;
> +
> +ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size - 
> hdr.frame_size);
> +if (ret < 0)
> +return ret;
> +
> +ret = ff_ac3_parse_header(&gbc, &hdr2);
> +if (ret < 0)
> +return AVERROR_INVALIDDATA;
> +
> +if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
> +hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
> +pkt->size -= hdr.frame_size;
> +pkt->data += hdr.frame_size;
> +} else {
> +pkt->size = 0;
> +}
> +} else {
> +pkt->size = 0;
> +}
> +
> +return 0;
> +}
> +
> +static const enum AVCodecID codec_ids[] =

[FFmpeg-devel] [PATCH 2/2] avcodec: add eac3_core bitstream filter

2018-03-28 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/bitstream_filters.texi |  4 ++
 libavcodec/Makefile|  1 +
 libavcodec/bitstream_filters.c |  1 +
 libavcodec/eac3_core_bsf.c | 86 ++
 4 files changed, 92 insertions(+)
 create mode 100644 libavcodec/eac3_core_bsf.c

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 982e3edac8..7322af6550 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -75,6 +75,10 @@ the header stored in extradata to the key packets:
 ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra 
out.ts
 @end example
 
+@section eac3_core
+
+Extract the core from a E-AC-3 stream, dropping extra channels.
+
 @section extract_extradata
 
 Extract the in-band extradata.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index aaef6c3ab8..8220ad855d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)  += 
aac_adtstoasc_bsf.o mpeg4audio.o
 OBJS-$(CONFIG_CHOMP_BSF)  += chomp_bsf.o
 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
+OBJS-$(CONFIG_EAC3_CORE_BSF)  += eac3_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  h2645_parse.o
 OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 12211225bb..18b698a85f 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -28,6 +28,7 @@ extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
 extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
+extern const AVBitStreamFilter ff_eac3_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_filter_units_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
diff --git a/libavcodec/eac3_core_bsf.c b/libavcodec/eac3_core_bsf.c
new file mode 100644
index 00..86a23f24d8
--- /dev/null
+++ b/libavcodec/eac3_core_bsf.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * 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 "avcodec.h"
+#include "bsf.h"
+#include "get_bits.h"
+#include "ac3_parser_internal.h"
+
+static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
+{
+AC3HeaderInfo hdr;
+GetBitContext gbc;
+int ret;
+
+ret = ff_bsf_get_packet_ref(ctx, pkt);
+if (ret < 0)
+return ret;
+ret = init_get_bits8(&gbc, pkt->data, pkt->size);
+if (ret < 0)
+goto fail;
+
+ret = ff_ac3_parse_header(&gbc, &hdr);
+if (ret < 0) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+
+if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
+hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
+pkt->size = hdr.frame_size;
+} else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size > 
hdr.frame_size) {
+AC3HeaderInfo hdr2;
+
+ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size - 
hdr.frame_size);
+if (ret < 0)
+goto fail;
+
+ret = ff_ac3_parse_header(&gbc, &hdr2);
+if (ret < 0) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+
+if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
+hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
+pkt->size -= hdr.frame_size;
+pkt->data += hdr.frame_size;
+} else {
+pkt->size = 0;
+}
+} else {
+pkt->size = 0;
+}
+
+return 0;
+fail:
+av_packet_unref(pkt);
+return ret;
+}
+
+static const enum AVCodecID codec_ids[] = {
+AV_CODEC_ID_EAC3, AV_CODEC_ID_NONE,
+};
+
+const AVBitStreamFilter ff_eac3_core_bsf = {
+.name  = "eac3_core",
+.filter= eac3_core_filter,
+.codec_ids = codec_ids,
+};
-- 
2.11.0

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec: add eac3_core bitstream filter

2018-03-28 Thread Paul B Mahol
On 3/28/18, James Almer  wrote:
> On 3/28/2018 4:00 PM, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  doc/bitstream_filters.texi |  4 +++
>>  libavcodec/Makefile|  1 +
>>  libavcodec/bitstream_filters.c |  1 +
>>  libavcodec/eac3_core_bsf.c | 80
>> ++
>>  4 files changed, 86 insertions(+)
>>  create mode 100644 libavcodec/eac3_core_bsf.c
>>
>> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
>> index 982e3edac8..7322af6550 100644
>> --- a/doc/bitstream_filters.texi
>> +++ b/doc/bitstream_filters.texi
>> @@ -75,6 +75,10 @@ the header stored in extradata to the key packets:
>>  ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v
>> dump_extra out.ts
>>  @end example
>>
>> +@section eac3_core
>> +
>> +Extract the core from a E-AC-3 stream, dropping extra channels.
>> +
>>  @section extract_extradata
>>
>>  Extract the in-band extradata.
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index aaef6c3ab8..8220ad855d 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)  +=
>> aac_adtstoasc_bsf.o mpeg4audio.o
>>  OBJS-$(CONFIG_CHOMP_BSF)  += chomp_bsf.o
>>  OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
>>  OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
>> +OBJS-$(CONFIG_EAC3_CORE_BSF)  += eac3_core_bsf.o
>>  OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
>>   h2645_parse.o
>>  OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
>> diff --git a/libavcodec/bitstream_filters.c
>> b/libavcodec/bitstream_filters.c
>> index 12211225bb..18b698a85f 100644
>> --- a/libavcodec/bitstream_filters.c
>> +++ b/libavcodec/bitstream_filters.c
>> @@ -28,6 +28,7 @@ extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
>>  extern const AVBitStreamFilter ff_chomp_bsf;
>>  extern const AVBitStreamFilter ff_dump_extradata_bsf;
>>  extern const AVBitStreamFilter ff_dca_core_bsf;
>> +extern const AVBitStreamFilter ff_eac3_core_bsf;
>>  extern const AVBitStreamFilter ff_extract_extradata_bsf;
>>  extern const AVBitStreamFilter ff_filter_units_bsf;
>>  extern const AVBitStreamFilter ff_h264_metadata_bsf;
>> diff --git a/libavcodec/eac3_core_bsf.c b/libavcodec/eac3_core_bsf.c
>> new file mode 100644
>> index 00..85feb2583b
>> --- /dev/null
>> +++ b/libavcodec/eac3_core_bsf.c
>> @@ -0,0 +1,80 @@
>> +/*
>> + * Copyright (c) 2018 Paul B Mahol
>> + *
>> + * 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 "avcodec.h"
>> +#include "bsf.h"
>> +#include "get_bits.h"
>> +#include "libavutil/mem.h"
>
> Why?
>
>> +#include "ac3_parser_internal.h"
>> +
>> +static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
>> +{
>> +AC3HeaderInfo hdr;
>> +GetBitContext gbc;
>> +int ret;
>> +
>> +ret = ff_bsf_get_packet_ref(ctx, pkt);
>> +if (ret < 0)
>> +return ret;
>> +ret = init_get_bits8(&gbc, pkt->data, pkt->size);
>> +if (ret < 0)
>> +return ret;
>
> av_packet_unref(pkt);
>
> Same with every other failure below, so maybe doing a goto fail would be
> easier.
>
>> +
>> +ret = ff_ac3_parse_header(&gbc, &hdr);
>> +if (ret < 0)
>> +return AVERROR_INVALIDDATA;
>> +
>> +if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
>> +hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
>> +pkt->size = hdr.frame_size;
>> +} else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size >
>> hdr.frame_size) {
>> +AC3HeaderInfo hdr2;
>> +
>> +ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size
>> - hdr.frame_size);
>> +if (ret < 0)
>> +return ret;
>> +
>> +ret = ff_ac3_parse_header(&gbc, &hdr2);
>> +if (ret < 0)
>> +return AVERROR_INVALIDDATA;
>> +
>> +if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
>> +hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
>> +pkt->size -= hdr.frame_size;
>> +pkt->data += hdr.frame_size;
>> +} else {
>> +   

Re: [FFmpeg-devel] [PATCH 2/2] avcodec: add eac3_core bitstream filter

2018-03-28 Thread James Almer
On 3/28/2018 4:53 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/bitstream_filters.texi |  4 ++
>  libavcodec/Makefile|  1 +
>  libavcodec/bitstream_filters.c |  1 +
>  libavcodec/eac3_core_bsf.c | 86 
> ++
>  4 files changed, 92 insertions(+)
>  create mode 100644 libavcodec/eac3_core_bsf.c

Should be ok if tested. Thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg: prevent premature EOF in sub2video with nullptr AVSubtitles

2018-03-28 Thread Jan Ekström
From: Jan Ekström 

With some streams multiple nullptr AVSubtitles can get pushed
into sub2video_update() in a row.

This causes end_pts, and on the next round pts, to become
INT64_MAX, latter of which signals EOF in framesync, leading to
complete loss of subtitles from that point on.

Thus, utilize the previous sub2video.end_pts as both the pts and
end_pts in case a nullptr AVSubtitle is received. This lets further
incoming subtitle packets be properly processed, as EOF is not hit
in framesync.

Signed-off-by: Jan Ekström 
---
 fftools/ffmpeg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1b2e37b8d8..398ed278d7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -248,8 +248,7 @@ void sub2video_update(InputStream *ist, AVSubtitle *sub)
  AV_TIME_BASE_Q, ist->st->time_base);
 num_rects = sub->num_rects;
 } else {
-pts   = ist->sub2video.end_pts;
-end_pts   = INT64_MAX;
+pts   = end_pts = ist->sub2video.end_pts;
 num_rects = 0;
 }
 if (sub2video_get_blank_frame(ist) < 0) {
-- 
2.14.3

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


Re: [FFmpeg-devel] [PATCHv2 1/2] ffmpeg: fallback to codecpar parameters on input filter eof

2018-03-28 Thread Marton Balint


On Sat, 24 Mar 2018, Marton Balint wrote:


Fixes ticket #6854 and the following simpler case:

ffmpeg -f lavfi -i testsrc=d=1 -f lavfi -i testsrc=d=0 -filter_complex overlay 
-f null none

Signed-off-by: Marton Balint 
---
fftools/ffmpeg.c | 33 +
1 file changed, 21 insertions(+), 12 deletions(-)


Pushed the series. Will add fate tests as time permits...

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


Re: [FFmpeg-devel] [PATCHv2] avfilter/af_pan: reject expressions referencing the same channel multiple times

2018-03-28 Thread Marton Balint


On Sun, 25 Mar 2018, Nicolas George wrote:


Marton Balint (2018-03-25):

Fixes parsing of expressions like c0=c0+c0 or c0=c0|c0=c1.  Previously no
error was thrown and for input channels, only the last gain factor was used,
for output channels the source channel gains were combined.

Signed-off-by: Marton Balint 
---
 libavfilter/af_pan.c | 16 
 1 file changed, 16 insertions(+)


LGTM, thanks.


Pushed, thanks.

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


Re: [FFmpeg-devel] [PATCH] avcodec/dcaenc: Use aac psychoacoustic model for dcaenc

2018-03-28 Thread Michael Niedermayer
On Tue, Mar 27, 2018 at 02:26:45AM +0300, Даниил Чередник wrote:
> Now it should be fine. Second patch has been fixed.
> 
> On Mon, Mar 26, 2018 at 3:59 PM, Даниил Чередник 
> wrote:
> 
> > Hi.
> > Yes, I reproduced it on mac. A bit strange, I run fate with valgrind
> > during patch preparation, it was ok.
> > I will fix it, and send updated patch.
> >
> > Thank you!
> >
> > On Sun, Mar 25, 2018 at 5:57 PM, Michael Niedermayer <
> > mich...@niedermayer.cc> wrote:
> >
> >> On Sun, Mar 25, 2018 at 01:55:42PM +0300, Даниил Чередник wrote:
> >> [...]
> >>
> >> >  libavcodec/dcaenc.c   |  369 --
> >> 
> >> >  libavcodec/psymodel.c |1
> >> >  tests/fate/acodec.mak |4
> >> >  3 files changed, 156 insertions(+), 218 deletions(-)
> >> > fd146632a7f29530a59d35abd63149c81b4dfcc6
> >> 0002-avcodec-dcaenc-Use-aac-psychoacoustic-model-for-DCA-.patch
> >> > From 99d937a0828bbd60aef52d7979c75f8c21989145 Mon Sep 17 00:00:00 2001
> >> > From: Daniil Cherednik 
> >> > Date: Sun, 4 Mar 2018 13:14:17 +
> >> > Subject: [PATCH 2/2] avcodec/dcaenc: Use aac psychoacoustic model for
> >> DCA
> >> >  encoder
> >> >
> >> > There are several reasons to replace dca psychoacoustic to common model:
> >> >  - dca psychoacoustic has some quality problems especially at high
> >> frequency bands
> >> >  - unclear implementation
> >> >  - aac implementation allows to use tonality measurement for future
> >> improvements
> >> >  - a bit faster
> >>
> >> This breaks
> >> make -j12 fate-acodec-dca
> >> (segfaults)
> >>
> >> tell me if you can reproduce? If not ill rebuild with debug symbols and
> >> get a
> >> backtrace
> >>
> >> [...]
> >> --
> >> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >>
> >> If you drop bombs on a foreign country and kill a hundred thousand
> >> innocent people, expect your government to call the consequence
> >> "unprovoked inhuman terrorist attacks" and use it to justify dropping
> >> more bombs and killing more people. The technology changed, the idea is
> >> old.
> >>
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >>
> >
> >
> > --
> > Daniil Cherednik
> >
> 
> 
> 
> -- 
> Daniil Cherednik

[...]

> 57b2e6d001a856c9434fe6ad1856cb3f24443a83  
> 0002-avcodec-dcaenc-Use-aac-psychoacoustic-model-for-DCA-.patch
> From 49b4f2a966719c24f54c026c438680557c35e96b Mon Sep 17 00:00:00 2001
> From: Daniil Cherednik 
> Date: Sun, 4 Mar 2018 13:14:17 +
> Subject: [PATCH 2/2] avcodec/dcaenc: Use aac psychoacoustic model for DCA
>  encoder
> 
> There are several reasons to replace dca psychoacoustic to common model:
>  - dca psychoacoustic has some quality problems especially at high frequency 
> bands
>  - unclear implementation
>  - aac implementation allows to use tonality measurement for future 
> improvements
>  - a bit faster
> 
> Signed-off-by: Daniil Cherednik 
> ---
>  libavcodec/dcaenc.c   | 369 
> +-
>  libavcodec/psymodel.c |   1 +
>  tests/fate/acodec.mak |   4 +-
>  3 files changed, 156 insertions(+), 218 deletions(-)

breaks fate on arm qemu

TESTacodec-dca
--- -   2018-03-29 00:37:01.286083392 +0200
+++ tests/data/fate/acodec-dca  2018-03-29 00:37:01.283607451 +0200
@@ -1 +1 @@
-c610f911aa74656132abb650be6b548a
+503d8eac7238d87aae6f92808231e0c0
Test acodec-dca failed. Look at tests/data/fate/acodec-dca.err for details.
make: *** [fate-acodec-dca] Error 1
 

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/get_bits: Make sure the input bitstream with padding can be addressed

2018-03-28 Thread Michael Niedermayer
On Wed, Mar 28, 2018 at 01:11:06AM -0300, James Almer wrote:
> On 3/25/2018 9:13 PM, Michael Niedermayer wrote:
> > On Sat, Mar 24, 2018 at 01:56:26AM +0100, Michael Niedermayer wrote:
> >> Signed-off-by: Michael Niedermayer 
> >> ---
> >>  libavcodec/get_bits.h | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > will apply
> 
> HOSTCClibavcodec/qdm2_tablegen.o
> In file included from src/libavcodec/tableprint_vlc.h:40,
>  from src/libavcodec/qdm2_tablegen.c:25:
> src/libavcodec/get_bits.h: In function 'init_get_bits':
> src/libavcodec/get_bits.h:432: error: 'AV_INPUT_BUFFER_PADDING_SIZE'
> undeclared (first use in this function)
> src/libavcodec/get_bits.h:432: error: (Each undeclared identifier is
> reported only once
> src/libavcodec/get_bits.h:432: error: for each function it appears in.)
> /home/fate/src/ffbuild/common.mak:152: recipe for target
> 'libavcodec/qdm2_tablegen.o' failed
> 
> When compiling with --enable-hardcoded-tables

will fix

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg: prevent premature EOF in sub2video with nullptr AVSubtitles

2018-03-28 Thread Jan Ekström
On Thu, Mar 29, 2018 at 12:53 AM, Jan Ekström  wrote:
> From: Jan Ekström 
>
> With some streams multiple nullptr AVSubtitles can get pushed
> into sub2video_update() in a row.
>
> This causes end_pts, and on the next round pts, to become
> INT64_MAX, latter of which signals EOF in framesync, leading to
> complete loss of subtitles from that point on.
>
> Thus, utilize the previous sub2video.end_pts as both the pts and
> end_pts in case a nullptr AVSubtitle is received. This lets further
> incoming subtitle packets be properly processed, as EOF is not hit
> in framesync.

For context, this seems to mostly be happening at commercial breaks
with some TV channels where a filter chain re-configuration happens at
the beginning and the end due to input format changes (usually with
audio, main programme having 5.1 and advertisements having stereo for
example). Filter chain re-configuration seems related as this does not
seem to happen when the audio filter is removed from the chain.

For example:
- Without audio ("[0:v:0][0:s:0]overlay=eof_action=pass[overlay_out]")
[dvbsub] normal AVSubtitle: utilized values: pts=10949137,
end_pts=13649137, num_rects=0
[dvbsub] nullptr AVSubtitle: utilized values: pts=13649137,
end_pts=9223372036854775807

[dvbsub] normal AVSubtitle: utilized values: pts=18783049,
end_pts=21483049, num_rects=2

- With audio 
("[0:v:0][0:s:0]overlay=eof_action=pass[overlay_out];[0:a:0]aresample=48000[a_out]")
[dvbsub] normal AVSubtitle: utilized values: pts=10949137,
end_pts=13649137, num_rects=0
[dvbsub] nullptr AVSubtitle: utilized values: pts=13649137,
end_pts=9223372036854775807

[graph_0_in_0_1] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3
[Parsed_aresample_4] ch:2 chl:stereo fmt:fltp r:48000Hz -> ch:2
chl:stereo fmt:fltp r:48000Hz
[auto_scaler_0] w:720 h:576 fmt:bgra sar:0/1 -> w:720 h:576
fmt:yuva420p sar:0/1 flags:0x2
[dvbsub] nullptr AVSubtitle: utilized values: pts=9223372036854775807,
end_pts=9223372036854775807

[graph_0_in_0_1] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x60f
[Parsed_aresample_4] ch:6 chl:5.1(side) fmt:fltp r:48000Hz -> ch:2
chl:stereo fmt:fltp r:48000Hz
[dvbsub] nullptr AVSubtitle: utilized values: pts=9223372036854775807,
end_pts=9223372036854775807
[dvbsub] normal AVSubtitle: utilized values: pts=18783049,
end_pts=21483049, num_rects=2

Best regards,
Jan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [GSOC] [PATCH] SRCNN filter

2018-03-28 Thread Michael Niedermayer
On Wed, Mar 28, 2018 at 11:17:40AM +0300, Sergey Lavrushkin wrote:
> > [...]
> > > +#define OFFSET(x) offsetof(SRCNNContext, x)
> > > +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
> > > +static const AVOption srcnn_options[] = {
> > > +{ "config_file", "path to configuration file with network
> > parameters", OFFSET(config_file_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0,
> > 0, FLAGS },
> > > +{ NULL }
> > > +};
> > > +
> > > +AVFILTER_DEFINE_CLASS(srcnn);
> > > +
> > > +#define CHECK_FILE(file)if (ferror(file) || feof(file)){ \
> > > +av_log(context, AV_LOG_ERROR, "error
> > reading configuration file\n");\
> > > +fclose(file); \
> > > +return AVERROR(EIO); \
> > > +}
> > > +
> > > +#define CHECK_ALLOCATION(conv, file)if
> > (allocate_and_read_convolution_data(&conv, file)){ \
> > > +av_log(context,
> > AV_LOG_ERROR, "could not allocate memory for convolutions\n"); \
> > > +fclose(file); \
> > > +return AVERROR(ENOMEM); \
> > > +}
> > > +
> >
> > > +static int allocate_and_read_convolution_data(Convolution* conv, FILE*
> > config_file)
> > > +{
> > > +int32_t kernel_size = conv->output_channels * conv->size *
> > conv->size * conv->input_channels;
> > > +conv->kernel = av_malloc(kernel_size * sizeof(double));
> > > +if (!conv->kernel){
> > > +return 1;
> >
> > this should return an AVERROR code for consistency with the rest of
> > the codebase
> >
> 
> Ok.
> 
> 
> > > +}
> >
> > > +fread(conv->kernel, sizeof(double), kernel_size, config_file);
> >
> > directly reading data types is not portable, it would for example be
> > endian specific
> > and using avio for reading may be better, though fread is as far as iam
> > concerned also ok
> >
> 
> Ok, I understand the problem, but I have not really worked with it before,
> so I need an advice of how to properly fix it. If I understand correctly,
> for

> int32_t I need to check endianness and reverse bytes if necessary. But with

see avio_rb32()
might not be as fast as reading a whole array and byteswaping though.
Not sure it matters


> doubles it is more complicated. Should I write a IEEE 754 converter from
> binary
> to double or maybe I can somehow check IEEE 754 doubles support and
> depending
> on it either stick to the default network weights, or just read bytes and
> check
> endianness, if IEEE 754 doubles are supported? Or maybe avio provide some
> utility to deal with this problem?

something like this should work:
av_int2float(avio_rb32(pb));
av_int2double(avio_rb64(pb));

> 
> 
> > [...]
> > > +/**
> > > + * @file
> > > + * Default cnn weights for x2 upsampling with srcnn filter.
> > > + */
> > > +
> > > +/// First convolution kernel
> >
> > > +static double conv1_kernel[] = {
> >
> > static data should be also const, otherwise it may be changed and could
> > cause
> > thread saftey issues
> >
> 
> Ok, I just wanted to not allocate additional memory in case of using
> default weights.

well, there can be more than one instance of a filter running at the same time
so static variables that are actually changing will affect the other
filter instance


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Michael Niedermayer
On Wed, Mar 28, 2018 at 07:53:31PM +0100, Derek Buitenhuis wrote:
> On 3/28/2018 7:49 PM, wm4 wrote:
> > You just need to change * to **. Then the size of the struct doesn't
> > matter anymore for array access and can be excluded from the ABI.
> 
> To be thorough: Does anyone else have opinions on this approach?

Its how AVStreams are living in AVFormatContext too
so to me it seems thats the obvious and consistent way to go.
i do not know if there are any unforseen issues with that ...

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data

2018-03-28 Thread Michael Niedermayer
On Wed, Mar 28, 2018 at 09:35:12PM +0300, Jan Ekström wrote:
> On Wed, Mar 28, 2018 at 9:12 PM, Michael Niedermayer
>  wrote:
> >> +/**
> >> + * An in-order array of entries for the given timeline.
> >> + * Each entry contains information on which samples to display for a
> >> + * particular edit.
> >> + */
> >> +AVTimelineEntry *entries;
> >
> > This is problematic as its non extensible. (unless iam missing something)
> > Consider that a field is added to AVTimelineEntry, the entries array would
> > have a larger element size and that would require all user apps to be 
> > rebuild
> >
> 
> So you would prefer some sort of iterator? Or a size entry like with
> some of the entries in AVEncryptionInfo? I have a feeling this was
> based off of the following added into AVEncryptionInfo:
> +AVSubsampleEncryptionInfo *subsamples;
> +uint32_t subsample_count;
> 
> Which now would seem to be similarly not being extendable?
> 
> > Also, if you want to support quicktime more fully theres more needed.
> > QT can for example switch even between codecs mid stream IIRC
> > not sure we want to support this
> >
> 
> Thankfully, that has little to do with virtual timelines (edit lists)
> as far as I can tell?

Well, no unless we want a single unified API that represents information
about timespans.
We can use completely unrelated systems to handle the virtual timeline,
the codec and related changes, chapters, ...


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc/videotoolbox: fix failure to decode PAFF

2018-03-28 Thread Rodger Combs
---
 libavcodec/videotoolbox.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index f82c31c5df..57b6698e1b 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -326,11 +326,8 @@ static int videotoolbox_set_frame(AVCodecContext *avctx, 
AVFrame *frame)
 
 CVPixelBufferRef *ref = (CVPixelBufferRef *)frame->buf[0]->data;
 
-if (*ref) {
-av_log(avctx, AV_LOG_ERROR, "videotoolbox: frame already set?\n");
-av_frame_unref(frame);
-return AVERROR_EXTERNAL;
-}
+if (*ref)
+CVPixelBufferRelease(*ref);
 
 *ref = vtctx->frame;
 vtctx->frame = NULL;
-- 
2.16.2

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


[FFmpeg-devel] [PATCH] [RFC] avformat/movenc: support writing iTunes cover image

2018-03-28 Thread Timo Teräs
Fixes https://trac.ffmpeg.org/ticket/2798

This makes movenc handle AV_DISPOSITION_ATTACHED_PIC and write
the associated pictures in iTunes cover atom. This corresponds
to how 'mov' demuxer parses and exposes the cover images when
reading.

Tested to produce valid stream with:
 ffmpeg -i movie.mp4 -i thumb.jpg -disposition:v:1 attached_pic
-map 0 -map 1 -c copy out.mp4

The cover image is also copied corretly with:
 ffmpeg -i movie.mp4 -map 0 -c copy out.mp4

AtomicParseley says that the attached_pic stream is properly
not visible in the main tracks of the file. Though, I am not
sure if there's any side-effects of having internal stream
without any packets. We may need to arm the mov muxer with
additional checks for streams without any packets.

It may make sense to move the code in mov_write_packet() that
grabs the attached picture to generic code in mux.c. Seems there's
currently no other muxer supporting cover images than mp3 and
it seems to use special code to handle them.

Signed-off-by: Timo Teräs 
Cc: Matthieu Bouron 
---
 fftools/ffmpeg.c |  1 +
 libavformat/movenc.c | 67 
 2 files changed, 68 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1b2e37b8d8..b6751d7faa 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3562,6 +3562,7 @@ static int init_output_stream(OutputStream *ost, char 
*error, int error_len)
 { "hearing_impaired", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_HEARING_IMPAIRED  },.unit = "flags" },
 { "visual_impaired" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_VISUAL_IMPAIRED   },.unit = "flags" },
 { "clean_effects"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_CLEAN_EFFECTS },.unit = "flags" },
+{ "attached_pic", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_ATTACHED_PIC  },.unit = "flags" },
 { "captions", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_CAPTIONS  },.unit = "flags" },
 { "descriptions", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_DESCRIPTIONS  },.unit = "flags" },
 { "dependent"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_DISPOSITION_DEPENDENT },.unit = "flags" },
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 230aeb6a6d..5400b2747e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3414,6 +3414,54 @@ static int mov_write_int8_metadata(AVFormatContext *s, 
AVIOContext *pb,
 return size;
 }
 
+static int mov_write_covr(AVIOContext *pb, AVFormatContext *s)
+{
+int64_t pos = 0;
+int i;
+
+for (i = 0; i < s->nb_streams; i++) {
+AVStream *st = s->streams[i];
+enum AVCodecID codec_id = st->codecpar->codec_id;
+int type;
+
+if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC))
+continue;
+
+switch (codec_id) {
+case AV_CODEC_ID_MJPEG:
+type = 0xD;
+break;
+case AV_CODEC_ID_PNG:
+type = 0xE;
+break;
+case AV_CODEC_ID_BMP:
+type = 0x1B;
+break;
+default:
+av_log(s, AV_LOG_ERROR, "unsupported codec %s for cover, skipping",
+   av_fourcc2str(st->codecpar->codec_tag));
+continue;
+}
+
+if (!pos) {
+pos = avio_tell(pb);
+avio_wb32(pb, 0);
+ffio_wfourcc(pb, "covr");
+}
+
+avio_wb32(pb, 16 + st->attached_pic.size);
+ffio_wfourcc(pb, "data");
+avio_wb32(pb, type);
+avio_wb32(pb , 0);
+avio_write(pb, st->attached_pic.data, st->attached_pic.size);
+}
+
+if (pos)
+ return update_size(pb, pos);
+
+return 0;
+}
+
 /* iTunes meta data list */
 static int mov_write_ilst_tag(AVIOContext *pb, MOVMuxContext *mov,
   AVFormatContext *s)
@@ -3451,6 +3499,7 @@ static int mov_write_ilst_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 mov_write_int8_metadata  (s, pb, "hdvd","hd_video",  1);
 mov_write_int8_metadata  (s, pb, "pgap","gapless_playback",1);
 mov_write_int8_metadata  (s, pb, "cpil","compilation", 1);
+mov_write_covr(pb, s);
 mov_write_trkn_tag(pb, mov, s, 0); // track number
 mov_write_trkn_tag(pb, mov, s, 1); // disc number
 mov_write_tmpo_tag(pb, s);
@@ -5480,6 +5529,24 @@ static int mov_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (!pkt) {
 mov_flush_fragment(s, 1);
 return 1;
+} if (s->streams[pkt->stream_index]->disposition & 
AV_DISPOSITION_ATTACHED_PIC) {
+AVStream *st = s->streams[pkt->stream_index];
+int ret;
+
+if (st->nb_frames >= 1) {
+ /* warn only once */
+ if (st->nb_frames == 1)
+ av_log(s, AV_LOG_WARNING, "Got more than one pictu

Re: [FFmpeg-devel] [PATCH v3 2/3] avutil/log: add av_log_set_opts function

2018-03-28 Thread Tobias Rapp

On 28.03.2018 17:11, wm4 wrote:

On Wed, 28 Mar 2018 17:03:39 +0200
Tobias Rapp  wrote:


Allows to set log level and flag values from string.

Signed-off-by: Tobias Rapp 
---
  doc/APIchanges  |  3 +++
  libavutil/log.c | 76 +
  libavutil/log.h | 16 +++
  libavutil/version.h |  2 +-
  4 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 83c7a40..2d14452 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
  
  API changes, most recent first:
  
+2018-03-xx - xxx - lavu 56.13.100 - log.h

+  Add av_log_set_opts().
+
  2018-03-xx - xxx - lavc 58.16.100 - avcodec.h
Add FF_SUB_CHARENC_MODE_IGNORE.
  
diff --git a/libavutil/log.c b/libavutil/log.c

index 0a99d01..af32cd6 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -34,6 +34,7 @@
  #endif
  #include 
  #include 
+#include "avassert.h"
  #include "avutil.h"
  #include "bprint.h"
  #include "common.h"
@@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, 
const char*, va_list))
  av_log_callback = callback;
  }
  
+int av_log_set_opts(const char *arg)

+{
+const struct { const char *name; int level; } log_levels[] = {
+{ "quiet"  , AV_LOG_QUIET   },
+{ "panic"  , AV_LOG_PANIC   },
+{ "fatal"  , AV_LOG_FATAL   },
+{ "error"  , AV_LOG_ERROR   },
+{ "warning", AV_LOG_WARNING },
+{ "info"   , AV_LOG_INFO},
+{ "verbose", AV_LOG_VERBOSE },
+{ "debug"  , AV_LOG_DEBUG   },
+{ "trace"  , AV_LOG_TRACE   },
+};
+const char *token;
+char *tail;
+int flags = av_log_get_flags();
+int level = av_log_get_level();
+int cmd, i = 0;
+
+av_assert0(arg);
+while (*arg) {
+token = arg;
+if (*token == '+' || *token == '-') {
+cmd = *token++;
+} else {
+cmd = 0;
+}
+if (!i && !cmd) {
+flags = 0;  /* missing relative prefix, build absolute value */
+}
+if (!strncmp(token, "repeat", 6)) {
+if (cmd == '-') {
+flags |= AV_LOG_SKIP_REPEATED;
+} else {
+flags &= ~AV_LOG_SKIP_REPEATED;
+}
+arg = token + 6;
+} else if (!strncmp(token, "level", 5)) {
+if (cmd == '-') {
+flags &= ~AV_LOG_PRINT_LEVEL;
+} else {
+flags |= AV_LOG_PRINT_LEVEL;
+}
+arg = token + 5;
+} else {
+break;
+}
+i++;
+}
+if (!*arg) {
+goto end;
+} else if (*arg == '+') {
+arg++;
+} else if (!i) {
+flags = av_log_get_flags();  /* level value without prefix, reset 
flags */
+}
+
+for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
+if (!strcmp(arg, log_levels[i].name)) {
+level = log_levels[i].level;
+goto end;
+}
+}
+
+level = strtol(arg, &tail, 10);
+if (*tail) {
+return -1;
+}
+
+end:
+av_log_set_flags(flags);
+av_log_set_level(level);
+return 0;
+}
+
  static void missing_feature_sample(int sample, void *avc, const char *msg,
 va_list argument_list)
  {
diff --git a/libavutil/log.h b/libavutil/log.h
index d9554e6..97010f7 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -356,6 +356,22 @@ void av_log_set_flags(int arg);
  int av_log_get_flags(void);
  
  /**

+ * Set log flags and level as an option string. Accepts "repeat" and "level"
+ * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL,
+ * followed by the log level specified either by name ("warning", "info",
+ * "verbose", etc.) or by number.
+ *
+ * When flags are prefixed with "+" or "-" the change is relative to the
+ * current flags value. When both flags and level are present a "+" separator
+ * is expected between last flag and before level.
+ *
+ * @param  arg  log option string
+ * @return Returns a negative value if parsing the option string failed,
+ * otherwise returns 0.
+ */
+int av_log_set_opts(const char *arg);
+
+/**
   * @}
   */
  
diff --git a/libavutil/version.h b/libavutil/version.h

index d3dd2df..296c24b 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
   */
  
  #define LIBAVUTIL_VERSION_MAJOR  56

-#define LIBAVUTIL_VERSION_MINOR  12
+#define LIBAVUTIL_VERSION_MINOR  13
  #define LIBAVUTIL_VERSION_MICRO 100
  
  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \


Seems like a step backwards. Why can't it stay in the fftools thing?


When v2 of the patch was reviewed in 
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/227077.html it was 
suggested to move the code into libavutil so that other applications can 
make use of it. I agree that it can be useful for command-line apps that 
interface with li