ret = av_interleaved_write_frame(ffmpeg->fmt_ctx, pkt);
}
else {
+ bsfc->time_base_in = st->time_base;
+ avcodec_parameters_copy(bsfc->par_in, st->codecpar);
+ av_bsf_init(bsfc);
+
ret = av_bsf_send_packet(bsfc, pkt);
while( ret >= 0 ) {
FFPacket bs;
if( ret == AVERROR_EOF ) return -1;
break;
}
+ //printf(" filter name %s \n", bsfc->filter[0].name);
+ //avcodec_parameters_copy(ffmpeg->fmt_ctx->streams[0]->codecpar, bsfc->par_out);
+ //avcodec_parameters_copy(st->codecpar, bsfc->par_out);
av_packet_rescale_ts(bs, avctx->time_base, st->time_base);
bs->stream_index = st->index;
ret = av_interleaved_write_frame(ffmpeg->fmt_ctx, bs);
+++ /dev/null
-diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
-index 88fdbeaf1e..f39d2e7cc4 100644
---- a/fftools/cmdutils.c
-+++ b/fftools/cmdutils.c
-@@ -1184,6 +1184,7 @@ static void print_buildconf(int flags, int level)
-
- void show_banner(int argc, char **argv, const OptionDef *options)
- {
-+ return;
- int idx = locate_option(argc, argv, options, "version");
- if (hide_banner || idx)
- return;
+++ /dev/null
-diff --git a/libavformat/bluray.c b/libavformat/bluray.c
-index 635c4f1b87..80a2e2c3d2 100644
---- a/libavformat/bluray.c
-+++ b/libavformat/bluray.c
-@@ -28,7 +28,7 @@
- #include "libavutil/opt.h"
-
- #define BLURAY_PROTO_PREFIX "bluray:"
--#define MIN_PLAYLIST_LENGTH 180 /* 3 min */
-+#define MIN_PLAYLIST_LENGTH 0
-
- typedef struct {
- const AVClass *class;
+++ /dev/null
-diff -git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
---- a/libavformat/mpegtsenc.c 2021-04-08 15:28:40.000000000 -0600
-+++ b/libavformat/mpegtsenc.c 2021-05-29 11:47:43.834039463 -0600
-@@ -81,9 +81,11 @@
- int64_t sdt_period; /* SDT period in PCR time base */
- int64_t pat_period; /* PAT/PMT period in PCR time base */
- int nb_services;
-- int64_t first_pcr;
- int first_dts_checked;
-- int64_t next_pcr;
-+ int64_t pcr_pos, pcr;
-+ int64_t first_pcr, next_pcr;
-+ int64_t delay;
-+ int pcr_stream_pid;
- int mux_rate; ///< set to 1 when VBR
- int pes_payload_size;
- int64_t total_size;
-@@ -243,7 +245,7 @@
- int data_st_warning;
-
- int64_t pcr_period; /* PCR period in PCR time base */
-- int64_t last_pcr;
-+ int64_t pcr_timer;
-
- /* For Opus */
- int opus_queued_samples;
-@@ -833,18 +835,18 @@
- return 0;
- }
-
--static int64_t get_pcr(const MpegTSWrite *ts)
-+static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
- {
-- return av_rescale(ts->total_size + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
-- ts->first_pcr;
-+ int64_t pos = avio_tell(pb) + 11;
-+ return ts->pcr + (ts->mux_rate == 1 ? (pos - ts->pcr_pos) * 8 :
-+ av_rescale(pos - ts->pcr_pos, 8 * PCR_TIME_BASE, ts->mux_rate));
- }
-
- static void write_packet(AVFormatContext *s, const uint8_t *packet)
- {
- MpegTSWrite *ts = s->priv_data;
- if (ts->m2ts_mode) {
-- int64_t pcr = get_pcr(s->priv_data);
-- uint32_t tp_extra_header = pcr % 0x3fffffff;
-+ uint32_t tp_extra_header = get_pcr(ts, s->pb) % 0x3fffffff;
- tp_extra_header = AV_RB32(&tp_extra_header);
- avio_write(s->pb, (unsigned char *) &tp_extra_header,
- sizeof(tp_extra_header));
-@@ -930,9 +932,6 @@
- else
- ts_st->pcr_period = 1;
- }
--
-- // output a PCR as soon as possible
-- ts_st->last_pcr = ts->first_pcr - ts_st->pcr_period;
- }
-
- static void select_pcr_streams(AVFormatContext *s)
-@@ -993,6 +992,7 @@
-
- if (s->max_delay < 0) /* Not set by the caller */
- s->max_delay = 0;
-+ ts->delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
-
- // round up to a whole number of TS packets
- ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14;
-@@ -1048,7 +1048,9 @@
- /* MPEG pid values < 16 are reserved. Applications which set st->id in
- * this range are assigned a calculated pid. */
- if (st->id < 16) {
-- if (ts->m2ts_mode) {
-+ if (ts->start_pid >= 0)
-+ ts_st->pid = ts->start_pid + i;
-+ else if (ts->m2ts_mode) {
- switch (st->codecpar->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- ts_st->pid = ts->m2ts_video_pid++;
-@@ -1075,9 +1077,9 @@
- av_log(s, AV_LOG_ERROR, "Cannot automatically assign PID for stream %d\n", st->index);
- return AVERROR(EINVAL);
- }
-- } else {
-- ts_st->pid = ts->start_pid + i;
- }
-+ else
-+ ts_st->pid = START_PID + i;
- } else {
- ts_st->pid = st->id;
- }
-@@ -1144,8 +1146,12 @@
-
- ts->last_pat_ts = AV_NOPTS_VALUE;
- ts->last_sdt_ts = AV_NOPTS_VALUE;
-- ts->pat_period = av_rescale(ts->pat_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-- ts->sdt_period = av_rescale(ts->sdt_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->pat_period = ts->pat_period_us < 0 ? -1 :
-+ av_rescale(ts->pat_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->sdt_period = ts->sdt_period_us < 0 ? -1 :
-+ av_rescale(ts->sdt_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->pcr = 0;
-+ ts->pcr_pos = 0;
-
- if (ts->mux_rate == 1)
- av_log(s, AV_LOG_VERBOSE, "muxrate VBR, ");
-@@ -1153,34 +1159,37 @@
- av_log(s, AV_LOG_VERBOSE, "muxrate %d, ", ts->mux_rate);
- av_log(s, AV_LOG_VERBOSE,
- "sdt every %"PRId64" ms, pat/pmt every %"PRId64" ms\n",
-- av_rescale(ts->sdt_period, 1000, PCR_TIME_BASE),
-- av_rescale(ts->pat_period, 1000, PCR_TIME_BASE));
-+ ts->sdt_period < 0 ? -1 : av_rescale(ts->sdt_period, 1000, PCR_TIME_BASE),
-+ ts->pat_period < 0 ? -1 : av_rescale(ts->pat_period, 1000, PCR_TIME_BASE));
-
- return 0;
- }
-
- /* send SDT, PAT and PMT tables regularly */
--static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt, int64_t pcr)
-+static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt)
- {
- MpegTSWrite *ts = s->priv_data;
- int i;
-
-- if ((pcr != AV_NOPTS_VALUE && ts->last_sdt_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_sdt_ts >= ts->sdt_period) ||
-- force_sdt
-- ) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_sdt_ts = FFMAX(pcr, ts->last_sdt_ts);
-- mpegts_write_sdt(s);
-- }
-- if ((pcr != AV_NOPTS_VALUE && ts->last_pat_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_pat_ts >= ts->pat_period) ||
-- force_pat) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_pat_ts = FFMAX(pcr, ts->last_pat_ts);
-- mpegts_write_pat(s);
-- for (i = 0; i < ts->nb_services; i++)
-- mpegts_write_pmt(s, ts->services[i]);
-+ if (ts->sdt_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_sdt_ts == AV_NOPTS_VALUE || pcr >= ts->last_sdt_ts + ts->sdt_period)
-+ force_sdt = 1;
-+ if (force_sdt) {
-+ ts->last_sdt_ts = pcr;
-+ mpegts_write_sdt(s);
-+ }
-+ }
-+ if (ts->pat_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_pat_ts == AV_NOPTS_VALUE || pcr >= ts->last_pat_ts + ts->pat_period)
-+ force_pat = 1;
-+ if (force_pat) {
-+ ts->last_pat_ts = pcr;
-+ mpegts_write_pat(s);
-+ for (i = 0; i < ts->nb_services; i++)
-+ mpegts_write_pmt(s, ts->services[i]);
-+ }
- }
- }
-
-@@ -1217,25 +1226,29 @@
- static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
- {
- MpegTSWrite *ts = s->priv_data;
-- MpegTSWriteStream *ts_st = st->priv_data;
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ MpegTSWriteStream *ts_st = st ? st->priv_data : 0;
-+ uint32_t pcr_pid = ts_st ? ts_st->pid : ts->pcr_stream_pid;
- uint8_t *q;
- uint8_t buf[TS_PACKET_SIZE];
-
- q = buf;
- *q++ = 0x47;
-- *q++ = ts_st->pid >> 8;
-- *q++ = ts_st->pid;
-- *q++ = 0x20 | ts_st->cc; /* Adaptation only */
-+ *q++ = pcr_pid >> 8;
-+ *q++ = pcr_pid;
-+ uint32_t flags = 0x20; /* Adaptation only */
- /* Continuity Count field does not increment (see 13818-1 section 2.4.3.3) */
-+ if(ts_st) flags |= ts_st->cc;
-+ *q++ = flags;
- *q++ = TS_PACKET_SIZE - 5; /* Adaptation Field Length */
- *q++ = 0x10; /* Adaptation flags: PCR present */
-- if (ts_st->discontinuity) {
-+ if (ts_st && ts_st->discontinuity) {
- q[-1] |= 0x80;
- ts_st->discontinuity = 0;
- }
-
- /* PCR coded into 6 bytes */
-- q += write_pcr_bits(q, get_pcr(ts));
-+ q += write_pcr_bits(q, pcr);
-
- /* stuffing bytes */
- memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
-@@ -1303,9 +1316,9 @@
- uint8_t *q;
- int val, is_start, len, header_len, write_pcr, is_dvb_subtitle, is_dvb_teletext, flags;
- int afc_len, stuffing_len;
-- int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
- int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key;
- int force_sdt = 0;
-+ int64_t pcr;
-
- av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO);
- if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
-@@ -1320,20 +1333,19 @@
-
- is_start = 1;
- while (payload_size > 0) {
-- int64_t pcr = AV_NOPTS_VALUE;
-- if (ts->mux_rate > 1)
-- pcr = get_pcr(ts);
-- else if (dts != AV_NOPTS_VALUE)
-- pcr = (dts - delay) * 300;
--
-- retransmit_si_info(s, force_pat, force_sdt, pcr);
-- force_pat = 0;
-- force_sdt = 0;
-+ // add 11, pcr references the last byte of program clock reference base
-+ ts->pcr_pos = avio_tell(s->pb) + 11;
-+ pcr = ts->pcr = ts->mux_rate != 1 ?
-+ av_rescale(ts->pcr_pos, 8 * PCR_TIME_BASE, ts->mux_rate) :
-+ (dts == AV_NOPTS_VALUE ? 0 : (dts - ts->delay) * 300);
-+ if (force_pat || force_sdt) {
-+ retransmit_si_info(s, force_pat, force_sdt);
-+ force_pat = force_sdt = 0;
-+ }
-
- write_pcr = 0;
- if (ts->mux_rate > 1) {
- /* Send PCR packets for all PCR streams if needed */
-- pcr = get_pcr(ts);
- if (pcr >= ts->next_pcr) {
- int64_t next_pcr = INT64_MAX;
- for (int i = 0; i < s->nb_streams; i++) {
-@@ -1343,36 +1355,43 @@
- AVStream *st2 = s->streams[st2_index];
- MpegTSWriteStream *ts_st2 = st2->priv_data;
- if (ts_st2->pcr_period) {
-- if (pcr - ts_st2->last_pcr >= ts_st2->pcr_period) {
-- ts_st2->last_pcr = FFMAX(pcr - ts_st2->pcr_period, ts_st2->last_pcr + ts_st2->pcr_period);
-- if (st2 != st) {
-+ if (pcr >= ts_st2->pcr_timer) {
-+ ts_st2->pcr_timer = pcr + ts_st2->pcr_period;
-+ if (st2 != st) {
- mpegts_insert_pcr_only(s, st2);
-- pcr = get_pcr(ts);
- } else {
- write_pcr = 1;
- }
- }
-- next_pcr = FFMIN(next_pcr, ts_st2->last_pcr + ts_st2->pcr_period);
-+ next_pcr = FFMIN(next_pcr, ts_st2->pcr_timer);
- }
- }
- ts->next_pcr = next_pcr;
- }
-- if (dts != AV_NOPTS_VALUE && (dts - pcr / 300) > delay) {
-- /* pcr insert gets priority over null packet insert */
-- if (write_pcr)
-- mpegts_insert_pcr_only(s, st);
-- else
-- mpegts_insert_null_packet(s);
-- /* recalculate write_pcr and possibly retransmit si_info */
-- continue;
-- }
-- } else if (ts_st->pcr_period && pcr != AV_NOPTS_VALUE) {
-- if (pcr - ts_st->last_pcr >= ts_st->pcr_period && is_start) {
-- ts_st->last_pcr = FFMAX(pcr - ts_st->pcr_period, ts_st->last_pcr + ts_st->pcr_period);
-+ }
-+ else if (ts_st->pcr_period) {
-+ if (pcr >= ts_st->pcr_timer) {
-+ ts_st->pcr_timer = pcr + ts_st->pcr_period;
- write_pcr = 1;
- }
- }
-
-+ if (write_pcr && ts->pcr_stream_pid >= 0) {
-+ mpegts_insert_pcr_only(s, 0);
-+ continue;
-+ }
-+
-+ if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE &&
-+ (dts - pcr / 300) > ts->delay) {
-+ /* pcr insert gets priority over null packet insert */
-+ if (write_pcr)
-+ mpegts_insert_pcr_only(s, st);
-+ else
-+ mpegts_insert_null_packet(s);
-+ /* recalculate write_pcr and possibly retransimit si_info */
-+ continue;
-+ }
-+
- /* prepare packet header */
- q = buf;
- *q++ = 0x47;
-@@ -1400,7 +1419,6 @@
- if (write_pcr) {
- set_af_flag(buf, 0x10);
- q = get_ts_payload_start(buf);
-- // add 11, pcr references the last byte of program clock reference base
- if (dts != AV_NOPTS_VALUE && dts < pcr / 300)
- av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
- extend_af(buf, write_pcr_bits(q, pcr));
-@@ -1678,8 +1696,8 @@
- uint8_t *data = NULL;
- MpegTSWrite *ts = s->priv_data;
- MpegTSWriteStream *ts_st = st->priv_data;
-- const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) * 2;
-- const int64_t max_audio_delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) / 2;
-+ const int64_t delay_ticks2 = ts->delay * 2;
-+ const int64_t max_audio_delay = ts->delay / 2;
- int64_t dts = pkt->dts, pts = pkt->pts;
- int opus_samples = 0;
- buffer_size_t side_data_size;
-@@ -1699,9 +1717,9 @@
- }
-
- if (pts != AV_NOPTS_VALUE)
-- pts += delay;
-+ pts += delay_ticks2;
- if (dts != AV_NOPTS_VALUE)
-- dts += delay;
-+ dts += delay_ticks2;
- }
-
- if (!ts_st->first_timestamp_checked && (pts == AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE)) {
-@@ -2098,8 +2116,10 @@
- 0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV }, 0x01, 0xff, ENC, "mpegts_service_type" },
- { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
- OFFSET(pmt_start_pid), AV_OPT_TYPE_INT, { .i64 = 0x1000 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
-+ { "mpegts_pcr_stream_pid", "create seperate PCR stream on this pid.",
-+ OFFSET(pcr_stream_pid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0x1f00, ENC },
- { "mpegts_start_pid", "Set the first pid.",
-- OFFSET(start_pid), AV_OPT_TYPE_INT, { .i64 = 0x0100 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
-+ OFFSET(start_pid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, LAST_OTHER_PID, ENC },
- { "mpegts_m2ts_mode", "Enable m2ts mode.", OFFSET(m2ts_mode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, ENC },
- { "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC },
- { "pes_payload_size", "Minimum PES packet payload in bytes",
-@@ -2121,10 +2141,10 @@
- OFFSET(omit_video_pes_length), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
- { "pcr_period", "PCR retransmission time in milliseconds",
- OFFSET(pcr_period_ms), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, ENC },
-- { "pat_period", "PAT/PMT retransmission time limit in seconds",
-+ { "pat_period", "PAT/PMT retransmission time limit in ms, -1 no pat",
- OFFSET(pat_period_us), AV_OPT_TYPE_DURATION, { .i64 = PAT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
-- { "sdt_period", "SDT retransmission time limit in seconds",
-- OFFSET(sdt_period_us), AV_OPT_TYPE_DURATION, { .i64 = SDT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
-+ { "sdt_period", "SDT retransmission time limit in ms, -1 no sdt",
-+ OFFSET(sdt_period_us), AV_OPT_TYPE_INT64, { .i64 = SDT_RETRANS_TIME * 1000LL }, -1, INT64_MAX, ENC },
- { NULL },
- };
-
-diff -git a/libavformat/mpegts.h b/libavformat/mpegts.h
---- a/libavformat/mpegts.h 2020-10-15 12:32:22.417967898 -0600
-+++ b/libavformat/mpegts.h 2020-10-15 12:32:46.463055553 -0600
-@@ -64,6 +64,7 @@
- /* PID from 0x1FFC to 0x1FFE may be assigned as needed to PMT, elementary
- * streams and other data tables */
- #define NULL_PID 0x1FFF /* Null packet (used for fixed bandwidth padding) */
-+#define START_PID 0x0400
-
- /* m2ts pids */
- #define M2TS_PMT_PID 0x0100
+++ /dev/null
-diff --git a/libavformat/avformat.h b/libavformat/avformat.h
-index e91e7f1d33..0f9b26a6d3 100644
---- a/libavformat/avformat.h
-+++ b/libavformat/avformat.h
-@@ -480,6 +480,9 @@ typedef struct AVProbeData {
- The user or muxer can override this through
- AVFormatContext.avoid_negative_ts
- */
-+#define AVFMT_SEEK_NOSTREAMS 0x80000 /**< Stream index ignored by seek,
-+ or some streams fail to seek
-+ */
-
- #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
-
-@@ -650,7 +653,8 @@ typedef struct AVInputFormat {
- /**
- * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
- * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
-- * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
-+ * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS,
-+ * AVFMT_SEEK_NOSTREAMS
- */
- int flags;
-
-diff --git a/libavformat/dv.c b/libavformat/dv.c
-index e99422d4b5..58ce1bbb5f 100644
---- a/libavformat/dv.c
-+++ b/libavformat/dv.c
-@@ -642,6 +642,7 @@ static int dv_probe(const AVProbeData *p)
- AVInputFormat ff_dv_demuxer = {
- .name = "dv",
- .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .priv_data_size = sizeof(RawDVContext),
- .read_probe = dv_probe,
- .read_header = dv_read_header,
-diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
-index cff7f0cb54..8b6d22aff2 100644
---- a/libavformat/matroskadec.c
-+++ b/libavformat/matroskadec.c
-@@ -4251,6 +4251,7 @@ static const AVClass webm_dash_class = {
- AVInputFormat ff_matroska_demuxer = {
- .name = "matroska,webm",
- .long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .extensions = "mkv,mk3d,mka,mks,webm",
- .priv_data_size = sizeof(MatroskaDemuxContext),
- .read_probe = matroska_probe,
-@@ -4264,6 +4265,7 @@ AVInputFormat ff_matroska_demuxer = {
- AVInputFormat ff_webm_dash_manifest_demuxer = {
- .name = "webm_dash_manifest",
- .long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .priv_data_size = sizeof(MatroskaDemuxContext),
- .read_header = webm_dash_manifest_read_header,
- .read_packet = webm_dash_manifest_read_packet,
-diff --git a/libavformat/utils.c b/libavformat/utils.c
-index 807d9f10cb..55a444e7b6 100644
---- a/libavformat/utils.c
-+++ b/libavformat/utils.c
-@@ -2486,6 +2486,13 @@ static int seek_frame_internal(AVFormatContext *s, int stream_index,
- return seek_frame_byte(s, stream_index, timestamp, flags);
- }
-
-+ if (stream_index != -1 && (s->iformat->flags & AVFMT_SEEK_NOSTREAMS)) {
-+ timestamp = av_rescale_q(timestamp,
-+ s->streams[stream_index]->time_base,
-+ AV_TIME_BASE_Q);
-+ stream_index = -1;
-+ }
-+
- if (stream_index < 0) {
- stream_index = av_find_default_stream_index(s);
- if (stream_index < 0)
+++ /dev/null
-diff --git a/libavfilter/formats.c b/libavfilter/formats.c
-index de4315369d..f430908343 100644
---- a/libavfilter/formats.c
-+++ b/libavfilter/formats.c
-@@ -107,11 +107,13 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
- possibly causing a lossy conversion elsewhere in the graph.
- To avoid that, pretend that there are no common formats to force the
- insertion of a conversion filter. */
-- if (type == AVMEDIA_TYPE_VIDEO)
-- for (i = 0; i < a->nb_formats; i++)
-+ if (type == AVMEDIA_TYPE_VIDEO) {
-+ for (i = 0; i < a->nb_formats; i++) {
-+ const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
-+ if( !adesc ) continue;
- for (j = 0; j < b->nb_formats; j++) {
-- const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
- const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
-+ if( !bdesc ) continue;
- alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
- chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
- if (a->formats[i] == b->formats[j]) {
-@@ -119,6 +121,8 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
- chroma1|= adesc->nb_components > 1;
- }
- }
-+ }
-+ }
-
- // If chroma or alpha can be lost through merging then do not merge
- if (alpha2 > alpha1 || chroma2 > chroma1)
+++ /dev/null
-diff --git a/libavcodec/vdpau_mpeg12.c b/libavcodec/vdpau_mpeg12.c
-index 72220ffb4e..5687c416c9 100644
---- a/libavcodec/vdpau_mpeg12.c
-+++ b/libavcodec/vdpau_mpeg12.c
-@@ -114,6 +114,7 @@ const AVHWAccel ff_mpeg1_vdpau_hwaccel = {
- .frame_priv_data_size = sizeof(struct vdpau_picture_context),
- .init = vdpau_mpeg1_init,
- .uninit = ff_vdpau_common_uninit,
-+ .frame_params = ff_vdpau_common_frame_params,
- .priv_data_size = sizeof(VDPAUContext),
- .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
- };
+++ /dev/null
-diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
-index 3b29a189e9..681a4187c5 100644
---- a/libavcodec/h263dec.c
-+++ b/libavcodec/h263dec.c
-@@ -684,7 +684,7 @@ frame_end:
- if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
- ff_mpeg4_frame_end(avctx, buf, buf_size);
-
-- if (!s->divx_packed && avctx->hwaccel)
-+ if (s->divx_packed && avctx->hwaccel)
- ff_thread_finish_setup(avctx);
-
- av_assert1(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
+++ /dev/null
-diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
-index 9bd0a555d4..111a9f3a46 100644
---- a/libavformat/mpegenc.c
-+++ b/libavformat/mpegenc.c
-@@ -976,9 +976,9 @@ static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr)
- PacketDesc *pkt_desc;
-
- while ((pkt_desc = stream->predecode_packet) &&
-+ pkt_desc != stream->premux_packet &&
- scr > pkt_desc->dts) { // FIXME: > vs >=
-- if (stream->buffer_index < pkt_desc->size ||
-- stream->predecode_packet == stream->premux_packet) {
-+ if (stream->buffer_index < pkt_desc->size) {
- av_log(ctx, AV_LOG_ERROR,
- "buffer underflow st=%d bufi=%d size=%d\n",
- i, stream->buffer_index, pkt_desc->size);
+++ /dev/null
-diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
-index 718a449b6e..84685fe1d9 100644
---- a/libavutil/hwcontext_cuda.c
-+++ b/libavutil/hwcontext_cuda.c
-@@ -269,9 +269,11 @@ static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
- CudaFunctions *cu = hwctx->internal->cuda_dl;
-
- if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
-+#ifdef CUDA_PRIMARY_CTX
- if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
- CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
- else
-+#endif
- CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
-
- hwctx->cuda_ctx = NULL;
-@@ -321,7 +323,7 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
- cu = hwctx->internal->cuda_dl;
-
- hwctx->internal->flags = flags;
--
-+#ifdef CUDA_PRIMARY_CTX
- if (flags & AV_CUDA_USE_PRIMARY_CONTEXT) {
- ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
- &dev_flags, &dev_active));
-@@ -342,7 +344,9 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
- hwctx->internal->cuda_device));
- if (ret < 0)
- return ret;
-- } else {
-+ } else
-+#endif
-+ {
- ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
- hwctx->internal->cuda_device));
- if (ret < 0)
+++ /dev/null
-diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
-index dbef5495af..fba06d8ccf 100644
---- a/libavutil/hwcontext_vdpau.c
-+++ b/libavutil/hwcontext_vdpau.c
-@@ -68,6 +68,11 @@ static const VDPAUPixFmtMap pix_fmts_420[] = {
- { 0, AV_PIX_FMT_NONE, },
- };
-
-+static const VDPAUPixFmtMap pix_fmts_420j[] = {
-+ { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUVJ420P },
-+ { 0, AV_PIX_FMT_NONE, },
-+};
-+
- static const VDPAUPixFmtMap pix_fmts_422[] = {
- { VDP_YCBCR_FORMAT_NV12, AV_PIX_FMT_NV16 },
- { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUV422P },
-@@ -92,6 +97,7 @@ static const struct {
- const VDPAUPixFmtMap *map;
- } vdpau_pix_fmts[] = {
- { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUV420P, pix_fmts_420 },
-+ { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUVJ420P, pix_fmts_420j },
- { VDP_CHROMA_TYPE_422, AV_PIX_FMT_YUV422P, pix_fmts_422 },
- { VDP_CHROMA_TYPE_444, AV_PIX_FMT_YUV444P, pix_fmts_444 },
- #ifdef VDP_YCBCR_FORMAT_P016
+++ /dev/null
-diff --git a/libavcodec/encode.c b/libavcodec/encode_fprint.c
-index 89df523..cca0cc1 100644
---- a/libavcodec/encode.c
-+++ b/libavcodec/encode_fprint.c
-@@ -191,7 +191,7 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
- }
-
- if (!frame->buf[0]) {
-- if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
-+ if (avci->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
- (avci->frame_thread_encoder && avctx->active_thread_type & FF_THREAD_FRAME)))
- return AVERROR_EOF;
-
-@@ -246,8 +246,10 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
- }
- }
-
-- if (avci->draining && !got_packet)
-+ if (avci->draining && !got_packet) {
-+ fflush(stderr);
- avci->draining_done = 1;
-+ }
-
- end:
- if (ret < 0 || !got_packet)
-@@ -372,10 +374,16 @@ int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame
- if (avci->draining)
- return AVERROR_EOF;
-
-- if (avci->buffer_frame->data[0])
-+ if (avci->buffer_frame->data[0]) {
-+ if (!frame) {
-+ fflush(stderr);
-+ av_frame_unref(avci->buffer_frame);
-+ }
- return AVERROR(EAGAIN);
-+ }
-
- if (!frame) {
-+ fflush(stderr);
- avci->draining = 1;
- } else {
- ret = encode_send_frame_internal(avctx, frame);
+++ /dev/null
---- a/libavcodec/wrapped_avframe.c.orig 2021-06-15 22:37:02.955552877 +0300
-+++ b/libavcodec/wrapped_avframe.c 2021-06-15 23:50:34.439553140 +0300
-@@ -109,6 +109,36 @@
- return 0;
- }
-
-+
-+
-+static const enum AVPixelFormat pix_fmts_all[] = {
-+ AV_PIX_FMT_YUV411P,
-+ AV_PIX_FMT_YUV420P,
-+ AV_PIX_FMT_YUVJ420P,
-+ AV_PIX_FMT_YUV422P,
-+ AV_PIX_FMT_YUVJ422P,
-+ AV_PIX_FMT_YUV444P,
-+ AV_PIX_FMT_YUVJ444P,
-+ AV_PIX_FMT_YUV420P10,
-+ AV_PIX_FMT_YUV422P10,
-+ AV_PIX_FMT_YUV444P10,
-+ AV_PIX_FMT_YUV420P12,
-+ AV_PIX_FMT_YUV422P12,
-+ AV_PIX_FMT_YUV444P12,
-+ AV_PIX_FMT_YUV420P14,
-+ AV_PIX_FMT_YUV422P14,
-+ AV_PIX_FMT_YUV444P14,
-+ AV_PIX_FMT_YUV420P16,
-+ AV_PIX_FMT_YUV422P16,
-+ AV_PIX_FMT_YUV444P16,
-+ AV_PIX_FMT_GRAY8,
-+ AV_PIX_FMT_GRAY9,
-+ AV_PIX_FMT_GRAY10,
-+ AV_PIX_FMT_GRAY12,
-+ AV_PIX_FMT_GRAY16,
-+ AV_PIX_FMT_NONE
-+};
-+
- AVCodec ff_wrapped_avframe_encoder = {
- .name = "wrapped_avframe",
- .long_name = NULL_IF_CONFIG_SMALL("AVFrame to AVPacket passthrough"),
-@@ -116,6 +146,7 @@
- .id = AV_CODEC_ID_WRAPPED_AVFRAME,
- .encode2 = wrapped_avframe_encode,
- .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
-+ .pix_fmts = pix_fmts_all,
- };
-
- AVCodec ff_wrapped_avframe_decoder = {
+++ /dev/null
---- a/libavformat/yuv4mpegenc.c.orig 2021-06-15 23:40:32.239553104 +0300
-+++ b/libavformat/yuv4mpegenc.c 2021-06-15 23:40:40.851553105 +0300
-@@ -313,7 +313,7 @@
- av_log(s, AV_LOG_ERROR, "'%s' is not an official yuv4mpegpipe pixel format. "
- "Use '-strict -1' to encode to this pixel format.\n",
- av_get_pix_fmt_name(s->streams[0]->codecpar->format));
-- return AVERROR(EINVAL);
-+ //return AVERROR(EINVAL);
- }
- av_log(s, AV_LOG_WARNING, "Warning: generating non standard YUV stream. "
- "Mjpegtools will not work.\n");
+++ /dev/null
-diff --git a/libavformat/avidec.c b/libavformat/avidec.c
-index 5cf67a4771..5bd2372c27 100644
---- a/libavformat/avidec.c
-+++ b/libavformat/avidec.c
-@@ -1942,6 +1942,7 @@ AVInputFormat ff_avi_demuxer = {
- .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
- .priv_data_size = sizeof(AVIContext),
- .extensions = "avi",
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .read_probe = avi_probe,
- .read_header = avi_read_header,
- .read_packet = avi_read_packet,
+++ /dev/null
---- ffmpeg-4.4/libavcodec/aaccoder.c.orig 2021-05-08 11:52:41.824074401 +0300
-+++ ffmpeg-4.4/libavcodec/aaccoder.c 2021-05-08 11:55:06.868074410 +0300
-@@ -800,7 +800,7 @@
-
- for (sid_sf_boost = 0; sid_sf_boost < 4; sid_sf_boost++) {
- float dist1 = 0.0f, dist2 = 0.0f;
-- int B0 = 0, B1 = 0;
-+ int B0_ = 0, B1 = 0;
- int minidx;
- int mididx, sididx;
- int midcb, sidcb;
-@@ -862,12 +862,12 @@
- sididx,
- sidcb,
- mslambda / (minthr * bmax), INFINITY, &b4, NULL, 0);
-- B0 += b1+b2;
-+ B0_ += b1+b2;
- B1 += b3+b4;
- dist1 -= b1+b2;
- dist2 -= b3+b4;
- }
-- cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0;
-+ cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0_;
- if (cpe->ms_mask[w*16+g]) {
- if (sce0->band_type[w*16+g] != NOISE_BT && sce1->band_type[w*16+g] != NOISE_BT) {
- sce0->sf_idx[w*16+g] = mididx;
-@@ -879,7 +879,7 @@
- cpe->ms_mask[w*16+g] = 0;
- }
- break;
-- } else if (B1 > B0) {
-+ } else if (B1 > B0_) {
- /* More boost won't fix this */
- break;
- }
+++ /dev/null
---- ffmpeg-4.4/libavcodec/libdav1d.c 2021-04-09 00:28:39.000000000 +0300
-+++ ffmpeg-4.4/libavcodec/libdav1d.c 2022-03-27 15:54:53.212041349 +0300
-@@ -33,6 +33,9 @@
- #include "decode.h"
- #include "internal.h"
-
-+#define FF_DAV1D_VERSION_AT_LEAST(x,y) \
-+ (DAV1D_API_VERSION_MAJOR > (x) || DAV1D_API_VERSION_MAJOR == (x) && DAV1D_API_VERSION_MINOR >= (y))
-+
- typedef struct Libdav1dContext {
- AVClass *class;
- Dav1dContext *c;
-@@ -145,6 +148,15 @@
- if (dav1d->operating_point >= 0)
- s.operating_point = dav1d->operating_point;
-
-+#if FF_DAV1D_VERSION_AT_LEAST(6,0)
-+ if (dav1d->frame_threads || dav1d->tile_threads)
-+ s.n_threads = FFMAX(dav1d->frame_threads, dav1d->tile_threads);
-+ else
-+ s.n_threads = FFMIN(threads, DAV1D_MAX_THREADS);
-+ s.max_frame_delay = (c->flags & AV_CODEC_FLAG_LOW_DELAY) ? 1 : s.n_threads;
-+ av_log(c, AV_LOG_DEBUG, "Using %d threads, %d max_frame_delay\n",
-+ s.n_threads, s.max_frame_delay);
-+#else
- s.n_tile_threads = dav1d->tile_threads
- ? dav1d->tile_threads
- : FFMIN(floor(sqrt(threads)), DAV1D_MAX_TILE_THREADS);
-@@ -153,6 +165,7 @@
- : FFMIN(ceil(threads / s.n_tile_threads), DAV1D_MAX_FRAME_THREADS);
- av_log(c, AV_LOG_DEBUG, "Using %d frame threads, %d tile threads\n",
- s.n_frame_threads, s.n_tile_threads);
-+#endif
-
- res = dav1d_open(&dav1d->c, &s);
- if (res < 0)
-@@ -185,6 +198,9 @@
- Libdav1dContext *dav1d = c->priv_data;
- Dav1dData *data = &dav1d->data;
- Dav1dPicture pic = { 0 }, *p = &pic;
-+#if FF_DAV1D_VERSION_AT_LEAST(5,1)
-+ enum Dav1dEventFlags event_flags = 0;
-+#endif
- int res;
-
- if (!data->sz) {
-@@ -456,11 +472,18 @@
- return 0;
- }
-
-+#ifndef DAV1D_MAX_FRAME_THREADS
-+#define DAV1D_MAX_FRAME_THREADS DAV1D_MAX_THREADS
-+#endif
-+#ifndef DAV1D_MAX_TILE_THREADS
-+#define DAV1D_MAX_TILE_THREADS DAV1D_MAX_THREADS
-+#endif
-+
- #define OFFSET(x) offsetof(Libdav1dContext, x)
- #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
- static const AVOption libdav1d_options[] = {
-- { "tilethreads", "Tile threads", OFFSET(tile_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_TILE_THREADS, VD },
-- { "framethreads", "Frame threads", OFFSET(frame_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_THREADS, VD },
-+ { "tilethreads", "Tile threads", OFFSET(tile_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_TILE_THREADS, VD | AV_OPT_FLAG_DEPRECATED },
-+ { "framethreads", "Frame threads", OFFSET(frame_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_THREADS, VD | AV_OPT_FLAG_DEPRECATED },
- { "filmgrain", "Apply Film Grain", OFFSET(apply_grain), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD | AV_OPT_FLAG_DEPRECATED },
- { "oppoint", "Select an operating point of the scalable bitstream", OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 31, VD },
- { "alllayers", "Output all spatial layers", OFFSET(all_layers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
+++ /dev/null
---- ffmpeg-4.4/libavcodec/hevc_mvs.c.orig 2021-05-08 12:22:19.580985429 +0300
-+++ ffmpeg-4.4/libavcodec/hevc_mvs.c 2021-05-08 12:29:05.340985454 +0300
-@@ -307,8 +307,8 @@
- const int xB1 = x0 + nPbW - 1;
- const int yB1 = y0 - 1;
-
-- const int xB0 = x0 + nPbW;
-- const int yB0 = y0 - 1;
-+ const int xB0_ = x0 + nPbW;
-+ const int yB0_ = y0 - 1;
-
- const int xA0 = x0 - 1;
- const int yA0 = y0 + nPbH;
-@@ -365,14 +365,14 @@
- }
-
- // above right spatial merge candidate
-- is_available_b0 = AVAILABLE(cand_up_right, B0) &&
-- xB0 < s->ps.sps->width &&
-- PRED_BLOCK_AVAILABLE(B0) &&
-- !is_diff_mer(s, xB0, yB0, x0, y0);
-+ is_available_b0 = AVAILABLE(cand_up_right, B0_) &&
-+ xB0_ < s->ps.sps->width &&
-+ PRED_BLOCK_AVAILABLE(B0_) &&
-+ !is_diff_mer(s, xB0_, yB0_, x0, y0);
-
- if (is_available_b0 &&
-- !(is_available_b1 && COMPARE_MV_REFIDX(B0, B1))) {
-- mergecandlist[nb_merge_cand] = TAB_MVF_PU(B0);
-+ !(is_available_b1 && COMPARE_MV_REFIDX(B0_, B1))) {
-+ mergecandlist[nb_merge_cand] = TAB_MVF_PU(B0_);
- if (merge_idx == nb_merge_cand)
- return;
- nb_merge_cand++;
-@@ -588,7 +588,7 @@
- MvField *tab_mvf = s->ref->tab_mvf;
- int isScaledFlag_L0 = 0;
- int availableFlagLXA0 = 1;
-- int availableFlagLXB0 = 1;
-+ int availableFlagLXB0_ = 1;
- int numMVPCandLX = 0;
- int min_pu_width = s->ps.sps->min_pu_width;
-
-@@ -596,7 +596,7 @@
- int is_available_a0;
- int xA1, yA1;
- int is_available_a1;
-- int xB0, yB0;
-+ int xB0_, yB0_;
- int is_available_b0;
- int xB1, yB1;
- int is_available_b1;
-@@ -677,12 +677,12 @@
- b_candidates:
- // B candidates
- // above right spatial merge candidate
-- xB0 = x0 + nPbW;
-- yB0 = y0 - 1;
-+ xB0_ = x0 + nPbW;
-+ yB0_ = y0 - 1;
-
-- is_available_b0 = AVAILABLE(cand_up_right, B0) &&
-- xB0 < s->ps.sps->width &&
-- PRED_BLOCK_AVAILABLE(B0);
-+ is_available_b0 = AVAILABLE(cand_up_right, B0_) &&
-+ xB0_ < s->ps.sps->width &&
-+ PRED_BLOCK_AVAILABLE(B0_);
-
- // above spatial merge candidate
- xB1 = x0 + nPbW - 1;
-@@ -696,10 +696,10 @@
-
- // above right spatial merge candidate
- if (is_available_b0) {
-- if (MP_MX(B0, pred_flag_index_l0, mxB)) {
-+ if (MP_MX(B0_, pred_flag_index_l0, mxB)) {
- goto scalef;
- }
-- if (MP_MX(B0, pred_flag_index_l1, mxB)) {
-+ if (MP_MX(B0_, pred_flag_index_l1, mxB)) {
- goto scalef;
- }
- }
-@@ -723,40 +723,40 @@
- goto scalef;
- }
- }
-- availableFlagLXB0 = 0;
-+ availableFlagLXB0_ = 0;
-
- scalef:
- if (!isScaledFlag_L0) {
-- if (availableFlagLXB0) {
-+ if (availableFlagLXB0_) {
- availableFlagLXA0 = 1;
- mxA = mxB;
- }
-- availableFlagLXB0 = 0;
-+ availableFlagLXB0_ = 0;
-
- // XB0 and L1
- if (is_available_b0) {
-- availableFlagLXB0 = MP_MX_LT(B0, pred_flag_index_l0, mxB);
-- if (!availableFlagLXB0)
-- availableFlagLXB0 = MP_MX_LT(B0, pred_flag_index_l1, mxB);
-+ availableFlagLXB0_ = MP_MX_LT(B0_, pred_flag_index_l0, mxB);
-+ if (!availableFlagLXB0_)
-+ availableFlagLXB0_ = MP_MX_LT(B0_, pred_flag_index_l1, mxB);
- }
-
-- if (is_available_b1 && !availableFlagLXB0) {
-- availableFlagLXB0 = MP_MX_LT(B1, pred_flag_index_l0, mxB);
-- if (!availableFlagLXB0)
-- availableFlagLXB0 = MP_MX_LT(B1, pred_flag_index_l1, mxB);
-+ if (is_available_b1 && !availableFlagLXB0_) {
-+ availableFlagLXB0_ = MP_MX_LT(B1, pred_flag_index_l0, mxB);
-+ if (!availableFlagLXB0_)
-+ availableFlagLXB0_ = MP_MX_LT(B1, pred_flag_index_l1, mxB);
- }
-
-- if (is_available_b2 && !availableFlagLXB0) {
-- availableFlagLXB0 = MP_MX_LT(B2, pred_flag_index_l0, mxB);
-- if (!availableFlagLXB0)
-- availableFlagLXB0 = MP_MX_LT(B2, pred_flag_index_l1, mxB);
-+ if (is_available_b2 && !availableFlagLXB0_) {
-+ availableFlagLXB0_ = MP_MX_LT(B2, pred_flag_index_l0, mxB);
-+ if (!availableFlagLXB0_)
-+ availableFlagLXB0_ = MP_MX_LT(B2, pred_flag_index_l1, mxB);
- }
- }
-
- if (availableFlagLXA0)
- mvpcand_list[numMVPCandLX++] = mxA;
-
-- if (availableFlagLXB0 && (!availableFlagLXA0 || mxA.x != mxB.x || mxA.y != mxB.y))
-+ if (availableFlagLXB0_ && (!availableFlagLXA0 || mxA.x != mxB.x || mxA.y != mxB.y))
- mvpcand_list[numMVPCandLX++] = mxB;
-
- //temporal motion vector prediction candidate
+++ /dev/null
---- ffmpeg-4.4/libavcodec/opus_pvq.c.orig 2021-05-08 12:19:49.996985421 +0300
-+++ ffmpeg-4.4/libavcodec/opus_pvq.c 2021-05-08 12:21:12.440985425 +0300
-@@ -495,12 +495,12 @@
- uint32_t N0 = N;
- int N_B = N / blocks;
- int N_B0 = N_B;
-- int B0 = blocks;
-+ int B0_ = blocks;
- int time_divide = 0;
- int recombine = 0;
- int inv = 0;
- float mid = 0, side = 0;
-- int longblocks = (B0 == 1);
-+ int longblocks = (B0_ == 1);
- uint32_t cm = 0;
-
- if (N == 1) {
-@@ -532,7 +532,7 @@
- /* Band recombining to increase frequency resolution */
-
- if (lowband &&
-- (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {
-+ (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0_ > 1)) {
- for (i = 0; i < N; i++)
- lowband_scratch[i] = lowband[i];
- lowband = lowband_scratch;
-@@ -556,13 +556,13 @@
- time_divide++;
- tf_change++;
- }
-- B0 = blocks;
-+ B0_ = blocks;
- N_B0 = N_B;
-
- /* Reorganize the samples in time order instead of frequency order */
-- if (B0 > 1 && (quant || lowband))
-+ if (B0_ > 1 && (quant || lowband))
- celt_deinterleave_hadamard(pvq->hadamard_tmp, quant ? X : lowband,
-- N_B >> recombine, B0 << recombine,
-+ N_B >> recombine, B0_ << recombine,
- longblocks);
- }
-
-@@ -604,7 +604,7 @@
- if (quant) {
- if (stereo && N > 2)
- ff_opus_rc_enc_uint_step(rc, itheta, qn / 2);
-- else if (stereo || B0 > 1)
-+ else if (stereo || B0_ > 1)
- ff_opus_rc_enc_uint(rc, itheta, qn + 1);
- else
- ff_opus_rc_enc_uint_tri(rc, itheta, qn);
-@@ -619,7 +619,7 @@
- } else {
- if (stereo && N > 2)
- itheta = ff_opus_rc_dec_uint_step(rc, qn / 2);
-- else if (stereo || B0 > 1)
-+ else if (stereo || B0_ > 1)
- itheta = ff_opus_rc_dec_uint(rc, qn+1);
- else
- itheta = ff_opus_rc_dec_uint_tri(rc, qn);
-@@ -725,7 +725,7 @@
-
- /* Give more bits to low-energy MDCTs than they would
- * otherwise deserve */
-- if (B0 > 1 && !stereo && (itheta & 0x3fff)) {
-+ if (B0_ > 1 && !stereo && (itheta & 0x3fff)) {
- if (itheta > 8192)
- /* Rough approximation for pre-echo masking */
- delta -= delta >> (4 - duration);
-@@ -764,14 +764,14 @@
- cmt = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks,
- next_lowband2, duration, NULL, next_level,
- gain * side, NULL, fill >> blocks);
-- cm |= cmt << ((B0 >> 1) & (stereo - 1));
-+ cm |= cmt << ((B0_ >> 1) & (stereo - 1));
- } else {
- /* For a stereo split, the high bits of fill are always zero,
- * so no folding will be done to the side. */
- cm = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks,
- next_lowband2, duration, NULL, next_level,
- gain * side, NULL, fill >> blocks);
-- cm <<= ((B0 >> 1) & (stereo - 1));
-+ cm <<= ((B0_ >> 1) & (stereo - 1));
- rebalance = sbits - (rebalance - f->remaining2);
- if (rebalance > 3 << 3 && itheta != 16384)
- mbits += rebalance - (3 << 3);
-@@ -842,13 +842,13 @@
- int k;
-
- /* Undo the sample reorganization going from time order to frequency order */
-- if (B0 > 1)
-+ if (B0_ > 1)
- celt_interleave_hadamard(pvq->hadamard_tmp, X, N_B >> recombine,
-- B0 << recombine, longblocks);
-+ B0_ << recombine, longblocks);
-
- /* Undo time-freq changes that we did earlier */
- N_B = N_B0;
-- blocks = B0;
-+ blocks = B0_;
- for (k = 0; k < time_divide; k++) {
- blocks >>= 1;
- N_B <<= 1;
+++ /dev/null
---- ffmpeg-4.4/libavcodec/libx264.c.orig
-+++ ffmpeg-4.4/libavcodec/libx264.c
-@@ -790,6 +790,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
- av_log(avctx, AV_LOG_ERROR,
- "x264 too old for AVC Intra, at least version 142 needed\n");
- #endif
-+
-+ if (x4->avcintra_class > 200) {
-+#if X264_BUILD < 164
-+ av_log(avctx, AV_LOG_ERROR,
-+ "x264 too old for AVC Intra 300/480, at least version 164 needed\n");
-+ return AVERROR(EINVAL);
-+#else
-+ /* AVC-Intra 300/480 only supported by Sony XAVC flavor */
-+ x4->params.i_avcintra_flavor = X264_AVCINTRA_FLAVOR_SONY;
-+#endif
-+ }
-+
- if (x4->b_bias != INT_MIN)
- x4->params.i_bframe_bias = x4->b_bias;
- if (x4->b_pyramid >= 0)
-@@ -921,6 +933,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
- }
- }
-
-+#if X264_BUILD >= 142
-+ /* Separate headers not supported in AVC-Intra mode */
-+ if (x4->params.i_avcintra_class >= 0)
-+ x4->params.b_repeat_headers = 1;
-+#endif
-
- {
- AVDictionaryEntry *en = NULL;
-@@ -1123,7 +1140,7 @@ static const AVOption options[] = {
- { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, "nal-hrd" },
- { "vbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
- { "cbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
-- { "avcintra-class","AVC-Intra class 50/100/200", OFFSET(avcintra_class),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 200 , VE},
-+ { "avcintra-class","AVC-Intra class 50/100/200/300/480", OFFSET(avcintra_class),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 480 , VE},
- { "me_method", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
- { "motion-est", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
- { "dia", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_DIA }, INT_MIN, INT_MAX, VE, "motion-est" },
+++ /dev/null
---- /dev/null 2021-12-05 17:02:04.576000000 +0300
-+++ ./libavcodec/pcm-bluenc.c 2021-12-08 16:22:32.519865993 +0300
-@@ -0,0 +1,332 @@
-+/*
-+ * LPCM codecs for PCM formats found in Blu-ray m2ts streams
-+ * Copyright (c) 2018 Paul B Mahol
-+ *
-+ * This file is part of FFmpeg.
-+ *
-+ * FFmpeg is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU Lesser General Public
-+ * License as published by the Free Software Foundation; either
-+ * version 2.1 of the License, or (at your option) any later version.
-+ *
-+ * FFmpeg is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-+ * Lesser General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU Lesser General Public
-+ * License along with FFmpeg; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-+ */
-+
-+#include "avcodec.h"
-+#include "bytestream.h"
-+#include "internal.h"
-+
-+typedef struct PCMBDContext {
-+ uint8_t header[4]; // Header added to every frame
-+ int block_size; // Size of a block of samples in bytes
-+ int samples_per_block; // Number of samples per channel per block
-+ int groups_per_block; // Number of 20/24-bit sample groups per block
-+ uint8_t *extra_samples; // Pointer to leftover samples from a frame
-+ int extra_sample_count; // Number of leftover samples in the buffer
-+} PCMBDContext;
-+
-+static av_cold int pcm_bd_encode_init(AVCodecContext *avctx)
-+{
-+ PCMBDContext *s = avctx->priv_data;
-+ int quant, freq;
-+ uint16_t frame_size;
-+ uint8_t ch_layout = 0;
-+
-+ 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_S20:
-+ avctx->bits_per_coded_sample = 20;
-+ quant = 2;
-+ break;
-+*/
-+ case AV_SAMPLE_FMT_S32:
-+ avctx->bits_per_coded_sample = 24;
-+ quant = 3;
-+ break;
-+ }
-+
-+ avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
-+ avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
-+ if (avctx->bit_rate > 19800000) {
-+ av_log(avctx, AV_LOG_ERROR, "Too big bitrate: reduce sample rate, bitdepth or channels.\n");
-+ return AVERROR(EINVAL);
-+ }
-+
-+ if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
-+ switch (avctx->channels) {
-+ case 1:
-+ s->block_size = avctx->channels * 4;
-+ break;
-+ default:
-+ s->block_size = avctx->channels * 2;
-+ break;
-+ }
-+ s->samples_per_block = 1;
-+ frame_size = 2008 / s->block_size;
-+ } else {
-+ switch (avctx->channels) {
-+ case 1:
-+ s->block_size = 2 * avctx->channels * avctx->bits_per_coded_sample / 8;
-+ s->samples_per_block = 1;
-+ break;
-+ case 2:
-+ case 4:
-+ /* one group has all the samples needed */
-+ s->block_size = avctx->channels * avctx->bits_per_coded_sample / 8;
-+ s->samples_per_block = 1;
-+ s->groups_per_block = 2;
-+ break;
-+ case 8:
-+ case 6:
-+ /* two groups have all the samples needed */
-+ s->block_size = avctx->channels * avctx->bits_per_coded_sample / 8;
-+ s->samples_per_block = 1;
-+ // s->groups_per_block = 2;
-+ break;
-+ default:
-+ /* need avctx->channels groups */
-+ s->block_size = 4 * avctx->channels *
-+ avctx->bits_per_coded_sample / 8;
-+ s->samples_per_block = 4;
-+ s->groups_per_block = avctx->channels;
-+ break;
-+ }
-+
-+ frame_size = FFALIGN(2008 / s->block_size, s->samples_per_block);
-+ }
-+
-+ 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_5POINT1:
-+ case AV_CH_LAYOUT_5POINT1_BACK:
-+ ch_layout = 9;
-+ break;
-+ case AV_CH_LAYOUT_7POINT1:
-+ ch_layout = 11;
-+ break;
-+ default:
-+ av_log(avctx, AV_LOG_ERROR, "Not yet implemented ch layout!\n");
-+ }
-+// description on the web:
-+/* http://forum.doom9.org/showthread.php?t=152897
-+
-+It's a header.
-+
-+size in bytes = 16 bits (big endian)
-+channel assignment = 4 bits
-+sampling frequency = 4 bits
-+bits per sample = 2 bits
-+start flag = 1 bit
-+reserved = 5 bits
-+
-+channel assignment
-+1 = mono
-+3 = stereo
-+4 = 3/0
-+5 = 2/1
-+6 = 3/1
-+7 = 2/2
-+8 = 3/2
-+9 = 3/2+lfe
-+10 = 3/4
-+11 = 3/4+lfe
-+
-+sampling frequency
-+1 = 48 kHz
-+4 = 96 kHz
-+5 = 192 kHz
-+
-+bits per sample
-+1 = 16
-+2 = 20
-+3 = 24
-+*/
-+
-+ s->header[2] = (ch_layout << 4) | (freq);
-+ s->header[3] = (quant << 6) | 0x1 ;
-+
-+
-+ avctx->frame_size = frame_size; // in num. of samples
-+
-+ return 0;
-+}
-+
-+static int pcm_bd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-+ const AVFrame *frame, int *got_packet_ptr)
-+{
-+ PCMBDContext *s = avctx->priv_data;
-+ int samples, channels;
-+ int64_t pkt_size = (frame->nb_samples / s->samples_per_block) * s->block_size + 4;
-+ const int16_t *src16;
-+ const int32_t *src32;
-+ PutByteContext pb;
-+ int ret;
-+
-+ if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0)
-+ return ret;
-+
-+ AV_WB16(s->header, pkt_size - 4);
-+ memcpy(avpkt->data, s->header, 4);
-+
-+ src16 = (const int16_t *)frame->data[0];
-+ src32 = (const int32_t *)frame->data[0];
-+
-+ bytestream2_init_writer(&pb, avpkt->data + 4, avpkt->size - 4);
-+
-+ int num_source_channels = FFALIGN(avctx->channels, 2);
-+ // int num_source_channels = avctx->channels;
-+ // int sample_size = (num_source_channels *
-+ // (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
-+ samples = frame->nb_samples * num_source_channels;
-+
-+ switch (avctx->sample_fmt) {
-+ case AV_SAMPLE_FMT_S16:
-+ switch (avctx->channels) {
-+ case 1:
-+ do {
-+ do {
-+ channels = avctx->channels;
-+ bytestream2_put_be16(&pb, *src16++);
-+ } while (--channels);
-+ bytestream2_put_be16(&pb, 0);
-+ } while (--samples);
-+ break;
-+ case 2:
-+ do {
-+ bytestream2_put_be16(&pb, *src16++);
-+ } while (--samples);
-+ break;
-+ case 6:
-+ do {
-+ bytestream2_put_be16(&pb, src16[0]);
-+ bytestream2_put_be16(&pb, src16[1]);
-+ bytestream2_put_be16(&pb, src16[2]);
-+ bytestream2_put_be16(&pb, src16[4]);
-+ bytestream2_put_be16(&pb, src16[5]);
-+ bytestream2_put_be16(&pb, src16[3]);
-+ src16+=6;
-+ } while (--samples);
-+ break;
-+ case 8:
-+ do {
-+ bytestream2_put_be16(&pb, src16[0]);
-+ bytestream2_put_be16(&pb, src16[1]);
-+ bytestream2_put_be16(&pb, src16[2]);
-+ bytestream2_put_be16(&pb, src16[6]);
-+ bytestream2_put_be16(&pb, src16[4]);
-+ bytestream2_put_be16(&pb, src16[5]);
-+ bytestream2_put_be16(&pb, src16[7]);
-+ bytestream2_put_be16(&pb, src16[3]);
-+ src16+=8;
-+ } while (--samples);
-+ break;
-+
-+ default:
-+ av_log(avctx, AV_LOG_ERROR, "this ch config not implemented for s16!\n");
-+ break;
-+ }
-+ break;
-+ case AV_SAMPLE_FMT_S32:
-+ switch (avctx->channels) {
-+ case 2:
-+ case 4:
-+ do {
-+ bytestream2_put_be24(&pb, (*src32++) >> 8);
-+ } while (--samples);
-+ break;
-+ case 8:
-+ do {
-+ bytestream2_put_be24(&pb, src32[0] >> 8);
-+ bytestream2_put_be24(&pb, src32[1] >> 8);
-+ bytestream2_put_be24(&pb, src32[2] >> 8);
-+ bytestream2_put_be24(&pb, src32[6] >> 8);
-+ bytestream2_put_be24(&pb, src32[4] >> 8);
-+ bytestream2_put_be24(&pb, src32[5] >> 8);
-+ bytestream2_put_be24(&pb, src32[7] >> 8);
-+ bytestream2_put_be24(&pb, src32[3] >> 8);
-+ src32+=8;
-+ } while (--samples);
-+ break;
-+ case 6:
-+ do {
-+ bytestream2_put_be24(&pb, src32[0] >> 8);
-+ bytestream2_put_be24(&pb, src32[1] >> 8);
-+ bytestream2_put_be24(&pb, src32[2] >> 8);
-+ bytestream2_put_be24(&pb, src32[4] >> 8);
-+ bytestream2_put_be24(&pb, src32[5] >> 8);
-+ bytestream2_put_be24(&pb, src32[3] >> 8);
-+ src32+=6;
-+ } while (--samples);
-+ break;
-+ case 1:
-+ do {
-+ do {
-+ channels = avctx->channels;
-+ bytestream2_put_be24(&pb, (*src32++) >> 8);
-+ } while (--channels);
-+ bytestream2_put_be24(&pb, 0);
-+ } while (--samples);
-+ break;
-+ default:
-+ av_log(avctx, AV_LOG_ERROR, "this bitdepth not implemented!\n");
-+ break;
-+ }
-+ break;
-+ }
-+
-+ avpkt->pts = frame->pts;
-+ avpkt->size = pkt_size;
-+ avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
-+ *got_packet_ptr = 1;
-+
-+ return 0;
-+}
-+
-+AVCodec ff_pcm_bluray_encoder = {
-+ .name = "pcm_bluray",
-+ .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|24-bit big-endian for bluray media"),
-+ .type = AVMEDIA_TYPE_AUDIO,
-+ .id = AV_CODEC_ID_PCM_BLURAY,
-+ .priv_data_size = sizeof(PCMBDContext),
-+ .init = pcm_bd_encode_init,
-+ .encode2 = pcm_bd_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_5POINT1,
-+ AV_CH_LAYOUT_5POINT1_BACK,
-+ 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,
-+};
---- ./libavcodec/allcodecs.orig 2021-04-09 00:28:39.000000000 +0300
-+++ ./libavcodec/allcodecs.c 2021-12-06 15:45:03.333762281 +0300
-@@ -523,6 +523,7 @@
- /* PCM codecs */
- extern AVCodec ff_pcm_alaw_encoder;
- extern AVCodec ff_pcm_alaw_decoder;
-+extern AVCodec ff_pcm_bluray_encoder;
- extern AVCodec ff_pcm_bluray_decoder;
- extern AVCodec ff_pcm_dvd_encoder;
- extern AVCodec ff_pcm_dvd_decoder;
---- ./libavcodec/Makefile.orig 2021-04-09 00:28:39.000000000 +0300
-+++ ./libavcodec/Makefile 2021-12-06 21:11:19.365842066 +0300
-@@ -789,6 +789,7 @@
- OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o
- OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o
- OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o
-+OBJS-$(CONFIG_PCM_BLURAY_ENCODER) += pcm-bluenc.o
- OBJS-$(CONFIG_PCM_DVD_DECODER) += pcm-dvd.o
- OBJS-$(CONFIG_PCM_DVD_ENCODER) += pcm-dvdenc.o
- OBJS-$(CONFIG_PCM_F16LE_DECODER) += pcm.o
+++ /dev/null
---- ffmpeg-4.4/libavcodec/pcm-bluenc.c 2022-04-24 09:45:43.921091116 +0300
-+++ ffmpeg-4.4/libavcodec/pcm-bluenc.c 2022-04-24 16:07:28.537982120 +0300
-@@ -1,6 +1,5 @@
- /*
- * LPCM codecs for PCM formats found in Blu-ray m2ts streams
-- * Copyright (c) 2018 Paul B Mahol
- *
- * This file is part of FFmpeg.
- *
-@@ -19,314 +18,305 @@
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-+#include "libavutil/channel_layout.h"
- #include "avcodec.h"
- #include "bytestream.h"
-+//#include "codec_internal.h"
-+#include "encode.h"
- #include "internal.h"
-
--typedef struct PCMBDContext {
-- uint8_t header[4]; // Header added to every frame
-- int block_size; // Size of a block of samples in bytes
-- int samples_per_block; // Number of samples per channel per block
-- int groups_per_block; // Number of 20/24-bit sample groups per block
-- uint8_t *extra_samples; // Pointer to leftover samples from a frame
-- int extra_sample_count; // Number of leftover samples in the buffer
--} PCMBDContext;
-+typedef struct BlurayPCMEncContext {
-+ uint16_t header; // Header added to every frame
-+} BlurayPCMEncContext;
-
--static av_cold int pcm_bd_encode_init(AVCodecContext *avctx)
-+static av_cold int pcm_bluray_encode_init(AVCodecContext *avctx)
- {
-- PCMBDContext *s = avctx->priv_data;
-- int quant, freq;
-- uint16_t frame_size;
-- uint8_t ch_layout = 0;
--
-+ BlurayPCMEncContext *s = avctx->priv_data;
-+ uint8_t ch_layout;
-+ int quant, freq, frame_size;
-+
-+ switch(avctx->sample_fmt) {
-+ case AV_SAMPLE_FMT_S16:
-+ avctx->bits_per_coded_sample = 16;
-+ frame_size = 240;
-+ quant =1;
-+ break;
-+ case AV_SAMPLE_FMT_S32:
-+ avctx->bits_per_coded_sample = 24;
-+ frame_size = 360;
-+ quant =3;
-+ break;
-+ default:
-+ return AVERROR_BUG;
-+ }
-+
- switch (avctx->sample_rate) {
- case 48000:
- freq = 1;
- break;
- case 96000:
-+ //frame_size *= 2;
- freq = 4;
- break;
- case 192000:
-- freq = 5;
-- break;
-+ //frame_size *= 4;
-+ freq = 5;
-+ break;
-+ default:
-+ return AVERROR_BUG;
- }
-
-- switch (avctx->sample_fmt) {
-- case AV_SAMPLE_FMT_S16:
-- avctx->bits_per_coded_sample = 16;
-- quant = 1;
-+ //frame_size *= avctx->channels;
-+
-+ switch (avctx->channel_layout) {
-+ case AV_CH_LAYOUT_MONO:
-+ ch_layout = 1;
- break;
--/* case AV_SAMPLE_FMT_S20:
-- avctx->bits_per_coded_sample = 20;
-- quant = 2;
-+ case AV_CH_LAYOUT_STEREO:
-+ ch_layout = 3;
- break;
--*/
-- case AV_SAMPLE_FMT_S32:
-- avctx->bits_per_coded_sample = 24;
-- quant = 3;
-+ case AV_CH_LAYOUT_SURROUND:
-+ ch_layout = 4;
- break;
-- }
--
-- avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
-- avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
-- if (avctx->bit_rate > 19800000) {
-- av_log(avctx, AV_LOG_ERROR, "Too big bitrate: reduce sample rate, bitdepth or channels.\n");
-- return AVERROR(EINVAL);
-- }
--
-- if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
-- switch (avctx->channels) {
-- case 1:
-- s->block_size = avctx->channels * 4;
-- break;
-- default:
-- s->block_size = avctx->channels * 2;
-+ case AV_CH_LAYOUT_2_1:
-+ ch_layout = 5;
- break;
-- }
-- s->samples_per_block = 1;
-- frame_size = 2008 / s->block_size;
-- } else {
-- switch (avctx->channels) {
-- case 1:
-- s->block_size = 2 * avctx->channels * avctx->bits_per_coded_sample / 8;
-- s->samples_per_block = 1;
-- break;
-- case 2:
-- case 4:
-- /* one group has all the samples needed */
-- s->block_size = avctx->channels * avctx->bits_per_coded_sample / 8;
-- s->samples_per_block = 1;
-- s->groups_per_block = 2;
-- break;
-- case 8:
-- case 6:
-- /* two groups have all the samples needed */
-- s->block_size = avctx->channels * avctx->bits_per_coded_sample / 8;
-- s->samples_per_block = 1;
-- // s->groups_per_block = 2;
-- break;
-- default:
-- /* need avctx->channels groups */
-- s->block_size = 4 * avctx->channels *
-- avctx->bits_per_coded_sample / 8;
-- s->samples_per_block = 4;
-- s->groups_per_block = avctx->channels;
-- break;
-- }
--
-- frame_size = FFALIGN(2008 / s->block_size, s->samples_per_block);
-+ 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_BACK:
-+ 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;
- }
-
-- 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_5POINT1:
-- case AV_CH_LAYOUT_5POINT1_BACK:
-- ch_layout = 9;
-- break;
-- case AV_CH_LAYOUT_7POINT1:
-- ch_layout = 11;
-- break;
-- default:
-- av_log(avctx, AV_LOG_ERROR, "Not yet implemented ch layout!\n");
-- }
--// description on the web:
--/* http://forum.doom9.org/showthread.php?t=152897
--
--It's a header.
--
--size in bytes = 16 bits (big endian)
--channel assignment = 4 bits
--sampling frequency = 4 bits
--bits per sample = 2 bits
--start flag = 1 bit
--reserved = 5 bits
--
--channel assignment
--1 = mono
--3 = stereo
--4 = 3/0
--5 = 2/1
--6 = 3/1
--7 = 2/2
--8 = 3/2
--9 = 3/2+lfe
--10 = 3/4
--11 = 3/4+lfe
--
--sampling frequency
--1 = 48 kHz
--4 = 96 kHz
--5 = 192 kHz
--
--bits per sample
--1 = 16
--2 = 20
--3 = 24
--*/
--
-- s->header[2] = (ch_layout << 4) | (freq);
-- s->header[3] = (quant << 6) | 0x1 ;
--
--
-- avctx->frame_size = frame_size; // in num. of samples
-+ s->header = (((ch_layout << 4) | freq) << 8) | (quant << 6);
-+ avctx->frame_size = frame_size;
-
- return 0;
- }
-
--static int pcm_bd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-- const AVFrame *frame, int *got_packet_ptr)
-+static int pcm_bluray_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-+ const AVFrame *frame, int *got_packet_ptr)
- {
-- PCMBDContext *s = avctx->priv_data;
-- int samples, channels;
-- int64_t pkt_size = (frame->nb_samples / s->samples_per_block) * s->block_size + 4;
-+ 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;
-
-- if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0)
-+ 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(s->header, pkt_size - 4);
-- memcpy(avpkt->data, s->header, 4);
-+ 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);
-
-- int num_source_channels = FFALIGN(avctx->channels, 2);
-- // int num_source_channels = avctx->channels;
-- // int sample_size = (num_source_channels *
-- // (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
-- samples = frame->nb_samples * num_source_channels;
--
-- switch (avctx->sample_fmt) {
-- case AV_SAMPLE_FMT_S16:
-- switch (avctx->channels) {
-- case 1:
-- do {
-- do {
-- channels = avctx->channels;
-- bytestream2_put_be16(&pb, *src16++);
-- } while (--channels);
-- bytestream2_put_be16(&pb, 0);
-- } while (--samples);
-- break;
-- case 2:
-- do {
-- bytestream2_put_be16(&pb, *src16++);
-- } while (--samples);
-- break;
-- case 6:
-- do {
-- bytestream2_put_be16(&pb, src16[0]);
-- bytestream2_put_be16(&pb, src16[1]);
-- bytestream2_put_be16(&pb, src16[2]);
-- bytestream2_put_be16(&pb, src16[4]);
-- bytestream2_put_be16(&pb, src16[5]);
-- bytestream2_put_be16(&pb, src16[3]);
-- src16+=6;
-- } while (--samples);
-- break;
-- case 8:
-- do {
-- bytestream2_put_be16(&pb, src16[0]);
-- bytestream2_put_be16(&pb, src16[1]);
-- bytestream2_put_be16(&pb, src16[2]);
-- bytestream2_put_be16(&pb, src16[6]);
-- bytestream2_put_be16(&pb, src16[4]);
-- bytestream2_put_be16(&pb, src16[5]);
-- bytestream2_put_be16(&pb, src16[7]);
-- bytestream2_put_be16(&pb, src16[3]);
-- src16+=8;
-- } while (--samples);
-- break;
--
-- default:
-- av_log(avctx, AV_LOG_ERROR, "this ch config not implemented for s16!\n");
-+ 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_bufferu(&pb, frame->data[0], samples * 2);
-+#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, (const uint8_t *)src16, avctx->ch_layout.nb_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;
-- case AV_SAMPLE_FMT_S32:
-- switch (avctx->channels) {
-- case 2:
-- case 4:
-- do {
-- bytestream2_put_be24(&pb, (*src32++) >> 8);
-- } while (--samples);
-- break;
-- case 8:
-- do {
-- bytestream2_put_be24(&pb, src32[0] >> 8);
-- bytestream2_put_be24(&pb, src32[1] >> 8);
-- bytestream2_put_be24(&pb, src32[2] >> 8);
-- bytestream2_put_be24(&pb, src32[6] >> 8);
-- bytestream2_put_be24(&pb, src32[4] >> 8);
-- bytestream2_put_be24(&pb, src32[5] >> 8);
-- bytestream2_put_be24(&pb, src32[7] >> 8);
-- bytestream2_put_be24(&pb, src32[3] >> 8);
-- src32+=8;
-- } while (--samples);
-- break;
-- case 6:
-- do {
-- bytestream2_put_be24(&pb, src32[0] >> 8);
-- bytestream2_put_be24(&pb, src32[1] >> 8);
-- bytestream2_put_be24(&pb, src32[2] >> 8);
-- bytestream2_put_be24(&pb, src32[4] >> 8);
-- bytestream2_put_be24(&pb, src32[5] >> 8);
-- bytestream2_put_be24(&pb, src32[3] >> 8);
-- src32+=6;
-- } while (--samples);
-- break;
-- case 1:
-- do {
-- do {
-- channels = avctx->channels;
-- bytestream2_put_be24(&pb, (*src32++) >> 8);
-- } while (--channels);
-- bytestream2_put_be24(&pb, 0);
-- } while (--samples);
-- break;
-- default:
-- av_log(avctx, AV_LOG_ERROR, "this bitdepth not implemented!\n");
-- break;
-- }
-- break;
-+ /* remapping: L, R, C, LBack, RBack, LF */
-+ case AV_CH_LAYOUT_5POINT1_BACK:
-+ 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;
-+ default:
-+ return AVERROR_BUG;
- }
-
-- avpkt->pts = frame->pts;
-- avpkt->size = pkt_size;
-+ avpkt->pts = frame->pts;
- avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
- *got_packet_ptr = 1;
-
- return 0;
- }
-
--AVCodec ff_pcm_bluray_encoder = {
-- .name = "pcm_bluray",
-- .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|24-bit big-endian for bluray media"),
-- .type = AVMEDIA_TYPE_AUDIO,
-- .id = AV_CODEC_ID_PCM_BLURAY,
-- .priv_data_size = sizeof(PCMBDContext),
-- .init = pcm_bd_encode_init,
-- .encode2 = pcm_bd_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_5POINT1,
-- AV_CH_LAYOUT_5POINT1_BACK,
-- 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,
-+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,
-+ .supported_samplerates = (const int[]) { 48000, 96000, 192000, 0 },
-+//#define FF_API_OLD_CHANNEL_LAYOUT 1
-+#if 1
-+ .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_BACK,
-+ AV_CH_LAYOUT_7POINT0,
-+ AV_CH_LAYOUT_7POINT1,
-+ 0 },
-+#endif
-+#if 0
-+ .p.ch_layouts = (const AVChannelLayout[]) {
-+ AV_CHANNEL_LAYOUT_MONO,
-+ AV_CHANNEL_LAYOUT_STEREO,
-+ AV_CHANNEL_LAYOUT_SURROUND,
-+ AV_CHANNEL_LAYOUT_2_1,
-+ AV_CHANNEL_LAYOUT_4POINT0,
-+ AV_CHANNEL_LAYOUT_2_2,
-+ AV_CHANNEL_LAYOUT_5POINT0,
-+ AV_CHANNEL_LAYOUT_5POINT1,
-+ AV_CHANNEL_LAYOUT_7POINT0,
-+ AV_CHANNEL_LAYOUT_7POINT1,
-+ { 0 } },
-+#endif
-+ .sample_fmts = (const enum AVSampleFormat[]) {
-+ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE },
-+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
-+ .capabilities = AV_CODEC_CAP_DR1,
- };