Re: [FFmpeg-devel] [PATCH 7/30] avformat/matroskaenc: Avoid allocations for SeekHead

2020-03-05 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> On Fri, Feb 28, 2020 at 6:10 AM Andreas Rheinhardt <
> andreas.rheinha...@gmail.com> wrote:
> 
>> On Tue, Feb 25, 2020 at 2:24 PM Andreas Rheinhardt <
>> andreas.rheinha...@gmail.com> wrote:
>>
>>> Andreas Rheinhardt:
 Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Up until e7ddafd5, the Matroska muxer wrote two SeekHeads: One at the
>> beginning referencing the main level 1 elements (i.e. not the Clusters)
>> and one at the end, referencing the Clusters. This second SeekHead was
>> useless and has therefore been removed. Yet the SeekHead-related
>> functions and structures are still geared towards this usecase: They
>> are built around an allocated array of variable size that gets
>> reallocated every time an element is added to it although the maximum
>> number of Seek entries is a small compile-time constant, so that one 
>> should
>> rather include the array in the SeekHead structure itself; and said
>> structure should be contained in the MatroskaMuxContext instead of being
>> allocated separately.
>>
>> The earlier code reserved space for a SeekHead with 10 entries, although
>> we currently write at most 6. Reducing said number implied that every
>> Matroska/Webm file will be 84 bytes smaller and required to adapt
>> several FATE tests; furthermore, the reserved amount overestimated the
>> amount needed for for the SeekHead's length field and how many bytes
>> need to be reserved to write a EBML Void element, bringing the total
>> reduction to 89 bytes.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>
> Ping.
>
> - Andreas
>
 Ping (the actual patch (which has been omitted for brevity) is here:
 https://ffmpeg.org/pipermail/ffmpeg-devel/2020-February/256997.html).

 - Andreas

>>> Another ping.
>>>
>>> - Andreas
>>>
>>
>> Ping.
>>
>> - Andreas
>>
> 
> Ping.
> 
> - Andreas
> 
Ping.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH V2 3/3] avfilter/vf_dnn_processing.c: add frame size change support for planar yuv format

2020-03-05 Thread Guo, Yejun


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> myp...@gmail.com
> Sent: Friday, March 06, 2020 10:49 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH V2 3/3] avfilter/vf_dnn_processing.c: add
> frame size change support for planar yuv format
> 
> On Tue, Feb 25, 2020 at 5:24 PM Guo, Yejun  wrote:
> >
> > The Y channel is handled by dnn, and also resized by dnn. The UV channels
> > are resized with swscale.
> For me, this is a little weird to resize Y with dnn backend but resize
> UV channel with FFmpeg swscale, is it used the same scale algorithm ?
> 

thanks for the review. The Y channel and UV channel use different algorithms,
the algorithm for Y channel is trained with dnn, while UV channel ignored in 
dnn model.

It would be nice if all channels are handled by the dnn model. But, for the 
popular
dnn models I know, they just handle the Y channel, that's the reason that we
have to ask swscale's help to handle UV channels. And the same idea is also
used in vf_sr.c, we can first handle this case.

I can add such support once I see there are some popular good models
which handle YUV channels together.

thanks
yejun

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] avcodec/exr: add cineon lin2log trc

2020-03-05 Thread mindmark
From: Mark Reid 

Hi,
The following patch adds a cineon lin2log color transfer characteristic to exr.
The purpose of this patch is to allow preserving of the dynamic range of an
exr file when converting to DPX or when using video filter such as 3d luts.
I wasn't sure if adding it to the AVColorTransferCharacteristic enum was the
correct approach, as this might be a exr specific thing but I figured it was a 
good starting point.

changes since v1:
- updated fate test

---
 libavcodec/exr.c   |  2 ++
 libavutil/color_utils.c| 14 ++
 libavutil/pixfmt.h |  1 +
 tests/ref/fate/color_utils | 19 +++
 4 files changed, 36 insertions(+)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 1db30a1ae0..f2900a7921 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1938,6 +1938,8 @@ static const AVOption options[] = {
 AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST2084 },  INT_MIN, INT_MAX, 
VD, "apply_trc_type"},
 { "smpte428_1",   "SMPTE ST 428-1",   0,
 AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST428_1 }, INT_MIN, INT_MAX, 
VD, "apply_trc_type"},
+{ "lin2log",  "Default Cineon/DPX log",   0,
+AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_CINE_LIN2LOG }, INT_MIN, INT_MAX, 
VD, "apply_trc_type"},

 { NULL },
 };
diff --git a/libavutil/color_utils.c b/libavutil/color_utils.c
index eb8bc7b5fc..e33c019d4a 100644
--- a/libavutil/color_utils.c
+++ b/libavutil/color_utils.c
@@ -167,6 +167,16 @@ static double avpriv_trc_arib_std_b67(double Lc) {
 (Lc <= 1.0 / 12.0 ? sqrt(3.0 * Lc) : a * log(12.0 * Lc - b) + c);
 }

