Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff94632

Browse files
authored
Merge pull request#326 from avTranscoder/dev/ffmpeg_5.0
FFmpeg 5.0
2 parents5c3756b +59f17bf commitff94632

25 files changed

+236
-105
lines changed

‎src/AvTranscoder/Library.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern "C" {
1111
#else
1212
#include<libswresample/version.h>
1313
#endif
14+
#include<libavcodec/avcodec.h>
1415
#include<libavformat/avformat.h>
1516
#include<libavfilter/avfilter.h>
1617
}

‎src/AvTranscoder/codec/ICodec.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class AvExport ICodec
5454
#ifndef SWIG
5555
AVCodecContext&getAVCodecContext() {return *_avCodecContext; }
5656
const AVCodecContext&getAVCodecContext()const {return *_avCodecContext; }
57-
AVCodec&getAVCodec() {return *_avCodec; }
5857
const AVCodec&getAVCodec()const {return *_avCodec; }
5958
#endif
6059

@@ -66,7 +65,7 @@ class AvExport ICodec
6665

6766
protected:
6867
AVCodecContext* _avCodecContext;///< Full codec instance description (has ownership)
69-
AVCodec* _avCodec;///< Codec abstract description
68+
constAVCodec* _avCodec;///< Codec abstract description
7069
constbool _isCodecContextAllocated;///< Is the AVCodecContext allocated by the class
7170

7271
ECodecType _type;

‎src/AvTranscoder/common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define_AV_TRANSCODER_COMMON_HPP_
33

44
#defineAVTRANSCODER_VERSION_MAJOR0
5-
#defineAVTRANSCODER_VERSION_MINOR15
6-
#defineAVTRANSCODER_VERSION_MICRO5
5+
#defineAVTRANSCODER_VERSION_MINOR16
6+
#defineAVTRANSCODER_VERSION_MICRO0
77

88
#include<AvTranscoder/system.hpp>
99

‎src/AvTranscoder/data/coded/CodedData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void CodedData::assign(const size_t size, const int value)
8787

8888
voidCodedData::initAVPacket()
8989
{
90-
av_init_packet(&_packet);
90+
_packet = *av_packet_alloc();
9191
_packet.data =NULL;
9292
_packet.size =0;
9393
}

‎src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ bool AudioDecoder::decodeNextFrame(IFrame& frameBuffer)
8787
if(!_isSetup)
8888
setupDecoder();
8989

90-
int got_frame =0;
90+
bool got_frame =false;
9191
while(!got_frame)
9292
{
9393
CodedData data;
@@ -98,18 +98,27 @@ bool AudioDecoder::decodeNextFrame(IFrame& frameBuffer)
9898
// decoding
9999
// @note could be called several times to return the remaining frames (last call with an empty packet)
100100
// @see CODEC_CAP_DELAY
101-
int ret =avcodec_decode_audio4(&_inputStream->getAudioCodec().getAVCodecContext(), &frameBuffer.getAVFrame(),
102-
&got_frame, &data.getAVPacket());
101+
int ret =avcodec_send_packet(&_inputStream->getAudioCodec().getAVCodecContext(), &data.getAVPacket());
102+
103103
if(ret <0)
104104
{
105-
throwstd::runtime_error("An error occurredduring audiodecoding:" +getDescriptionFromErrorCode(ret));
105+
throwstd::runtime_error("An error occurredsending audiopacket to decoder:" +getDescriptionFromErrorCode(ret));
106106
}
107107

108+
ret =avcodec_receive_frame(&_inputStream->getAudioCodec().getAVCodecContext(), &frameBuffer.getAVFrame());
109+
110+
if (ret ==0)
111+
got_frame =true;
112+
elseif (ret ==AVERROR(EAGAIN) || ret == AVERROR_EOF)
113+
got_frame =false;
114+
else
115+
throwstd::runtime_error("An error occurred receiving audio packet from decoder:" +getDescriptionFromErrorCode(ret));
116+
108117
// fixed channel layout value after decoding
109118
frameBuffer.getAVFrame().channel_layout = channelLayout;
110119

111120
// if no frame could be decompressed
112-
if(!nextPacketRead &&ret ==0 &&got_frame ==0)
121+
if(!nextPacketRead && got_frame ==0)
113122
decodeNextFrame =false;
114123
else
115124
decodeNextFrame =true;

‎src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,22 @@ bool VideoDecoder::decodeNextFrame(IFrame& frameBuffer)
9494
// decoding
9595
// @note could be called several times to return the remaining frames (last call with an empty packet)
9696
// @see CODEC_CAP_DELAY
97-
constint ret =avcodec_decode_video2(&_inputStream->getVideoCodec().getAVCodecContext(), &frameBuffer.getAVFrame(),
98-
&got_frame, &data.getAVPacket());
99-
if(ret <0)
100-
{
101-
throwstd::runtime_error("An error occurred during video decoding:" +getDescriptionFromErrorCode(ret));
102-
}
97+
int ret =avcodec_send_packet(&_inputStream->getVideoCodec().getAVCodecContext(), &data.getAVPacket());
98+
99+
if (ret <0 && (nextPacketRead || ret != AVERROR_EOF))
100+
throwstd::runtime_error("An error occurred sending video packet to decoder:" +getDescriptionFromErrorCode(ret));
101+
102+
ret =avcodec_receive_frame(&_inputStream->getVideoCodec().getAVCodecContext(), &frameBuffer.getAVFrame());
103+
104+
if (ret ==0)
105+
got_frame =true;
106+
elseif (ret ==AVERROR(EAGAIN) || ret == AVERROR_EOF)
107+
got_frame =false;
108+
else
109+
throwstd::runtime_error("An error occurred receiving video packet from decoder:" +getDescriptionFromErrorCode(ret));
103110

104111
// if no frame could be decompressed
105-
if(!nextPacketRead && ret ==0 &&got_frame ==0)
112+
if ((!nextPacketRead && ret ==0) || !got_frame)
106113
decodeNextFrame =false;
107114
else
108115
decodeNextFrame =true;

‎src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
}
88

