[FFmpeg-devel] Error when decoding the HEVC WPP streams with ffmpeg

2018-07-09 Thread Liwei Wang
Hi,
 I suffered a problem that when I decoded the HEVC WPP video with
ffmpeg 4.0 with the option "-thread_type slice", there was something wrong
with the output stream. Please find the attachment for the screenshot.
 This is the command: ffmpeg.exe -thread_type slice -threads 16 -i
Traffic_4096x2048_30p_500kbps.hevc out.yuv.

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


Re: [FFmpeg-devel] [PATCH] fate: allow temp files for passed test to be kept

2018-07-09 Thread Gyan Doshi


On 09-07-2018 10:06 AM, Gyan Doshi wrote:


Will push tonight if no objections.


Pushed as 0bd48ab2d9e463b75ef52c0eaa0cc00c4c385cce
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] How to wire asm to the makefile

2018-07-09 Thread Book Moons
Cleaning the build folder did the trick. Hadn't even thought of it. Prior 
builds had an exploratory C version. Appreciate it.

On July 9, 2018 4:49 PM, James Almer  wrote:

> On 7/9/2018 1:29 AM, Book Moons wrote:
> 
> > Hello,
> > 
> > I have a Power optimized function in asm for an upcoming patch. Having some 
> > trouble figuring out how to wire it up to the makefiles / build system. Are 
> > there any docs on how to do that?
> > 
> > The only other example of Power asm seems to be 
> > libavcodec/ppc/fft_altivec.S. That's simply appended to the OBJS-yes 
> > variable:
> > 
> > OBJS-$(CONFIG_FFT) += ppc/fft_init.o
> > 
> > ppc/fft_altivec.o
> > 
> > ppc/fft_vsx.o
> > 
> > Doing the same thing in the relevant makefile (for libswscale/ppc) doesn't 
> > seem to work.
> > 
> > OBJS += ppc/swscale_altivec.o
> > 
> > ppc/yuv2rgb_altivec.o
> > 
> > ppc/yuv2yuv_altivec.o
> > 
> > ppc/hScale8To15_vsx.o
> > 
> > It looks for a .c file. Building with that change gives this error:
> > 
> > > make: *** No rule to make target 'src/libswscale/ppc/hScale8To15_vsx.c', 
> > > needed by 'libswscale/ppc/hScale8To15_vsx.o'. Stop.
> 
> First, always make sure to clean the build folder. Rogue .d files
> 
> (created by the build system) usually result in gnu make assuming wrong
> 
> dependencies if you made some changes to the source tree after they were
> 
> created.
> 
> That aside, are you sure your file is called hScale8To15_vsx.S and not
> 
> hScale8To15_vsx.s? The build system expects .S, not .s
> 
> Otherwise, I can't say why it looks for a .c file when in libavcodec it
> 
> handles fft_altivec.S just fine.
> 
> 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 3/5] avcodec/libaomenc: export Sequence Header and Metadata OBUs as extradata

2018-07-09 Thread James Almer
On 7/9/2018 6:53 PM, Niki Bowe wrote:
> Hi James,
> I passed along your wish for aom_codec_get_global_headers().
> Tom created this bug for tracking:
> https://bugs.chromium.org/p/aomedia/issues/detail?id=2012

Thanks a lot! It would simplify the libaom wrapper a lot and actually
allow us to write the extradata in Matroska directly during transcoding
without requiring some big intrusive changes to that muxer.

To be more specific, aom_codec_get_global_headers() should be callable
and return a sequence header OBU (and any relevant Metadata OBU) after
calling aom_codec_enc_init() but before the first aom_codec_encode()
call. This is what x264_encoder_headers() in libx264 and
ISVCEncoder::EncodeParameterSets in libopenh264 let you do, for example.
Requiring first to pass image data with aom_codec_encode() to be able to
generate the Sequence Header would make virtually no difference compared
to what I'm implementing in this patch.

I see for that matter that aom_codec_control() can be called after
aom_codec_enc_init() and it evidently can have an effect in the eventual
contents of the Sequence Header. Knowing this, and assuming it's not the
case already, perhaps certain aome_enc_control_id values (like for
example color config related ones) should be forbidden to be set after
aom_codec_get_global_headers() is called. Otherwise the headers the
function returns could become invalid if aom_codec_control() was
successfully called afterwards.

> 
> 
> On Mon, Jul 9, 2018 at 11:29 AM James Almer  wrote:
> 
>> aom_codec_get_global_headers() is not implemented as of libaom 1.0.0
>> for AV1, so we're forced to extract the relevant header OBUs from the
>> first packet and propagate them as packet side data for now.
>>
>> Signed-off-by: James Almer 
>> ---
>> This is far from ideal. Whereas the mp4 muxer can handle extradata
>> propagated as packet side data without issues, the Matroska one can't
>> feasibly do it since it would require to reserve space for it, and we
>> don't know just how big the resulting extradata can be as it may have
>> an arbitrary amount of OBUs.
>>
>> libaom should ideally implement aom_codec_get_global_headers() for
>> AV1 (Which is clearly inspired by similar functionality in libx264
>> and other encoders, and can be used before any kind of image data is
>> sent to the encoder), so lobby is welcome :p
>>
>>  configure  |  1 +
>>  libavcodec/libaomenc.c | 41 +
>>  2 files changed, 42 insertions(+)
>>
>> diff --git a/configure b/configure
>> index 1066df6621..a76dd06736 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3046,6 +3046,7 @@ hevc_videotoolbox_encoder_deps="pthreads"
>>  hevc_videotoolbox_encoder_select="videotoolbox_encoder"
>>  libaom_av1_decoder_deps="libaom"
>>  libaom_av1_encoder_deps="libaom"
>> +libaom_av1_encoder_select="extract_extradata_bsf"
>>  libcelt_decoder_deps="libcelt"
>>  libcodec2_decoder_deps="libcodec2"
>>  libcodec2_encoder_deps="libcodec2"
>> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
>> index 41b05dc1c0..0b75dc139c 100644
>> --- a/libavcodec/libaomenc.c
>> +++ b/libavcodec/libaomenc.c
>> @@ -55,6 +55,7 @@ struct FrameListData {
>>
>>  typedef struct AOMEncoderContext {
>>  AVClass *class;
>> +AVBSFContext *bsf;
>>  struct aom_codec_ctx encoder;
>>  struct aom_image rawimg;
>>  struct aom_fixed_buf twopass_stats;
>> @@ -202,6 +203,7 @@ static av_cold int aom_free(AVCodecContext *avctx)
>>  av_freep(&ctx->twopass_stats.buf);
>>  av_freep(&avctx->stats_out);
>>  free_frame_list(ctx->coded_frame_list);
>> +av_bsf_free(&ctx->bsf);
>>  return 0;
>>  }
>>
>> @@ -463,6 +465,28 @@ static av_cold int aom_init(AVCodecContext *avctx,
>>  if (!cpb_props)
>>  return AVERROR(ENOMEM);
>>
>> +if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
>> +const AVBitStreamFilter *filter =
>> av_bsf_get_by_name("extract_extradata");
>> +int ret;
>> +
>> +if (!filter) {
>> +av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream
>> filter "
>> +   "not found. This is a bug, please report it.\n");
>> +return AVERROR_BUG;
>> +}
>> +ret = av_bsf_alloc(filter, &ctx->bsf);
>> +if (ret < 0)
>> +return ret;
>> +
>> +ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
>> +if (ret < 0)
>> +   return ret;
>> +
>> +ret = av_bsf_init(ctx->bsf);
>> +if (ret < 0)
>> +   return ret;
>> +}
>> +
>>  if (enccfg.rc_end_usage == AOM_CBR ||
>>  enccfg.g_pass != AOM_RC_ONE_PASS) {
>>  cpb_props->max_bitrate = avctx->rc_max_rate;
>> @@ -494,6 +518,7 @@ static inline void cx_pktcpy(struct FrameListData *dst,
>>  static int storeframe(AVCodecContext *avctx, struct FrameListData
>> *cx_frame,
>>AVPacket *pkt)
>>  {
>> +AOMContext *ctx = avctx->priv_data;
>>  int ret = ff_alloc

Re: [FFmpeg-devel] [PATCH 5/5] avformat/movenc: add support for AV1 streams

2018-07-09 Thread Hendrik Leppkes
On Tue, Jul 10, 2018 at 12:29 AM Baptiste Coudurier
 wrote:
>
> Hi James,
>
> On Mon, Jul 9, 2018 at 11:26 AM, James Almer  wrote:
>
> [...]
>
>
> > @@ -5438,7 +5461,7 @@ int ff_mov_write_packet(AVFormatContext *s,
> > AVPacket *pkt)
> >  av_log(s, AV_LOG_WARNING, "pts has no value\n");
> >  pkt->pts = pkt->dts;
> >  }
> > -if (pkt->dts != pkt->pts)
> > +if (pkt->dts != pkt->pts && par->codec_id != AV_CODEC_ID_AV1)
> >  trk->flags |= MOV_TRACK_CTTS;
> >  trk->cluster[trk->entry].cts   = pkt->pts - pkt->dts;
> >  trk->cluster[trk->entry].flags = 0;
> >
>
> [...]
>
> Interesting, is there a spec document that would explicitly mention that
> AV1 forbids "ctts" atom ?
>

The draft spec does:
https://aomediacodec.github.io/av1-isobmff/#sampleformat

Unlike many video standards, AV1 does not distinguish the display
order from the decoding order, but achieves similar effects by
grouping multiple frames within a sample. Therefore, composition
offsets are not used. In tracks using the AV1SampleEntry, the ctts box
and composition offsets in movie fragments SHALL NOT be used.

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


Re: [FFmpeg-devel] [PATCH 5/5] avformat/movenc: add support for AV1 streams

2018-07-09 Thread James Almer
On 7/9/2018 7:23 PM, Baptiste Coudurier wrote:
> Hi James,
> 
> On Mon, Jul 9, 2018 at 11:26 AM, James Almer  wrote:
> 
> [...]
> 
> 
>> @@ -5438,7 +5461,7 @@ int ff_mov_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>  av_log(s, AV_LOG_WARNING, "pts has no value\n");
>>  pkt->pts = pkt->dts;
>>  }
>> -if (pkt->dts != pkt->pts)
>> +if (pkt->dts != pkt->pts && par->codec_id != AV_CODEC_ID_AV1)
>>  trk->flags |= MOV_TRACK_CTTS;
>>  trk->cluster[trk->entry].cts   = pkt->pts - pkt->dts;
>>  trk->cluster[trk->entry].flags = 0;
>>
> 
> [...]
> 
> Interesting, is there a spec document that would explicitly mention that
> AV1 forbids "ctts" atom ?
> 
> Thanks!


Yes, https://aomediacodec.github.io/av1-isobmff/#sampleformat

"Unlike many video standards, AV1 does not distinguish the display order
from the decoding order, but achieves similar effects by grouping
multiple frames within a sample. Therefore, composition offsets are not
used. In tracks using the AV1SampleEntry, the ctts box and composition
offsets in movie fragments SHALL NOT be used. Similarly, the is_leading
flag, if used, SHALL be set to 0 or 2."
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/5] avformat/movenc: add support for AV1 streams

2018-07-09 Thread Baptiste Coudurier
Hi James,

On Mon, Jul 9, 2018 at 11:26 AM, James Almer  wrote:

[...]


> @@ -5438,7 +5461,7 @@ int ff_mov_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>  av_log(s, AV_LOG_WARNING, "pts has no value\n");
>  pkt->pts = pkt->dts;
>  }
> -if (pkt->dts != pkt->pts)
> +if (pkt->dts != pkt->pts && par->codec_id != AV_CODEC_ID_AV1)
>  trk->flags |= MOV_TRACK_CTTS;
>  trk->cluster[trk->entry].cts   = pkt->pts - pkt->dts;
>  trk->cluster[trk->entry].flags = 0;
>

[...]

Interesting, is there a spec document that would explicitly mention that
AV1 forbids "ctts" atom ?

Thanks!

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


Re: [FFmpeg-devel] [PATCH 3/5] avcodec/libaomenc: export Sequence Header and Metadata OBUs as extradata

2018-07-09 Thread Niki Bowe
Hi James,
I passed along your wish for aom_codec_get_global_headers().
Tom created this bug for tracking:
https://bugs.chromium.org/p/aomedia/issues/detail?id=2012


On Mon, Jul 9, 2018 at 11:29 AM James Almer  wrote:

> aom_codec_get_global_headers() is not implemented as of libaom 1.0.0
> for AV1, so we're forced to extract the relevant header OBUs from the
> first packet and propagate them as packet side data for now.
>
> Signed-off-by: James Almer 
> ---
> This is far from ideal. Whereas the mp4 muxer can handle extradata
> propagated as packet side data without issues, the Matroska one can't
> feasibly do it since it would require to reserve space for it, and we
> don't know just how big the resulting extradata can be as it may have
> an arbitrary amount of OBUs.
>
> libaom should ideally implement aom_codec_get_global_headers() for
> AV1 (Which is clearly inspired by similar functionality in libx264
> and other encoders, and can be used before any kind of image data is
> sent to the encoder), so lobby is welcome :p
>
>  configure  |  1 +
>  libavcodec/libaomenc.c | 41 +
>  2 files changed, 42 insertions(+)
>
> diff --git a/configure b/configure
> index 1066df6621..a76dd06736 100755
> --- a/configure
> +++ b/configure
> @@ -3046,6 +3046,7 @@ hevc_videotoolbox_encoder_deps="pthreads"
>  hevc_videotoolbox_encoder_select="videotoolbox_encoder"
>  libaom_av1_decoder_deps="libaom"
>  libaom_av1_encoder_deps="libaom"
> +libaom_av1_encoder_select="extract_extradata_bsf"
>  libcelt_decoder_deps="libcelt"
>  libcodec2_decoder_deps="libcodec2"
>  libcodec2_encoder_deps="libcodec2"
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 41b05dc1c0..0b75dc139c 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -55,6 +55,7 @@ struct FrameListData {
>
>  typedef struct AOMEncoderContext {
>  AVClass *class;
> +AVBSFContext *bsf;
>  struct aom_codec_ctx encoder;
>  struct aom_image rawimg;
>  struct aom_fixed_buf twopass_stats;
> @@ -202,6 +203,7 @@ static av_cold int aom_free(AVCodecContext *avctx)
>  av_freep(&ctx->twopass_stats.buf);
>  av_freep(&avctx->stats_out);
>  free_frame_list(ctx->coded_frame_list);
> +av_bsf_free(&ctx->bsf);
>  return 0;
>  }
>
> @@ -463,6 +465,28 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  if (!cpb_props)
>  return AVERROR(ENOMEM);
>
> +if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
> +const AVBitStreamFilter *filter =
> av_bsf_get_by_name("extract_extradata");
> +int ret;
> +
> +if (!filter) {
> +av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream
> filter "
> +   "not found. This is a bug, please report it.\n");
> +return AVERROR_BUG;
> +}
> +ret = av_bsf_alloc(filter, &ctx->bsf);
> +if (ret < 0)
> +return ret;
> +
> +ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
> +if (ret < 0)
> +   return ret;
> +
> +ret = av_bsf_init(ctx->bsf);
> +if (ret < 0)
> +   return ret;
> +}
> +
>  if (enccfg.rc_end_usage == AOM_CBR ||
>  enccfg.g_pass != AOM_RC_ONE_PASS) {
>  cpb_props->max_bitrate = avctx->rc_max_rate;
> @@ -494,6 +518,7 @@ static inline void cx_pktcpy(struct FrameListData *dst,
>  static int storeframe(AVCodecContext *avctx, struct FrameListData
> *cx_frame,
>AVPacket *pkt)
>  {
> +AOMContext *ctx = avctx->priv_data;
>  int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz, 0);
>  if (ret < 0) {
>  av_log(avctx, AV_LOG_ERROR,
> @@ -505,6 +530,22 @@ static int storeframe(AVCodecContext *avctx, struct
> FrameListData *cx_frame,
>
>  if (!!(cx_frame->flags & AOM_FRAME_IS_KEY))
>  pkt->flags |= AV_PKT_FLAG_KEY;
> +
> +if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
> +ret = av_bsf_send_packet(ctx->bsf, pkt);
> +if (ret < 0) {
> +av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
> +   "failed to send input packet\n");
> +return ret;
> +}
> +ret = av_bsf_receive_packet(ctx->bsf, pkt);
> +
> +if (ret < 0) {
> +av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
> +   "failed to receive output packet\n");
> +return ret;
> +}
> +}
>  return pkt->size;
>  }
>
> --
> 2.18.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


-- 

Nikolas Bowe |  SWE |  nb...@google.com |  408-565-5137
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/movenc: Write version 2 of audio atom if channels is not known

2018-07-09 Thread Michael Niedermayer
On Sun, Jul 08, 2018 at 12:54:25AM +0200, Michael Niedermayer wrote:
> The version 1 needs the channel count and would divide by 0
> Fixes: division by 0
> Fixes: fpe_movenc.c_1108_1.ogg
> Fixes: fpe_movenc.c_1108_2.ogg
> Fixes: fpe_movenc.c_1108_3.wav
> 
> Found-by: #CHEN HONGXU# 
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/movenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply


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

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.


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


Re: [FFmpeg-devel] [PATCH 5/5] avformat/movenc: add support for AV1 streams

2018-07-09 Thread James Almer
On 7/9/2018 6:08 PM, Michael Niedermayer wrote:
> On Mon, Jul 09, 2018 at 03:26:54PM -0300, James Almer wrote:
>> Signed-off-by: James Almer 
>> ---
>> ff_av1_filter_obus() could eventually be replaced by an autoinserted
>> filter_units bsf, assuming it doesn't slow down the muxing process
>> too much (CBS is fast reading packets, but not so much assembling and
>> writing packets).
>> ff_isom_write_av1c() however can't be replaced given filter_units
>> doesn't handle extradata (either codecpar or packet side data).
>>
> [...]
>> diff --git a/libavformat/av1.h b/libavformat/av1.h
>> new file mode 100644
>> index 00..733034c12d
>> --- /dev/null
>> +++ b/libavformat/av1.h
>> @@ -0,0 +1,70 @@
>> +/*
>> + * AV1 helper functions for muxers
>> + *
>> + * 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 AVFORMAT_AV1_H
>> +#define AVFORMAT_AV1_H
>> +
>> +#include 
>> +
>> +#include "avio.h"
>> +
>> +/**
>> + * Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and 
>> write
>> + * the resulting bitstream to the provided AVIOContext.
>> + *
>> + * @param pb pointer to the AVIOContext where the filtered bitstream shall 
>> be
>> + *   written
>> + * @param buf input data buffer
>> + * @param size size of the input data buffer
>> + *
>> + * @return the amount of bytes written in case of success, a negative 
>> AVERROR
>> + * code in case of failure
>> + */
>> +int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size);
>> +
>> +/**
>> + * Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and 
>> write
>> + * the resulting bitstream to a newly allocated data buffer.
>> + *
>> + * @param pb pointer to the AVIOContext where the filtered bitstream shall 
>> be
>> + *   written
>> + * @param buf input data buffer
> 
>> + * @param out pointer to pointer that will hold the allocated data buffer
>> + * @param size size of the input data buffer. The size of the resulting 
>> output
>> +   data buffer will be written here
>> + *
>> + * @return the amount of bytes written in case of success, a negative 
>> AVERROR
>> + * code in case of failure
> 
> this leaves it unspecified what happens to out/size in case of errors
> are they 0/null are they undefined, left as before ?

Depending on when in the function an error happens, i will either be
untouched or *out will be set to NULL.
I can make it so the latter always happens in case of failure and
document it as such if that's preferred, but the current callers pass a
pointer to a pointer set to NULL, so that's already guaranteed.

This is based on ff_avc_parse_nal_units_buf() and
ff_hevc_annexb2mp4_buf(), for that matter, so those could also be fixed.

> 
> 
>> + */
>> +int ff_av1_filter_obus_buf(const uint8_t *buf, uint8_t **out, int *size);
>> +
>> +/**
>> + * Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided
>> + * AVIOContext.
>> + *
>> + * @param pb pointer to the AVIOContext where the hvcC shall be written
>> + * @param buf input data buffer
> 
>> + * @param size size of the input data buffer
> 
> very minor nitpick but you could add "in bytes"

Sure.

> 
> 
>> + *
>> + * @return 0 in case of success, a negative AVERROR code in case of failure
> 
> if >= 0 is defined as success then its possible to use this in the future
> for some additional information without the need to review all callers

I can make this change, but as you well mention below it doesn't really
matter since it's internal, so anything defined now can be changed later.

> 
> i guess most of this doesnt matter much as its not public API ...
> 
> 
> 
> [...]
> 
> 
> 
> ___
> 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 5/5] avformat/movenc: add support for AV1 streams

2018-07-09 Thread Michael Niedermayer
On Mon, Jul 09, 2018 at 03:26:54PM -0300, James Almer wrote:
> Signed-off-by: James Almer 
> ---
> ff_av1_filter_obus() could eventually be replaced by an autoinserted
> filter_units bsf, assuming it doesn't slow down the muxing process
> too much (CBS is fast reading packets, but not so much assembling and
> writing packets).
> ff_isom_write_av1c() however can't be replaced given filter_units
> doesn't handle extradata (either codecpar or packet side data).
> 
[...]
> diff --git a/libavformat/av1.h b/libavformat/av1.h
> new file mode 100644
> index 00..733034c12d
> --- /dev/null
> +++ b/libavformat/av1.h
> @@ -0,0 +1,70 @@
> +/*
> + * AV1 helper functions for muxers
> + *
> + * 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 AVFORMAT_AV1_H
> +#define AVFORMAT_AV1_H
> +
> +#include 
> +
> +#include "avio.h"
> +
> +/**
> + * Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and 
> write
> + * the resulting bitstream to the provided AVIOContext.
> + *
> + * @param pb pointer to the AVIOContext where the filtered bitstream shall be
> + *   written
> + * @param buf input data buffer
> + * @param size size of the input data buffer
> + *
> + * @return the amount of bytes written in case of success, a negative AVERROR
> + * code in case of failure
> + */
> +int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size);
> +
> +/**
> + * Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and 
> write
> + * the resulting bitstream to a newly allocated data buffer.
> + *
> + * @param pb pointer to the AVIOContext where the filtered bitstream shall be
> + *   written
> + * @param buf input data buffer

> + * @param out pointer to pointer that will hold the allocated data buffer
> + * @param size size of the input data buffer. The size of the resulting 
> output
> +   data buffer will be written here
> + *
> + * @return the amount of bytes written in case of success, a negative AVERROR
> + * code in case of failure

this leaves it unspecified what happens to out/size in case of errors
are they 0/null are they undefined, left as before ?


> + */
> +int ff_av1_filter_obus_buf(const uint8_t *buf, uint8_t **out, int *size);
> +
> +/**
> + * Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided
> + * AVIOContext.
> + *
> + * @param pb pointer to the AVIOContext where the hvcC shall be written
> + * @param buf input data buffer

> + * @param size size of the input data buffer

very minor nitpick but you could add "in bytes"


> + *
> + * @return 0 in case of success, a negative AVERROR code in case of failure

if >= 0 is defined as success then its possible to use this in the future
for some additional information without the need to review all callers

i guess most of this doesnt matter much as its not public API ...



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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


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


Re: [FFmpeg-devel] How to wire asm to the makefile

2018-07-09 Thread James Almer
On 7/9/2018 1:29 AM, Book Moons wrote:
> Hello,
> 
> I have a Power optimized function in asm for an upcoming patch. Having some 
> trouble figuring out how to wire it up to the makefiles / build system. Are 
> there any docs on how to do that?
> 
> The only other example of Power asm seems to be libavcodec/ppc/fft_altivec.S. 
> That's simply appended to the OBJS-yes variable:
> 
> OBJS-$(CONFIG_FFT)   += ppc/fft_init.o\
>   ppc/fft_altivec.o \
>   ppc/fft_vsx.o
> 
> Doing the same thing in the relevant makefile (for libswscale/ppc) doesn't 
> seem to work.
> 
> OBJS += ppc/swscale_altivec.o \
> ppc/yuv2rgb_altivec.o   \
> ppc/yuv2yuv_altivec.o   \
> ppc/hScale8To15_vsx.o
> 
> It looks for a .c file. Building with that change gives this error:
> 
>> make: *** No rule to make target 'src/libswscale/ppc/hScale8To15_vsx.c', 
>> needed by 'libswscale/ppc/hScale8To15_vsx.o'. Stop.

First, always make sure to clean the build folder. Rogue .d files
(created by the build system) usually result in gnu make assuming wrong
dependencies if you made some changes to the source tree after they were
created.

That aside, are you sure your file is called hScale8To15_vsx.S and not
hScale8To15_vsx.s? The build system expects .S, not .s
Otherwise, I can't say why it looks for a .c file when in libavcodec it
handles fft_altivec.S just fine.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Use channel count if channel layout is undefined

2018-07-09 Thread Michael Niedermayer
On Mon, Jul 09, 2018 at 01:55:37PM +0100, Marcin Gorzel wrote:
> Thank you for your comments Michael and apologies if my commit message was
> inadequate (I am new to this forum and this is my first patch).
> 
> The bug can be reproduced when downmixing audio with more than 8 channels,
> for example:
> 
> ./ffmpeg -i input_9ch.wav -filter:a:0
> pan="6c|c0=0.166*c0+0.166*c6|c1=c1|c2=c2|c3=c3|c4=c4|c5=c5" -y
> output_6ch.wav
> 
> The result is noisy output in the first channel.
> 
> #6790 applies the fix to the swr_set_matrix() method but a similar fix
> needs to be applied to the swri_rematrix_init()
> and swri_rematrix_init_x86() as well.
> 

> Since currently the number of in/out channels is determined based on the
> channel layout (av_get_channel_layout_nb_channels(s->in_ch_layout)) my
> patch first checks if the channel layout is non-zero, and if it 0, then it
> falls back to using the (user) channel count instead.

theres the layout and the channel count

before  one is checked and used and if possible and if not the other
afterwards  one is checked and used and if possible and if not the other

the patch seems to just check the other field
I dont know how to match this up with the explanation of what this patch
does.
Quite possibly iam missing something 


> 
> Re. FFMIN: Agreed. I could add checks if the channel count is within
> supported range. For example if s->user_out_ch_count < SWR_CH_MAX and
> s->user_in_ch_count
> < SWR_CH_MAX inside swr_init() method (for example, similarly as is done in
> swresample.c:178)?

Each field has a defined range in libswresample/options.c
the AVOption code checks this when setting the field

If the value in the table is wrong, thats what should be fixed.
If something sets it ignoring the value, that code should be fixed.
i dont think we should add a check without first understanding what
sets it outside the range





> 
> Thanks,
> 
> Marcin
> 
> On Sat, Jul 7, 2018 at 2:04 AM Michael Niedermayer 
> wrote:
> 
> > On Fri, Jul 06, 2018 at 03:15:58PM +0100, Marcin Gorzel wrote:
> > > Rematrixing supports up to 64 channels but there is only a limited
> > number of channel layouts defined. Currently, in/out channel count is
> > obtained from the channel layout so if the channel layout is undefined
> > (e.g. for 9, 10, 11 channels etc.) the in/out channel count will be 0 and
> > the rematrixing will fail. This change adds a check if the channel layout
> > is non-zero, and if not, prefers to use the in|out_ch_count instead. This
> > seems to be related to ticket #6790.
> > > ---
> > >  libswresample/rematrix.c  | 18 --
> > >  libswresample/x86/rematrix_init.c |  8 ++--
> > >  2 files changed, 18 insertions(+), 8 deletions(-)
> >
> > Iam not completely sure what this is trying to do exactly
> > but the commit message inadequently describes it.
> >
> > #6790 is already fixed, the commit message doesnt explain how its related
> >
> > also the FFMIN is wrong. If the user provided a value outside
> > the supported range the code must have failed with an error
> > already or something is not working correctly.
> >
> > How can the bug this fixes be reproduced ?
> >
> > Thanks
> >
> > [...]
> >
> > --
> > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > I know you won't believe me, but the highest form of Human Excellence is
> > to question oneself and others. -- Socrates
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> 
> -- 
> 
> Marcin Gorzel |  Software Engineer |  gor...@google.com |
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


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


[FFmpeg-devel] [PATCH 0/5] AV1 support in mp4

2018-07-09 Thread James Almer
What the subject says.

There are a few comments in some of the patches as well.

James Almer (5):
  avcodec: add AV1 packet split API
  avcodec/extract_extradata: add support for AV1
  avcodec/libaomenc: export Sequence Header and Metadata OBUs as
extradata
  avformat/mov: add support for AV1 streams
  avformat/movenc: add support for AV1 streams

 configure  |   1 +
 libavcodec/Makefile|   2 +-
 libavcodec/av1.h   |  42 ++
 libavcodec/av1_parse.c | 103 +++
 libavcodec/av1_parse.h | 126 +
 libavcodec/extract_extradata_bsf.c |  80 ++
 libavcodec/libaomenc.c |  41 ++
 libavformat/Makefile   |   2 +-
 libavformat/av1.c  | 107 
 libavformat/av1.h  |  70 
 libavformat/isom.c |   1 +
 libavformat/mov.c  |  31 +++
 libavformat/movenc.c   |  36 +++--
 13 files changed, 633 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/av1.h
 create mode 100644 libavcodec/av1_parse.c
 create mode 100644 libavcodec/av1_parse.h
 create mode 100644 libavformat/av1.c
 create mode 100644 libavformat/av1.h

-- 
2.18.0

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


[FFmpeg-devel] [PATCH 5/5] avformat/movenc: add support for AV1 streams

2018-07-09 Thread James Almer
Signed-off-by: James Almer 
---
ff_av1_filter_obus() could eventually be replaced by an autoinserted
filter_units bsf, assuming it doesn't slow down the muxing process
too much (CBS is fast reading packets, but not so much assembling and
writing packets).
ff_isom_write_av1c() however can't be replaced given filter_units
doesn't handle extradata (either codecpar or packet side data).

 libavformat/Makefile |   2 +-
 libavformat/av1.c| 107 +++
 libavformat/av1.h|  70 
 libavformat/movenc.c |  36 ---
 4 files changed, 207 insertions(+), 8 deletions(-)
 create mode 100644 libavformat/av1.c
 create mode 100644 libavformat/av1.h

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 8fb075f06f..f2f3aabdc2 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -302,7 +302,7 @@ OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
 OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
 OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
 OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o 
replaygain.o
-OBJS-$(CONFIG_MOV_MUXER) += movenc.o avc.o hevc.o vpcc.o \
+OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vpcc.o 
\
 movenchint.o mov_chan.o rtp.o \
 movenccenc.o rawutils.o
 OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
diff --git a/libavformat/av1.c b/libavformat/av1.c
new file mode 100644
index 00..3b200176a5
--- /dev/null
+++ b/libavformat/av1.c
@@ -0,0 +1,107 @@
+/*
+ * AV1 helper functions for muxers
+ * Copyright (c) 2018 James Almer 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/mem.h"
+#include "libavcodec/av1.h"
+#include "libavcodec/av1_parse.h"
+#include "av1.h"
+#include "avio.h"
+
+int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
+{
+const uint8_t *end = buf + size;
+int64_t obu_size;
+int start_pos, type, temporal_id, spatial_id;
+
+size = 0;
+while (buf < end) {
+int ret = parse_obu_header(buf, end - buf, &obu_size, &start_pos,
+   &type, &temporal_id, &spatial_id);
+if (ret < 0)
+return ret;
+
+obu_size += start_pos;
+if (obu_size > INT_MAX)
+return AVERROR_INVALIDDATA;
+
+switch (type) {
+case AV1_OBU_TEMPORAL_DELIMITER:
+case AV1_OBU_REDUNDANT_FRAME_HEADER:
+case AV1_OBU_PADDING:
+break;
+default:
+avio_write(pb, buf, obu_size);
+size += obu_size;
+break;
+}
+buf += obu_size;
+}
+
+return size;
+}
+
+int ff_av1_filter_obus_buf(const uint8_t *buf, uint8_t **out, int *size)
+{
+AVIOContext *pb;
+int ret;
+
+ret = avio_open_dyn_buf(&pb);
+if (ret < 0)
+return ret;
+
+ret = ff_av1_filter_obus(pb, buf, *size);
+*size = avio_close_dyn_buf(pb, out);
+
+if (ret < 0)
+av_freep(out);
+
+return ret;
+}
+
+int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
+{
+int64_t obu_size;
+int start_pos, type, temporal_id, spatial_id;
+
+while (size > 0) {
+int ret = parse_obu_header(buf, size, &obu_size, &start_pos,
+   &type, &temporal_id, &spatial_id);
+if (ret < 0)
+return ret;
+
+obu_size += start_pos;
+if (obu_size > INT_MAX)
+return AVERROR_INVALIDDATA;
+
+switch (type) {
+case AV1_OBU_SEQUENCE_HEADER:
+case AV1_OBU_METADATA:
+avio_write(pb, buf, obu_size);
+size -= obu_size;
+break;
+default:
+break;
+}
+buf += obu_size;
+}
+
+return 0;
+}
diff --git a/libavformat/av1.h b/libavformat/av1.h
new file mode 100644
index 00..733034c12d
--- /dev/null
+++ b/libavformat/av1.h
@@ -0,0 +1,70 @@
+/*
+ * AV1 helper functions for muxers
+ *
+ * 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
+ * Licens

[FFmpeg-devel] [PATCH 4/5] avformat/mov: add support for AV1 streams

2018-07-09 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/isom.c |  1 +
 libavformat/mov.c  | 31 +++
 2 files changed, 32 insertions(+)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 2792371c25..ce66d1bcd4 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -188,6 +188,7 @@ const AVCodecTag ff_codec_movvideo_tags[] = {
 
 { AV_CODEC_ID_VP8,  MKTAG('v', 'p', '0', '8') }, /* VP8 */
 { AV_CODEC_ID_VP9,  MKTAG('v', 'p', '0', '9') }, /* VP9 */
+{ AV_CODEC_ID_AV1,  MKTAG('a', 'v', '0', '1') }, /* AV1 */
 
 { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', ' ') },
 { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') }, /* Apple MPEG-1 
Camcorder */
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1346ffe480..e8f9b5fede 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5182,6 +5182,36 @@ static int mov_read_tmcd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+static int mov_read_av1c(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVStream *st;
+int ret, version;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams - 1];
+
+if (atom.size < 5) {
+av_log(c->fc, AV_LOG_ERROR, "Empty AV1 Codec Configuration Box\n");
+return AVERROR_INVALIDDATA;
+}
+
+version = avio_r8(pb);
+if (version != 0) {
+av_log(c->fc, AV_LOG_WARNING, "Unknown AV1 Codec Configuration Box 
version %d\n", version);
+return 0;
+}
+avio_skip(pb, 3); /* flags */
+
+avio_skip(pb, 1); /* reserved, initial_presentation_delay_present, 
initial_presentation_delay_minus_one */
+
+ret = ff_get_extradata(c->fc, st->codecpar, pb, atom.size - 5);
+if (ret < 0)
+return ret;
+
+return 0;
+}
+
 static int mov_read_vpcc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
@@ -6619,6 +6649,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('A','A','L','P'), mov_read_avid },
 { MKTAG('A','R','E','S'), mov_read_ares },
 { MKTAG('a','v','s','s'), mov_read_avss },
+{ MKTAG('a','v','1','C'), mov_read_av1c },
 { MKTAG('c','h','p','l'), mov_read_chpl },
 { MKTAG('c','o','6','4'), mov_read_stco },
 { MKTAG('c','o','l','r'), mov_read_colr },
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 1/5] avcodec: add AV1 packet split API