+static double avpriv_trc_cine_lin2log(double Lc) {
+const double blackpoint =  95.0;
+const double whitepoint = 685.0;
+const double gamma  =   0.6;
+const double offset =  pow(10, (blackpoint - whitepoint) * 0.002 / gamma);
+const double gain   = 1.0 / (1.0 - offset);
+
+return (log10((Lc + offset) / gain) / (0.002 / gamma) + whitepoint ) / 
1023.0;
+}
+
 avpriv_trc_function avpriv_get_trc_function_from_trc(enum 
AVColorTransferCharacteristic trc)
 {
 avpriv_trc_function func = NULL;
@@ -225,6 +235,10 @@ avpriv_trc_function avpriv_get_trc_function_from_trc(enum 
AVColorTransferCharact
 func = avpriv_trc_arib_std_b67;
 break;

+case AVCOL_TRC_CINE_LIN2LOG:
+func = avpriv_trc_cine_lin2log;
+break;
+
 case AVCOL_TRC_RESERVED0:
 case AVCOL_TRC_UNSPECIFIED:
 case AVCOL_TRC_RESERVED:
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 1c625cfc8a..1f3f9988d7 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -499,6 +499,7 @@ enum AVColorTransferCharacteristic {
 AVCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1
 AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428,
 AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
+AVCOL_TRC_CINE_LIN2LOG = 19, ///< Default Cineon/DPX linear to log 1D curve
 AVCOL_TRC_NB ///< Not part of ABI
 };

diff --git a/tests/ref/fate/color_utils b/tests/ref/fate/color_utils
index 10f8055916..41221c131a 100644
--- a/tests/ref/fate/color_utils
+++ b/tests/ref/fate/color_utils
@@ -302,3 +302,22 @@ AVColorTransferCharacteristic=18 calling 
func(15123.456700) expected=2.725380
 AVColorTransferCharacteristic=18 calling func(19845.889230) expected=2.773978
 AVColorTransferCharacteristic=18 calling func(98678.423100) expected=3.060803
 AVColorTransferCharacteristic=18 calling func(9.88) expected=3.063182
+AVColorTransferCharacteristic=19 calling func(-0.10) expected=nan
+AVColorTransferCharacteristic=19 calling func(-0.018054) expected=nan
+AVColorTransferCharacteristic=19 calling func(-0.01) expected=-0.240327
+AVColorTransferCharacteristic=19 calling func(-0.004490) expected=0.023018
+AVColorTransferCharacteristic=19 calling func(0.00) expected=0.091481
+AVColorTransferCharacteristic=19 calling func(0.003162) expected=0.124195
+AVColorTransferCharacteristic=19 calling func(0.005000) expected=0.139945
+AVColorTransferCharacteristic=19 calling func(0.009000) expected=0.168690
+AVColorTransferCharacteristic=19 calling func(0.015000) expected=0.202405
+AVColorTransferCharacteristic=19 calling func(0.10) expected=0.388020
+AVColorTransferCharacteristic=19 calling func(1.00) expected=0.669584
+AVColorTransferCharacteristic=19 calling func(52.37) expected=1.172373
+AVColorTransferCharacteristic=19 calling func(125.098765) expected=1.283258
+AVColorTransferCharacteristic=19 calling func(1999.111230) expected=1.636205
+AVColorTransferCharacteristic=19 calling func(6945.443000) expected=1.794815
+AVColorTransferCharacteristic=19 calling func(15123.456700) expected=1.893921
+AVColorTransferCharacteristic=19 calling func(19845.889230) expected=1.928531
+AVColorTransferCharacteristic=19 calling func(98678.423100) expected=2.132798
+AVColorTransferCharacteristic=19 calling func(9.88) expected=2.134492
--

[FFmpeg-devel] [PATCH v2] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Hongcheng Zhong
This patch fixes Bug #8469
If x264 baseline profile is used with other profiles,
start_pts will be initialized to audio stream's first pts,
while the duration is calculated based on video stream's pts.
In this patch the start_pts is initialized with the correct stream's first pts.

Signed-off-by: Hongcheng Zhong 
---
 libavformat/hlsenc.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f6dd894..19aa2b1 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -126,6 +126,7 @@ typedef struct VariantStream {
 int has_video;
 int has_subtitle;
 int new_start;
+int start_pts_from_audio;
 double dpp;   // duration per packet
 int64_t start_pts;
 int64_t end_pts;
@@ -2274,6 +2275,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 if (vs->start_pts == AV_NOPTS_VALUE) {
 vs->start_pts = pkt->pts;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+vs->start_pts_from_audio = 1;
+}
+if (vs->start_pts_from_audio && st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
+vs->start_pts = pkt->pts;
+vs->start_pts_from_audio = 0;
 }
 
if (vs->has_video) {
-- 
2.7.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH V2 3/3] avfilter/vf_dnn_processing.c: add frame size change support for planar yuv format

2020-03-05 Thread myp...@gmail.com
On Tue, Feb 25, 2020 at 5:24 PM Guo, Yejun  wrote:
>
> The Y channel is handled by dnn, and also resized by dnn. The UV channels
> are resized with swscale.
For me, this is a little weird to resize Y with dnn backend but resize
UV channel with FFmpeg swscale, is it used the same scale algorithm ?

> The command to use espcn.pb (see vf_sr) looks like:
> ./ffmpeg -i 480p.jpg -vf 
> format=yuv420p,dnn_processing=dnn_backend=tensorflow:model=espcn.pb:input=x:output=y
>  -y tmp.espcn.jpg
>
> Signed-off-by: Guo, Yejun 
> ---
>  doc/filters.texi|  9 +
>  libavfilter/vf_dnn_processing.c | 37 ++---
>  2 files changed, 39 insertions(+), 7 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 33b7857..e3df8f9 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -9155,6 +9155,7 @@ ffmpeg -i INPUT -f lavfi -i 
> nullsrc=hd720,geq='r=128+80*(sin(sqrt((X-W/2)*(X-W/2
>  @end example
>  @end itemize
>
> +@anchor{dnn_processing}
>  @section dnn_processing
>
>  Do image processing with deep neural networks. It works together with 
> another filter
> @@ -9216,6 +9217,12 @@ Handle the Y channel with srcnn.pb (see @ref{sr} 
> filter) for frame with yuv420p
>  ./ffmpeg -i 480p.jpg -vf 
> format=yuv420p,scale=w=iw*2:h=ih*2,dnn_processing=dnn_backend=tensorflow:model=srcnn.pb:input=x:output=y
>  -y srcnn.jpg
>  @end example
>
> +@item
> +Handle the Y channel with espcn.pb (see @ref{sr} filter), which changes 
> frame size, for format yuv420p (planar YUV formats supported):
> +@example
> +./ffmpeg -i 480p.jpg -vf 
> format=yuv420p,dnn_processing=dnn_backend=tensorflow:model=espcn.pb:input=x:output=y
>  -y tmp.espcn.jpg
> +@end example
> +
>  @end itemize
>
>  @section drawbox
> @@ -17369,6 +17376,8 @@ Default value is @code{2}. Scale factor is necessary 
> for SRCNN model, because it
>  input upscaled using bicubic upscaling with proper scale factor.
>  @end table
>
> +This feature can also be finished with @ref{dnn_processing} filter.
> +
>  @section ssim
>
>  Obtain the SSIM (Structural SImilarity Metric) between two input videos.
> diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
> index f9458f0..7f40f85 100644
> --- a/libavfilter/vf_dnn_processing.c
> +++ b/libavfilter/vf_dnn_processing.c
> @@ -51,6 +51,8 @@ typedef struct DnnProcessingContext {
>
>  struct SwsContext *sws_gray8_to_grayf32;
>  struct SwsContext *sws_grayf32_to_gray8;
> +struct SwsContext *sws_uv_scale;
> +int sws_uv_height;
>  } DnnProcessingContext;
>
>  #define OFFSET(x) offsetof(DnnProcessingContext, x)
> @@ -274,6 +276,18 @@ static int prepare_sws_context(AVFilterLink *outlink)
> outlink->h,
> AV_PIX_FMT_GRAY8,
> 0, NULL, NULL, NULL);
> +
> +if (inlink->w != outlink->w || inlink->h != outlink->h) {
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
> +int sws_src_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
> +int sws_src_w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
> +int sws_dst_h = AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h);
> +int sws_dst_w = AV_CEIL_RSHIFT(outlink->w, desc->log2_chroma_w);
> +ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h, 
> AV_PIX_FMT_GRAY8,
> +   sws_dst_w, sws_dst_h, 
> AV_PIX_FMT_GRAY8,
> +   SWS_BICUBIC, NULL, NULL, 
> NULL);
> +ctx->sws_uv_height = sws_src_h;
> +}
>  return 0;
>  default:
>  //do nothing
> @@ -404,13 +418,21 @@ static av_always_inline int isPlanarYUV(enum 
> AVPixelFormat pix_fmt)
>
>  static int copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const 
> AVFrame *in)
>  {
> -const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(in->format);
> -int uv_height = AV_CEIL_RSHIFT(in->height, desc->log2_chroma_h);
> -for (int i = 1; i < 3; ++i) {
> -int bytewidth = av_image_get_linesize(in->format, in->width, i);
> -av_image_copy_plane(out->data[i], out->linesize[i],
> -in->data[i], in->linesize[i],
> -bytewidth, uv_height);
> +if (!ctx->sws_uv_scale) {
> +av_assert0(in->height == out->height && in->width == out->width);
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(in->format);
> +int uv_height = AV_CEIL_RSHIFT(in->height, desc->log2_chroma_h);
> +for (int i = 1; i < 3; ++i) {
> +int bytewidth = av_image_get_linesize(in->format, in->width, i);
> +av_image_copy_plane(out->data[i], out->linesize[i],
> +in->data[i], in->linesize[i],
> +bytewidth, uv_height);
> +}
> +

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Hongcheng Zhong
- On Mar 6, 2020, at 11:08 AM, Andreas Rheinhardt 
andreas.rheinha...@gmail.com wrote:

> Hongcheng Zhong:
>> - On Mar 6, 2020, at 12:55 AM, Andreas Rheinhardt
>> andreas.rheinha...@gmail.com wrote:
>> 
>>> Hongcheng Zhong:
 - On Mar 5, 2020, at 11:38 PM, lq l...@chinaffmpeg.org wrote:

>> 2020年3月5日 下午9:41,Hongcheng Zhong  写道:
>>
>> This patch fixes Bug #8469
>> If x264 baseline profile is used with other profiles,
>> start_pts will be initialized to audio stream's first pts,
>> while the duration is calculated based on video stream's pts.
>> In this patch the start_pts is initialized with the correct stream's 
>> first pts.
>>
>> Signed-off-by: Hongcheng Zhong 
>> ---
>> libavformat/hlsenc.c | 10 +-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index f6dd894..3b2434f 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -126,6 +126,7 @@ typedef struct VariantStream {
>> int has_video;
>> int has_subtitle;
>> int new_start;
>> +int start_pts_from_audio;
>> double dpp;   // duration per packet
>> int64_t start_pts;
>> int64_t end_pts;
>> @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, 
>> AVPacket
>> *pkt)
>>
>> if (vs->start_pts == AV_NOPTS_VALUE) {
>> vs->start_pts = pkt->pts;
>> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>> +vs->start_pts_from_audio = 1;
>> +}
>> +if (vs->start_pts_from_audio && st->codecpar->codec_type ==
>> AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
>> +vs->start_pts = pkt->pts;
>> +vs->start_pts_from_audio = 0;
>> }
>>
>> -   if (vs->has_video) {
>> +if (vs->has_video) {
> What’s happen with this line?
>> can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
>> ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
>> HLS_SPLIT_BY_TIME));
>> is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
>> (pkt->stream_index == vs->reference_stream_index);
>> @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
>> vs->sequence   = hls->start_sequence;
>> vs->start_pts  = AV_NOPTS_VALUE;
>> vs->end_pts  = AV_NOPTS_VALUE;
>> +vs->start_pts_from_audio = 0;
>> vs->current_segment_final_filename_fmt[0] = '\0';
>>
>> if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
>> HLS_INDEPENDENT_SEGMENTS) {
>> --
>> 2.7.4
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

 Actually, this line is useless because that vs is initialized as all zero.
 Should I remove this line and submit this patch as v2 again? Thanks for 
 your
 reply.
>>>
>>> But vs->has_video is initialized to a potentially nonzero value in
>>> hls_init().
>>>
>>> - Andreas
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>> 
>> I write that line to make sure that vs->start_pts_from_audio is initialized 
>> as
>> 0.
>> Since `hls->var_streams = av_mallocz(sizeof(*hls->var_streams) *
>> nb_varstreams);`
>> in hlsenc.c: 1897, var_streams is allocated with av_mallocz(), that line is 
>> not
>> necessary.
> 
> There seems to be a misunderstanding: The line that Steven asked about
> is "if (vs->has_video) {". By changing it you mixed cosmetic changes
> and functional ones; this should not be done.
> Steven did not ask about "vs->start_pts_from_audio = 0;". But you are
> right: It is redundant.
> 
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Sorry, my mistake. "Cosmetic changes should be kept in separate patches."
Thanks a lot for pointing this out.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 7/7] avformat/audiointerleave: use a fixed frame duration for non-audio packets

2020-03-05 Thread Andreas Rheinhardt
Marton Balint:
> The packet durations might not be set properly which can cause the MXF muxer
> to write more than one packet of a stream to an edit unit messing up the
> constant byte per element index...
> 
> Also use nb_samples directly to calculate dts of audio packets because adding
> packet durations might not be precise.
> 
> Signed-off-by: Marton Balint 
> ---
>  libavformat/audiointerleave.c | 12 +---
>  libavformat/audiointerleave.h |  3 ++-
>  libavformat/gxfenc.c  |  2 +-
>  libavformat/mxfenc.c  |  2 +-
>  4 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
> index 2e83031bd6..0643159770 100644
> --- a/libavformat/audiointerleave.c
> +++ b/libavformat/audiointerleave.c
> @@ -40,6 +40,7 @@ void ff_audio_interleave_close(AVFormatContext *s)
>  
>  int ff_audio_interleave_init(AVFormatContext *s,
>   const int samples_per_frame,
> + const int frame_duration,
>   AVRational time_base)
>  {
>  int i;
> @@ -48,6 +49,10 @@ int ff_audio_interleave_init(AVFormatContext *s,
>  av_log(s, AV_LOG_ERROR, "timebase not set for audio interleave\n");
>  return AVERROR(EINVAL);
>  }
> +if (!frame_duration) {
> +av_log(s, AV_LOG_ERROR, "frame_duration not set for audio 
> interleave\n");
> +return AVERROR(EINVAL);
> +}

Shouldn't this be an assert given that we know that it is known at
compiletime that this error can't be triggered?

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Andreas Rheinhardt
Hongcheng Zhong:
> - On Mar 6, 2020, at 12:55 AM, Andreas Rheinhardt 
> andreas.rheinha...@gmail.com wrote:
> 
>> Hongcheng Zhong:
>>> - On Mar 5, 2020, at 11:38 PM, lq l...@chinaffmpeg.org wrote:
>>>
> 2020年3月5日 下午9:41,Hongcheng Zhong  写道:
>
> This patch fixes Bug #8469
> If x264 baseline profile is used with other profiles,
> start_pts will be initialized to audio stream's first pts,
> while the duration is calculated based on video stream's pts.
> In this patch the start_pts is initialized with the correct stream's 
> first pts.
>
> Signed-off-by: Hongcheng Zhong 
> ---
> libavformat/hlsenc.c | 10 +-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f6dd894..3b2434f 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -126,6 +126,7 @@ typedef struct VariantStream {
> int has_video;
> int has_subtitle;
> int new_start;
> +int start_pts_from_audio;
> double dpp;   // duration per packet
> int64_t start_pts;
> int64_t end_pts;
> @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, 
> AVPacket
> *pkt)
>
> if (vs->start_pts == AV_NOPTS_VALUE) {
> vs->start_pts = pkt->pts;
> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
> +vs->start_pts_from_audio = 1;
> +}
> +if (vs->start_pts_from_audio && st->codecpar->codec_type ==
> AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
> +vs->start_pts = pkt->pts;
> +vs->start_pts_from_audio = 0;
> }
>
> -   if (vs->has_video) {
> +if (vs->has_video) {
 What’s happen with this line?
> can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
> ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
> HLS_SPLIT_BY_TIME));
> is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
> (pkt->stream_index == vs->reference_stream_index);
> @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
> vs->sequence   = hls->start_sequence;
> vs->start_pts  = AV_NOPTS_VALUE;
> vs->end_pts  = AV_NOPTS_VALUE;
> +vs->start_pts_from_audio = 0;
> vs->current_segment_final_filename_fmt[0] = '\0';
>
> if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
> HLS_INDEPENDENT_SEGMENTS) {
> --
> 2.7.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>>
>>> Actually, this line is useless because that vs is initialized as all zero.
>>> Should I remove this line and submit this patch as v2 again? Thanks for your
>>> reply.
>>
>> But vs->has_video is initialized to a potentially nonzero value in
>> hls_init().
>>
>> - Andreas
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> I write that line to make sure that vs->start_pts_from_audio is initialized 
> as 0.
> Since `hls->var_streams = av_mallocz(sizeof(*hls->var_streams) * 
> nb_varstreams);`
> in hlsenc.c: 1897, var_streams is allocated with av_mallocz(), that line is 
> not 
> necessary.

There seems to be a misunderstanding: The line that Steven asked about
is "if (vs->has_video) {". By changing it you mixed cosmetic changes
and functional ones; this should not be done.
Steven did not ask about "vs->start_pts_from_audio = 0;". But you are
right: It is redundant.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] libavcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-03-05 Thread Wang Cao
On Wed, Mar 4, 2020 at 1:38 AM Moritz Barsnick  wrote:

> On Wed, Mar 04, 2020 at 05:59:03 +0800, Wang Cao wrote:
> > Signed-off-by: Wang Cao 
> > ---
> >  doc/encoders.texi  | 39 +++
> >  libavcodec/libaomenc.c | 38 ++
>
> Again, I suggest bumping MICRO once more.
>
Done.

> > +@item superres_denominator
> > +The denominator for superres to use when @option{superres-mode} is
> @option{fixed}. Valid value
> > +ranges from 8 to 16.
> > +
> > +@item superres_kf_denominator
> > +The denominator for superres to use on key frames is fixed when
> > +@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to
> 16.
>
> I believe "is fixed " is not needed in this sentence, or even
> confusing.
>
Done.

> >  [AOME_SET_TUNING]   = "AOME_SET_TUNING",
> > +[AV1E_SET_ENABLE_SUPERRES] = "AV1E_SET_ENABLE_SUPERRES",
>
> The other '=' in this block are aligned.
>
> > +if (ctx->superres_mode >= 0)
> > +  enccfg.rc_superres_mode = ctx->superres_mode;
> > +if (ctx->superres_qthresh > 0)
> > +  enccfg.rc_superres_qthresh = ctx->superres_qthresh;
> > +if (ctx->superres_kf_qthresh > 0)
> > +  enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
> > +if (ctx->superres_denominator >= 0)
> > +  enccfg.rc_superres_denominator = ctx->superres_denominator;
> > +if (ctx->superres_kf_denominator >= 0)
> > +  enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
>
> It looks like indentation is off - ffmpeg uses four spaces.
>
> (Is this struct zero-initialized / memset()'d?)

Yes it is initialized before through aom_codec_enc_config_default

>
>
>  { "ssim","SSIM as distortion metric", 0,
> AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
> > +{ "enable-superres", "Enable super-resolution mode",
> OFFSET(enable_superres), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> > +{ "superres-mode",   "Select super-resultion mode",
> OFFSET(superres_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4, VE,
> "superres_mode"},
> > +{ "none","No frame superres allowed", 0,
> AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "superres_mode"},
> > +{ "fixed",   "All frames are coded at the specified scale
> and super-resolved", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE,
> "superres_mode"},
> > +{ "random",  "All frames are coded at a random scale and
> super-resolved.", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE,
> "superres_mode"},
> > +{ "qthresh", "Superres scale for a frame is determined
> based on q_index",  0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE,
> "superres_mode"},
> > +{ "auto","Automatically select superres for appropriate
> frames",   0, AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0, VE,
> "superres_mode"},
>
> Several remarks:
> - The "none" entry should also be aligned, just like the entry "fixed"
>   and following... (starting at   "0, AV_OPT_TYPE_CONST", if you see
>   what I mean).
> - Is "auto" a value given by the library? I'm asking because
>   we tend to use "-1" for our internal "auto", and use that as a
>   default, if desired.
>   (From looking at libaom, they indeed use 4 for "auto".)
> - Can you directly use the enumerations provided as SUPERRES_MODE by
>   libaom, or are they not public?
> - If you cannot reuse said enum (and its resulting range
>   [-1, SUPERRES_MODES - 1]), you should define your own as enum
>   SuperresModes { AOM_SUPERRES_MODE_NONE, AOM_SUPERRES_MODE_FIXED, ,
>   AOM_SUPERRES_MODE_NB }, use these in the options definition above,
>   and set the allowed range to [-1, AOM_SUPERRES_MODE_NB - 1].
>
> This is a good approach to improve the readability. Done.

> Cheers,
> Moritz
>
Please find the changes in the updated patch. Thanks!
-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/2] avcodec/libaomenc.c: Add a libaom command-line option 'tune'

2020-03-05 Thread Wang Cao
Signed-off-by: Wang Cao 
---
Made changes according to the review.
- Bump the MICRO version of libavcodec.
- Use enum for 'tune' option consts for better consistency

 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c |  7 +++
 libavcodec/version.h   |  2 +-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..0a74ecce9b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric the encoder is tune with. Default is @code{psnr}.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..df7819b429 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -94,6 +94,7 @@ typedef struct AOMEncoderContext {
 int enable_intrabc;
 int enable_restoration;
 int usage;
+int tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ static const AVOption options[] = {
 { "usage",   "Quality and compression efficiency vs speed 
tradeof", OFFSET(usage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "usage"},
 { "good","Good quality",  0, AV_OPT_TYPE_CONST, {.i64 = 0 
/* AOM_USAGE_GOOD_QUALITY */}, 0, 0, VE, "usage"},
 { "realtime","Realtime encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 1 
/* AOM_USAGE_REALTIME */}, 0, 0, VE, "usage"},
+{ "tune","The metric that encoder tunes for. Automatically 
choosen by encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
AOM_TUNE_SSIM, VE, "tune"},
+{ "psnr","PSNR as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
+{ "ssim","SSIM as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
 { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 36536c3725..03d7f32f1c 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  73
-#define LIBAVCODEC_VERSION_MICRO 102
+#define LIBAVCODEC_VERSION_MICRO 103
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.25.0.265.gbab2e86ba0-goog

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 2/2] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-03-05 Thread Wang Cao
Signed-off-by: Wang Cao 
---
The changes are made according to the code review
- Bump the MICRO version
- Use enum for Super resolution mode consts. The original enum in libaom
  is not public so a enum is defined and matched the original enum
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 47 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 0a74ecce9b..04f05e7c9b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1608,6 +1608,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resultion mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}. Valid value 
+ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when 
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode} 
is 
+@option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when 
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index df7819b429..0f4c0377cc 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -95,6 +95,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -134,6 +140,16 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
+};
+
+enum AOMSuperresModes {
+AOM_SUPERRES_MODE_NONE= 0,
+AOM_SUPERRES_MODE_FIXED   = 1,
+AOM_SUPERRES_MODE_RANDOM  = 2,
+AOM_SUPERRES_MODE_QTHRESH = 3,
+AOM_SUPERRES_MODE_AUTO= 4,
+AOM_SUPERRES_MODE_NB
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -203,6 +219,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -545,6 +568,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 0)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 0)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -687,6 +721,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if 

[FFmpeg-devel] [PATCH] avcodec/vp9: use a buffer pool to allocate VP9Frame extradata

2020-03-05 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/vp9.c| 13 -
 libavcodec/vp9dec.h |  4 
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7aaae9b792..7ee375d4d0 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -112,10 +112,20 @@ static int vp9_frame_alloc(AVCodecContext *avctx, 
VP9Frame *f)
 return ret;
 
 sz = 64 * s->sb_cols * s->sb_rows;
-f->extradata = av_buffer_allocz(sz * (1 + sizeof(VP9mvrefPair)));
+if (sz != s->frame_extradata_pool_size) {
+av_buffer_pool_uninit(>frame_extradata_pool);
+s->frame_extradata_pool = av_buffer_pool_init(sz * (1 + 
sizeof(VP9mvrefPair)), NULL);
+if (!s->frame_extradata_pool) {
+s->frame_extradata_pool_size = 0;
+goto fail;
+}
+s->frame_extradata_pool_size = sz;
+}
+f->extradata = av_buffer_pool_get(s->frame_extradata_pool);
 if (!f->extradata) {
 goto fail;
 }
+memset(f->extradata->data, 0, f->extradata->size);
 
 f->segmentation_map = f->extradata->data;
 f->mv = (VP9mvrefPair *) (f->extradata->data + sz);
@@ -1210,6 +1220,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
 vp9_frame_unref(avctx, >s.frames[i]);
 av_frame_free(>s.frames[i].tf.f);
 }
+av_buffer_pool_uninit(>frame_extradata_pool);
 for (i = 0; i < 8; i++) {
 if (s->s.refs[i].f->buf[0])
 ff_thread_release_buffer(avctx, >s.refs[i]);
diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h
index 66573edc79..de02b146f0 100644
--- a/libavcodec/vp9dec.h
+++ b/libavcodec/vp9dec.h
@@ -152,6 +152,10 @@ typedef struct VP9Context {
 int block_alloc_using_2pass;
 uint16_t mvscale[3][2];
 uint8_t mvstep[3][2];
+
+// frame specific buffer pools
+AVBufferPool *frame_extradata_pool;
+int frame_extradata_pool_size;
 } VP9Context;
 
 struct VP9TileData {
-- 
2.25.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH V2 3/3] avfilter/vf_dnn_processing.c: add frame size change support for planar yuv format

2020-03-05 Thread Guo, Yejun


> -Original Message-
> From: Guo, Yejun
> Sent: Tuesday, February 25, 2020 5:15 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Guo, Yejun 
> Subject: [PATCH V2 3/3] avfilter/vf_dnn_processing.c: add frame size change
> support for planar yuv format
> 
> The Y channel is handled by dnn, and also resized by dnn. The UV channels
> are resized with swscale.
> 
> The command to use espcn.pb (see vf_sr) looks like:
> ./ffmpeg -i 480p.jpg -vf
> format=yuv420p,dnn_processing=dnn_backend=tensorflow:model=espcn.pb:in
> put=x:output=y -y tmp.espcn.jpg
> 
> Signed-off-by: Guo, Yejun 
> ---
>  doc/filters.texi|  9 +
>  libavfilter/vf_dnn_processing.c | 37 ++---
>  2 files changed, 39 insertions(+), 7 deletions(-)

this patch set asks for review, thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 01/14] h264_mp4toannexb: Remove unnecessary check

2020-03-05 Thread Michael Niedermayer
On Sun, Dec 15, 2019 at 11:56:00PM +0100, Michael Niedermayer wrote:
> On Sat, Dec 14, 2019 at 11:19:13PM +0100, Andreas Rheinhardt wrote:
> > There can be at most 31 SPS and 255 PPS in the mp4/Matroska extradata.
> > Given that each has a size of at most 2^16-1, the length of the output
> > derived from these parameter sets can never overflow an ordinary 32 bit
> > integer. So use a simple uint32_t instead of uint64_t and replace the
> > unnecessary check with an av_assert1.
> > 
> > Signed-off-by: Andreas Rheinhardt 
> > ---
> >  libavcodec/h264_mp4toannexb_bsf.c | 10 +++---
> >  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> will apply

will apply the rest of the patchset

thx

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

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/exr: add cineon lin2log trc

2020-03-05 Thread mindmark
From: Mark Reid 

Hi,
The following patch adds a cineon lin2log color transfer characteristic to exr.
The purpose of this patch is to allow preserving of the dynamic range of an
exr file when converting to DPX or when using video filter such as 3d luts.
I wasn't sure if adding it to the AVColorTransferCharacteristic enum was the
correct approach as this might be a exr specific thing but I figured it was a 
good starting point.

---
 libavcodec/exr.c|  2 ++
 libavutil/color_utils.c | 14 ++
 libavutil/pixfmt.h  |  1 +
 3 files changed, 17 insertions(+)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 1db30a1ae0..f2900a7921 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1938,6 +1938,8 @@ static const AVOption options[] = {
 AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST2084 },  INT_MIN, INT_MAX, 
VD, "apply_trc_type"},
 { "smpte428_1",   "SMPTE ST 428-1",   0,
 AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST428_1 }, INT_MIN, INT_MAX, 
VD, "apply_trc_type"},
+{ "lin2log",  "Default Cineon/DPX log",   0,
+AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_CINE_LIN2LOG }, INT_MIN, INT_MAX, 
VD, "apply_trc_type"},

 { NULL },
 };
diff --git a/libavutil/color_utils.c b/libavutil/color_utils.c
index eb8bc7b5fc..e33c019d4a 100644
--- a/libavutil/color_utils.c
+++ b/libavutil/color_utils.c
@@ -167,6 +167,16 @@ static double avpriv_trc_arib_std_b67(double Lc) {
 (Lc <= 1.0 / 12.0 ? sqrt(3.0 * Lc) : a * log(12.0 * Lc - b) + c);
 }

+static double avpriv_trc_cine_lin2log(double Lc) {
+const double blackpoint =  95.0;
+const double whitepoint = 685.0;
+const double gamma  =   0.6;
+const double offset =  pow(10, (blackpoint - whitepoint) * 0.002 / gamma);
+const double gain   = 1.0 / (1.0 - offset);
+
+return (log10((Lc + offset) / gain) / (0.002 / gamma) + whitepoint ) / 
1023.0;
+}
+
 avpriv_trc_function avpriv_get_trc_function_from_trc(enum 
AVColorTransferCharacteristic trc)
 {
 avpriv_trc_function func = NULL;
@@ -225,6 +235,10 @@ avpriv_trc_function avpriv_get_trc_function_from_trc(enum 
AVColorTransferCharact
 func = avpriv_trc_arib_std_b67;
 break;

+case AVCOL_TRC_CINE_LIN2LOG:
+func = avpriv_trc_cine_lin2log;
+break;
+
 case AVCOL_TRC_RESERVED0:
 case AVCOL_TRC_UNSPECIFIED:
 case AVCOL_TRC_RESERVED:
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 1c625cfc8a..1f3f9988d7 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -499,6 +499,7 @@ enum AVColorTransferCharacteristic {
 AVCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1
 AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428,
 AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
+AVCOL_TRC_CINE_LIN2LOG = 19, ///< Default Cineon/DPX linear to log 1D curve
 AVCOL_TRC_NB ///< Not part of ABI
 };

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs_av1_syntax_template: Set seen_frame_header only after successfull uncompressed_header()

2020-03-05 Thread Michael Niedermayer
On Sat, Dec 14, 2019 at 03:21:57PM -0300, James Almer wrote:
> On 12/14/2019 2:43 PM, Michael Niedermayer wrote:
> > Fixes: assertion failure
> > Fixes: 
> > 19301/clusterfuzz-testcase-minimized-ffmpeg_BSF_AV1_FRAME_MERGE_fuzzer-5743212006473728
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/cbs_av1_syntax_template.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavcodec/cbs_av1_syntax_template.c 
> > b/libavcodec/cbs_av1_syntax_template.c
> > index 523f9359e4..01c180e4af 100644
> > --- a/libavcodec/cbs_av1_syntax_template.c
> > +++ b/libavcodec/cbs_av1_syntax_template.c
> > @@ -1601,8 +1601,6 @@ static int 
> > FUNC(frame_header_obu)(CodedBitstreamContext *ctx, RWContext *rw,
> >  else
> >  HEADER("Frame Header");
> >  
> > -priv->seen_frame_header = 1;
> > -
> >  #ifdef READ
> >  start_pos = get_bits_count(rw);
> >  #else
> > @@ -1611,6 +1609,8 @@ static int 
> > FUNC(frame_header_obu)(CodedBitstreamContext *ctx, RWContext *rw,
> >  
> >  CHECK(FUNC(uncompressed_header)(ctx, rw, current));
> >  
> > +priv->seen_frame_header = 1;
> > +
> >  if (current->show_existing_frame) {
> >  priv->seen_frame_header = 0;
> >  } else {
> 
> What's the assertion that fails? av_assert0(priv->frame_header_ref &&
> priv->frame_header)? If so, then if priv->frame_header_ref fails to be
> allocated and the error is ignored, the same assertion could trigger as
> seen_frame_header will be 1 even after this patch.
> 

> I think you can just remove the above line instead of moving it. Right
> below the call to uncompressed_header() it's going to be set to either 0
> or 1 anyway.

will apply with this suggestion

thx


> Another option could be replacing the assertion for a simple check for
> priv->frame_header_ref that returns invalid data if it's not set.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Whats the most studid thing your enemy could do ? Blow himself up
Whats the most studid thing you could do ? Give up your rights and
freedom because your enemy blew himself up.



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] fftools/ffplay: fix possible memory leak in decoder

2020-03-05 Thread Marton Balint
Fixes ticket #8549.

Signed-off-by: Marton Balint 
---
 fftools/ffplay.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index fee0619f7c..f6511e4afd 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -644,7 +644,10 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 if (packet_queue_get(d->queue, , 1, >pkt_serial) < 0)
 return -1;
 }
-} while (d->queue->serial != d->pkt_serial);
+if (d->queue->serial == d->pkt_serial)
+break;
+av_packet_unref();
+} while (1);
 
 if (pkt.data == flush_pkt.data) {
 avcodec_flush_buffers(d->avctx);
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] lavd/avfoundation: Add basic transport control observation, for capable devices.

2020-03-05 Thread Thilo Borgmann
Hi,

fixes infinite loop waiting for input using e.g. tape devices that suport 
transport control.

-Thilo
From 656f1fe2a91bda6099d0ed3848dce9aec55c8932 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann 
Date: Thu, 5 Mar 2020 12:32:49 +0100
Subject: [PATCH] lavd/avfoundation: Add basic transport control observation
 for capable devices.

---
 libavdevice/avfoundation.m | 67 --
 1 file changed, 59 insertions(+), 8 deletions(-)

diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index 0d854a1..43b2edb 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -88,7 +88,6 @@ typedef struct
 int64_t first_pts;
 int64_t first_audio_pts;
 pthread_mutex_t frame_lock;
-pthread_cond_t  frame_wait_cond;
 id  avf_delegate;
 id  avf_audio_delegate;
 
@@ -130,6 +129,10 @@ typedef struct
 AVCaptureAudioDataOutput *audio_output;
 CMSampleBufferRef current_frame;
 CMSampleBufferRef current_audio_frame;
+
+AVCaptureDevice  *observed_device;
+AVCaptureDeviceTransportControlsPlaybackMode observed_mode;
+int  observed_quit;
 } AVFContext;
 
 static void lock_frames(AVFContext* ctx)
@@ -163,10 +166,50 @@ static void unlock_frames(AVFContext* ctx)
 {
 if (self = [super init]) {
 _context = context;
+
+// start observing if a device is set for it
+if (_context->observed_device) {
+NSString *keyPath = 
NSStringFromSelector(@selector(transportControlsPlaybackMode));
+NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew;
+
+[_context->observed_device addObserver: self
+forKeyPath: keyPath
+   options: options
+   context: _context];
+}
 }
 return self;
 }
 
+- (void)dealloc {
+// stop observing if a device is set for it
+NSString *keyPath = 
NSStringFromSelector(@selector(transportControlsPlaybackMode));
+[_context->observed_device removeObserver: self forKeyPath: keyPath];
+[super dealloc];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath
+  ofObject:(id)object
+change:(NSDictionary *)change
+   context:(void *)context {
+if (context == _context) {
+AVCaptureDeviceTransportControlsPlaybackMode mode =
+[change[NSKeyValueChangeNewKey] integerValue];
+
+if (mode != _context->observed_mode) {
+if (mode == AVCaptureDeviceTransportControlsNotPlayingMode) {
+_context->observed_quit = 1;
+}
+_context->observed_mode = mode;
+}
+} else {
+[super observeValueForKeyPath: keyPath
+ ofObject: object
+   change: change
+  context: context];
+}
+}
+
 - (void)  captureOutput:(AVCaptureOutput *)captureOutput
   didOutputSampleBuffer:(CMSampleBufferRef)videoFrame
  fromConnection:(AVCaptureConnection *)connection
@@ -179,8 +222,6 @@ static void unlock_frames(AVFContext* ctx)
 
 _context->current_frame = (CMSampleBufferRef)CFRetain(videoFrame);
 
-pthread_cond_signal(&_context->frame_wait_cond);
-
 unlock_frames(_context);
 
 ++_context->frames_captured;
@@ -225,8 +266,6 @@ static void unlock_frames(AVFContext* ctx)
 
 _context->current_audio_frame = (CMSampleBufferRef)CFRetain(audioFrame);
 
-pthread_cond_signal(&_context->frame_wait_cond);
-
 unlock_frames(_context);
 
 ++_context->audio_frames_captured;
@@ -253,7 +292,6 @@ static void destroy_context(AVFContext* ctx)
 av_freep(>audio_buffer);
 
 pthread_mutex_destroy(>frame_lock);
-pthread_cond_destroy(>frame_wait_cond);
 
 if (ctx->current_frame) {
 CFRelease(ctx->current_frame);
@@ -499,6 +537,15 @@ static int add_video_device(AVFormatContext *s, 
AVCaptureDevice *video_device)
 }
 [ctx->video_output setAlwaysDiscardsLateVideoFrames:ctx->drop_late_frames];
 
+// check for transport control support and set observer device if supported
+int trans_ctrl = [video_device transportControlsSupported];
+AVCaptureDeviceTransportControlsPlaybackMode trans_mode = [video_device 
transportControlsPlaybackMode];
+
+if (trans_ctrl) {
+ctx->observed_mode   = trans_mode;
+ctx->observed_device = video_device;
+}
+
 ctx->avf_delegate = [[AVFFrameReceiver alloc] initWithContext:ctx];
 
 queue = dispatch_queue_create("avf_queue", NULL);
@@ -709,7 +756,6 @@ static int avf_read_header(AVFormatContext *s)
 ctx->first_audio_pts= av_gettime();
 
 pthread_mutex_init(>frame_lock, NULL);
-pthread_cond_init(>frame_wait_cond, NULL);
 
 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 

[FFmpeg-devel] [PATCH v2 6/7] avformat/mxfenc: allow all frame rates if -strict mode is set to unofficial or lower

2020-03-05 Thread Marton Balint
There was no consensus wheter or not to allow unofficial frame rates due to
possible interoperability issues, a compromise is to only allow it if -strict
mode is set to unofficial.

Signed-off-by: Marton Balint 
---
 libavformat/mxfenc.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 51e2dc5f31..6279ba9d6d 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2413,8 +2413,12 @@ static int mxf_init_timecode(AVFormatContext *s, 
AVStream *st, AVRational tbc)
 AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
 
 if (!ff_mxf_get_content_package_rate(tbc)) {
-av_log(s, AV_LOG_ERROR, "Unsupported frame rate %d/%d\n", tbc.den, 
tbc.num);
-return AVERROR(EINVAL);
+if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
+av_log(s, AV_LOG_ERROR, "Unsupported frame rate %d/%d. Set -strict 
option to 'unofficial' or lower in order to allow it!\n", tbc.den, tbc.num);
+return AVERROR(EINVAL);
+} else {
+av_log(s, AV_LOG_WARNING, "Unofficial frame rate %d/%d.\n", 
tbc.den, tbc.num);
+}
 }
 
 mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 7/7] avformat/audiointerleave: use a fixed frame duration for non-audio packets

