Re: [FFmpeg-devel] [PATCH v3 5/6] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-27 Thread Andreas Rheinhardt
Marton Balint:
> 
> 
> On Mon, 27 Apr 2020, Marton Balint wrote:
> 
>>
>> On Sun, 26 Apr 2020, Andreas Rheinhardt wrote:
>>
> 
> [...]
> 
>>>
>>> And this filter does more than just repacketizing the samples: It also
>>> discards the timing of its input and makes up completely new timestamps
>>> and durations. This needs to be documented.
>>
>> Ok, will do.
> 
> I have given this some additional thought. Maybe it is better to keep
> the original timestamps instead of creating new. Keeping the start
> timestamp should definitely be supported by default and to make this
> filter analogous to af_asetnsamples, I am inclined to keep other
> timestamps as well. The code does not even look ugly, and
> retimeinterleave does not care about the timestamps anyway, just the
> durations. So I think I will resubmit a new version which will make an
> effort to keep the original timestamps. We can make it switchable if
> later it turns out that regenerating would be better.
> 
Sounds very good. In fact, the only reason I was ok with that is that I
thought this bsf to be a helper for retimeinterleave and I had the
impression that retimeinterleave depends on the timestamps being set in
the way the earlier version set them.

- 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 v3 5/6] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-27 Thread Marton Balint



On Mon, 27 Apr 2020, Marton Balint wrote:



On Sun, 26 Apr 2020, Andreas Rheinhardt wrote:



[...]



And this filter does more than just repacketizing the samples: It also
discards the timing of its input and makes up completely new timestamps
and durations. This needs to be documented.


Ok, will do.


I have given this some additional thought. Maybe it is better to keep the 
original timestamps instead of creating new. Keeping the start timestamp 
should definitely be supported by default and to make this filter 
analogous to af_asetnsamples, I am inclined to keep other timestamps as 
well. The code does not even look ugly, and retimeinterleave does not care 
about the timestamps anyway, just the durations. So I think I will 
resubmit a new version which will make an effort to keep the original 
timestamps. We can make it switchable if later it turns out that 
regenerating would be better.


Regards,
Marton
___
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 v3 5/6] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-27 Thread Marton Balint


On Sun, 26 Apr 2020, Andreas Rheinhardt wrote:


Marton Balint:

Signed-off-by: Marton Balint 
---
 Changelog  |   1 +
 doc/bitstream_filters.texi |  30 ++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/pcm_rechunk_bsf.c   | 206 +
 libavcodec/version.h   |   2 +-
 6 files changed, 240 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/pcm_rechunk_bsf.c

diff --git a/Changelog b/Changelog
index d9fcd8bb0a..6b0c911279 100644
--- a/Changelog
+++ b/Changelog
@@ -59,6 +59,7 @@ version :
 - mv30 decoder
 - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
 - WebP parser
+- pcm_rechunk bitstream filter


 version 4.2:
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8fe5b3ad75..70c276feed 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -548,6 +548,36 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
 @section null
 This bitstream filter passes the packets through unchanged.

+@section pcm_rechunk
+
+Repacketize PCM audio to a fixed number of samples per packet or a fixed packet
+rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
+filter,ffmpeg-filters} but works on audio packets instead of audio frames.
+
+@table @option
+@item nb_out_samples, n
+Set the number of samples per each output audio packet. The number is intended
+as the number of samples @emph{per each channel}. Default value is 1024.
+
+@item pad, p
+If set to 1, the filter will pad the last audio packet with silence, so that it
+will contain the same number of samples (or roughly the same number of samples,
+see @option{frame_rate}) as the previous ones. Default value is 1.
+
+@item frame_rate, r
+This option makes the filter output a fixed numer of packets per second instead
+of a fixed number of samples per packet. If the audio sample rate is not
+divisible by the frame rate then the number of samples will not be constant but
+will vary slightly so that each packet will start as close as to the frame


"as close to the frame boundary as possible" or "as close as possible to
the frame boundary"


+boundary as possible. Using this option has precedence over 
@option{nb_out_samples}.
+@end table
+
+You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio
+for NTSC frame rate using the @option{frame_rate} option.
+@example
+ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=3/1001 
-f framecrc -
+@end example
+
 @section prores_metadata

 Modify color property metadata embedded in prores stream.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88944d9a3a..35968bdaf7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += 
mp3_header_decompress_bsf.o \
 OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
+OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6b5ffe4d70..9e701191f8 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
+extern const AVBitStreamFilter ff_pcm_rechunk_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
new file mode 100644
index 00..2a038fd79b
--- /dev/null
+++ b/libavcodec/pcm_rechunk_bsf.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2020 Marton Balint
+ *
+ * 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 

Re: [FFmpeg-devel] [PATCH v3 5/6] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-25 Thread Andreas Rheinhardt
Marton Balint:
> Signed-off-by: Marton Balint 
> ---
>  Changelog  |   1 +
>  doc/bitstream_filters.texi |  30 ++
>  libavcodec/Makefile|   1 +
>  libavcodec/bitstream_filters.c |   1 +
>  libavcodec/pcm_rechunk_bsf.c   | 206 
> +
>  libavcodec/version.h   |   2 +-
>  6 files changed, 240 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/pcm_rechunk_bsf.c
> 
> diff --git a/Changelog b/Changelog
> index d9fcd8bb0a..6b0c911279 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -59,6 +59,7 @@ version :
>  - mv30 decoder
>  - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
>  - WebP parser
> +- pcm_rechunk bitstream filter
>  
>  
>  version 4.2:
> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> index 8fe5b3ad75..70c276feed 100644
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -548,6 +548,36 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
>  @section null
>  This bitstream filter passes the packets through unchanged.
>  
> +@section pcm_rechunk
> +
> +Repacketize PCM audio to a fixed number of samples per packet or a fixed 
> packet
> +rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
> +filter,ffmpeg-filters} but works on audio packets instead of audio frames.
> +
> +@table @option
> +@item nb_out_samples, n
> +Set the number of samples per each output audio packet. The number is 
> intended
> +as the number of samples @emph{per each channel}. Default value is 1024.
> +
> +@item pad, p
> +If set to 1, the filter will pad the last audio packet with silence, so that 
> it
> +will contain the same number of samples (or roughly the same number of 
> samples,
> +see @option{frame_rate}) as the previous ones. Default value is 1.
> +
> +@item frame_rate, r
> +This option makes the filter output a fixed numer of packets per second 
> instead
> +of a fixed number of samples per packet. If the audio sample rate is not
> +divisible by the frame rate then the number of samples will not be constant 
> but
> +will vary slightly so that each packet will start as close as to the frame

"as close to the frame boundary as possible" or "as close as possible to
the frame boundary"

> +boundary as possible. Using this option has precedence over 
> @option{nb_out_samples}.
> +@end table
> +
> +You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz 
> audio
> +for NTSC frame rate using the @option{frame_rate} option.
> +@example
> +ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf 
> pcm_rechunk=r=3/1001 -f framecrc -
> +@end example
> +
>  @section prores_metadata
>  
>  Modify color property metadata embedded in prores stream.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 88944d9a3a..35968bdaf7 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += 
> mp3_header_decompress_bsf.o \
>  OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
>  OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
>  OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
> +OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o
>  OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
>  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
>  OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
> diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
> index 6b5ffe4d70..9e701191f8 100644
> --- a/libavcodec/bitstream_filters.c
> +++ b/libavcodec/bitstream_filters.c
> @@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
>  extern const AVBitStreamFilter ff_mov2textsub_bsf;
>  extern const AVBitStreamFilter ff_noise_bsf;
>  extern const AVBitStreamFilter ff_null_bsf;
> +extern const AVBitStreamFilter ff_pcm_rechunk_bsf;
>  extern const AVBitStreamFilter ff_prores_metadata_bsf;
>  extern const AVBitStreamFilter ff_remove_extradata_bsf;
>  extern const AVBitStreamFilter ff_text2movsub_bsf;
> diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
> new file mode 100644
> index 00..2a038fd79b
> --- /dev/null
> +++ b/libavcodec/pcm_rechunk_bsf.c
> @@ -0,0 +1,206 @@
> +/*
> + * Copyright (c) 2020 Marton Balint
> + *
> + * 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