Skip to content

Commit 7fcc1b6

Browse files
MarcAntoine-Arnaudvalnoel
authored andcommitted
changes to support FFmpeg 4.1
1 parent f8b8e8f commit 7fcc1b6

File tree

9 files changed

+59
-18
lines changed

9 files changed

+59
-18
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 2.8.11)
22

33
project(AvTranscoder)
44

5+
# All libraries will be put in INSTALL_PREFIX/lib
6+
# RPATH of host points INSTALL_PREFIX/lib
7+
# see: http://www.cmake.org/Wiki/CMake_RPATH_handling
8+
set(CMAKE_MACOSX_RPATH 1)
9+
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
10+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
11+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
12+
13+
514
# Define AvTranscoder default path to profiles
615
add_definitions(-DAVTRANSCODER_DEFAULT_AVPROFILES="${CMAKE_INSTALL_PREFIX}/share/avprofiles")
716

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)
7777
if(profile.count(constants::avProfileProcessStat))
7878
{
7979
LOG_INFO("SetUp video encoder to compute statistics during process")
80+
#ifdef AV_CODEC_FLAG_PSNR
81+
encoderFlags |= AV_CODEC_FLAG_PSNR;
82+
#else
8083
encoderFlags |= CODEC_FLAG_PSNR;
84+
#endif
8185
}
8286
_codec.getAVCodecContext().flags |= encoderFlags;
8387
_codec.openCodec();

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ IOutputStream::EWrappingStatus OutputFile::wrap(const CodedData& data, const siz
200200
packet.dts = av_rescale_q(data.getAVPacket().dts, srcTimeBase, dstTimeBase);
201201
}
202202
// add stream PTS if already incremented
203-
const int currentStreamPTS = _outputStreams.at(streamIndex)->getStreamPTS();
204-
if(packet.pts != AV_NOPTS_VALUE && packet.pts < currentStreamPTS)
205-
{
206-
packet.pts += currentStreamPTS;
207-
packet.dts += currentStreamPTS;
208-
}
203+
// const int currentStreamPTS = _outputStreams.at(streamIndex)->getStreamPTS();
204+
// if(packet.pts != AV_NOPTS_VALUE && packet.pts < currentStreamPTS)
205+
// {
206+
// packet.pts += currentStreamPTS;
207+
// packet.dts += currentStreamPTS;
208+
// }
209209
}
210210

211211
// copy duration of packet wrapped
@@ -332,11 +332,19 @@ void OutputFile::setOutputStream(AVStream& avStream, const ICodec& codec)
332332
// depending on the format, place global headers in extradata instead of every keyframe
333333
if(_formatContext.getAVOutputFormat().flags & AVFMT_GLOBALHEADER)
334334
{
335+
#ifdef AV_CODEC_FLAG_GLOBAL_HEADER
336+
avStream.codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
337+
#else
335338
avStream.codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
339+
#endif
336340
}
337341