2020-03-05 Thread Marton Balint
The packet durations might not be set properly which can cause the MXF muxer
to write more than one packet of a stream to an edit unit messing up the
constant byte per element index...

Also use nb_samples directly to calculate dts of audio packets because adding
packet durations might not be precise.

Signed-off-by: Marton Balint 
---
 libavformat/audiointerleave.c | 12 +---
 libavformat/audiointerleave.h |  3 ++-
 libavformat/gxfenc.c  |  2 +-
 libavformat/mxfenc.c  |  2 +-
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index 2e83031bd6..0643159770 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -40,6 +40,7 @@ void ff_audio_interleave_close(AVFormatContext *s)
 
 int ff_audio_interleave_init(AVFormatContext *s,
  const int samples_per_frame,
+ const int frame_duration,
  AVRational time_base)
 {
 int i;
@@ -48,6 +49,10 @@ int ff_audio_interleave_init(AVFormatContext *s,
 av_log(s, AV_LOG_ERROR, "timebase not set for audio interleave\n");
 return AVERROR(EINVAL);
 }
+if (!frame_duration) {
+av_log(s, AV_LOG_ERROR, "frame_duration not set for audio 
interleave\n");
+return AVERROR(EINVAL);
+}
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
 AudioInterleaveContext *aic = st->priv_data;
@@ -67,6 +72,8 @@ int ff_audio_interleave_init(AVFormatContext *s,
 if (!(aic->fifo = av_fifo_alloc_array(100, max_samples)))
 return AVERROR(ENOMEM);
 aic->fifo_size = 100 * max_samples;
+} else {
+aic->frame_duration = frame_duration;
 }
 }
 
@@ -94,10 +101,9 @@ static int interleave_new_audio_packet(AVFormatContext *s, 
AVPacket *pkt,
 if (size < pkt->size)
 memset(pkt->data + size, 0, pkt->size - size);
 
-pkt->dts = pkt->pts = aic->dts;
+pkt->dts = pkt->pts = av_rescale_q(aic->nb_samples, st->time_base, 
aic->time_base);
 pkt->duration = av_rescale_q(nb_samples, st->time_base, aic->time_base);
 pkt->stream_index = stream_index;
-aic->dts += pkt->duration;
 aic->nb_samples += nb_samples;
 aic->n++;
 
@@ -124,7 +130,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, 
AVPacket *out, AVPacket *pkt
 } else {
 // rewrite pts and dts to be decoded time line position
 pkt->pts = pkt->dts = aic->dts;
-aic->dts += pkt->duration;
+aic->dts += aic->frame_duration;
 if ((ret = ff_interleave_add_packet(s, pkt, compare_ts)) < 0)
 return ret;
 }
diff --git a/libavformat/audiointerleave.h b/libavformat/audiointerleave.h
index 0933310f4c..0c284dedb6 100644
--- a/libavformat/audiointerleave.h
+++ b/libavformat/audiointerleave.h
@@ -34,10 +34,11 @@ typedef struct AudioInterleaveContext {
 uint64_t dts; ///< current dts
 int sample_size;  ///< size of one sample all channels included
 int samples_per_frame;///< samples per frame if fixed, 0 otherwise
+int frame_duration;   ///< frame duration for non-audio data
 AVRational time_base; ///< time base of output audio packets
 } AudioInterleaveContext;
 
-int ff_audio_interleave_init(AVFormatContext *s, const int samples_per_frame, 
AVRational time_base);
+int ff_audio_interleave_init(AVFormatContext *s, const int samples_per_frame, 
const int frame_duration, AVRational time_base);
 void ff_audio_interleave_close(AVFormatContext *s);
 
 /**
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index e7536a6a7e..552cc57a3f 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -818,7 +818,7 @@ static int gxf_write_header(AVFormatContext *s)
 sc->order = s->nb_streams - st->index;
 }
 
-if (ff_audio_interleave_init(s, GXF_samples_per_frame, (AVRational){ 1, 
48000 }) < 0)
+if (ff_audio_interleave_init(s, GXF_samples_per_frame, 2, (AVRational){ 1, 
48000 }) < 0)
 return -1;
 
 if (tcr && vsc)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 6279ba9d6d..ac409d9ccf 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2646,7 +2646,7 @@ static int mxf_write_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 mxf->timecode_track->index = -1;
 
-if (ff_audio_interleave_init(s, 0, av_inv_q(mxf->tc.rate)) < 0)
+if (ff_audio_interleave_init(s, 0, 1, av_inv_q(mxf->tc.rate)) < 0)
 return -1;
 
 return 0;
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 3/7] avformat/mxfenc: move content package rates and timebase combinations to a separate struct

2020-03-05 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/mxf.c | 32 
 libavformat/mxf.h |  5 +
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 10ccd770e3..80626e2a16 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -131,25 +131,25 @@ int ff_mxf_decode_pixel_layout(const char 
pixel_layout[16], enum AVPixelFormat *
 return -1;
 }
 
-static const AVRational mxf_time_base[] = {
-{ 1001, 24000 },
-{ 1, 24},
-{ 1001, 3 },
-{ 1001, 6 },
-{ 1, 25 },
-{ 1, 50 },
-{ 1, 60 },
-{ 0, 0}
-};
-
-static const int mxf_content_package_rates[] = {
-3, 2, 7, 13, 4, 10, 12,
+/**
+ * See SMPTE 326M-2000 Section 7.2 Content package rate
+ * MXFContentPackageRate->rate is bits b5..b0.
+ */
+static const MXFContentPackageRate mxf_content_package_rates[] = {
+{  2, { 1,24} },
+{  3, { 1001, 24000 } },
+{  4, { 1,25} },
+{  7, { 1001, 3 } },
+{ 10, { 1,50} },
+{ 12, { 1,60} },
+{ 13, { 1001, 6 } },
+{0}
 };
 
 int ff_mxf_get_content_package_rate(AVRational time_base)
 {
-for (int i = 0; mxf_time_base[i].num; i++)
-if (!av_cmp_q(time_base, mxf_time_base[i]))
-return mxf_content_package_rates[i];
+for (int i = 0; mxf_content_package_rates[i].rate; i++)
+if (!av_cmp_q(time_base, mxf_content_package_rates[i].tb))
+return mxf_content_package_rates[i].rate;
 return 0;
 }
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index 2669269830..f2fff2781e 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -59,6 +59,11 @@ enum MXFFrameLayout {
 SegmentedFrame,
 };
 
+typedef struct MXFContentPackageRate {
+int rate;
+AVRational tb;
+} MXFContentPackageRate;
+
 typedef struct KLVPacket {
 UID key;
 int64_t offset;
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/7] avformat/audiointerleave: disallow using a samples_per_frame array

2020-03-05 Thread Marton Balint
Only MXF used an actual sample array, and that is unneeded there because simple
rounding rules can be used instead.

Signed-off-by: Marton Balint 
---
 libavformat/audiointerleave.c | 24 +++-
 libavformat/audiointerleave.h |  7 ---
 libavformat/gxfenc.c  |  2 +-
 libavformat/mxfenc.c  |  7 ++-
 4 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index 6797546a44..2e83031bd6 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -39,14 +39,11 @@ void ff_audio_interleave_close(AVFormatContext *s)
 }
 
 int ff_audio_interleave_init(AVFormatContext *s,
- const int *samples_per_frame,
+ const int samples_per_frame,
  AVRational time_base)
 {
 int i;
 
-if (!samples_per_frame)
-return AVERROR(EINVAL);
-
 if (!time_base.num) {
 av_log(s, AV_LOG_ERROR, "timebase not set for audio interleave\n");
 return AVERROR(EINVAL);
@@ -56,6 +53,8 @@ int ff_audio_interleave_init(AVFormatContext *s,
 AudioInterleaveContext *aic = st->priv_data;
 
 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+int max_samples = samples_per_frame ? samples_per_frame :
+  av_rescale_rnd(st->codecpar->sample_rate, 
time_base.num, time_base.den, AV_ROUND_UP);
 aic->sample_size = (st->codecpar->channels *
 
av_get_bits_per_sample(st->codecpar->codec_id)) / 8;
 if (!aic->sample_size) {
@@ -63,12 +62,11 @@ int ff_audio_interleave_init(AVFormatContext *s,
 return AVERROR(EINVAL);
 }
 aic->samples_per_frame = samples_per_frame;
-aic->samples = aic->samples_per_frame;
 aic->time_base = time_base;
 
-aic->fifo_size = 100* *aic->samples;
-if (!(aic->fifo= av_fifo_alloc_array(100, *aic->samples)))
+if (!(aic->fifo = av_fifo_alloc_array(100, max_samples)))
 return AVERROR(ENOMEM);
+aic->fifo_size = 100 * max_samples;
 }
 }
 
@@ -81,7 +79,9 @@ static int interleave_new_audio_packet(AVFormatContext *s, 
AVPacket *pkt,
 AVStream *st = s->streams[stream_index];
 AudioInterleaveContext *aic = st->priv_data;
 int ret;
-int frame_size = *aic->samples * aic->sample_size;
+int nb_samples = aic->samples_per_frame ? aic->samples_per_frame :
+ (av_rescale_q(aic->n + 1, 
av_make_q(st->codecpar->sample_rate, 1), av_inv_q(aic->time_base)) - 
aic->nb_samples);
+int frame_size = nb_samples * aic->sample_size;
 int size = FFMIN(av_fifo_size(aic->fifo), frame_size);
 if (!size || (!flush && size == av_fifo_size(aic->fifo)))
 return 0;
@@ -95,13 +95,11 @@ static int interleave_new_audio_packet(AVFormatContext *s, 
AVPacket *pkt,
 memset(pkt->data + size, 0, pkt->size - size);
 
 pkt->dts = pkt->pts = aic->dts;
-pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);
+pkt->duration = av_rescale_q(nb_samples, st->time_base, aic->time_base);
 pkt->stream_index = stream_index;
 aic->dts += pkt->duration;
-
-aic->samples++;
-if (!*aic->samples)
-aic->samples = aic->samples_per_frame;
+aic->nb_samples += nb_samples;
+aic->n++;
 
 return pkt->size;
 }
diff --git a/libavformat/audiointerleave.h b/libavformat/audiointerleave.h
index f28d5fefcc..0933310f4c 100644
--- a/libavformat/audiointerleave.h
+++ b/libavformat/audiointerleave.h
@@ -29,14 +29,15 @@
 typedef struct AudioInterleaveContext {
 AVFifoBuffer *fifo;
 unsigned fifo_size;   ///< size of currently allocated FIFO
+int64_t n;///< number of generated packets
+int64_t nb_samples;   ///< number of generated samples
 uint64_t dts; ///< current dts
 int sample_size;  ///< size of one sample all channels included
-const int *samples_per_frame; ///< must be 0-terminated
-const int *samples;   ///< current samples per frame, pointer to 
samples_per_frame
+int samples_per_frame;///< samples per frame if fixed, 0 otherwise
 AVRational time_base; ///< time base of output audio packets
 } AudioInterleaveContext;
 
-int ff_audio_interleave_init(AVFormatContext *s, const int *samples_per_frame, 
AVRational time_base);
+int ff_audio_interleave_init(AVFormatContext *s, const int samples_per_frame, 
AVRational time_base);
 void ff_audio_interleave_close(AVFormatContext *s);
 
 /**
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 9eebefc683..e7536a6a7e 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -663,7 +663,7 @@ static int gxf_write_umf_packet(AVFormatContext *s)
 return updatePacketSize(pb, pos);
 }
 
-static const int 

[FFmpeg-devel] [PATCH v2 5/7] avformat/mxfenc: factorize timecode checking and setting

2020-03-05 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/mxfenc.c | 32 +---
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 93d840ebbf..51e2dc5f31 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2407,17 +2407,24 @@ static void mxf_gen_umid(AVFormatContext *s)
 mxf->instance_number = seed & 0xFF;
 }
 
-static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational rate)
+static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational tbc)
 {
 MXFContext *mxf = s->priv_data;
 AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
+
+if (!ff_mxf_get_content_package_rate(tbc)) {
+av_log(s, AV_LOG_ERROR, "Unsupported frame rate %d/%d\n", tbc.den, 
tbc.num);
+return AVERROR(EINVAL);
+}
+
+mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
 if (!tcr)
 tcr = av_dict_get(st->metadata, "timecode", NULL, 0);
 
 if (tcr)
-return av_timecode_init_from_string(>tc, rate, tcr->value, s);
+return av_timecode_init_from_string(>tc, av_inv_q(tbc), 
tcr->value, s);
 else
-return av_timecode_init(>tc, rate, 0, 0, s);
+return av_timecode_init(>tc, av_inv_q(tbc), 0, 0, s);
 }
 
 static int mxf_write_header(AVFormatContext *s)
@@ -2454,7 +2461,7 @@ static int mxf_write_header(AVFormatContext *s)
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 const AVPixFmtDescriptor *pix_desc = 
av_pix_fmt_desc_get(st->codecpar->format);
 // TODO: should be avg_frame_rate
-AVRational rate, tbc = st->time_base;
+AVRational tbc = st->time_base;
 // Default component depth to 8
 sc->component_depth = 8;
 sc->h_chroma_sub_sample = 2;
@@ -2479,16 +2486,9 @@ static int mxf_write_header(AVFormatContext *s)
 }
 
 mxf->content_package_rate = ff_mxf_get_content_package_rate(tbc);
-if (!mxf->content_package_rate) {
-av_log(s, AV_LOG_ERROR, "Unsupported video frame rate %d/%d\n",
-   tbc.den, tbc.num);
-return AVERROR(EINVAL);
-}
-mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
 mxf->time_base = tbc;
-rate = av_inv_q(mxf->time_base);
 avpriv_set_pts_info(st, 64, mxf->time_base.num, 
mxf->time_base.den);
-if((ret = mxf_init_timecode(s, st, rate)) < 0)
+if((ret = mxf_init_timecode(s, st, tbc)) < 0)
 return ret;
 
 if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
@@ -2564,16 +2564,10 @@ static int mxf_write_header(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
-if (!ff_mxf_get_content_package_rate(tbc)) {
-av_log(s, AV_LOG_ERROR, "Unsupported timecode frame rate 
%d/%d\n", tbc.den, tbc.num);
-return AVERROR(EINVAL);
-}
-
 mxf->time_base = st->time_base;
-if((ret = mxf_init_timecode(s, st, av_inv_q(tbc))) < 0)
+if((ret = mxf_init_timecode(s, st, tbc)) < 0)
 return ret;
 
-mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
 mxf->edit_unit_byte_count = 
(av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
 sc->index = INDEX_WAV;
 } else {
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 2/7] avformat/mxf: get rid of samples per frame array usage

2020-03-05 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/mxf.c| 44 
 libavformat/mxf.h|  6 --
 libavformat/mxfdec.c | 23 +++
 libavformat/mxfenc.c | 22 ++
 4 files changed, 17 insertions(+), 78 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 451cbcfb2c..10ccd770e3 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -131,16 +131,6 @@ int ff_mxf_decode_pixel_layout(const char 
pixel_layout[16], enum AVPixelFormat *
 return -1;
 }
 
-static const MXFSamplesPerFrame mxf_spf[] = {
-{ { 1001, 24000 }, { 2002, 0,0,0,0,0 } }, // FILM 23.976
-{ { 1, 24},{ 2000, 0,0,0,0,0 } }, // FILM 24
-{ { 1001, 3 }, { 1602, 1601, 1602, 1601, 1602, 0 } }, // NTSC 29.97
-{ { 1001, 6 }, { 801,  801,  800,  801,  801,  0 } }, // NTSC 59.94
-{ { 1, 25 },   { 1920, 0,0,0,0,0 } }, // PAL 25
-{ { 1, 50 },   { 960,  0,0,0,0,0 } }, // PAL 50
-{ { 1, 60 },   { 800,  0,0,0,0,0 } },
-};
-
 static const AVRational mxf_time_base[] = {
 { 1001, 24000 },
 { 1, 24},
@@ -152,40 +142,14 @@ static const AVRational mxf_time_base[] = {
 { 0, 0}
 };
 
-const MXFSamplesPerFrame *ff_mxf_get_samples_per_frame(AVFormatContext *s,
-   AVRational time_base)
-{
-int idx = av_find_nearest_q_idx(time_base, mxf_time_base);
-AVRational diff = av_sub_q(time_base, mxf_time_base[idx]);
-
-diff.num = FFABS(diff.num);
-
-if (av_cmp_q(diff, (AVRational){1, 1000}) >= 0)
-return NULL;
-
-if (av_cmp_q(time_base, mxf_time_base[idx]))
-av_log(s, AV_LOG_WARNING,
-   "%d/%d input time base matched %d/%d container time base\n",
-   time_base.num, time_base.den,
-   mxf_spf[idx].time_base.num,
-   mxf_spf[idx].time_base.den);
-
-return _spf[idx];
-}
-
 static const int mxf_content_package_rates[] = {
 3, 2, 7, 13, 4, 10, 12,
 };
 
 int ff_mxf_get_content_package_rate(AVRational time_base)
 {
-int idx = av_find_nearest_q_idx(time_base, mxf_time_base);
-AVRational diff = av_sub_q(time_base, mxf_time_base[idx]);
-
-diff.num = FFABS(diff.num);
-
-if (av_cmp_q(diff, (AVRational){1, 1000}) >= 0)
-return -1;
-
-return mxf_content_package_rates[idx];
+for (int i = 0; mxf_time_base[i].num; i++)
+if (!av_cmp_q(time_base, mxf_time_base[i]))
+return mxf_content_package_rates[i];
+return 0;
 }
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index f32124f772..2669269830 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -82,18 +82,12 @@ typedef struct MXFCodecUL {
 MXFWrappingIndicatorType wrapping_indicator_type;
 } MXFCodecUL;
 
-typedef struct {
-struct AVRational time_base;
-int samples_per_frame[6];
-} MXFSamplesPerFrame;
-
 extern const MXFCodecUL ff_mxf_data_definition_uls[];
 extern const MXFCodecUL ff_mxf_codec_uls[];
 extern const MXFCodecUL ff_mxf_pixel_format_uls[];
 extern const MXFCodecUL ff_mxf_codec_tag_uls[];
 
 int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum AVPixelFormat 
*pix_fmt);
-const MXFSamplesPerFrame *ff_mxf_get_samples_per_frame(AVFormatContext *s, 
AVRational time_base);
 int ff_mxf_get_content_package_rate(AVRational time_base);
 
 
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 9a48e2d2d1..9113e2a09c 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3307,20 +3307,17 @@ static int mxf_get_next_track_edit_unit(MXFContext 
*mxf, MXFTrack *track, int64_
 static int64_t mxf_compute_sample_count(MXFContext *mxf, AVStream *st,
 int64_t edit_unit)
 {
-int i, total = 0, size = 0;
 MXFTrack *track = st->priv_data;
 AVRational time_base = av_inv_q(track->edit_rate);
 AVRational sample_rate = av_inv_q(st->time_base);
-const MXFSamplesPerFrame *spf = NULL;
-int64_t sample_count;
 
 // For non-audio sample_count equals current edit unit
 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
 return edit_unit;
 
-if ((sample_rate.num / sample_rate.den) == 48000)
-spf = ff_mxf_get_samples_per_frame(mxf->fc, time_base);
-if (!spf) {
+if ((sample_rate.num / sample_rate.den) == 48000) {
+return av_rescale_q(edit_unit, sample_rate, track->edit_rate);
+} else {
 int remainder = (sample_rate.num * time_base.num) %
 (time_base.den * sample_rate.den);
 if (remainder)
@@ -3331,20 +3328,6 @@ static int64_t mxf_compute_sample_count(MXFContext *mxf, 
AVStream *st,
sample_rate.num, sample_rate.den);
 return av_rescale_q(edit_unit, sample_rate, track->edit_rate);
 }
-
-while (spf->samples_per_frame[size]) {
-total += spf->samples_per_frame[size];
-size++;
-}
-

[FFmpeg-devel] [PATCH v2 4/7] avformat/mxfenc: add some missing content package rates

2020-03-05 Thread Marton Balint
Fixes ticket #8523.

Signed-off-by: Marton Balint 
---
 libavformat/mxf.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 80626e2a16..7d154ca9d3 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -139,10 +139,23 @@ static const MXFContentPackageRate 
mxf_content_package_rates[] = {
 {  2, { 1,24} },
 {  3, { 1001, 24000 } },
 {  4, { 1,25} },
+{  6, { 1,30} },
 {  7, { 1001, 3 } },
+{  8, { 1   , 48} },
+{  9, { 1001, 48000 } },
 { 10, { 1,50} },
 { 12, { 1,60} },
 { 13, { 1001, 6 } },
+{ 14, { 1,72} },
+{ 15, { 1001, 72000 } },
+{ 16, { 1,75} },
+{ 18, { 1,90} },
+{ 19, { 1001, 9 } },
+{ 20, { 1,96} },
+{ 21, { 1001, 96000 } },
+{ 22, { 1,100   } },
+{ 24, { 1,120   } },
+{ 25, { 1001, 12} },
 {0}
 };
 
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Hongcheng Zhong
- On Mar 6, 2020, at 12:55 AM, Andreas Rheinhardt 
andreas.rheinha...@gmail.com wrote:

> Hongcheng Zhong:
>> - On Mar 5, 2020, at 11:38 PM, lq l...@chinaffmpeg.org wrote:
>> 
 2020年3月5日 下午9:41,Hongcheng Zhong  写道:

 This patch fixes Bug #8469
 If x264 baseline profile is used with other profiles,
 start_pts will be initialized to audio stream's first pts,
 while the duration is calculated based on video stream's pts.
 In this patch the start_pts is initialized with the correct stream's first 
 pts.

 Signed-off-by: Hongcheng Zhong 
 ---
 libavformat/hlsenc.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

 diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
 index f6dd894..3b2434f 100644
 --- a/libavformat/hlsenc.c
 +++ b/libavformat/hlsenc.c
 @@ -126,6 +126,7 @@ typedef struct VariantStream {
 int has_video;
 int has_subtitle;
 int new_start;
 +int start_pts_from_audio;
 double dpp;   // duration per packet
 int64_t start_pts;
 int64_t end_pts;
 @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, 
 AVPacket
 *pkt)

 if (vs->start_pts == AV_NOPTS_VALUE) {
 vs->start_pts = pkt->pts;
 +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
 +vs->start_pts_from_audio = 1;
 +}
 +if (vs->start_pts_from_audio && st->codecpar->codec_type ==
 AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
 +vs->start_pts = pkt->pts;
 +vs->start_pts_from_audio = 0;
 }

 -   if (vs->has_video) {
 +if (vs->has_video) {
>>> What’s happen with this line?
 can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
 ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
 HLS_SPLIT_BY_TIME));
 is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
 (pkt->stream_index == vs->reference_stream_index);
 @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
 vs->sequence   = hls->start_sequence;
 vs->start_pts  = AV_NOPTS_VALUE;
 vs->end_pts  = AV_NOPTS_VALUE;
 +vs->start_pts_from_audio = 0;
 vs->current_segment_final_filename_fmt[0] = '\0';

 if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
 HLS_INDEPENDENT_SEGMENTS) {
 --
 2.7.4

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

 To unsubscribe, visit link above, or email
 ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>> 
>> Actually, this line is useless because that vs is initialized as all zero.
>> Should I remove this line and submit this patch as v2 again? Thanks for your
>> reply.
> 
> But vs->has_video is initialized to a potentially nonzero value in
> hls_init().
> 
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

I write that line to make sure that vs->start_pts_from_audio is initialized as 
0.
Since `hls->var_streams = av_mallocz(sizeof(*hls->var_streams) * 
nb_varstreams);`
in hlsenc.c: 1897, var_streams is allocated with av_mallocz(), that line is not 
necessary.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Andreas Rheinhardt
Hongcheng Zhong:
> - On Mar 5, 2020, at 11:38 PM, lq l...@chinaffmpeg.org wrote:
> 
>>> 2020年3月5日 下午9:41,Hongcheng Zhong  写道:
>>>
>>> This patch fixes Bug #8469
>>> If x264 baseline profile is used with other profiles,
>>> start_pts will be initialized to audio stream's first pts,
>>> while the duration is calculated based on video stream's pts.
>>> In this patch the start_pts is initialized with the correct stream's first 
>>> pts.
>>>
>>> Signed-off-by: Hongcheng Zhong 
>>> ---
>>> libavformat/hlsenc.c | 10 +-
>>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> index f6dd894..3b2434f 100644
>>> --- a/libavformat/hlsenc.c
>>> +++ b/libavformat/hlsenc.c
>>> @@ -126,6 +126,7 @@ typedef struct VariantStream {
>>> int has_video;
>>> int has_subtitle;
>>> int new_start;
>>> +int start_pts_from_audio;
>>> double dpp;   // duration per packet
>>> int64_t start_pts;
>>> int64_t end_pts;
>>> @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, 
>>> AVPacket
>>> *pkt)
>>>
>>> if (vs->start_pts == AV_NOPTS_VALUE) {
>>> vs->start_pts = pkt->pts;
>>> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>>> +vs->start_pts_from_audio = 1;
>>> +}
>>> +if (vs->start_pts_from_audio && st->codecpar->codec_type ==
>>> AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
>>> +vs->start_pts = pkt->pts;
>>> +vs->start_pts_from_audio = 0;
>>> }
>>>
>>> -   if (vs->has_video) {
>>> +if (vs->has_video) {
>> What’s happen with this line?
>>> can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
>>> ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
>>> HLS_SPLIT_BY_TIME));
>>> is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
>>> (pkt->stream_index == vs->reference_stream_index);
>>> @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
>>> vs->sequence   = hls->start_sequence;
>>> vs->start_pts  = AV_NOPTS_VALUE;
>>> vs->end_pts  = AV_NOPTS_VALUE;
>>> +vs->start_pts_from_audio = 0;
>>> vs->current_segment_final_filename_fmt[0] = '\0';
>>>
>>> if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
>>> HLS_INDEPENDENT_SEGMENTS) {
>>> --
>>> 2.7.4
>>>
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> Actually, this line is useless because that vs is initialized as all zero.
> Should I remove this line and submit this patch as v2 again? Thanks for your 
> reply.

But vs->has_video is initialized to a potentially nonzero value in
hls_init().

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Hongcheng Zhong
- On Mar 5, 2020, at 11:38 PM, lq l...@chinaffmpeg.org wrote:

>> 2020年3月5日 下午9:41,Hongcheng Zhong  写道:
>> 
>> This patch fixes Bug #8469
>> If x264 baseline profile is used with other profiles,
>> start_pts will be initialized to audio stream's first pts,
>> while the duration is calculated based on video stream's pts.
>> In this patch the start_pts is initialized with the correct stream's first 
>> pts.
>> 
>> Signed-off-by: Hongcheng Zhong 
>> ---
>> libavformat/hlsenc.c | 10 +-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index f6dd894..3b2434f 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -126,6 +126,7 @@ typedef struct VariantStream {
>> int has_video;
>> int has_subtitle;
>> int new_start;
>> +int start_pts_from_audio;
>> double dpp;   // duration per packet
>> int64_t start_pts;
>> int64_t end_pts;
>> @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, 
>> AVPacket
>> *pkt)
>> 
>> if (vs->start_pts == AV_NOPTS_VALUE) {
>> vs->start_pts = pkt->pts;
>> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>> +vs->start_pts_from_audio = 1;
>> +}
>> +if (vs->start_pts_from_audio && st->codecpar->codec_type ==
>> AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
>> +vs->start_pts = pkt->pts;
>> +vs->start_pts_from_audio = 0;
>> }
>> 
>> -   if (vs->has_video) {
>> +if (vs->has_video) {
> What’s happen with this line?
>> can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
>> ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
>> HLS_SPLIT_BY_TIME));
>> is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
>> (pkt->stream_index == vs->reference_stream_index);
>> @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
>> vs->sequence   = hls->start_sequence;
>> vs->start_pts  = AV_NOPTS_VALUE;
>> vs->end_pts  = AV_NOPTS_VALUE;
>> +vs->start_pts_from_audio = 0;
>> vs->current_segment_final_filename_fmt[0] = '\0';
>> 
>> if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
>> HLS_INDEPENDENT_SEGMENTS) {
>> --
>> 2.7.4
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Actually, this line is useless because that vs is initialized as all zero.
Should I remove this line and submit this patch as v2 again? Thanks for your 
reply.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] dashenc: more accurate time values in playlist.mpd

2020-03-05 Thread Alfred E. Heggestad



On 05/03/2020 15:37, Carl Eugen Hoyos wrote:

Am Do., 5. März 2020 um 11:08 Uhr schrieb Alfred E. Heggestad
:


-int64_t update_period = c->last_duration / AV_TIME_BASE;
+double update_period = (double)c->last_duration / AV_TIME_BASE;


Can't you instead do int64 update_period = last_duration * 1000 / AV_TIME_BASE
to avoid using doubles that will potentially break automatic testing?



in this case the update_period will be in [milliseconds] units.
how should I print that ?


or we can use write_time() to print it, in AV_TIME_BASE units:


int64_t update_period = c->last_duration;

avio_printf(out, "\tminimumUpdatePeriod=\"");
write_time(out, update_period);
avio_printf(out, "\"\n");





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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Steven Liu


> 2020年3月5日 下午9:41,Hongcheng Zhong  写道:
> 
> This patch fixes Bug #8469
> If x264 baseline profile is used with other profiles,
> start_pts will be initialized to audio stream's first pts,
> while the duration is calculated based on video stream's pts.
> In this patch the start_pts is initialized with the correct stream's first 
> pts.
> 
> Signed-off-by: Hongcheng Zhong 
> ---
> libavformat/hlsenc.c | 10 +-
> 1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f6dd894..3b2434f 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -126,6 +126,7 @@ typedef struct VariantStream {
> int has_video;
> int has_subtitle;
> int new_start;
> +int start_pts_from_audio;
> double dpp;   // duration per packet
> int64_t start_pts;
> int64_t end_pts;
> @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
> 
> if (vs->start_pts == AV_NOPTS_VALUE) {
> vs->start_pts = pkt->pts;
> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
> +vs->start_pts_from_audio = 1;
> +}
> +if (vs->start_pts_from_audio && st->codecpar->codec_type == 
> AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
> +vs->start_pts = pkt->pts;
> +vs->start_pts_from_audio = 0;
> }
> 
> -   if (vs->has_video) {
> +if (vs->has_video) {
What’s happen with this line?
> can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
> ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
> HLS_SPLIT_BY_TIME));
> is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && 
> (pkt->stream_index == vs->reference_stream_index);
> @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
> vs->sequence   = hls->start_sequence;
> vs->start_pts  = AV_NOPTS_VALUE;
> vs->end_pts  = AV_NOPTS_VALUE;
> +vs->start_pts_from_audio = 0;
> vs->current_segment_final_filename_fmt[0] = '\0';
> 
> if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
> HLS_INDEPENDENT_SEGMENTS) {
> -- 
> 2.7.4
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread James Almer
On 3/5/2020 9:42 AM, Paul B Mahol wrote:
> On 3/5/20, Lynne  wrote:
>> Mar 5, 2020, 11:57 by one...@gmail.com:
>>
>>> On 3/5/20, Paul B Mahol  wrote:
>>>
 On 3/5/20, Andreas Rheinhardt  wrote:

> Paul B Mahol:
>
>> On 3/5/20, Andreas Rheinhardt  wrote:
>>
>>> Am 05.03.2020 um 00:05 schrieb James Almer:
>>>
 On 3/4/2020 7:51 PM, Paul B Mahol wrote:

> On 3/4/20, James Almer  wrote:
>
>> On 3/4/2020 7:26 PM, Paul B Mahol wrote:
>>
>>> Signed-off-by: Paul B Mahol 
>>> ---
>>>  libavformat/Makefile |   1 +
>>>  libavformat/ac4dec.c | 104
>>> +++
>>>  libavformat/allformats.c |   1 +
>>>  3 files changed, 106 insertions(+)
>>>  create mode 100644 libavformat/ac4dec.c
>>>
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index e0681058a2..b4e8d20e65 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+=
>>> aadec.o
>>>  OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o
>>> img2.o
>>> rawdec.o
>>>  OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
>>>  OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
>>> +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
>>>  OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
>>>  OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
>>>  OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
>>> diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
>>> new file mode 100644
>>> index 00..8c6e539409
>>> --- /dev/null
>>> +++ b/libavformat/ac4dec.c
>>> @@ -0,0 +1,104 @@
>>> +/*
>>> + * RAW AC-4 demuxer
>>> + * Copyright (c) 2019 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 "libavutil/avassert.h"
>>> +#include "libavutil/crc.h"
>>> +#include "avformat.h"
>>> +#include "rawdec.h"
>>> +
>>> +static int ac4_probe(const AVProbeData *p)
>>> +{
>>> +const uint8_t *buf = p->buf;
>>> +int left = p->buf_size;
>>> +int max_frames = 0;
>>> +
>>> +while (left > 7) {
>>> +int size;
>>> +
>>> +if (buf[0] == 0xAC &&
>>> +(buf[1] == 0x40 ||
>>> + buf[1] == 0x41)) {
>>> +size = (buf[2] << 8) | buf[3];
>>> +if (size == 0x)
>>> +size = 3 + (buf[4] << 16) | (buf[5] << 8) |
>>> buf[6];
>>> +size += 4;
>>> +if (buf[1] == 0x41)
>>> +size += 2;
>>> +max_frames++;
>>> +left -= size;
>>> +buf += size;
>>> +} else {
>>> +break;
>>> +}
>>> +}
>>> +
>>> +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
>>> +}
>>> +
>>> +static int ac4_read_header(AVFormatContext *s)
>>> +{
>>> +AVStream *st;
>>> +
>>> +st = avformat_new_stream(s, NULL);
>>> +if (!st)
>>> +return AVERROR(ENOMEM);
>>> +
>>> +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>>> +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
>>> +
>>> +return 0;
>>> +}
>>> +
>>> +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
>>> +{
>>> +AVIOContext *pb = s->pb;
>>> +int64_t pos;
>>> +uint16_t sync;
>>> +int ret, size;
>>> +

Re: [FFmpeg-devel] [PATCH] dashenc: more accurate time values in playlist.mpd

2020-03-05 Thread Carl Eugen Hoyos
Am Do., 5. März 2020 um 11:08 Uhr schrieb Alfred E. Heggestad
:

> -int64_t update_period = c->last_duration / AV_TIME_BASE;
> +double update_period = (double)c->last_duration / AV_TIME_BASE;

Can't you instead do int64 update_period = last_duration * 1000 / AV_TIME_BASE
to avoid using doubles that will potentially break automatic testing?

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts

2020-03-05 Thread Hongcheng Zhong
This patch fixes Bug #8469
If x264 baseline profile is used with other profiles,
start_pts will be initialized to audio stream's first pts,
while the duration is calculated based on video stream's pts.
In this patch the start_pts is initialized with the correct stream's first pts.

Signed-off-by: Hongcheng Zhong 
---
 libavformat/hlsenc.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f6dd894..3b2434f 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -126,6 +126,7 @@ typedef struct VariantStream {
 int has_video;
 int has_subtitle;
 int new_start;
+int start_pts_from_audio;
 double dpp;   // duration per packet
 int64_t start_pts;
 int64_t end_pts;
@@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 if (vs->start_pts == AV_NOPTS_VALUE) {
 vs->start_pts = pkt->pts;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+vs->start_pts_from_audio = 1;
+}
+if (vs->start_pts_from_audio && st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
+vs->start_pts = pkt->pts;
+vs->start_pts_from_audio = 0;
 }
 
-   if (vs->has_video) {
+if (vs->has_video) {
 can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
 ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
HLS_SPLIT_BY_TIME));
 is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && 
(pkt->stream_index == vs->reference_stream_index);
@@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s)
 vs->sequence   = hls->start_sequence;
 vs->start_pts  = AV_NOPTS_VALUE;
 vs->end_pts  = AV_NOPTS_VALUE;
+vs->start_pts_from_audio = 0;
 vs->current_segment_final_filename_fmt[0] = '\0';
 
 if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & 
HLS_INDEPENDENT_SEGMENTS) {
-- 
2.7.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Lynne
Mar 5, 2020, 11:57 by one...@gmail.com:

> On 3/5/20, Paul B Mahol  wrote:
>
>> On 3/5/20, Andreas Rheinhardt  wrote:
>>
>>> Paul B Mahol:
>>>
 On 3/5/20, Andreas Rheinhardt  wrote:

> Am 05.03.2020 um 00:05 schrieb James Almer:
>
>> On 3/4/2020 7:51 PM, Paul B Mahol wrote:
>>
>>> On 3/4/20, James Almer  wrote:
>>>
 On 3/4/2020 7:26 PM, Paul B Mahol wrote:

> Signed-off-by: Paul B Mahol 
> ---
>  libavformat/Makefile |   1 +
>  libavformat/ac4dec.c | 104
> +++
>  libavformat/allformats.c |   1 +
>  3 files changed, 106 insertions(+)
>  create mode 100644 libavformat/ac4dec.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index e0681058a2..b4e8d20e65 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+=
> aadec.o
>  OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o
> img2.o
> rawdec.o
>  OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
>  OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
> +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
>  OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
>  OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
>  OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
> diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
> new file mode 100644
> index 00..8c6e539409
> --- /dev/null
> +++ b/libavformat/ac4dec.c
> @@ -0,0 +1,104 @@
> +/*
> + * RAW AC-4 demuxer
> + * Copyright (c) 2019 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 "libavutil/avassert.h"
> +#include "libavutil/crc.h"
> +#include "avformat.h"
> +#include "rawdec.h"
> +
> +static int ac4_probe(const AVProbeData *p)
> +{
> +const uint8_t *buf = p->buf;
> +int left = p->buf_size;
> +int max_frames = 0;
> +
> +while (left > 7) {
> +int size;
> +
> +if (buf[0] == 0xAC &&
> +(buf[1] == 0x40 ||
> + buf[1] == 0x41)) {
> +size = (buf[2] << 8) | buf[3];
> +if (size == 0x)
> +size = 3 + (buf[4] << 16) | (buf[5] << 8) |
> buf[6];
> +size += 4;
> +if (buf[1] == 0x41)
> +size += 2;
> +max_frames++;
> +left -= size;
> +buf += size;
> +} else {
> +break;
> +}
> +}
> +
> +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
> +}
> +
> +static int ac4_read_header(AVFormatContext *s)
> +{
> +AVStream *st;
> +
> +st = avformat_new_stream(s, NULL);
> +if (!st)
> +return AVERROR(ENOMEM);
> +
> +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
> +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
> +
> +return 0;
> +}
> +
> +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +AVIOContext *pb = s->pb;
> +int64_t pos;
> +uint16_t sync;
> +int ret, size;
> +
> +if (avio_feof(s->pb))
> +return AVERROR_EOF;
> +
> +pos   = avio_tell(s->pb);
> +sync = avio_rb16(pb);
>

 If there are sync codes then it sounds like the proper thing to do
 is,
 much like with AC3, writing a trivial parser 

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Paul B Mahol
On 3/5/20, Lynne  wrote:
> Mar 5, 2020, 11:57 by one...@gmail.com:
>
>> On 3/5/20, Paul B Mahol  wrote:
>>
>>> On 3/5/20, Andreas Rheinhardt  wrote:
>>>
 Paul B Mahol:

> On 3/5/20, Andreas Rheinhardt  wrote:
>
>> Am 05.03.2020 um 00:05 schrieb James Almer:
>>
>>> On 3/4/2020 7:51 PM, Paul B Mahol wrote:
>>>
 On 3/4/20, James Almer  wrote:

> On 3/4/2020 7:26 PM, Paul B Mahol wrote:
>
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavformat/Makefile |   1 +
>>  libavformat/ac4dec.c | 104
>> +++
>>  libavformat/allformats.c |   1 +
>>  3 files changed, 106 insertions(+)
>>  create mode 100644 libavformat/ac4dec.c
>>
>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>> index e0681058a2..b4e8d20e65 100644
>> --- a/libavformat/Makefile
>> +++ b/libavformat/Makefile
>> @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+=
>> aadec.o
>>  OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o
>> img2.o
>> rawdec.o
>>  OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
>>  OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
>> +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
>>  OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
>>  OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
>>  OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
>> diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
>> new file mode 100644
>> index 00..8c6e539409
>> --- /dev/null
>> +++ b/libavformat/ac4dec.c
>> @@ -0,0 +1,104 @@
>> +/*
>> + * RAW AC-4 demuxer
>> + * Copyright (c) 2019 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 "libavutil/avassert.h"
>> +#include "libavutil/crc.h"
>> +#include "avformat.h"
>> +#include "rawdec.h"
>> +
>> +static int ac4_probe(const AVProbeData *p)
>> +{
>> +const uint8_t *buf = p->buf;
>> +int left = p->buf_size;
>> +int max_frames = 0;
>> +
>> +while (left > 7) {
>> +int size;
>> +
>> +if (buf[0] == 0xAC &&
>> +(buf[1] == 0x40 ||
>> + buf[1] == 0x41)) {
>> +size = (buf[2] << 8) | buf[3];
>> +if (size == 0x)
>> +size = 3 + (buf[4] << 16) | (buf[5] << 8) |
>> buf[6];
>> +size += 4;
>> +if (buf[1] == 0x41)
>> +size += 2;
>> +max_frames++;
>> +left -= size;
>> +buf += size;
>> +} else {
>> +break;
>> +}
>> +}
>> +
>> +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
>> +}
>> +
>> +static int ac4_read_header(AVFormatContext *s)
>> +{
>> +AVStream *st;
>> +
>> +st = avformat_new_stream(s, NULL);
>> +if (!st)
>> +return AVERROR(ENOMEM);
>> +
>> +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>> +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
>> +
>> +return 0;
>> +}
>> +
>> +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
>> +{
>> +AVIOContext *pb = s->pb;
>> +int64_t pos;
>> +uint16_t sync;
>> +int ret, size;
>> +
>> +if (avio_feof(s->pb))
>> +return AVERROR_EOF;
>> +
>> +pos   = avio_tell(s->pb);
>> +sync = avio_rb16(pb);

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Paul B Mahol
On 3/5/20, Paul B Mahol  wrote:
> On 3/5/20, Andreas Rheinhardt  wrote:
>> Paul B Mahol:
>>> On 3/5/20, Andreas Rheinhardt  wrote:
 Am 05.03.2020 um 00:05 schrieb James Almer:
> On 3/4/2020 7:51 PM, Paul B Mahol wrote:
>> On 3/4/20, James Almer  wrote:
>>> On 3/4/2020 7:26 PM, Paul B Mahol wrote:
 Signed-off-by: Paul B Mahol 
 ---
   libavformat/Makefile |   1 +
   libavformat/ac4dec.c | 104
 +++
   libavformat/allformats.c |   1 +
   3 files changed, 106 insertions(+)
   create mode 100644 libavformat/ac4dec.c

 diff --git a/libavformat/Makefile b/libavformat/Makefile
 index e0681058a2..b4e8d20e65 100644
 --- a/libavformat/Makefile
 +++ b/libavformat/Makefile
 @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+=
 aadec.o
   OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o
 img2.o
 rawdec.o
   OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
   OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
 +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
   OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
   OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
   OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
 diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
 new file mode 100644
 index 00..8c6e539409
 --- /dev/null
 +++ b/libavformat/ac4dec.c
 @@ -0,0 +1,104 @@
 +/*
 + * RAW AC-4 demuxer
 + * Copyright (c) 2019 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 "libavutil/avassert.h"
 +#include "libavutil/crc.h"
 +#include "avformat.h"
 +#include "rawdec.h"
 +
 +static int ac4_probe(const AVProbeData *p)
 +{
 +const uint8_t *buf = p->buf;
 +int left = p->buf_size;
 +int max_frames = 0;
 +
 +while (left > 7) {
 +int size;
 +
 +if (buf[0] == 0xAC &&
 +(buf[1] == 0x40 ||
 + buf[1] == 0x41)) {
 +size = (buf[2] << 8) | buf[3];
 +if (size == 0x)
 +size = 3 + (buf[4] << 16) | (buf[5] << 8) |
 buf[6];
 +size += 4;
 +if (buf[1] == 0x41)
 +size += 2;
 +max_frames++;
 +left -= size;
 +buf += size;
 +} else {
 +break;
 +}
 +}
 +
 +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
 +}
 +
 +static int ac4_read_header(AVFormatContext *s)
 +{
 +AVStream *st;
 +
 +st = avformat_new_stream(s, NULL);
 +if (!st)
 +return AVERROR(ENOMEM);
 +
 +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
 +
 +return 0;
 +}
 +
 +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
 +{
 +AVIOContext *pb = s->pb;
 +int64_t pos;
 +uint16_t sync;
 +int ret, size;
 +
 +if (avio_feof(s->pb))
 +return AVERROR_EOF;
 +
 +pos   = avio_tell(s->pb);
 +sync = avio_rb16(pb);
>>>
>>> If there are sync codes then it sounds like the proper thing to do
>>> is,
>>> much like with AC3, writing a trivial parser to assemble frames and
>>> then
>>> use ff_raw_audio_read_header() and ff_raw_read_partial_packet() here
>>> instead of custom functions.
>>
>> That is over complication for simple parsing 

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Paul B Mahol
On 3/5/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> On 3/5/20, Andreas Rheinhardt  wrote:
>>> Am 05.03.2020 um 00:05 schrieb James Almer:
 On 3/4/2020 7:51 PM, Paul B Mahol wrote:
> On 3/4/20, James Almer  wrote:
>> On 3/4/2020 7:26 PM, Paul B Mahol wrote:
>>> Signed-off-by: Paul B Mahol 
>>> ---
>>>   libavformat/Makefile |   1 +
>>>   libavformat/ac4dec.c | 104
>>> +++
>>>   libavformat/allformats.c |   1 +
>>>   3 files changed, 106 insertions(+)
>>>   create mode 100644 libavformat/ac4dec.c
>>>
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index e0681058a2..b4e8d20e65 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+= aadec.o
>>>   OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o
>>> img2.o
>>> rawdec.o
>>>   OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
>>>   OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
>>> +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
>>>   OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
>>>   OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
>>>   OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
>>> diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
>>> new file mode 100644
>>> index 00..8c6e539409
>>> --- /dev/null
>>> +++ b/libavformat/ac4dec.c
>>> @@ -0,0 +1,104 @@
>>> +/*
>>> + * RAW AC-4 demuxer
>>> + * Copyright (c) 2019 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 "libavutil/avassert.h"
>>> +#include "libavutil/crc.h"
>>> +#include "avformat.h"
>>> +#include "rawdec.h"
>>> +
>>> +static int ac4_probe(const AVProbeData *p)
>>> +{
>>> +const uint8_t *buf = p->buf;
>>> +int left = p->buf_size;
>>> +int max_frames = 0;
>>> +
>>> +while (left > 7) {
>>> +int size;
>>> +
>>> +if (buf[0] == 0xAC &&
>>> +(buf[1] == 0x40 ||
>>> + buf[1] == 0x41)) {
>>> +size = (buf[2] << 8) | buf[3];
>>> +if (size == 0x)
>>> +size = 3 + (buf[4] << 16) | (buf[5] << 8) | buf[6];
>>> +size += 4;
>>> +if (buf[1] == 0x41)
>>> +size += 2;
>>> +max_frames++;
>>> +left -= size;
>>> +buf += size;
>>> +} else {
>>> +break;
>>> +}
>>> +}
>>> +
>>> +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
>>> +}
>>> +
>>> +static int ac4_read_header(AVFormatContext *s)
>>> +{
>>> +AVStream *st;
>>> +
>>> +st = avformat_new_stream(s, NULL);
>>> +if (!st)
>>> +return AVERROR(ENOMEM);
>>> +
>>> +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>>> +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
>>> +
>>> +return 0;
>>> +}
>>> +
>>> +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
>>> +{
>>> +AVIOContext *pb = s->pb;
>>> +int64_t pos;
>>> +uint16_t sync;
>>> +int ret, size;
>>> +
>>> +if (avio_feof(s->pb))
>>> +return AVERROR_EOF;
>>> +
>>> +pos   = avio_tell(s->pb);
>>> +sync = avio_rb16(pb);
>>
>> If there are sync codes then it sounds like the proper thing to do is,
>> much like with AC3, writing a trivial parser to assemble frames and
>> then
>> use ff_raw_audio_read_header() and ff_raw_read_partial_packet() here
>> instead of custom functions.
>
> That is over complication for simple parsing like here.
> Every raw packet have exact frame size set in bitstream.

 So does AC3, judging by how its parser assembles frames.

 An AVParser will let you resync after a bad seek, read 

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Andreas Rheinhardt
Paul B Mahol:
> On 3/5/20, Andreas Rheinhardt  wrote:
>> Am 05.03.2020 um 00:05 schrieb James Almer:
>>> On 3/4/2020 7:51 PM, Paul B Mahol wrote:
 On 3/4/20, James Almer  wrote:
> On 3/4/2020 7:26 PM, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>   libavformat/Makefile |   1 +
>>   libavformat/ac4dec.c | 104
>> +++
>>   libavformat/allformats.c |   1 +
>>   3 files changed, 106 insertions(+)
>>   create mode 100644 libavformat/ac4dec.c
>>
>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>> index e0681058a2..b4e8d20e65 100644
>> --- a/libavformat/Makefile
>> +++ b/libavformat/Makefile
>> @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+= aadec.o
>>   OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o img2.o
>> rawdec.o
>>   OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
>>   OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
>> +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
>>   OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
>>   OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
>>   OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
>> diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
>> new file mode 100644
>> index 00..8c6e539409
>> --- /dev/null
>> +++ b/libavformat/ac4dec.c
>> @@ -0,0 +1,104 @@
>> +/*
>> + * RAW AC-4 demuxer
>> + * Copyright (c) 2019 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 "libavutil/avassert.h"
>> +#include "libavutil/crc.h"
>> +#include "avformat.h"
>> +#include "rawdec.h"
>> +
>> +static int ac4_probe(const AVProbeData *p)
>> +{
>> +const uint8_t *buf = p->buf;
>> +int left = p->buf_size;
>> +int max_frames = 0;
>> +
>> +while (left > 7) {
>> +int size;
>> +
>> +if (buf[0] == 0xAC &&
>> +(buf[1] == 0x40 ||
>> + buf[1] == 0x41)) {
>> +size = (buf[2] << 8) | buf[3];
>> +if (size == 0x)
>> +size = 3 + (buf[4] << 16) | (buf[5] << 8) | buf[6];
>> +size += 4;
>> +if (buf[1] == 0x41)
>> +size += 2;
>> +max_frames++;
>> +left -= size;
>> +buf += size;
>> +} else {
>> +break;
>> +}
>> +}
>> +
>> +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
>> +}
>> +
>> +static int ac4_read_header(AVFormatContext *s)
>> +{
>> +AVStream *st;
>> +
>> +st = avformat_new_stream(s, NULL);
>> +if (!st)
>> +return AVERROR(ENOMEM);
>> +
>> +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>> +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
>> +
>> +return 0;
>> +}
>> +
>> +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
>> +{
>> +AVIOContext *pb = s->pb;
>> +int64_t pos;
>> +uint16_t sync;
>> +int ret, size;
>> +
>> +if (avio_feof(s->pb))
>> +return AVERROR_EOF;
>> +
>> +pos   = avio_tell(s->pb);
>> +sync = avio_rb16(pb);
>
> If there are sync codes then it sounds like the proper thing to do is,
> much like with AC3, writing a trivial parser to assemble frames and then
> use ff_raw_audio_read_header() and ff_raw_read_partial_packet() here
> instead of custom functions.

 That is over complication for simple parsing like here.
 Every raw packet have exact frame size set in bitstream.
>>>
>>> So does AC3, judging by how its parser assembles frames.
>>>
>>> An AVParser will let you resync after a bad seek, read frames in non
>>> seekable input like a pipe, read frames within badly muxed files,
>>> simplify the demuxer, etc, and is a matter of just looking for that
>>> 16bit sync code and assembling 

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Paul B Mahol
On 3/5/20, Andreas Rheinhardt  wrote:
> Am 05.03.2020 um 00:05 schrieb James Almer:
>> On 3/4/2020 7:51 PM, Paul B Mahol wrote:
>>> On 3/4/20, James Almer  wrote:
 On 3/4/2020 7:26 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>   libavformat/Makefile |   1 +
>   libavformat/ac4dec.c | 104
> +++
>   libavformat/allformats.c |   1 +
>   3 files changed, 106 insertions(+)
>   create mode 100644 libavformat/ac4dec.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index e0681058a2..b4e8d20e65 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+= aadec.o
>   OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o img2.o
> rawdec.o
>   OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
>   OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
> +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
>   OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
>   OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
>   OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
> diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
> new file mode 100644
> index 00..8c6e539409
> --- /dev/null
> +++ b/libavformat/ac4dec.c
> @@ -0,0 +1,104 @@
> +/*
> + * RAW AC-4 demuxer
> + * Copyright (c) 2019 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 "libavutil/avassert.h"
> +#include "libavutil/crc.h"
> +#include "avformat.h"
> +#include "rawdec.h"
> +
> +static int ac4_probe(const AVProbeData *p)
> +{
> +const uint8_t *buf = p->buf;
> +int left = p->buf_size;
> +int max_frames = 0;
> +
> +while (left > 7) {
> +int size;
> +
> +if (buf[0] == 0xAC &&
> +(buf[1] == 0x40 ||
> + buf[1] == 0x41)) {
> +size = (buf[2] << 8) | buf[3];
> +if (size == 0x)
> +size = 3 + (buf[4] << 16) | (buf[5] << 8) | buf[6];
> +size += 4;
> +if (buf[1] == 0x41)
> +size += 2;
> +max_frames++;
> +left -= size;
> +buf += size;
> +} else {
> +break;
> +}
> +}
> +
> +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
> +}
> +
> +static int ac4_read_header(AVFormatContext *s)
> +{
> +AVStream *st;
> +
> +st = avformat_new_stream(s, NULL);
> +if (!st)
> +return AVERROR(ENOMEM);
> +
> +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
> +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
> +
> +return 0;
> +}
> +
> +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +AVIOContext *pb = s->pb;
> +int64_t pos;
> +uint16_t sync;
> +int ret, size;
> +
> +if (avio_feof(s->pb))
> +return AVERROR_EOF;
> +
> +pos   = avio_tell(s->pb);
> +sync = avio_rb16(pb);

 If there are sync codes then it sounds like the proper thing to do is,
 much like with AC3, writing a trivial parser to assemble frames and then
 use ff_raw_audio_read_header() and ff_raw_read_partial_packet() here
 instead of custom functions.
>>>
>>> That is over complication for simple parsing like here.
>>> Every raw packet have exact frame size set in bitstream.
>>
>> So does AC3, judging by how its parser assembles frames.
>>
>> An AVParser will let you resync after a bad seek, read frames in non
>> seekable input like a pipe, read frames within badly muxed files,
>> simplify the demuxer, etc, and is a matter of just looking for that
>> 16bit sync code and assembling a frame. Essentially just re-implementing
>> what you already did in ac4_probe().
>>
>
> If it is intended that the actual AVPackets should not 

Re: [FFmpeg-devel] [PATCH] dashenc: more accurate time values in playlist.mpd

2020-03-05 Thread Alfred E. Heggestad

On 05/03/2020 11:40, Moritz Barsnick wrote:

On Thu, Mar 05, 2020 at 11:01:19 +0100, Alfred E. Heggestad wrote:

-avio_printf(out,
"\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration /
AV_TIME_BASE);
+avio_printf(out,
"\tsuggestedPresentationDelay=\"PT%.3fS\"\n", (double)c->last_duration /
AV_TIME_BASE);


Your patch is corrupted by newlines, which makes it impossible to apply
it easily (or even automatically). Please resend it as an attachment,
or using "git send-email".



thanks,

here is the patch attached.



/alfred

From c569a1d970d27e814f54dbacf5dac7a337efb0d6 Mon Sep 17 00:00:00 2001
From: "Alfred E. Heggestad" 
Date: Thu, 5 Mar 2020 10:52:29 +0100
Subject: [PATCH] dashenc: more accurate time values in playlist.mpd

use 3 decimals for the following items:

- minBufferTime
- minimumUpdatePeriod
- timeShiftBufferDepth
- suggestedPresentationDelay

This improves buffering with shaka player

Signed-off-by: Alfred E. Heggestad 
---
 libavformat/dashenc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 94d463972a..37fbbbc1d2 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -774,7 +774,7 @@ static void write_time(AVIOContext *out, int64_t time)
 avio_printf(out, "%dH", hours);
 if (hours || minutes)
 avio_printf(out, "%dM", minutes);
-avio_printf(out, "%d.%dS", seconds, fractions / (AV_TIME_BASE / 10));
+avio_printf(out, "%d.%03dS", seconds, (fractions * 1000) / AV_TIME_BASE);
 }
 
 static void format_date(char *buf, int size, int64_t time_us)
@@ -1171,13 +1171,13 @@ static int write_manifest(AVFormatContext *s, int final)
 write_time(out, c->total_duration);
 avio_printf(out, "\"\n");
 } else {
-int64_t update_period = c->last_duration / AV_TIME_BASE;
+double update_period = (double)c->last_duration / AV_TIME_BASE;
 char now_str[100];
 if (c->use_template && !c->use_timeline)
 update_period = 500;
-avio_printf(out, "\tminimumUpdatePeriod=\"PT%"PRId64"S\"\n", 
update_period);
+avio_printf(out, "\tminimumUpdatePeriod=\"PT%.3fS\"\n", update_period);
 if (!c->ldash)
-avio_printf(out, 
"\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration / 
AV_TIME_BASE);
+avio_printf(out, "\tsuggestedPresentationDelay=\"PT%.3fS\"\n", 
(double)c->last_duration / AV_TIME_BASE);
 if (c->availability_start_time[0])
 avio_printf(out, "\tavailabilityStartTime=\"%s\"\n", 
c->availability_start_time);
 format_date(now_str, sizeof(now_str), av_gettime());
-- 
2.20.1 (Apple Git-117)

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] dashenc: more accurate time values in playlist.mpd

2020-03-05 Thread Moritz Barsnick
On Thu, Mar 05, 2020 at 11:01:19 +0100, Alfred E. Heggestad wrote:
> -avio_printf(out,
> "\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration /
> AV_TIME_BASE);
> +avio_printf(out,
> "\tsuggestedPresentationDelay=\"PT%.3fS\"\n", (double)c->last_duration /
> AV_TIME_BASE);

Your patch is corrupted by newlines, which makes it impossible to apply
it easily (or even automatically). Please resend it as an attachment,
or using "git send-email".

Thanks,
Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer

2020-03-05 Thread Paul B Mahol
On 3/5/20, James Almer  wrote:
> On 3/4/2020 7:51 PM, Paul B Mahol wrote:
>> On 3/4/20, James Almer  wrote:
>>> On 3/4/2020 7:26 PM, Paul B Mahol wrote:
 Signed-off-by: Paul B Mahol 
 ---
  libavformat/Makefile |   1 +
  libavformat/ac4dec.c | 104 +++
  libavformat/allformats.c |   1 +
  3 files changed, 106 insertions(+)
  create mode 100644 libavformat/ac4dec.c

 diff --git a/libavformat/Makefile b/libavformat/Makefile
 index e0681058a2..b4e8d20e65 100644
 --- a/libavformat/Makefile
 +++ b/libavformat/Makefile
 @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER)+= aadec.o
  OBJS-$(CONFIG_AAC_DEMUXER)   += aacdec.o apetag.o img2.o
 rawdec.o
  OBJS-$(CONFIG_AC3_DEMUXER)   += ac3dec.o rawdec.o
  OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
 +OBJS-$(CONFIG_AC4_DEMUXER)   += ac4dec.o
  OBJS-$(CONFIG_ACM_DEMUXER)   += acm.o rawdec.o
  OBJS-$(CONFIG_ACT_DEMUXER)   += act.o
  OBJS-$(CONFIG_ADF_DEMUXER)   += bintext.o sauce.o
 diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
 new file mode 100644
 index 00..8c6e539409
 --- /dev/null
 +++ b/libavformat/ac4dec.c
 @@ -0,0 +1,104 @@
 +/*
 + * RAW AC-4 demuxer
 + * Copyright (c) 2019 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 "libavutil/avassert.h"
 +#include "libavutil/crc.h"
 +#include "avformat.h"
 +#include "rawdec.h"
 +
 +static int ac4_probe(const AVProbeData *p)
 +{
 +const uint8_t *buf = p->buf;
 +int left = p->buf_size;
 +int max_frames = 0;
 +
 +while (left > 7) {
 +int size;
 +
 +if (buf[0] == 0xAC &&
 +(buf[1] == 0x40 ||
 + buf[1] == 0x41)) {
 +size = (buf[2] << 8) | buf[3];
 +if (size == 0x)
 +size = 3 + (buf[4] << 16) | (buf[5] << 8) | buf[6];
 +size += 4;
 +if (buf[1] == 0x41)
 +size += 2;
 +max_frames++;
 +left -= size;
 +buf += size;
 +} else {
 +break;
 +}
 +}
 +
 +return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
 +}
 +
 +static int ac4_read_header(AVFormatContext *s)
 +{
 +AVStream *st;
 +
 +st = avformat_new_stream(s, NULL);
 +if (!st)
 +return AVERROR(ENOMEM);
 +
 +st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 +st->codecpar->codec_id   = AV_CODEC_ID_AC4;
 +
 +return 0;
 +}
 +
 +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
 +{
 +AVIOContext *pb = s->pb;
 +int64_t pos;
 +uint16_t sync;
 +int ret, size;
 +
 +if (avio_feof(s->pb))
 +return AVERROR_EOF;
 +
 +pos   = avio_tell(s->pb);
 +sync = avio_rb16(pb);
>>>
>>> If there are sync codes then it sounds like the proper thing to do is,
>>> much like with AC3, writing a trivial parser to assemble frames and then
>>> use ff_raw_audio_read_header() and ff_raw_read_partial_packet() here
>>> instead of custom functions.
>>
>> That is over complication for simple parsing like here.
>> Every raw packet have exact frame size set in bitstream.
>
> So does AC3, judging by how its parser assembles frames.
>
> An AVParser will let you resync after a bad seek, read frames in non
> seekable input like a pipe, read frames within badly muxed files,
> simplify the demuxer, etc, and is a matter of just looking for that
> 16bit sync code and assembling a frame. Essentially just re-implementing
> what you already did in ac4_probe().

Disagree, it is over complication for zero gain.

>
>>
>>>
 +size = avio_rb16(pb);
 +if (size == 0x)
 +size = avio_rb24(pb);
 +
 +ret = av_get_packet(pb, pkt, size);
 +pkt->pos = pos;
 +

[FFmpeg-devel] [PATCH] dashenc: more accurate time values in playlist.mpd

2020-03-05 Thread Alfred E. Heggestad

use 3 decimals for the following items:

- minBufferTime
- minimumUpdatePeriod
- timeShiftBufferDepth
- suggestedPresentationDelay

This improves buffering with shaka player

Signed-off-by: Alfred E. Heggestad 
---
 libavformat/dashenc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 94d463972a..37fbbbc1d2 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -774,7 +774,7 @@ static void write_time(AVIOContext *out, int64_t time)
 avio_printf(out, "%dH", hours);
 if (hours || minutes)
 avio_printf(out, "%dM", minutes);
-avio_printf(out, "%d.%dS", seconds, fractions / (AV_TIME_BASE / 10));
+avio_printf(out, "%d.%03dS", seconds, (fractions * 1000) / 
AV_TIME_BASE);

 }

 static void format_date(char *buf, int size, int64_t time_us)
@@ -1171,13 +1171,13 @@ static int write_manifest(AVFormatContext *s, 
int final)

 write_time(out, c->total_duration);
 avio_printf(out, "\"\n");
 } else {
-int64_t update_period = c->last_duration / AV_TIME_BASE;
+double update_period = (double)c->last_duration / AV_TIME_BASE;
 char now_str[100];
 if (c->use_template && !c->use_timeline)
 update_period = 500;
-avio_printf(out, "\tminimumUpdatePeriod=\"PT%"PRId64"S\"\n", 
update_period);
+avio_printf(out, "\tminimumUpdatePeriod=\"PT%.3fS\"\n", 
update_period);

 if (!c->ldash)
-avio_printf(out, 
"\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration / 
AV_TIME_BASE);
+avio_printf(out, 
"\tsuggestedPresentationDelay=\"PT%.3fS\"\n", (double)c->last_duration / 
AV_TIME_BASE);

 if (c->availability_start_time[0])
 avio_printf(out, "\tavailabilityStartTime=\"%s\"\n", 
c->availability_start_time);

 format_date(now_str, sizeof(now_str), av_gettime());
--
2.20.1 (Apple Git-117)

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v8 4/4] avcodec/mpeg12dec: Add CPB coded side data

2020-03-05 Thread Nicolas Gaullier
This fixes mpeg2video stream copies to mpeg muxer like this:
  ffmpeg -i xdcamhd.mxf -c:v copy output.mpg
---
 libavcodec/mpeg12dec.c   | 7 +++
 tests/ref/fate/mxf-probe-d10 | 3 +++
 tests/ref/fate/ts-demux  | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 2945728edd..f3b33812ad 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1399,6 +1399,7 @@ static void mpeg_decode_sequence_extension(Mpeg1Context 
*s1)
 MpegEncContext *s = >mpeg_enc_ctx;
 int horiz_size_ext, vert_size_ext;
 int bit_rate_ext;
+AVCPBProperties *cpb_props;
 
 skip_bits(>gb, 1); /* profile and level esc*/
 s->avctx->profile   = get_bits(>gb, 3);
@@ -1430,6 +1431,12 @@ static void mpeg_decode_sequence_extension(Mpeg1Context 
*s1)
 ff_dlog(s->avctx, "sequence extension\n");
 s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
 
+if (cpb_props = ff_add_cpb_side_data(s->avctx)) {
+cpb_props->buffer_size = s1->rc_buffer_size;
+if (s->bit_rate != 0x3*400)
+cpb_props->max_bitrate = s->bit_rate;
+}
+
 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
 av_log(s->avctx, AV_LOG_DEBUG,
"profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, 
bitrate:%"PRId64"\n",
diff --git a/tests/ref/fate/mxf-probe-d10 b/tests/ref/fate/mxf-probe-d10
index ab564467b5..317d4ae4c5 100644
--- a/tests/ref/fate/mxf-probe-d10
+++ b/tests/ref/fate/mxf-probe-d10
@@ -50,6 +50,9 @@ DISPOSITION:clean_effects=0
 DISPOSITION:attached_pic=0
 DISPOSITION:timed_thumbnails=0
 
TAG:file_package_umid=0x060A2B340101010501010D131300AE86B20091310580080046A54011
+[SIDE_DATA]
+side_data_type=CPB properties
+[/SIDE_DATA]
 [/STREAM]
 [STREAM]
 index=1
diff --git a/tests/ref/fate/ts-demux b/tests/ref/fate/ts-demux
index eb13ecc684..cdf34d6af0 100644
--- a/tests/ref/fate/ts-demux
+++ b/tests/ref/fate/ts-demux
@@ -15,7 +15,7 @@
 1,   5760,   5760, 2880, 1536, 0xbab5129c
 1,   8640,   8640, 2880, 1536, 0x602f034b, S=1,1, 
0x00bd00bd
 1,  11520,  11520, 2880,  906, 0x69cdcbcd
-0,  32037,  36541, 1501,   114336, 0x37a215a8, S=1,1, 
0x00e000e0
+0,  32037,  36541, 1501,   114336, 0x37a215a8, S=2,1, 
0x00e000e0,   24, 0x663d0b52
 0,  33538,  33538, 1501,12560, 0xb559a3d4, F=0x0, S=1,
1, 0x00e000e0
 0,  35040,  35040, 1501,12704, 0x2614adf4, F=0x0, S=1,
1, 0x00e000e0
 0,  36541,  41046, 1501,51976, 0x9ff1dbfe, F=0x0, S=1,
1, 0x00e000e0
-- 
2.25.0.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v8 3/4] avcodec/utils: Fix ff_add_cpb_side_data() add twice

2020-03-05 Thread Nicolas Gaullier
Makes it behave similarly to av_stream_add_side_data().
---
 libavcodec/utils.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c4dc136d3c..08e2d5b68b 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1980,6 +1980,11 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext 
*avctx)
 AVPacketSideData *tmp;
 AVCPBProperties  *props;
 size_t size;
+int i;
+
+for (i = 0; i < avctx->nb_coded_side_data; i++)
+if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
+return (AVCPBProperties  *)avctx->coded_side_data[i].data;
 
 props = av_cpb_properties_alloc();
 if (!props)
-- 
2.25.0.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v8 1/4] avcodec/mpeg12dec: Do not alter avctx->rc_buffer_size

