aboutsummaryrefslogtreecommitdiff
path: root/emulators/emu64/files/patch-ffmpeg6
blob: 80f143f393898b91b3bbceb1441a4af12f59618e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From e09e645a88f37fa2a81d754cb9c86c4a584941a1 Mon Sep 17 00:00:00 2001
From: Felix Palmen <felix@palmen-it.de>
Date: Mon, 20 Mar 2023 09:42:43 +0100
Subject: [PATCH] Fix build with ffmpeg 6

This doesn't attempt to replace deprecated functions, it only replaces
functions that are gone (avcodec_encode_[audio|video]2) with
straight-forward replacement code.

It fixes the build with the latest 6.0 release and still builds fine
with ffmpeg 4.4
--- src/video_capture_class.cpp.orig	2021-07-08 16:55:15 UTC
+++ src/video_capture_class.cpp
@@ -87,7 +87,9 @@ bool VideoCaptureClass::StartCapture(const char *filen
 
     int ret;
 
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
     av_register_all();
+#endif
 
     //
     avformat_alloc_output_context2(&format_ctx, nullptr, nullptr, filename);
@@ -267,7 +269,7 @@ int VideoCaptureClass::GetRecordedFrameCount()
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void VideoCaptureClass::AddStream(OutputStream *ost, AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id)
+void VideoCaptureClass::AddStream(OutputStream *ost, AVFormatContext *oc, const AVCodec **codec, enum AVCodecID codec_id)
 {
     AVCodecContext *c;
     int i;
@@ -363,7 +365,7 @@ void VideoCaptureClass::CloseStream(OutputStream *ost)
     swr_free(&ost->swr_ctx);
 }
 
-bool VideoCaptureClass::OpenVideo(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
+bool VideoCaptureClass::OpenVideo(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
 {
     int ret;
     AVCodecContext *c = ost->enc;
@@ -431,7 +433,7 @@ AVFrame* VideoCaptureClass::AllocPicture(enum AVPixelF
     return picture;
 }
 
-bool VideoCaptureClass::OpenAudio(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
+bool VideoCaptureClass::OpenAudio(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
 {
     AVCodecContext *c;
     int nb_samples;
@@ -532,7 +534,10 @@ int VideoCaptureClass::WriteVideoFrame(AVFormatContext
     av_init_packet(&pkt);
 
     /* encode the image */
-    ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
+    ret = avcodec_receive_packet(c, &pkt);
+    if (ret == 0) got_packet = 1;
+    if (ret == AVERROR(EAGAIN)) ret = 0;
+    if (ret == 0) ret = avcodec_send_frame(c, frame);
     if (ret < 0)
     {
         char err_msg[AV_ERROR_MAX_STRING_SIZE];
@@ -562,7 +567,7 @@ int VideoCaptureClass::WriteAudioFrame(AVFormatContext
     AVPacket pkt = {}; // data and size must be 0;
     AVFrame *frame;
     int64_t ret;
-    int got_packet;
+    int got_packet = 0;
     int64_t dst_nb_samples;
     av_init_packet(&pkt);
     c = ost->enc;
@@ -595,7 +600,10 @@ int VideoCaptureClass::WriteAudioFrame(AVFormatContext
         frame->pts = av_rescale_q(ost->samples_count, AVRational{1, c->sample_rate}, c->time_base);
         ost->samples_count += dst_nb_samples;
     }
-    ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
+    ret = avcodec_receive_packet(c, &pkt);
+    if (ret == 0) got_packet = 1;
+    if (ret == AVERROR(EAGAIN)) ret = 0;
+    if (ret == 0) ret = avcodec_send_frame(c, frame);
 
     if (ret < 0)
     {
--- src/video_capture_class.h.orig	2021-07-08 16:55:15 UTC
+++ src/video_capture_class.h
@@ -31,6 +31,7 @@ using namespace std;
 
 extern "C"
 {
+    #include <libavcodec/avcodec.h>
     #include <libavutil/avassert.h>
     #include <libavutil/channel_layout.h>
     #include <libavutil/opt.h>
@@ -84,11 +85,11 @@ class VideoCaptureClass (public)
     bool mutex_01;
 
 private:
-    void AddStream(OutputStream *ost, AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id);
+    void AddStream(OutputStream *ost, AVFormatContext *oc, const AVCodec **codec, enum AVCodecID codec_id);
     void CloseStream(OutputStream *ost);
-    bool OpenVideo(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg);
+    bool OpenVideo(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg);
     AVFrame* AllocPicture(enum AVPixelFormat pix_fmt, int width, int height);
-    bool OpenAudio(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg);
+    bool OpenAudio(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg);
     AVFrame* AllocAudioFrame(enum AVSampleFormat sample_fmt, uint64_t channel_layout, int sample_rate, int nb_samples);
     int WriteFrame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt);
 
@@ -110,9 +111,9 @@ class VideoCaptureClass (public)
     int video_bitrate, audio_bitrate;
 
 
-    AVOutputFormat  *output_format;
+    const AVOutputFormat  *output_format;
     OutputStream audio_stream;
-    AVCodec *video_codec, *audio_codec;
+    const AVCodec *video_codec, *audio_codec;
     AVDictionary *options;
 
     uint8_t* source_video_data;