338342
// if the codec is experimental, allow it
343+
#ifdef AV_CODEC_CAP_EXPERIMENTAL
344+
if(codec.getAVCodec().capabilities & AV_CODEC_CAP_EXPERIMENTAL)
345+
#else
339346
if(codec.getAVCodec().capabilities & CODEC_CAP_EXPERIMENTAL)
347+
#endif
340348
{
341349
LOG_WARN("This codec is considered experimental by libav/ffmpeg:" << codec.getCodecName());
342350
avStream.codec->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;

src/AvTranscoder/filter/Filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Filter::Filter(const std::string& name, const std::string& options, const std::s
1515
, _options(options)
1616
, _instanceName(instanceName.empty() ? name : instanceName)
1717
{
18-
_filter = avfilter_get_by_name(name.c_str());
18+
_filter = (AVFilter*)avfilter_get_by_name(name.c_str());
1919
if(!_filter)
2020
{
2121
std::string msg("Cannot find filter ");

src/AvTranscoder/properties/StreamProperties.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ std::string StreamProperties::getCodecName() const
9393
if(!_codecContext || !_codec)
9494
throw std::runtime_error("unknown codec");
9595

96+
#ifdef AV_CODEC_CAP_TRUNCATED
97+
if(_codec->capabilities & AV_CODEC_CAP_TRUNCATED)
98+
_codecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
99+
#else
96100
if(_codec->capabilities & CODEC_CAP_TRUNCATED)
97101
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
102+
#endif
98103

99104
if(!_codec->name)
100105
throw std::runtime_error("unknown codec name");
@@ -107,9 +112,13 @@ std::string StreamProperties::getCodecLongName() const
107112
if(!_codecContext || !_codec)
108113
throw std::runtime_error("unknown codec");
109114

115+
#ifdef AV_CODEC_CAP_TRUNCATED
116+
if(_codec->capabilities & AV_CODEC_CAP_TRUNCATED)
117+
_codecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
118+
#else
110119
if(_codec->capabilities & CODEC_CAP_TRUNCATED)
111120
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
112-
121+
#endif
113122
if(!_codec->long_name)
114123
throw std::runtime_error("unknown codec long name");
115124

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ std::string VideoProperties::getProfileName() const
6262
if(!_codecContext || !_codec)
6363
throw std::runtime_error("unknown codec");
6464

65+
#ifdef AV_CODEC_CAP_TRUNCATED
66+
if(_codec->capabilities & AV_CODEC_CAP_TRUNCATED)
67+
_codecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
68+
#else
6569
if(_codec->capabilities & CODEC_CAP_TRUNCATED)
6670
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
71+
#endif
6772

6873
const char* profile = NULL;
6974
if((profile = av_get_profile_name(_codec, getProfile())) == NULL)
@@ -427,7 +432,8 @@ size_t VideoProperties::getDtgActiveFormat() const
427432
{
428433
if(!_codecContext)
429434
throw std::runtime_error("unknown codec context");
430-
return _codecContext->dtg_active_format;
435+
// return _codecContext->dtg_active_format;
436+
return 0;
431437
}
432438

433439
size_t VideoProperties::getReferencesFrames() const

src/AvTranscoder/stream/OutputStream.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ OutputStream::OutputStream(OutputFile& outputFile, const size_t streamIndex)
2020

2121
float OutputStream::getStreamDuration() const
2222
{
23-
const AVFrac& outputPTS = _outputAVStream.pts;
2423
const AVRational& outputTimeBase = _outputAVStream.time_base;
2524

2625
// check floating point exception
27-
if(outputTimeBase.den == 0 || outputPTS.den == 0)
26+
if(outputTimeBase.den == 0)
2827
{
2928
LOG_WARN("Cannot compute stream duration of output stream at index " << _streamIndex)
3029
return 0.f;
@@ -36,7 +35,7 @@ float OutputStream::getStreamDuration() const
3635
// returns the pts of the last muxed packet, converted from timebase to seconds
3736
return av_q2d(outputTimeBase) * av_stream_get_end_pts(&_outputAVStream);
3837
#else
39-
return av_q2d(outputTimeBase) * (outputPTS.val + (outputPTS.num / outputPTS.den));
38+
return av_q2d(outputTimeBase) * _outputAVStream.pts;
4039
#endif
4140
}
4241

@@ -45,11 +44,12 @@ size_t OutputStream::getNbFrames() const
4544
return _outputAVStream.nb_frames;
4645
}
4746

48-
int OutputStream::getStreamPTS() const
49-
{
50-
const AVFrac& outputPTS = _outputAVStream.pts;
51-
return (outputPTS.val + (outputPTS.num / outputPTS.den));
52-
}
47+
// int OutputStream::getStreamPTS() const
48+
// {
49+
// // const AVFrac& outputPTS = _outputAVStream.pts;
50+
// // return (outputPTS.val + (outputPTS.num / outputPTS.den));
51+
// return _outputAVStream.pts;
52+
// }
5353

5454
IOutputStream::EWrappingStatus OutputStream::wrap(const CodedData& data)
5555
{

src/AvTranscoder/stream/OutputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AvExport OutputStream : public IOutputStream
1818
size_t getStreamIndex() const { return _streamIndex; }
1919
float getStreamDuration() const;
2020
size_t getNbFrames() const; ///< If audio stream, returns number of packets
21-
int getStreamPTS() const; ///< Get current AVStream PTS
21+
// int getStreamPTS() const; ///< Get current AVStream PTS
2222

2323
bool isPTSGenerated() const { return _isPTSGenerated; }
2424
IOutputStream::EWrappingStatus wrap(const CodedData& data);

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,12 @@ void Transcoder::fillProcessStat(ProcessStat& processStat)
560560
if(encoder)
561561
{
562562
const AVCodecContext& encoderContext = encoder->getCodec().getAVCodecContext();
563+
564+
#ifdef AV_CODEC_FLAG_PSNR
565+
if(encoderContext.coded_frame && (encoderContext.flags & AV_CODEC_FLAG_PSNR))
566+
#else
563567
if(encoderContext.coded_frame && (encoderContext.flags & CODEC_FLAG_PSNR))
568+
#endif
564569
{
565570
videoStat.setQuality(encoderContext.coded_frame->quality);
566571
videoStat.setPSNR(encoderContext.coded_frame->error[0] /

0 commit comments

Comments
 (0)