2020-03-05 Thread Nicolas Gaullier
---
 libavcodec/mpeg12dec.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 17f9495a1d..2945728edd 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -64,6 +64,7 @@ typedef struct Mpeg1Context {
 int slice_count;
 AVRational save_aspect;
 int save_width, save_height, save_progressive_seq;
+int rc_buffer_size;
 AVRational frame_rate_ext;  /* MPEG-2 specific framerate modificator */
 int sync;   /* Did we reach a sync point like a 
GOP/SEQ/KEYFrame? */
 int tmpgexs;
@@ -1417,7 +1418,7 @@ static void mpeg_decode_sequence_extension(Mpeg1Context 
*s1)
 bit_rate_ext = get_bits(>gb, 12);  /* XXX: handle it */
 s->bit_rate += (bit_rate_ext << 18) * 400LL;
 check_marker(s->avctx, >gb, "after bit rate extension");
-s->avctx->rc_buffer_size += get_bits(>gb, 8) * 1024 * 16 << 10;
+s1->rc_buffer_size += get_bits(>gb, 8) * 1024 * 16 << 10;
 
 s->low_delay = get_bits1(>gb);
 if (s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
@@ -1433,7 +1434,7 @@ static void mpeg_decode_sequence_extension(Mpeg1Context 
*s1)
 av_log(s->avctx, AV_LOG_DEBUG,
"profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, 
bitrate:%"PRId64"\n",
s->avctx->profile, s->avctx->level, s->progressive_sequence, 
s->chroma_format,
-   s->avctx->rc_buffer_size, s->bit_rate);
+   s1->rc_buffer_size, s->bit_rate);
 }
 
 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
@@ -2118,7 +2119,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 }
 
-s->avctx->rc_buffer_size = get_bits(>gb, 10) * 1024 * 16;
+s1->rc_buffer_size = get_bits(>gb, 10) * 1024 * 16;
 skip_bits(>gb, 1);
 
 /* get matrix */
@@ -2167,7 +2168,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
 
 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
 av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%"PRId64", 
aspect_ratio_info: %d \n",
-   s->avctx->rc_buffer_size, s->bit_rate, s->aspect_ratio_info);
+   s1->rc_buffer_size, s->bit_rate, s->aspect_ratio_info);
 
 return 0;
 }
-- 
2.25.0.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v8 2/4] avformat/utils: Make find_stream_info get side data from codec context

2020-03-05 Thread Nicolas Gaullier
This will allow probing input coded side data, and also forwarding them to the 
output.
---
 libavformat/utils.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index cb15f6a4b3..a58e47fabc 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3599,6 +3599,21 @@ static int extract_extradata(AVStream *st, const 
AVPacket *pkt)
 return 0;
 }
 
+static int add_coded_side_data(AVStream *st, AVCodecContext *avctx)
+{
+int i;
+
+for (i = 0; i < avctx->nb_coded_side_data; i++) {
+const AVPacketSideData *sd_src = >coded_side_data[i];
+uint8_t *dst_data;
+dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size);
+if (!dst_data)
+return AVERROR(ENOMEM);
+memcpy(dst_data, sd_src->data, sd_src->size);
+}
+return 0;
+}
+
 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 {
 int i, count = 0, ret = 0, j;
@@ -4138,6 +4153,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 ret = avcodec_parameters_from_context(st->codecpar, 
st->internal->avctx);
 if (ret < 0)
 goto find_stream_info_err;
+ret = add_coded_side_data(st, st->internal->avctx);
+if (ret < 0)
+goto find_stream_info_err;
 #if FF_API_LOWRES
 // The decoder might reduce the video size by the lowres factor.
 if (st->internal->avctx->lowres && orig_w) {
-- 
2.25.0.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v8 0/4] Fix mpeg1/2 stream copy

2020-03-05 Thread Nicolas Gaullier
I have not received any feedback yet.
I repost here with all 4 patches, maybe it is easier for the review
- 1/4: fix mpeg12 decoder use of avctx->rc_buffer_size with is forbidden by API 
doc
- 2/4,3/4,4/4: fix mpeg1/2 stream copy
Thank you

Nicolas Gaullier (4):
  avcodec/mpeg12dec: Do not alter avctx->rc_buffer_size
  avformat/utils: Make find_stream_info get side data from codec context
  avcodec/utils: Fix ff_add_cpb_side_data() add twice
  avcodec/mpeg12dec: Add CPB coded side data

 libavcodec/mpeg12dec.c   | 16 
 libavcodec/utils.c   |  5 +
 libavformat/utils.c  | 18 ++
 tests/ref/fate/mxf-probe-d10 |  3 +++
 tests/ref/fate/ts-demux  |  2 +-
 5 files changed, 39 insertions(+), 5 deletions(-)

-- 
2.25.0.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".