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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
Index: gazebo-11.10.1/gazebo/common/AudioDecoder.cc
===================================================================
--- gazebo-11.10.1.orig/gazebo/common/AudioDecoder.cc
+++ gazebo-11.10.1/gazebo/common/AudioDecoder.cc
@@ -113,8 +113,13 @@ bool AudioDecoder::Decode(uint8_t **_out
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- bytesDecoded = avcodec_decode_audio4(this->codecCtx, decodedFrame,
- &gotFrame, &packet1);
+ bytesDecoded = avcodec_send_packet(this->codecCtx, &packet1);
+ if (bytesDecoded >= 0 || bytesDecoded == AVERROR_EOF) {
+ bytesDecoded = avcodec_receive_frame(this->codecCtx, decodedFrame);
+ gotFrame = bytesDecoded >= 0;
+ if (bytesDecoded == AVERROR(EAGAIN) || bytesDecoded == AVERROR_EOF) bytesDecoded = 0;
+ }
+
#ifndef _WIN32
# pragma GCC diagnostic pop
#endif
@@ -214,7 +219,7 @@ bool AudioDecoder::SetFile(const std::st
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- if (this->formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ if (this->formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
#ifndef _WIN32
# pragma GCC diagnostic pop
#endif
@@ -238,7 +243,9 @@ bool AudioDecoder::SetFile(const std::st
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- this->codecCtx = this->formatCtx->streams[audioStream]->codec;
+ this->codecCtx = avcodec_alloc_context3(nullptr);
+ avcodec_parameters_to_context(this->codecCtx, this->formatCtx->streams[audioStream]->codecpar);
+
#ifndef _WIN32
# pragma GCC diagnostic pop
#endif
Index: gazebo-11.10.1/gazebo/common/AudioDecoder.hh
===================================================================
--- gazebo-11.10.1.orig/gazebo/common/AudioDecoder.hh
+++ gazebo-11.10.1/gazebo/common/AudioDecoder.hh
@@ -75,7 +75,7 @@ namespace gazebo
private: AVCodecContext *codecCtx;
/// \brief libavcodec audio codec.
- private: AVCodec *codec;
+ private: const AVCodec *codec;
/// \brief Index of the audio stream.
private: int audioStream;
Index: gazebo-11.10.1/gazebo/common/Video.cc
===================================================================
--- gazebo-11.10.1.orig/gazebo/common/Video.cc
+++ gazebo-11.10.1/gazebo/common/Video.cc
@@ -77,7 +77,7 @@ void Video::Cleanup()
#ifdef HAVE_FFMPEG
bool Video::Load(const std::string &_filename)
{
- AVCodec *codec = nullptr;
+ const AVCodec *codec = nullptr;
this->videoStream = -1;
if (this->formatCtx || this->avFrame || this->codecCtx)
@@ -107,7 +107,7 @@ bool Video::Load(const std::string &_fil
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- if (this->formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ if (this->formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
#ifndef _WIN32
# pragma GCC diagnostic pop
#endif
@@ -128,13 +128,14 @@ bool Video::Load(const std::string &_fil
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- this->codecCtx = this->formatCtx->streams[this->videoStream]->codec;
+ this->codecCtx = avcodec_alloc_context3(nullptr);
+ avcodec_parameters_to_context(this->codecCtx, this->formatCtx->streams[this->videoStream]->codecpar);
#ifndef _WIN32
# pragma GCC diagnostic pop
#endif
// Find the decoder for the video stream
- codec = avcodec_find_decoder(this->codecCtx->codec_id);
+ codec = avcodec_find_decoder(this->formatCtx->streams[this->videoStream]->codecpar->codec_id);
if (codec == nullptr)
{
gzerr << "Codec not found\n";
@@ -231,15 +232,19 @@ bool Video::GetNextFrame(unsigned char *
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- int processedLength = avcodec_decode_video2(this->codecCtx, this->avFrame,
- &frameAvailable, &tmpPacket);
+ int processedLength = avcodec_send_packet(this->codecCtx, !tmpPacket.data && !tmpPacket.size ? nullptr : &tmpPacket);
#ifndef _WIN32
# pragma GCC diagnostic pop
#endif
+ if (processedLength >= 0 || processedLength == AVERROR_EOF) {
+ processedLength = avcodec_receive_frame(this->codecCtx, this->avFrame);
+ frameAvailable = processedLength >= 0;
+ if (processedLength == AVERROR(EAGAIN) || processedLength == AVERROR_EOF) processedLength = 0;
+ }
if (processedLength < 0)
{
gzerr << "Error while processing the data\n";
- break;
+ break;
}
tmpPacket.data = tmpPacket.data + processedLength;
Index: gazebo-11.10.1/gazebo/common/VideoEncoder.cc
===================================================================
--- gazebo-11.10.1.orig/gazebo/common/VideoEncoder.cc
+++ gazebo-11.10.1/gazebo/common/VideoEncoder.cc
@@ -224,7 +224,7 @@ bool VideoEncoder::Start(const std::stri
// The remainder of this function handles FFMPEG initialization of a video
// stream
- AVOutputFormat *outputFormat = nullptr;
+ const AVOutputFormat *outputFormat = nullptr;
// This 'if' and 'free' are just for safety. We chech the value of formatCtx
// below.
@@ -294,7 +294,7 @@ bool VideoEncoder::Start(const std::stri
}
// find the video encoder
- AVCodec *encoder = avcodec_find_encoder(
+ const AVCodec *encoder = avcodec_find_encoder(
this->dataPtr->formatCtx->oformat->video_codec);
if (!encoder)
{
|