2018-07-09 Thread James Almer
Signed-off-by: James Almer 
---
I talked with Mark Thompson about AV1 parsing code in libavcodec and
he told me he prefered to keep everything within his upcoming CBS
implementation. I very much agree the eventual decoder and avparser
should use it given they will require deep bitstream parsing, but
for the upcoming changes i only require to split the OBUs in a packet
(Which require minimal OBU header parsing to find where each one of
them start and end), so the overhead of parsing and writing full CBS
packets seem unnecesary.
This way i also have an inline function ready to be used in muxer
related libavformat code.

If there are still strong opinions about having AV1 parsing code in
avcodec separate from CBS, even if minimal, then I can reimplement
extract_extradata using the latter and move the header parsing code
to libavformat.

 libavcodec/av1_parse.c | 103 +
 libavcodec/av1_parse.h | 126 +
 2 files changed, 229 insertions(+)
 create mode 100644 libavcodec/av1_parse.c
 create mode 100644 libavcodec/av1_parse.h

diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
new file mode 100644
index 00..48feb9fb8a
--- /dev/null
+++ b/libavcodec/av1_parse.c
@@ -0,0 +1,103 @@
+/*
+ * AV1 common parsing code
+ *
+ * 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 "config.h"
+
+#include "libavutil/mem.h"
+
+#include "av1_parse.h"
+#include "bytestream.h"
+
+int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void 
*logctx)
+{
+int64_t obu_size;
+int start_pos, type, temporal_id, spatial_id;
+
+int ret = parse_obu_header(buf, length, &obu_size, &start_pos,
+   &type, &temporal_id, &spatial_id);
+if (ret < 0)
+return ret;
+
+if (obu_size > INT_MAX / 8 || obu_size < 0)
+return AVERROR(ERANGE);
+
+obu->type= type;
+obu->temporal_id = temporal_id;
+obu->spatial_id  = spatial_id;
+
+length = obu_size + start_pos;
+
+obu->data = buf + start_pos;
+obu->size = obu_size;
+obu->raw_data = buf;
+obu->raw_size = length;
+
+ret = init_get_bits(&obu->gb, obu->data, obu->size * 8);
+if (ret < 0)
+return ret;
+
+av_log(logctx, AV_LOG_DEBUG,
+   "obu_type: %d, temporal_id: %d, spatial_id: %d, payload size: %d\n",
+   obu->type, obu->temporal_id, obu->spatial_id, obu->size);
+
+return length;
+}
+
+int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void 
*logctx)
+{
+GetByteContext bc;
+int consumed;
+
+bytestream2_init(&bc, buf, length);
+pkt->nb_obus = 0;
+
+while (bytestream2_get_bytes_left(&bc) > 0) {
+AV1OBU *obu;
+
+if (pkt->obus_allocated < pkt->nb_obus + 1) {
+int new_size = pkt->obus_allocated + 1;
+AV1OBU *tmp = av_realloc_array(pkt->obus, new_size, sizeof(*tmp));
+if (!tmp)
+return AVERROR(ENOMEM);
+
+pkt->obus = tmp;
+memset(pkt->obus + pkt->obus_allocated, 0,
+   (new_size - pkt->obus_allocated) * sizeof(*tmp));
+pkt->obus_allocated = new_size;
+}
+obu = &pkt->obus[pkt->nb_obus];
+
+consumed = ff_av1_extract_obu(obu, bc.buffer, 
bytestream2_get_bytes_left(&bc), logctx);
+if (consumed < 0)
+return consumed;
+
+pkt->nb_obus++;
+
+bytestream2_skip(&bc, consumed);
+}
+
+return 0;
+}
+
+void ff_av1_packet_uninit(AV1Packet *pkt)
+{
+av_freep(&pkt->obus);
+pkt->obus_allocated = 0;
+}
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
new file mode 100644
index 00..84fc71c925
--- /dev/null
+++ b/libavcodec/av1_parse.h
@@ -0,0 +1,126 @@
+/*
+ * AV1 common parsing code
+ *
+ * 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
+ * MERCHANTA

[FFmpeg-devel] [PATCH 3/5] avcodec/libaomenc: export Sequence Header and Metadata OBUs as extradata

2018-07-09 Thread James Almer
aom_codec_get_global_headers() is not implemented as of libaom 1.0.0
for AV1, so we're forced to extract the relevant header OBUs from the
first packet and propagate them as packet side data for now.

Signed-off-by: James Almer 
---
This is far from ideal. Whereas the mp4 muxer can handle extradata
propagated as packet side data without issues, the Matroska one can't
feasibly do it since it would require to reserve space for it, and we
don't know just how big the resulting extradata can be as it may have
an arbitrary amount of OBUs.

libaom should ideally implement aom_codec_get_global_headers() for
AV1 (Which is clearly inspired by similar functionality in libx264
and other encoders, and can be used before any kind of image data is
sent to the encoder), so lobby is welcome :p

 configure  |  1 +
 libavcodec/libaomenc.c | 41 +
 2 files changed, 42 insertions(+)

diff --git a/configure b/configure
index 1066df6621..a76dd06736 100755
--- a/configure
+++ b/configure
@@ -3046,6 +3046,7 @@ hevc_videotoolbox_encoder_deps="pthreads"
 hevc_videotoolbox_encoder_select="videotoolbox_encoder"
 libaom_av1_decoder_deps="libaom"
 libaom_av1_encoder_deps="libaom"
+libaom_av1_encoder_select="extract_extradata_bsf"
 libcelt_decoder_deps="libcelt"
 libcodec2_decoder_deps="libcodec2"
 libcodec2_encoder_deps="libcodec2"
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 41b05dc1c0..0b75dc139c 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -55,6 +55,7 @@ struct FrameListData {
 
 typedef struct AOMEncoderContext {
 AVClass *class;
+AVBSFContext *bsf;
 struct aom_codec_ctx encoder;
 struct aom_image rawimg;
 struct aom_fixed_buf twopass_stats;
@@ -202,6 +203,7 @@ static av_cold int aom_free(AVCodecContext *avctx)
 av_freep(&ctx->twopass_stats.buf);
 av_freep(&avctx->stats_out);
 free_frame_list(ctx->coded_frame_list);
+av_bsf_free(&ctx->bsf);
 return 0;
 }
 
@@ -463,6 +465,28 @@ static av_cold int aom_init(AVCodecContext *avctx,
 if (!cpb_props)
 return AVERROR(ENOMEM);
 
+if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
+const AVBitStreamFilter *filter = 
av_bsf_get_by_name("extract_extradata");
+int ret;
+
+if (!filter) {
+av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream filter "
+   "not found. This is a bug, please report it.\n");
+return AVERROR_BUG;
+}
+ret = av_bsf_alloc(filter, &ctx->bsf);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
+if (ret < 0)
+   return ret;
+
+ret = av_bsf_init(ctx->bsf);
+if (ret < 0)
+   return ret;
+}
+
 if (enccfg.rc_end_usage == AOM_CBR ||
 enccfg.g_pass != AOM_RC_ONE_PASS) {
 cpb_props->max_bitrate = avctx->rc_max_rate;
@@ -494,6 +518,7 @@ static inline void cx_pktcpy(struct FrameListData *dst,
 static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
   AVPacket *pkt)
 {
+AOMContext *ctx = avctx->priv_data;
 int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz, 0);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR,
@@ -505,6 +530,22 @@ static int storeframe(AVCodecContext *avctx, struct 
FrameListData *cx_frame,
 
 if (!!(cx_frame->flags & AOM_FRAME_IS_KEY))
 pkt->flags |= AV_PKT_FLAG_KEY;
+
+if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
+ret = av_bsf_send_packet(ctx->bsf, pkt);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
+   "failed to send input packet\n");
+return ret;
+}
+ret = av_bsf_receive_packet(ctx->bsf, pkt);
+
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
+   "failed to receive output packet\n");
+return ret;
+}
+}
 return pkt->size;
 }
 
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 2/5] avcodec/extract_extradata: add support for AV1

2018-07-09 Thread James Almer
Global header OBUs can be exported straight out of containers like
ISOBMFF and Matroska, but for the rest (IVF, AV1 Annex-B
encapsulation, and of course raw AV1 bitstreams) this is required.

Signed-off-by: James Almer 
---
 libavcodec/Makefile|  2 +-
 libavcodec/av1.h   | 42 
 libavcodec/extract_extradata_bsf.c | 80 ++
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/av1.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 67b2626fc0..2d4bc48dab 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1046,7 +1046,7 @@ 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
+ av1_parse.o h2645_parse.o
 OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
 OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
diff --git a/libavcodec/av1.h b/libavcodec/av1.h
new file mode 100644
index 00..c989b69974
--- /dev/null
+++ b/libavcodec/av1.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AV1 common definitions
+ */
+
+#ifndef AVCODEC_AV1_H
+#define AVCODEC_AV1_H
+
+// OBU types (section 6.2.2).
+typedef enum {
+// 0 reserved.
+AV1_OBU_SEQUENCE_HEADER= 1,
+AV1_OBU_TEMPORAL_DELIMITER = 2,
+AV1_OBU_FRAME_HEADER   = 3,
+AV1_OBU_TILE_GROUP = 4,
+AV1_OBU_METADATA   = 5,
+AV1_OBU_FRAME  = 6,
+AV1_OBU_REDUNDANT_FRAME_HEADER = 7,
+AV1_OBU_TILE_LIST  = 8,
+// 9-14 reserved.
+AV1_OBU_PADDING= 15,
+} AV1_OBU_Type;
+
+#endif /* AVCODEC_AV1_H */
diff --git a/libavcodec/extract_extradata_bsf.c 
b/libavcodec/extract_extradata_bsf.c
index 082b3e749b..1184ef2a04 100644
--- a/libavcodec/extract_extradata_bsf.c
+++ b/libavcodec/extract_extradata_bsf.c
@@ -24,6 +24,8 @@
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
+#include "av1.h"
+#include "av1_parse.h"
 #include "bsf.h"
 #include "h2645_parse.h"
 #include "h264.h"
@@ -36,6 +38,9 @@ typedef struct ExtractExtradataContext {
 int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
uint8_t **data, int *size);
 
+/* AV1 specifc fields */
+AV1Packet av1_pkt;
+
 /* H264/HEVC specifc fields */
 H2645Packet h2645_pkt;
 
@@ -52,6 +57,78 @@ static int val_in_array(const int *arr, int len, int val)
 return 0;
 }
 
+static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
+ uint8_t **data, int *size)
+{
+static const int extradata_obu_types[] = {
+AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA,
+};
+ExtractExtradataContext *s = ctx->priv_data;
+
+int extradata_size = 0, filtered_size = 0;
+int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
+int i, ret = 0;
+
+ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
+if (ret < 0)
+return ret;
+
+for (i = 0; i < s->av1_pkt.nb_obus; i++) {
+AV1OBU *obu = &s->av1_pkt.obus[i];
+if (val_in_array(extradata_obu_types, nb_extradata_obu_types, 
obu->type)) {
+extradata_size += obu->raw_size;
+} else if (s->remove) {
+filtered_size += obu->raw_size;
+}
+}
+
+if (extradata_size) {
+AVBufferRef *filtered_buf;
+uint8_t *extradata, *filtered_data;
+
+if (s->remove) {
+filtered_buf = av_buffer_alloc(filtered_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
+if (!filtered_buf) {
+return AVERROR(ENOMEM);
+}
+memset(filtered_buf->data + filtered_size, 0, 
AV_INPUT_BUFFER_PADDING_SIZE);
+
+filtered_data = filtered_buf->data;
+}
+
+extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+if (!extradata) {
+ 

Re: [FFmpeg-devel] [PATCH] Use channel count if channel layout is undefined

2018-07-09 Thread Nicolas George
Marcin Gorzel (2018-07-09):
> ./ffmpeg -i input_9ch.wav -filter:a:0
> pan="6c|c0=0.166*c0+0.166*c6|c1=c1|c2=c2|c3=c3|c4=c4|c5=c5" -y
> output_6ch.wav
> 
> Without the patch, the output in the first channel (c0) is noise. After
> applying the patch, I can verify that two sine tones are mixed together and
> scaled properly.

Ok, so this is with an explicit matrix provided.

> Could you explain what you mean by "the actual layouts are necessary to build
> the matrix"?

When the matrix is not explicitly provided, lswr computes it. For that,
it needs the channel layout, because you do not mix a rear channel the
same way as a subwoofer. This patch absolutely needs to be tested under
these circumstances too.

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] Use channel count if channel layout is undefined

2018-07-09 Thread Marcin Gorzel
Hi Nicolas,


> Please remember to mention "lswr" or "libswresample" in the first line
> of the commit message.
>

Apologies, I will update the commit message.


> > Rematrixing supports up to 64 channels but there is only a limited
> > number of channel layouts defined. Currently, in/out channel count is
> > obtained from the channel layout so if the channel layout is undefined
> > (e.g. for 9, 10, 11 channels etc.) the in/out channel count will be 0
> > and the rematrixing will fail. This change adds a check if the channel
> > layout is non-zero, and if not, prefers to use the in|out_ch_count
> > instead. This seems to be related to ticket #6790.
>
> I do not understand how it can work: the actual layouts are necessary to
> build the matrix, otherwise it is not possible to know which channel
> needs to be mixed into which. Can you explain how this patch was tested?


I create a 9-channel wav file, with a different sine tone in each channel
(100Hz, 200Hz, 300Hz, ...).
I downmix it to 6 channels using the following command:

./ffmpeg -i input_9ch.wav -filter:a:0
pan="6c|c0=0.166*c0+0.166*c6|c1=c1|c2=c2|c3=c3|c4=c4|c5=c5" -y
output_6ch.wav

Without the patch, the output in the first channel (c0) is noise. After
applying the patch, I can verify that two sine tones are mixed together and
scaled properly.

Could you explain what you mean by "the actual layouts are necessary to build
the matrix"? In the case of input channel counts of 8 or more (16 is an
exception) the channel layout is 0, although the matrix is created
correctly? For example, based on the above example:

[Parsed_pan_0 @ 0x561d8777dbc0] [SWR @ 0x561d87787740] Using s16p
internally between filters
[Parsed_pan_0 @ 0x561d8777dbc0] o0 = 0.166 i0 + 0 i1 + 0 i2 + 0 i3 + 0 i4 +
0 i5 + 0.166 i6 + 0 i7 + 0 i8
[Parsed_pan_0 @ 0x561d8777dbc0] o1 = 0 i0 + 1 i1 + 0 i2 + 0 i3 + 0 i4 + 0
i5 + 0 i6 + 0 i7 + 0 i8
[Parsed_pan_0 @ 0x561d8777dbc0] o2 = 0 i0 + 0 i1 + 1 i2 + 0 i3 + 0 i4 + 0
i5 + 0 i6 + 0 i7 + 0 i8
[Parsed_pan_0 @ 0x561d8777dbc0] o3 = 0 i0 + 0 i1 + 0 i2 + 1 i3 + 0 i4 + 0
i5 + 0 i6 + 0 i7 + 0 i8
[Parsed_pan_0 @ 0x561d8777dbc0] o4 = 0 i0 + 0 i1 + 0 i2 + 0 i3 + 1 i4 + 0
i5 + 0 i6 + 0 i7 + 0 i8
[Parsed_pan_0 @ 0x561d8777dbc0] o5 = 0 i0 + 0 i1 + 0 i2 + 0 i3 + 0 i4 + 1
i5 + 0 i6 + 0 i7 + 0 i8
Output #0, wav, to 'output_6ch.wav':
  Metadata:
ISFT: Lavf58.17.101
Stream #0:0, 0, 1/48000: Audio: pcm_s16le ([1][0][0][0] / 0x0001),
48000 Hz, 5.1, s16, 4608 kb/s

Regards,

Marcin


-- 

Marcin Gorzel |  Software Engineer |  gor...@google.com |
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/avformat.h: Add av_stream_remove_side_data.

2018-07-09 Thread Jacob Trimble
On Tue, Jul 3, 2018 at 5:59 PM Michael Niedermayer
 wrote:
>
> On Tue, Jul 03, 2018 at 12:14:19PM -0700, Jacob Trimble wrote:
> > On Mon, Jul 2, 2018 at 6:07 PM Michael Niedermayer
> >  wrote:
> > >
> > > On Mon, Jun 25, 2018 at 04:03:32PM -0700, Jacob Trimble wrote:
> > > > Signed-off-by: Jacob Trimble 
> > > > ---
> > > >  libavformat/avformat.h |  8 
> > > >  libavformat/utils.c| 11 +++
> > > >  2 files changed, 19 insertions(+)
> > >
> > >
> > >
> > >
> > >
> > > >
> > > > diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> > > > index fdaffa5bf4..434c88837e 100644
> > > > --- a/libavformat/avformat.h
> > > > +++ b/libavformat/avformat.h
> > > > @@ -2167,6 +2167,14 @@ AVStream *avformat_new_stream(AVFormatContext 
> > > > *s, const AVCodec *c);
> > > >  int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType 
> > > > type,
> > > >  uint8_t *data, size_t size);
> > > >
> > > > +/**
> > > > + * Removes any existing side data of the given type.
> > > > + *
> > > > + * @param st stream
> > > > + * @param type side information type
> > > > + */
> > > > +void av_stream_remove_side_data(AVStream *st, enum 
> > > > AVPacketSideDataType type);
> > >
> > > What would use this and why ?
> > > The commit message does not explain this
> > >
> > > If side data is changing it probably should be put in AVPackets or 
> > > AVFrames
> > > not the stream.
> > >
> >
> > I am using this to removing the side data that contains the
> > AVEncryptionInitInfo objects once I handle them.  Since an MP4 file
> > can contain multiple pssh atoms, there can be multiple
> > AVEncryptionInitInfo structs.  To make it easier for me, I want to
> > remove the side data that contain them once I have handled them.  This
> > means that if the AVStream contains the side data, it is because of
> > new init info I haven't seen.  Since the pssh atoms are more "global"
> > it makes more sense to put them in the AVStream.
>
> I dont fully understand but
> If you intend to remove things while reading the "header" of a mp4 file
> these things probably should not be in side data to begin with but be
> internal to the demuxer.
>
> otherwise, after the header or outside the demuxer removal seems a "no go"
> but i may misunderstand what you intend to do. Please explain if iam
> totally off here with how i interpret this
>
> One simple API good vs. bad test btw should be to consider that theres
> a demuxer connected to a muxer.
> If this does not work to produce a equivalent file the API is not good
> for example if you change side data in the AVStream in the middle between
> outputing packets i would not expect the muxer to see this and thus not
> be able to reproduce this in the stored file.
>
> Also if you mess with the demxuers side data from outside, not only
> will this result in undefined behavior it also might be that you still
> need it when for example seeking back to the start
>
> again maybe i totally misunderstand what you intend here
>

I would expect the muxer to do what I am doing, it would remove the
side data when it handles the data so it doesn't have to keep a copy
of all the init data it has seen.

For example, consider converting fragmented MP4 into a different
fragmented MP4.  The pssh atoms can appear inside the fragments, so
the muxer should see the new pssh atoms and add them to the
current/next fragment while muxing.  The best way I see is to check if
the side data exists, handle it, and remove the side data.  The
alternative would be to convert the side data to the
AVEncryptionInitInfo struct at every step, then compare each element
against a copy the muxer has.  This is extremely slow and requires
storing the init data several different ways.

Another alternative would be to put the side data on the frames, but
this doesn't seem right either.  The init info is "header" data, so it
seems weird to put it on a random frame, and putting the data on every
frame would be more duplication and require the muxer/app to compare
them for every frame to detect new init info.

>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> The worst form of inequality is to try to make unequal things equal.
> -- Aristotle
> ___
> 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] Use channel count if channel layout is undefined

2018-07-09 Thread Nicolas George
Marcin Gorzel (2018-07-09):
> Subject: Re: [FFmpeg-devel] [PATCH] Use channel count if channel layout is 
> undefined

Please remember to mention "lswr" or "libswresample" in the first line
of the commit message.

> Rematrixing supports up to 64 channels but there is only a limited
> number of channel layouts defined. Currently, in/out channel count is
> obtained from the channel layout so if the channel layout is undefined
> (e.g. for 9, 10, 11 channels etc.) the in/out channel count will be 0
> and the rematrixing will fail. This change adds a check if the channel
> layout is non-zero, and if not, prefers to use the in|out_ch_count
> instead. This seems to be related to ticket #6790.

I do not understand how it can work: the actual layouts are necessary to
build the matrix, otherwise it is not possible to know which channel
needs to be mixed into which. Can you explain how this patch was tested?

Regards,

-- 
  Nicolas George


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


[FFmpeg-devel] [PATCH] Use channel count if channel layout is undefined

2018-07-09 Thread Marcin Gorzel
Rematrixing supports up to 64 channels but there is only a limited number of 
channel layouts defined. Currently, in/out channel count is obtained from the 
channel layout so if the channel layout is undefined (e.g. for 9, 10, 11 
channels etc.) the in/out channel count will be 0 and the rematrixing will 
fail. This change adds a check if the channel layout is non-zero, and if not, 
prefers to use the in|out_ch_count instead. This seems to be related to ticket 
#6790.
---
 libavcodec/utils.c|  1 +
 libswresample/rematrix.c  | 18 --
 libswresample/swresample.c| 10 ++
 libswresample/x86/rematrix_init.c |  8 ++--
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 59d41ccbb6..728f2b3355 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -674,6 +674,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 av_freep(&avctx->subtitle_header);
 
 if (avctx->channels > FF_SANE_NB_CHANNELS) {
+av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d.\n", 
avctx->channels);
 ret = AVERROR(EINVAL);
 goto free_and_end;
 }
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 8227730056..8c9fbf3804 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -69,10 +69,12 @@ int swr_set_matrix(struct SwrContext *s, const double 
*matrix, int stride)
 return AVERROR(EINVAL);
 memset(s->matrix, 0, sizeof(s->matrix));
 memset(s->matrix_flt, 0, sizeof(s->matrix_flt));
-nb_in = (s->user_in_ch_count > 0) ? s->user_in_ch_count :
-av_get_channel_layout_nb_channels(s->user_in_ch_layout);
-nb_out = (s->user_out_ch_count > 0) ? s->user_out_ch_count :
-av_get_channel_layout_nb_channels(s->user_out_ch_layout);
+nb_in = s->user_in_ch_layout != 0
+? av_get_channel_layout_nb_channels(s->user_in_ch_layout)
+: s->user_in_ch_count;
+nb_out = s->user_out_ch_layout != 0
+? av_get_channel_layout_nb_channels(s->user_out_ch_layout)
+: s->user_out_ch_count;
 for (out = 0; out < nb_out; out++) {
 for (in = 0; in < nb_in; in++)
 s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in];
@@ -384,8 +386,12 @@ av_cold static int auto_matrix(SwrContext *s)
 
 av_cold int swri_rematrix_init(SwrContext *s){
 int i, j;
-int nb_in  = av_get_channel_layout_nb_channels(s->in_ch_layout);
-int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
+int nb_in  = s->in_ch_layout != 0
+? av_get_channel_layout_nb_channels(s->in_ch_layout)
+: s->user_in_ch_count;
+int nb_out = s->out_ch_layout != 0
+? av_get_channel_layout_nb_channels(s->out_ch_layout)
+: s->user_out_ch_count;
 
 s->mix_any_f = NULL;
 
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 5bd39caac4..ecb9d97bc9 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -168,6 +168,16 @@ av_cold int swr_init(struct SwrContext *s){
 s-> in.ch_count  = s->  user_in_ch_count;
 s->used_ch_count = s->user_used_ch_count;
 
+if(s->user_out_ch_count > SWR_CH_MAX) {
+av_log(s, AV_LOG_ERROR, "Output channel count %d is unsupported.\n", 
s->user_out_ch_count);
+return AVERROR(EINVAL);
+}
+
+if(s->user_in_ch_count > SWR_CH_MAX) {
+av_log(s, AV_LOG_ERROR, "Input channel count %d is unsupported.\n", 
s->user_in_ch_count);
+return AVERROR(EINVAL);
+}
+
 s-> in_ch_layout = s-> user_in_ch_layout;
 s->out_ch_layout = s->user_out_ch_layout;
 
diff --git a/libswresample/x86/rematrix_init.c 
b/libswresample/x86/rematrix_init.c
index d71b41a73e..a6ae074926 100644
--- a/libswresample/x86/rematrix_init.c
+++ b/libswresample/x86/rematrix_init.c
@@ -33,8 +33,12 @@ D(int16, sse2)
 av_cold int swri_rematrix_init_x86(struct SwrContext *s){
 #if HAVE_X86ASM
 int mm_flags = av_get_cpu_flags();
-int nb_in  = av_get_channel_layout_nb_channels(s->in_ch_layout);
-int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
+int nb_in  = s->in_ch_layout != 0
+? av_get_channel_layout_nb_channels(s->in_ch_layout)
+: s->user_in_ch_count;
+int nb_out = s->out_ch_layout != 0
+? av_get_channel_layout_nb_channels(s->out_ch_layout)
+: s->user_out_ch_count;
 int num= nb_in * nb_out;
 int i,j;
 
-- 
2.18.0.203.gfac676dfb9-goog

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


Re: [FFmpeg-devel] [PATCH] Use channel count if channel layout is undefined

2018-07-09 Thread Marcin Gorzel
Thank you for your comments Michael and apologies if my commit message was
inadequate (I am new to this forum and this is my first patch).

The bug can be reproduced when downmixing audio with more than 8 channels,
for example:

./ffmpeg -i input_9ch.wav -filter:a:0
pan="6c|c0=0.166*c0+0.166*c6|c1=c1|c2=c2|c3=c3|c4=c4|c5=c5" -y
output_6ch.wav

The result is noisy output in the first channel.

#6790 applies the fix to the swr_set_matrix() method but a similar fix
needs to be applied to the swri_rematrix_init()
and swri_rematrix_init_x86() as well.

Since currently the number of in/out channels is determined based on the
channel layout (av_get_channel_layout_nb_channels(s->in_ch_layout)) my
patch first checks if the channel layout is non-zero, and if it 0, then it
falls back to using the (user) channel count instead.

Re. FFMIN: Agreed. I could add checks if the channel count is within
supported range. For example if s->user_out_ch_count < SWR_CH_MAX and
s->user_in_ch_count
< SWR_CH_MAX inside swr_init() method (for example, similarly as is done in
swresample.c:178)?

Thanks,

Marcin

On Sat, Jul 7, 2018 at 2:04 AM Michael Niedermayer 
wrote:

> On Fri, Jul 06, 2018 at 03:15:58PM +0100, Marcin Gorzel wrote:
> > Rematrixing supports up to 64 channels but there is only a limited
> number of channel layouts defined. Currently, in/out channel count is
> obtained from the channel layout so if the channel layout is undefined
> (e.g. for 9, 10, 11 channels etc.) the in/out channel count will be 0 and
> the rematrixing will fail. This change adds a check if the channel layout
> is non-zero, and if not, prefers to use the in|out_ch_count instead. This
> seems to be related to ticket #6790.
> > ---
> >  libswresample/rematrix.c  | 18 --
> >  libswresample/x86/rematrix_init.c |  8 ++--
> >  2 files changed, 18 insertions(+), 8 deletions(-)
>
> Iam not completely sure what this is trying to do exactly
> but the commit message inadequently describes it.
>
> #6790 is already fixed, the commit message doesnt explain how its related
>
> also the FFMIN is wrong. If the user provided a value outside
> the supported range the code must have failed with an error
> already or something is not working correctly.
>
> How can the bug this fixes be reproduced ?
>
> Thanks
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I know you won't believe me, but the highest form of Human Excellence is
> to question oneself and others. -- Socrates
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


-- 

Marcin Gorzel |  Software Engineer |  gor...@google.com |
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavfi/avgblur_opencl: fix using uninitialized value

2018-07-09 Thread Danil Iashchenko
Fixed using uninitialized value "global_work[0]" when calling "av_log".

---
 libavfilter/vf_avgblur_opencl.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_opencl.c
index d1d3eb1..772b14e 100644
--- a/libavfilter/vf_avgblur_opencl.c
+++ b/libavfilter/vf_avgblur_opencl.c
@@ -215,10 +215,6 @@ static int avgblur_opencl_filter_frame(AVFilterLink 
*inlink, AVFrame *input)
 radius_y = 0;
 }
 
-av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
-   "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
-   p, global_work[0], global_work[1]);
-
 for (i = 0; i < ctx->power[p]; i++) {
 CL_SET_KERNEL_ARG(ctx->kernel_horiz, 0, cl_mem, &inter);
 CL_SET_KERNEL_ARG(ctx->kernel_horiz, 1, cl_mem, i == 0 ? &src : 
&dst);
@@ -233,6 +229,10 @@ static int avgblur_opencl_filter_frame(AVFilterLink 
*inlink, AVFrame *input)
 if (err < 0)
 goto fail;
 
+av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
+   "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
+   p, global_work[0], global_work[1]);
+
 cle = clEnqueueNDRangeKernel(ctx->command_queue, 
ctx->kernel_horiz, 2, NULL,
  global_work, NULL,
  0, NULL, NULL);
-- 
2.7.4

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: improve compute after_init_list_dur

2018-07-09 Thread Steven Liu
fix ticket: 7305
vs->sequence - hls->start_sequence - vs->nb_entries is the
after_init_list_dur fragment numbers
fix the wrong compute way vs->sequence - vs->nb_entries

Signed-off-by: Steven Liu 
---
 libavformat/hlsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 2268f898b0..35a26e8875 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2178,7 +2178,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time 
> 0) {
 /* reset end_pts, hls->recording_time at end of the init hls list */
 int init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE;
-int after_init_list_dur = (vs->sequence - vs->nb_entries ) * hls->time 
* AV_TIME_BASE;
+int after_init_list_dur = (vs->sequence - hls->start_sequence - 
vs->nb_entries ) * (hls->time * AV_TIME_BASE);
 hls->recording_time = hls->time * AV_TIME_BASE;
 end_pts = init_list_dur + after_init_list_dur ;
 }
-- 
2.15.2 (Apple Git-101.1)



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