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

FFmpeg 5.0#326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
valnoel merged 5 commits intodevelopfromdev/ffmpeg_5.0
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionssrc/AvTranscoder/Library.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ extern "C" {
#else
#include <libswresample/version.h>
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
}
Expand Down
3 changes: 1 addition & 2 deletionssrc/AvTranscoder/codec/ICodec.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,6 @@ class AvExport ICodec
#ifndef SWIG
AVCodecContext& getAVCodecContext() { return *_avCodecContext; }
const AVCodecContext& getAVCodecContext() const { return *_avCodecContext; }
AVCodec& getAVCodec() { return *_avCodec; }
const AVCodec& getAVCodec() const { return *_avCodec; }
#endif

Expand All@@ -66,7 +65,7 @@ class AvExport ICodec

protected:
AVCodecContext* _avCodecContext; ///< Full codec instance description (has ownership)
AVCodec* _avCodec; ///< Codec abstract description
constAVCodec* _avCodec; ///< Codec abstract description
const bool _isCodecContextAllocated; ///< Is the AVCodecContext allocated by the class

ECodecType _type;
Expand Down
4 changes: 2 additions & 2 deletionssrc/AvTranscoder/common.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,8 +2,8 @@
#define _AV_TRANSCODER_COMMON_HPP_

#define AVTRANSCODER_VERSION_MAJOR 0
#define AVTRANSCODER_VERSION_MINOR15
#define AVTRANSCODER_VERSION_MICRO5
#define AVTRANSCODER_VERSION_MINOR16
#define AVTRANSCODER_VERSION_MICRO0

#include <AvTranscoder/system.hpp>

Expand Down
2 changes: 1 addition & 1 deletionsrc/AvTranscoder/data/coded/CodedData.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,7 +87,7 @@ void CodedData::assign(const size_t size, const int value)

void CodedData::initAVPacket()
{
av_init_packet(&_packet);
_packet = *av_packet_alloc();
_packet.data = NULL;
_packet.size = 0;
}
Expand Down
19 changes: 14 additions & 5 deletionssrc/AvTranscoder/decoder/AudioDecoder.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,7 +87,7 @@ bool AudioDecoder::decodeNextFrame(IFrame& frameBuffer)
if(!_isSetup)
setupDecoder();

