Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2021-05-28 19:37:36 +0300
committerSebastian Parborg <darkdefende@gmail.com>2021-05-28 19:37:36 +0300
commit9225fe933ae9904ea7bb646110308a921b37fc86 (patch)
treecfed4d4c8e80cb9f0531baede23f3735c6272c67 /intern/ffmpeg
parent33113506701fac51b8b4dc8f51975200f885e50a (diff)
Make encoded video fps correct with ffmpeg < 4.4
Before the FFmpeg commit: github.com/FFmpeg/FFmpeg/commit/1c0885334dda9ee8652e60c586fa2e3674056586 FFmpeg would use deprecated variables to calculate the video fps. We don't use these deprecated variables anymore, so ensure that the duration is correct in ffmpeg versions without this fix. Reviewed By: Sergey, Richard Antalik Differential Revision: http://developer.blender.org/D11417
Diffstat (limited to 'intern/ffmpeg')
-rw-r--r--intern/ffmpeg/ffmpeg_compat.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/intern/ffmpeg/ffmpeg_compat.h b/intern/ffmpeg/ffmpeg_compat.h
index 54a004d53e2..0c22cf82688 100644
--- a/intern/ffmpeg/ffmpeg_compat.h
+++ b/intern/ffmpeg/ffmpeg_compat.h
@@ -43,6 +43,55 @@
# define FFMPEG_INLINE static inline
#endif
+#if (LIBAVFORMAT_VERSION_MAJOR < 58) || \
+ ((LIBAVFORMAT_VERSION_MAJOR == 58) && (LIBAVFORMAT_VERSION_MINOR < 76))
+# define FFMPEG_USE_DURATION_WORKAROUND 1
+
+/* Before ffmpeg 4.4, package duration calculation used depricated variables to calculate the
+ * packet duration. Use the function from commit
+ * github.com/FFmpeg/FFmpeg/commit/1c0885334dda9ee8652e60c586fa2e3674056586
+ * to calculate the correct framerate for ffmpeg < 4.4.
+ */
+
+FFMPEG_INLINE
+void my_guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt)
+{
+ if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
+ av_log(s,
+ AV_LOG_WARNING,
+ "Packet with invalid duration %" PRId64 " in stream %d\n",
+ pkt->duration,
+ pkt->stream_index);
+ pkt->duration = 0;
+ }
+
+ if (pkt->duration) {
+ return;
+ }
+
+ switch (st->codecpar->codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) {
+ pkt->duration = av_rescale_q(1, av_inv_q(st->avg_frame_rate), st->time_base);
+ }
+ else if (st->time_base.num * 1000LL > st->time_base.den) {
+ pkt->duration = 1;
+ }
+ break;
+ case AVMEDIA_TYPE_AUDIO: {
+ int frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size);
+ if (frame_size && st->codecpar->sample_rate) {
+ pkt->duration = av_rescale_q(
+ frame_size, (AVRational){1, st->codecpar->sample_rate}, st->time_base);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+#endif
+
FFMPEG_INLINE
void my_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
{