99
#include<stdexcept>
10+
#include<libavcodec/avcodec.h>
1011

1112
namespaceavtranscoder
1213
{
@@ -93,8 +94,6 @@ void AudioEncoder::setupEncoder(const ProfileLoader::Profile& profile)
9394

9495
boolAudioEncoder::encodeFrame(const IFrame& sourceFrame, CodedData& codedFrame)
9596
{
96-
AVCodecContext& avCodecContext = _codec.getAVCodecContext();
97-
9897
AVPacket& packet = codedFrame.getAVPacket();
9998
const AVFrame& srcAvFrame = sourceFrame.getAVFrame();
10099
if(srcAvFrame.pts != (int)AV_NOPTS_VALUE)
@@ -121,7 +120,23 @@ bool AudioEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData)
121120
encodedData.data =NULL;
122121

123122
AVCodecContext& avCodecContext = _codec.getAVCodecContext();
124-
#if LIBAVCODEC_VERSION_MAJOR > 53
123+
#if LIBAVCODEC_VERSION_MAJOR > 58
124+
int ret =avcodec_send_frame(&avCodecContext, decodedData);
125+
126+
if(ret !=0)
127+
throwstd::runtime_error("Error sending audio frame to encoder:" +getDescriptionFromErrorCode(ret));
128+
129+
ret =avcodec_receive_packet(&avCodecContext, &encodedData);
130+
131+
if (ret ==0)
132+
returntrue;
133+
134+
if (ret ==AVERROR(EAGAIN) || ret == AVERROR_EOF)
135+
returnfalse;
136+
137+
throwstd::runtime_error("Error receiving audio frame from encoder:" +getDescriptionFromErrorCode(ret));
138+
139+
#elif LIBAVCODEC_VERSION_MAJOR > 53
125140
int gotPacket =0;
126141
constint ret =avcodec_encode_audio2(&avCodecContext, &encodedData, decodedData, &gotPacket);
127142
if(ret !=0)

‎src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)
110110

111111
boolVideoEncoder::encodeFrame(const IFrame& sourceFrame, CodedData& codedFrame)
112112
{
113-
AVCodecContext& avCodecContext = _codec.getAVCodecContext();
114-
115113
AVPacket& packet = codedFrame.getAVPacket();
116114
const AVFrame& srcAvFrame = sourceFrame.getAVFrame();
117115
if(srcAvFrame.pts != (int)AV_NOPTS_VALUE)
@@ -138,14 +136,31 @@ bool VideoEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData)
138136
encodedData.data =NULL;
139137