int got_frame =0;
bool got_frame =false;
while(!got_frame)
{
CodedData data;
Expand All@@ -98,18 +98,27 @@ bool AudioDecoder::decodeNextFrame(IFrame& frameBuffer)
// decoding
// @note could be called several times to return the remaining frames (last call with an empty packet)
// @see CODEC_CAP_DELAY
int ret =avcodec_decode_audio4(&_inputStream->getAudioCodec().getAVCodecContext(), &frameBuffer.getAVFrame(),
&got_frame, &data.getAVPacket());
int ret =avcodec_send_packet(&_inputStream->getAudioCodec().getAVCodecContext(), &data.getAVPacket());

if(ret < 0)
{
throw std::runtime_error("An error occurredduring audiodecoding: " + getDescriptionFromErrorCode(ret));
throw std::runtime_error("An error occurredsending audiopacket to decoder: " + getDescriptionFromErrorCode(ret));
}

ret = avcodec_receive_frame(&_inputStream->getAudioCodec().getAVCodecContext(), &frameBuffer.getAVFrame());

if (ret == 0)
got_frame = true;
else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
got_frame = false;
else
throw std::runtime_error("An error occurred receiving audio packet from decoder: " + getDescriptionFromErrorCode(ret));

// fixed channel layout value after decoding
frameBuffer.getAVFrame().channel_layout = channelLayout;

// if no frame could be decompressed
if(!nextPacketRead &&ret == 0 &&got_frame == 0)
if(!nextPacketRead && got_frame == 0)
decodeNextFrame = false;
else
decodeNextFrame = true;
Expand Down
21 changes: 14 additions & 7 deletionssrc/AvTranscoder/decoder/VideoDecoder.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -94,15 +94,22 @@ bool VideoDecoder::decodeNextFrame(IFrame& frameBuffer)
// decoding
// @note could be called several times to return the remaining frames (last call with an empty packet)
// @see CODEC_CAP_DELAY
const int ret = avcodec_decode_video2(&_inputStream->getVideoCodec().getAVCodecContext(), &frameBuffer.getAVFrame(),
&got_frame, &data.getAVPacket());
if(ret < 0)
{
throw std::runtime_error("An error occurred during video decoding: " + getDescriptionFromErrorCode(ret));
}
int ret = avcodec_send_packet(&_inputStream->getVideoCodec().getAVCodecContext(), &data.getAVPacket());

if (ret < 0 && (nextPacketRead || ret != AVERROR_EOF))
throw std::runtime_error("An error occurred sending video packet to decoder: " + getDescriptionFromErrorCode(ret));

ret = avcodec_receive_frame(&_inputStream->getVideoCodec().getAVCodecContext(), &frameBuffer.getAVFrame());

if (ret == 0)
got_frame = true;
else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
got_frame = false;
else
throw std::runtime_error("An error occurred receiving video packet from decoder: " + getDescriptionFromErrorCode(ret));

// if no frame could be decompressed
if(!nextPacketRead && ret == 0 &&got_frame == 0)
if ((!nextPacketRead && ret == 0) || !got_frame)
decodeNextFrame = false;
else
decodeNextFrame = true;
Expand Down
21 changes: 18 additions & 3 deletionssrc/AvTranscoder/encoder/AudioEncoder.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@ extern "C" {
}

#include <stdexcept>
#include <libavcodec/avcodec.h>

namespace avtranscoder
{
Expand DownExpand Up@@ -93,8 +94,6 @@ void AudioEncoder::setupEncoder(const ProfileLoader::Profile& profile)

bool AudioEncoder::encodeFrame(const IFrame& sourceFrame, CodedData& codedFrame)
{
AVCodecContext& avCodecContext = _codec.getAVCodecContext();

AVPacket& packet = codedFrame.getAVPacket();
const AVFrame& srcAvFrame = sourceFrame.getAVFrame();
if(srcAvFrame.pts != (int)AV_NOPTS_VALUE)
Expand All@@ -121,7 +120,23 @@ bool AudioEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData)
encodedData.data = NULL;

AVCodecContext& avCodecContext = _codec.getAVCodecContext();
#if LIBAVCODEC_VERSION_MAJOR > 53
#if LIBAVCODEC_VERSION_MAJOR > 58
int ret = avcodec_send_frame(&avCodecContext, decodedData);

if(ret != 0)
throw std::runtime_error("Error sending audio frame to encoder: " + getDescriptionFromErrorCode(ret));

ret = avcodec_receive_packet(&avCodecContext, &encodedData);

if (ret == 0)
return true;

if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return false;

throw std::runtime_error("Error receiving audio frame from encoder: " + getDescriptionFromErrorCode(ret));

#elif LIBAVCODEC_VERSION_MAJOR > 53
int gotPacket = 0;
const int ret = avcodec_encode_audio2(&avCodecContext, &encodedData, decodedData, &gotPacket);
if(ret != 0)
Expand Down
21 changes: 18 additions & 3 deletionssrc/AvTranscoder/encoder/VideoEncoder.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -110,8 +110,6 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)

bool VideoEncoder::encodeFrame(const IFrame& sourceFrame, CodedData& codedFrame)
{
AVCodecContext& avCodecContext = _codec.getAVCodecContext();

AVPacket& packet = codedFrame.getAVPacket();
const AVFrame& srcAvFrame = sourceFrame.getAVFrame();
if(srcAvFrame.pts != (int)AV_NOPTS_VALUE)
Expand All@@ -138,14 +136,31 @@ bool VideoEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData)
encodedData.data = NULL;

AVCodecContext& avCodecContext = _codec.getAVCodecContext();
#if LIBAVCODEC_VERSION_MAJOR > 53
#if LIBAVCODEC_VERSION_MAJOR > 58
int ret = avcodec_send_frame(&avCodecContext, decodedData);

if (ret != 0 && ret != AVERROR_EOF)
throw std::runtime_error("Error sending video frame to encoder: " + getDescriptionFromErrorCode(ret));

ret = avcodec_receive_packet(&avCodecContext, &encodedData);

if (ret == 0)
return true;

if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return false;

throw std::runtime_error("Error receiving video frame from encoder: " + getDescriptionFromErrorCode(ret));

#elif LIBAVCODEC_VERSION_MAJOR > 53
int gotPacket = 0;
const int ret = avcodec_encode_video2(&avCodecContext, &encodedData, decodedData, &gotPacket);
if(ret != 0)
{
throw std::runtime_error("Encode video frame error: avcodec encode video frame - " +
getDescriptionFromErrorCode(ret));
}

return gotPacket == 1;
#else
const int ret = avcodec_encode_video(&avCodecContext, encodedData.data, encodedData.size, decodedData);
Expand Down
11 changes: 4 additions & 7 deletionssrc/AvTranscoder/file/FormatContext.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ FormatContext::~FormatContext()
if(!_avFormatContext)
return;

// free the streams added
for(std::vector<AVStream*>::iterator it = _avStreamAllocated.begin(); it != _avStreamAllocated.end(); ++it)
avcodec_close((*it)->codec);

// free the format context
if(_isOpen)
avformat_close_input(&_avFormatContext);
Expand DownExpand Up@@ -151,7 +147,7 @@ AVStream& FormatContext::addAVStream(const AVCodec& avCodec)

bool FormatContext::seek(const uint64_t position, const int flag)
{
LOG_INFO("Seek in '" << _avFormatContext->filename << "' at " << position << " with flag '" << flag << "'")
LOG_INFO("Seek in '" << _avFormatContext->url << "' at " << position << " with flag '" << flag << "'")
const int err = av_seek_frame(_avFormatContext, -1, position, flag);
if(err < 0)
{
Expand DownExpand Up@@ -186,12 +182,13 @@ AVStream& FormatContext::getAVStream(size_t index) const

void FormatContext::setFilename(const std::string& filename)
{
strcpy(&_avFormatContext->filename[0], filename.c_str());
_avFormatContext->url = (char*)av_malloc(filename.size());
strcpy(_avFormatContext->url, filename.c_str());
}

void FormatContext::setOutputFormat(const std::string& filename, const std::string& shortName, const std::string& mimeType)
{
AVOutputFormat* oformat = av_guess_format(shortName.c_str(), filename.c_str(), mimeType.c_str());
constAVOutputFormat* oformat = av_guess_format(shortName.c_str(), filename.c_str(), mimeType.c_str());
if(!oformat)
{
std::string msg("Unable to find format for ");
Expand Down
4 changes: 2 additions & 2 deletionssrc/AvTranscoder/file/FormatContext.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -113,8 +113,8 @@ class AvExport FormatContext

#ifndef SWIG
AVFormatContext& getAVFormatContext() const { return *_avFormatContext; }
AVOutputFormat& getAVOutputFormat() const { return *_avFormatContext->oformat; }
AVInputFormat& getAVInputFormat() const { return *_avFormatContext->iformat; }
constAVOutputFormat& getAVOutputFormat() const { return *_avFormatContext->oformat; }
constAVInputFormat& getAVInputFormat() const { return *_avFormatContext->iformat; }
AVIOContext& getAVIOContext() const { return *_avFormatContext->pb; }
AVDictionary& getAVMetaData() const { return *_avFormatContext->metadata; }
AVStream& getAVStream(size_t index) const;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp