From: Good Guy Date: Fri, 27 Aug 2021 00:23:33 +0000 (-0600) Subject: ffmpeg upgrade from 4.3 to 4.4 / Andrew fixed patches except patch2/B by Freelancer X-Git-Tag: 2021-08~3 X-Git-Url: https://cinelerra-gg.org/git/?a=commitdiff_plain;h=b7045bda288a03559422862284a9cf411b63c072;p=goodguy%2Fcinelerra.git ffmpeg upgrade from 4.3 to 4.4 / Andrew fixed patches except patch2/B by Freelancer --- diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index a4a385cd..b05a455d 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -603,6 +603,7 @@ int FFStream::encode_frame(AVFrame *frame) ret = avcodec_send_frame(avctx, frame); if( !ret && frame ) return pkts; if( ret < 0 && ret != AVERROR(EAGAIN) ) break; + if ( ret == AVERROR(EAGAIN) && !frame ) continue; FFPacket opkt; ret = avcodec_receive_packet(avctx, opkt); if( !frame && ret == AVERROR_EOF ) return pkts; diff --git a/cinelerra-5.1/configure.ac b/cinelerra-5.1/configure.ac index 33491eef..78db7cfa 100644 --- a/cinelerra-5.1/configure.ac +++ b/cinelerra-5.1/configure.ac @@ -189,7 +189,7 @@ PKG_3RD([esound],[no], [ . ]) PKG_3RD([ffmpeg],[yes], - [ffmpeg-4.3], + [ffmpeg-4.4], [ libavutil/libavutil.a \ libavcodec/libavcodec.a \ libpostproc/libpostproc.a \ diff --git a/cinelerra-5.1/ffmpeg/plugin.opts b/cinelerra-5.1/ffmpeg/plugin.opts index 0e52a6d7..5837b441 100644 --- a/cinelerra-5.1/ffmpeg/plugin.opts +++ b/cinelerra-5.1/ffmpeg/plugin.opts @@ -376,6 +376,8 @@ vibrance #sr ###Input/output error #xstack ###Operation not permitted #agraphmonitor ###Input/output error +; new in 4.2 +dresser ; broken in 4.3 #anlms ###Input/output error #axcorrelate ###Input/output error @@ -394,3 +396,32 @@ vibrance #ass #drawtext #subtitles +; new in 4.4 +chromanr +afreqshift +aphseshift +adenorm +asupercut +asubcut +asuperpass +asuperstop +shufflepixels +tmidequalizer +estdif +epx +shear +kirsch +colortemperature +colorcontrast +colorcorrect +colorize +aexciter +exposure +monochrome +; broken in 4.4 +#speechnorm +#bitstream +#identity ###Input/output error +#msad ###Input/output error +#setts +#vif ###Input/output error diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0 new file mode 100644 index 00000000..f9760935 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0 @@ -0,0 +1,12 @@ +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; diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1 new file mode 100644 index 00000000..88631302 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1 @@ -0,0 +1,13 @@ +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; diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch2 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch2 new file mode 100644 index 00000000..e3a51af5 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch2 @@ -0,0 +1,369 @@ +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 diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3 new file mode 100644 index 00000000..28d3876f --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3 @@ -0,0 +1,74 @@ +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) diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5 new file mode 100644 index 00000000..32e7fe11 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5 @@ -0,0 +1,30 @@ +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) diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6 new file mode 100644 index 00000000..e59a17cc --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6 @@ -0,0 +1,12 @@ +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, + }; diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7 new file mode 100644 index 00000000..05d3b1d0 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7 @@ -0,0 +1,13 @@ +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); diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8 new file mode 100644 index 00000000..51bc09e3 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8 @@ -0,0 +1,16 @@ +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); diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9 new file mode 100644 index 00000000..0cf24e74 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9 @@ -0,0 +1,36 @@ +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) diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA new file mode 100644 index 00000000..6d181e3c --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA @@ -0,0 +1,24 @@ +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 diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchB b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchB new file mode 100644 index 00000000..848ce478 --- /dev/null +++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchB @@ -0,0 +1,43 @@ +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); diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.tar.xz b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.tar.xz new file mode 100644 index 00000000..30881566 Binary files /dev/null and b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.tar.xz differ