140138
AVCodecContext& avCodecContext = _codec.getAVCodecContext();
141-
#if LIBAVCODEC_VERSION_MAJOR > 53
139+
#if LIBAVCODEC_VERSION_MAJOR > 58
140+
int ret =avcodec_send_frame(&avCodecContext, decodedData);
141+
142+
if (ret !=0 && ret != AVERROR_EOF)
143+
throwstd::runtime_error("Error sending video frame to encoder:" +getDescriptionFromErrorCode(ret));
144+
145+
ret =avcodec_receive_packet(&avCodecContext, &encodedData);
146+
147+
if (ret ==0)
148+
returntrue;
149+
150+
if (ret ==AVERROR(EAGAIN) || ret == AVERROR_EOF)
151+
returnfalse;
152+
153+
throwstd::runtime_error("Error receiving video frame from encoder:" +getDescriptionFromErrorCode(ret));
154+
155+
#elif LIBAVCODEC_VERSION_MAJOR > 53
142156
int gotPacket =0;
143157
constint ret =avcodec_encode_video2(&avCodecContext, &encodedData, decodedData, &gotPacket);
144158
if(ret !=0)
145159
{
146160
throwstd::runtime_error("Encode video frame error: avcodec encode video frame -" +
147161
getDescriptionFromErrorCode(ret));
148162
}
163+
149164
return gotPacket ==1;
150165
#else
151166
constint ret =avcodec_encode_video(&avCodecContext, encodedData.data, encodedData.size, decodedData);

‎src/AvTranscoder/file/FormatContext.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ FormatContext::~FormatContext()
4646
if(!_avFormatContext)
4747
return;
4848

49-
// free the streams added
50-
for(std::vector<AVStream*>::iterator it = _avStreamAllocated.begin(); it != _avStreamAllocated.end(); ++it)
51-
avcodec_close((*it)->codec);
52-
5349
// free the format context
5450
if(_isOpen)
5551
avformat_close_input(&_avFormatContext);
@@ -151,7 +147,7 @@ AVStream& FormatContext::addAVStream(const AVCodec& avCodec)
151147

152148
boolFormatContext::seek(constuint64_t position,constint flag)
153149
{
154-
LOG_INFO("Seek in '" << _avFormatContext->filename <<"' at" << position <<" with flag '" << flag <<"'")
150+
LOG_INFO("Seek in '" << _avFormatContext->url <<"' at" << position <<" with flag '" << flag <<"'")
155151
constint err =av_seek_frame(_avFormatContext, -1, position, flag);
156152
if(err <0)
157153
{
@@ -186,12 +182,13 @@ AVStream& FormatContext::getAVStream(size_t index) const
186182

187183
voidFormatContext::setFilename(const std::string& filename)
188184
{
189-
strcpy(&_avFormatContext->filename[0], filename.c_str());
185+
_avFormatContext->url = (char*)av_malloc(filename.size());
186+
strcpy(_avFormatContext->url, filename.c_str());
190187
}
191188

192189
voidFormatContext::setOutputFormat(const std::string& filename,const std::string& shortName,const std::string& mimeType)
193190
{
194-
AVOutputFormat* oformat =av_guess_format(shortName.c_str(), filename.c_str(), mimeType.c_str());
191+
constAVOutputFormat* oformat =av_guess_format(shortName.c_str(), filename.c_str(), mimeType.c_str());
195192
if(!oformat)
196193
{
197194
std::stringmsg("Unable to find format for");

‎src/AvTranscoder/file/FormatContext.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class AvExport FormatContext
113113

114114
#ifndef SWIG
115115
AVFormatContext&getAVFormatContext()const {return *_avFormatContext; }
116-
AVOutputFormat&getAVOutputFormat()const {return *_avFormatContext->oformat; }
117-
AVInputFormat&getAVInputFormat()const {return *_avFormatContext->iformat; }
116+
constAVOutputFormat&getAVOutputFormat()const {return *_avFormatContext->oformat; }
117+
constAVInputFormat&getAVInputFormat()const {return *_avFormatContext->iformat; }
118118
AVIOContext&getAVIOContext()const {return *_avFormatContext->pb; }
119119
AVDictionary&getAVMetaData()const {return *_avFormatContext->metadata; }
120120
AVStream&getAVStream(size_t index)const;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp