* [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray
@ 2022-02-26 19:31 Paul B Mahol
2022-02-26 19:31 ` [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder Paul B Mahol
2022-02-27 17:47 ` [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Marton Balint
0 siblings, 2 replies; 8+ messages in thread
From: Paul B Mahol @ 2022-02-26 19:31 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
libavformat/mpegtsenc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 971b3f55d8..48cd54c770 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -2097,6 +2097,10 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
ts_st->dvb_ac3_desc = dvb_ac3_desc;
}
av_free(hdr);
+ } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY) {
+ mpegts_write_pes(s, st, buf, size, pts, dts,
+ pkt->flags & AV_PKT_FLAG_KEY, stream_id);
+ return 0;
}
if (ts_st->payload_size && (ts_st->payload_size + size > ts->pes_payload_size ||
--
2.33.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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder
2022-02-26 19:31 [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Paul B Mahol
@ 2022-02-26 19:31 ` Paul B Mahol
2022-02-28 19:31 ` Michael Niedermayer
2022-02-27 17:47 ` [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Marton Balint
1 sibling, 1 reply; 8+ messages in thread
From: Paul B Mahol @ 2022-02-26 19:31 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/pcm-blurayenc.c | 291 +++++++++++++++++++++++++++++++++++++
3 files changed, 293 insertions(+)
create mode 100644 libavcodec/pcm-blurayenc.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6076b4ad80..e34a9ae862 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -800,6 +800,7 @@ OBJS-$(CONFIG_ZMBV_ENCODER) += zmbvenc.o
# (AD)PCM decoders/encoders
OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_BLURAY_ENCODER) += pcm-blurayenc.o
OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o
OBJS-$(CONFIG_PCM_DVD_DECODER) += pcm-dvd.o
OBJS-$(CONFIG_PCM_DVD_ENCODER) += pcm-dvdenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d1e10197de..1be67e3ec3 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -531,6 +531,7 @@ extern const AVCodec ff_xma2_decoder;
/* PCM codecs */
extern const AVCodec ff_pcm_alaw_encoder;
extern const AVCodec ff_pcm_alaw_decoder;
+extern const AVCodec ff_pcm_bluray_encoder;
extern const AVCodec ff_pcm_bluray_decoder;
extern const AVCodec ff_pcm_dvd_encoder;
extern const AVCodec ff_pcm_dvd_decoder;
diff --git a/libavcodec/pcm-blurayenc.c b/libavcodec/pcm-blurayenc.c
new file mode 100644
index 0000000000..9201ad9690
--- /dev/null
+++ b/libavcodec/pcm-blurayenc.c
@@ -0,0 +1,291 @@
+/*
+ * LPCM codecs for PCM formats found in Blu-ray m2ts streams
+ *
+ * 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/channel_layout.h"
+#include "avcodec.h"
+#include "bytestream.h"
+#include "encode.h"
+#include "internal.h"
+
+typedef struct BlurayPCMEncContext {
+ uint16_t header; // Header added to every frame
+} BlurayPCMEncContext;
+
+static av_cold int pcm_bluray_encode_init(AVCodecContext *avctx)
+{
+ BlurayPCMEncContext *s = avctx->priv_data;
+ uint8_t ch_layout;
+ int quant, freq;
+
+ switch (avctx->sample_rate) {
+ case 48000:
+ freq = 1;
+ break;
+ case 96000:
+ freq = 4;
+ break;
+ case 192000:
+ freq = 5;
+ break;
+ }
+
+ switch (avctx->sample_fmt) {
+ case AV_SAMPLE_FMT_S16:
+ avctx->bits_per_coded_sample = 16;
+ quant = 1;
+ break;
+ case AV_SAMPLE_FMT_S32:
+ avctx->bits_per_coded_sample = 24;
+ quant = 3;
+ break;
+ }
+
+ switch (avctx->channel_layout) {
+ case AV_CH_LAYOUT_MONO:
+ ch_layout = 1;
+ break;
+ case AV_CH_LAYOUT_STEREO:
+ ch_layout = 3;
+ break;
+ case AV_CH_LAYOUT_SURROUND:
+ ch_layout = 4;
+ break;
+ case AV_CH_LAYOUT_2_1:
+ ch_layout = 5;
+ break;
+ case AV_CH_LAYOUT_4POINT0:
+ ch_layout = 6;
+ break;
+ case AV_CH_LAYOUT_2_2:
+ ch_layout = 7;
+ break;
+ case AV_CH_LAYOUT_5POINT0:
+ ch_layout = 8;
+ break;
+ case AV_CH_LAYOUT_5POINT1:
+ ch_layout = 9;
+ break;
+ case AV_CH_LAYOUT_7POINT0:
+ ch_layout = 10;
+ break;
+ case AV_CH_LAYOUT_7POINT1:
+ ch_layout = 11;
+ break;
+ default:
+ return AVERROR_BUG;
+ }
+
+ s->header = (((ch_layout << 4) | freq) << 8) | (quant << 6);
+
+ return 0;
+}
+
+static int pcm_bluray_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+ const AVFrame *frame, int *got_packet_ptr)
+{
+ BlurayPCMEncContext *s = avctx->priv_data;
+ int sample_size, samples, channel, num_dest_channels;
+ const int16_t *src16;
+ const int32_t *src32;
+ unsigned pkt_size;
+ PutByteContext pb;
+ int ret;
+
+ num_dest_channels = FFALIGN(avctx->channels, 2);
+ sample_size = (num_dest_channels *
+ (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
+ samples = frame->nb_samples;
+
+ pkt_size = sample_size * samples + 4;
+
+ if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0)
+ return ret;
+
+ AV_WB16(avpkt->data, pkt_size - 4);
+ AV_WB16(avpkt->data + 2, s->header);
+
+ src16 = (const int16_t *)frame->data[0];
+ src32 = (const int32_t *)frame->data[0];
+
+ bytestream2_init_writer(&pb, avpkt->data + 4, avpkt->size - 4);
+
+ switch (avctx->channel_layout) {
+ /* cases with same number of source and coded channels */
+ case AV_CH_LAYOUT_STEREO:
+ case AV_CH_LAYOUT_4POINT0:
+ case AV_CH_LAYOUT_2_2:
+ samples *= num_dest_channels;
+ if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
+#if HAVE_BIGENDIAN
+ bytestream2_put_buffer(&pb, src16, buf_size);
+#else
+ do {
+ bytestream2_put_be16u(&pb, *src16++);
+ } while (--samples);
+#endif
+ } else {
+ do {
+ bytestream2_put_be24u(&pb, (*src32++) >> 8);
+ } while (--samples);
+ }
+ break;
+ /* cases where number of source channels = coded channels + 1 */
+ case AV_CH_LAYOUT_MONO:
+ case AV_CH_LAYOUT_SURROUND:
+ case AV_CH_LAYOUT_2_1:
+ case AV_CH_LAYOUT_5POINT0:
+ if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
+ do {
+#if HAVE_BIGENDIAN
+ bytestream2_put_bufferu(&pb, src16, avctx->channels * 2);
+ src16 += avctx->channels;
+#else
+ channel = avctx->channels;
+ do {
+ bytestream2_put_be16u(&pb, *src16++);
+ } while (--channel);
+#endif
+ bytestream2_put_ne16(&pb, 0);
+ } while (--samples);
+ } else {
+ do {
+ channel = avctx->channels;
+ do {
+ bytestream2_put_be24u(&pb, (*src32++) >> 8);
+ } while (--channel);
+ bytestream2_put_ne24(&pb, 0);
+ } while (--samples);
+ }
+ break;
+ /* remapping: L, R, C, LBack, RBack, LF */
+ case AV_CH_LAYOUT_5POINT1:
+ if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
+ do {
+ bytestream2_put_be16u(&pb, src16[0]);
+ bytestream2_put_be16u(&pb, src16[1]);
+ bytestream2_put_be16u(&pb, src16[2]);
+ bytestream2_put_be16u(&pb, src16[4]);
+ bytestream2_put_be16u(&pb, src16[5]);
+ bytestream2_put_be16u(&pb, src16[3]);
+ src16 += 6;
+ } while (--samples);
+ } else {
+ do {
+ bytestream2_put_be24u(&pb, src32[0] >> 8);
+ bytestream2_put_be24u(&pb, src32[1] >> 8);
+ bytestream2_put_be24u(&pb, src32[2] >> 8);
+ bytestream2_put_be24u(&pb, src32[4] >> 8);
+ bytestream2_put_be24u(&pb, src32[5] >> 8);
+ bytestream2_put_be24u(&pb, src32[3] >> 8);
+ src32 += 6;
+ } while (--samples);
+ }
+ break;
+ /* remapping: L, R, C, LSide, LBack, RBack, RSide, <unused> */
+ case AV_CH_LAYOUT_7POINT0:
+ if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
+ do {
+ bytestream2_put_be16u(&pb, src16[0]);
+ bytestream2_put_be16u(&pb, src16[1]);
+ bytestream2_put_be16u(&pb, src16[2]);
+ bytestream2_put_be16u(&pb, src16[5]);
+ bytestream2_put_be16u(&pb, src16[3]);
+ bytestream2_put_be16u(&pb, src16[4]);
+ bytestream2_put_be16u(&pb, src16[6]);
+ src16 += 7;
+ bytestream2_put_ne16(&pb, 0);
+ } while (--samples);
+ } else {
+ do {
+ bytestream2_put_be24u(&pb, src32[0] >> 8);
+ bytestream2_put_be24u(&pb, src32[1] >> 8);
+ bytestream2_put_be24u(&pb, src32[2] >> 8);
+ bytestream2_put_be24u(&pb, src32[5] >> 8);
+ bytestream2_put_be24u(&pb, src32[3] >> 8);
+ bytestream2_put_be24u(&pb, src32[4] >> 8);
+ bytestream2_put_be24u(&pb, src32[6] >> 8);
+ src32 += 7;
+ bytestream2_put_ne24(&pb, 0);
+ } while (--samples);
+ }
+ break;
+ /* remapping: L, R, C, LSide, LBack, RBack, RSide, LF */
+ case AV_CH_LAYOUT_7POINT1:
+ if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
+ do {
+ bytestream2_put_be16u(&pb, src16[0]);
+ bytestream2_put_be16u(&pb, src16[1]);
+ bytestream2_put_be16u(&pb, src16[2]);
+ bytestream2_put_be16u(&pb, src16[6]);
+ bytestream2_put_be16u(&pb, src16[4]);
+ bytestream2_put_be16u(&pb, src16[5]);
+ bytestream2_put_be16u(&pb, src16[7]);
+ bytestream2_put_be16u(&pb, src16[3]);
+ src16 += 8;
+ } while (--samples);
+ } else {
+ do {
+ bytestream2_put_be24u(&pb, src32[0]);
+ bytestream2_put_be24u(&pb, src32[1]);
+ bytestream2_put_be24u(&pb, src32[2]);
+ bytestream2_put_be24u(&pb, src32[6]);
+ bytestream2_put_be24u(&pb, src32[4]);
+ bytestream2_put_be24u(&pb, src32[5]);
+ bytestream2_put_be24u(&pb, src32[7]);
+ bytestream2_put_be24u(&pb, src32[3]);
+ src32 += 8;
+ } while (--samples);
+ }
+ break;
+ }
+
+ avpkt->pts = frame->pts;
+ avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
+ *got_packet_ptr = 1;
+
+ return 0;
+}
+
+const AVCodec ff_pcm_bluray_encoder = {
+ .name = "pcm_bluray",
+ .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"),
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = AV_CODEC_ID_PCM_BLURAY,
+ .priv_data_size = sizeof(BlurayPCMEncContext),
+ .init = pcm_bluray_encode_init,
+ .encode2 = pcm_bluray_encode_frame,
+ .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME,
+ .supported_samplerates = (const int[]) { 48000, 96000, 192000, 0 },
+ .channel_layouts = (const uint64_t[]) {
+ AV_CH_LAYOUT_MONO,
+ AV_CH_LAYOUT_STEREO,
+ AV_CH_LAYOUT_SURROUND,
+ AV_CH_LAYOUT_2_1,
+ AV_CH_LAYOUT_4POINT0,
+ AV_CH_LAYOUT_2_2,
+ AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT1,
+ AV_CH_LAYOUT_7POINT0,
+ AV_CH_LAYOUT_7POINT1,
+ 0 },
+ .sample_fmts = (const enum AVSampleFormat[]) {
+ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE },
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
+};
--
2.33.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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray
2022-02-26 19:31 [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Paul B Mahol
2022-02-26 19:31 ` [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder Paul B Mahol
@ 2022-02-27 17:47 ` Marton Balint
2022-02-27 17:51 ` Paul B Mahol
1 sibling, 1 reply; 8+ messages in thread
From: Marton Balint @ 2022-02-27 17:47 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 26 Feb 2022, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
> libavformat/mpegtsenc.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index 971b3f55d8..48cd54c770 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -2097,6 +2097,10 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
> ts_st->dvb_ac3_desc = dvb_ac3_desc;
> }
> av_free(hdr);
> + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY) {
> + mpegts_write_pes(s, st, buf, size, pts, dts,
> + pkt->flags & AV_PKT_FLAG_KEY, stream_id);
> + return 0;
> }
This fixes what exactly?
Thanks,
Marton
>
> if (ts_st->payload_size && (ts_st->payload_size + size > ts->pes_payload_size ||
> --
> 2.33.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-request@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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray
2022-02-27 17:47 ` [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Marton Balint
@ 2022-02-27 17:51 ` Paul B Mahol
2022-02-27 17:55 ` Marton Balint
0 siblings, 1 reply; 8+ messages in thread
From: Paul B Mahol @ 2022-02-27 17:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, Feb 27, 2022 at 6:47 PM Marton Balint <cus@passwd.hu> wrote:
>
>
> On Sat, 26 Feb 2022, Paul B Mahol wrote:
>
> > Signed-off-by: Paul B Mahol <onemda@gmail.com>
> > ---
> > libavformat/mpegtsenc.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> > index 971b3f55d8..48cd54c770 100644
> > --- a/libavformat/mpegtsenc.c
> > +++ b/libavformat/mpegtsenc.c
> > @@ -2097,6 +2097,10 @@ static int
> mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
> > ts_st->dvb_ac3_desc = dvb_ac3_desc;
> > }
> > av_free(hdr);
> > + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY) {
> > + mpegts_write_pes(s, st, buf, size, pts, dts,
> > + pkt->flags & AV_PKT_FLAG_KEY, stream_id);
> > + return 0;
> > }
>
> This fixes what exactly?
>
-c copy for .m2ts file that have pcm_bluray audio codec.
> Thanks,
> Marton
>
> >
> > if (ts_st->payload_size && (ts_st->payload_size + size >
> ts->pes_payload_size ||
> > --
> > 2.33.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-request@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-request@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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray
2022-02-27 17:51 ` Paul B Mahol
@ 2022-02-27 17:55 ` Marton Balint
2022-02-27 20:45 ` Paul B Mahol
0 siblings, 1 reply; 8+ messages in thread
From: Marton Balint @ 2022-02-27 17:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, 27 Feb 2022, Paul B Mahol wrote:
> On Sun, Feb 27, 2022 at 6:47 PM Marton Balint <cus@passwd.hu> wrote:
>
>>
>>
>> On Sat, 26 Feb 2022, Paul B Mahol wrote:
>>
>>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>>> ---
>>> libavformat/mpegtsenc.c | 4 ++++
>>> 1 file changed, 4 insertions(+)
>>>
>>> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
>>> index 971b3f55d8..48cd54c770 100644
>>> --- a/libavformat/mpegtsenc.c
>>> +++ b/libavformat/mpegtsenc.c
>>> @@ -2097,6 +2097,10 @@ static int
>> mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
>>> ts_st->dvb_ac3_desc = dvb_ac3_desc;
>>> }
>>> av_free(hdr);
>>> + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY) {
>>> + mpegts_write_pes(s, st, buf, size, pts, dts,
>>> + pkt->flags & AV_PKT_FLAG_KEY, stream_id);
>>> + return 0;
>>> }
>>
>> This fixes what exactly?
>>
>
> -c copy for .m2ts file that have pcm_bluray audio codec.
Ok, but what happens without the patch?
Thanks,
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray
2022-02-27 17:55 ` Marton Balint
@ 2022-02-27 20:45 ` Paul B Mahol
0 siblings, 0 replies; 8+ messages in thread
From: Paul B Mahol @ 2022-02-27 20:45 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, Feb 27, 2022 at 6:56 PM Marton Balint <cus@passwd.hu> wrote:
>
>
> On Sun, 27 Feb 2022, Paul B Mahol wrote:
>
> > On Sun, Feb 27, 2022 at 6:47 PM Marton Balint <cus@passwd.hu> wrote:
> >
> >>
> >>
> >> On Sat, 26 Feb 2022, Paul B Mahol wrote:
> >>
> >>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> >>> ---
> >>> libavformat/mpegtsenc.c | 4 ++++
> >>> 1 file changed, 4 insertions(+)
> >>>
> >>> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> >>> index 971b3f55d8..48cd54c770 100644
> >>> --- a/libavformat/mpegtsenc.c
> >>> +++ b/libavformat/mpegtsenc.c
> >>> @@ -2097,6 +2097,10 @@ static int
> >> mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
> >>> ts_st->dvb_ac3_desc = dvb_ac3_desc;
> >>> }
> >>> av_free(hdr);
> >>> + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY) {
> >>> + mpegts_write_pes(s, st, buf, size, pts, dts,
> >>> + pkt->flags & AV_PKT_FLAG_KEY, stream_id);
> >>> + return 0;
> >>> }
> >>
> >> This fixes what exactly?
> >>
> >
> > -c copy for .m2ts file that have pcm_bluray audio codec.
>
> Ok, but what happens without the patch?
>
>
All pcm_bluray frames are concatenated together in one big payload, I
thought at first that it may need own parser...
Thanks,
> 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-request@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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder
2022-02-26 19:31 ` [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder Paul B Mahol
@ 2022-02-28 19:31 ` Michael Niedermayer
0 siblings, 0 replies; 8+ messages in thread
From: Michael Niedermayer @ 2022-02-28 19:31 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 8291 bytes --]
On Sat, Feb 26, 2022 at 08:31:43PM +0100, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/pcm-blurayenc.c | 291 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 293 insertions(+)
> create mode 100644 libavcodec/pcm-blurayenc.c
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 6076b4ad80..e34a9ae862 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -800,6 +800,7 @@ OBJS-$(CONFIG_ZMBV_ENCODER) += zmbvenc.o
> # (AD)PCM decoders/encoders
> OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o
> OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o
> +OBJS-$(CONFIG_PCM_BLURAY_ENCODER) += pcm-blurayenc.o
> OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o
> OBJS-$(CONFIG_PCM_DVD_DECODER) += pcm-dvd.o
> OBJS-$(CONFIG_PCM_DVD_ENCODER) += pcm-dvdenc.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index d1e10197de..1be67e3ec3 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -531,6 +531,7 @@ extern const AVCodec ff_xma2_decoder;
> /* PCM codecs */
> extern const AVCodec ff_pcm_alaw_encoder;
> extern const AVCodec ff_pcm_alaw_decoder;
> +extern const AVCodec ff_pcm_bluray_encoder;
> extern const AVCodec ff_pcm_bluray_decoder;
> extern const AVCodec ff_pcm_dvd_encoder;
> extern const AVCodec ff_pcm_dvd_decoder;
> diff --git a/libavcodec/pcm-blurayenc.c b/libavcodec/pcm-blurayenc.c
> new file mode 100644
> index 0000000000..9201ad9690
> --- /dev/null
> +++ b/libavcodec/pcm-blurayenc.c
> @@ -0,0 +1,291 @@
> +/*
> + * LPCM codecs for PCM formats found in Blu-ray m2ts streams
> + *
> + * 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/channel_layout.h"
> +#include "avcodec.h"
> +#include "bytestream.h"
> +#include "encode.h"
> +#include "internal.h"
> +
> +typedef struct BlurayPCMEncContext {
> + uint16_t header; // Header added to every frame
> +} BlurayPCMEncContext;
> +
> +static av_cold int pcm_bluray_encode_init(AVCodecContext *avctx)
> +{
> + BlurayPCMEncContext *s = avctx->priv_data;
> + uint8_t ch_layout;
> + int quant, freq;
> +
> + switch (avctx->sample_rate) {
> + case 48000:
> + freq = 1;
> + break;
> + case 96000:
> + freq = 4;
> + break;
> + case 192000:
> + freq = 5;
> + break;
> + }
> +
> + switch (avctx->sample_fmt) {
> + case AV_SAMPLE_FMT_S16:
> + avctx->bits_per_coded_sample = 16;
> + quant = 1;
> + break;
> + case AV_SAMPLE_FMT_S32:
> + avctx->bits_per_coded_sample = 24;
> + quant = 3;
> + break;
> + }
> +
> + switch (avctx->channel_layout) {
> + case AV_CH_LAYOUT_MONO:
> + ch_layout = 1;
> + break;
> + case AV_CH_LAYOUT_STEREO:
> + ch_layout = 3;
> + break;
> + case AV_CH_LAYOUT_SURROUND:
> + ch_layout = 4;
> + break;
> + case AV_CH_LAYOUT_2_1:
> + ch_layout = 5;
> + break;
> + case AV_CH_LAYOUT_4POINT0:
> + ch_layout = 6;
> + break;
> + case AV_CH_LAYOUT_2_2:
> + ch_layout = 7;
> + break;
> + case AV_CH_LAYOUT_5POINT0:
> + ch_layout = 8;
> + break;
> + case AV_CH_LAYOUT_5POINT1:
> + ch_layout = 9;
> + break;
> + case AV_CH_LAYOUT_7POINT0:
> + ch_layout = 10;
> + break;
> + case AV_CH_LAYOUT_7POINT1:
> + ch_layout = 11;
> + break;
> + default:
> + return AVERROR_BUG;
> + }
> +
> + s->header = (((ch_layout << 4) | freq) << 8) | (quant << 6);
> +
> + return 0;
> +}
> +
> +static int pcm_bluray_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
> + const AVFrame *frame, int *got_packet_ptr)
> +{
> + BlurayPCMEncContext *s = avctx->priv_data;
> + int sample_size, samples, channel, num_dest_channels;
> + const int16_t *src16;
> + const int32_t *src32;
> + unsigned pkt_size;
> + PutByteContext pb;
> + int ret;
> +
> + num_dest_channels = FFALIGN(avctx->channels, 2);
> + sample_size = (num_dest_channels *
> + (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
> + samples = frame->nb_samples;
> +
> + pkt_size = sample_size * samples + 4;
> +
> + if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0)
> + return ret;
> +
> + AV_WB16(avpkt->data, pkt_size - 4);
> + AV_WB16(avpkt->data + 2, s->header);
> +
> + src16 = (const int16_t *)frame->data[0];
> + src32 = (const int32_t *)frame->data[0];
> +
> + bytestream2_init_writer(&pb, avpkt->data + 4, avpkt->size - 4);
> +
> + switch (avctx->channel_layout) {
> + /* cases with same number of source and coded channels */
> + case AV_CH_LAYOUT_STEREO:
> + case AV_CH_LAYOUT_4POINT0:
> + case AV_CH_LAYOUT_2_2:
> + samples *= num_dest_channels;
> + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
> +#if HAVE_BIGENDIAN
> + bytestream2_put_buffer(&pb, src16, buf_size);
> +#else
fails to build for mips
src/libavcodec/pcm-blurayenc.c: In function ‘pcm_bluray_encode_frame’:
src/libavcodec/pcm-blurayenc.c:137:48: error: ‘buf_size’ undeclared (first use in this function); did you mean ‘pkt_size’?
bytestream2_put_buffer(&pb, src16, buf_size);
^~~~~~~~
pkt_size
src/libavcodec/pcm-blurayenc.c:137:48: note: each undeclared identifier is reported only once for each function it appears in
src/libavcodec/pcm-blurayenc.c:137:41: warning: passing argument 2 of ‘bytestream2_put_buffer’ from incompatible pointer type [-Wincompatible-pointer-types]
bytestream2_put_buffer(&pb, src16, buf_size);
^~~~~
In file included from src/libavcodec/pcm-blurayenc.c:23:0:
src/libavcodec/bytestream.h:286:38: note: expected ‘const uint8_t * {aka const unsigned char *}’ but argument is of type ‘const int16_t * {aka const short int *}’
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p,
^~~~~~~~~~~~~~~~~~~~~~
src/libavcodec/pcm-blurayenc.c:157:46: warning: passing argument 2 of ‘bytestream2_put_bufferu’ from incompatible pointer type [-Wincompatible-pointer-types]
bytestream2_put_bufferu(&pb, src16, avctx->channels * 2);
^~~~~
In file included from src/libavcodec/pcm-blurayenc.c:23:0:
src/libavcodec/bytestream.h:301:38: note: expected ‘const uint8_t * {aka const unsigned char *}’ but argument is of type ‘const int16_t * {aka const short int *}’
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p,
^~~~~~~~~~~~~~~~~~~~~~~
src/ffbuild/common.mak:78: recipe for target 'libavcodec/pcm-blurayenc.o' failed
make: *** [libavcodec/pcm-blurayenc.o] Error 1
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Elect your leaders based on what they did after the last election, not
based on what they say before an election.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray
@ 2022-02-28 21:24 Paul B Mahol
0 siblings, 0 replies; 8+ messages in thread
From: Paul B Mahol @ 2022-02-28 21:24 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
libavformat/mpegtsenc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 971b3f55d8..20dce56122 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -2097,6 +2097,10 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
ts_st->dvb_ac3_desc = dvb_ac3_desc;
}
av_free(hdr);
+ } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY && ts->m2ts_mode) {
+ mpegts_write_pes(s, st, buf, size, pts, dts,
+ pkt->flags & AV_PKT_FLAG_KEY, stream_id);
+ return 0;
}
if (ts_st->payload_size && (ts_st->payload_size + size > ts->pes_payload_size ||
--
2.33.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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-02-28 21:23 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-26 19:31 [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Paul B Mahol
2022-02-26 19:31 ` [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder Paul B Mahol
2022-02-28 19:31 ` Michael Niedermayer
2022-02-27 17:47 ` [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray Marton Balint
2022-02-27 17:51 ` Paul B Mahol
2022-02-27 17:55 ` Marton Balint
2022-02-27 20:45 ` Paul B Mahol
2022-02-28 21:24 Paul B Mahol
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git