Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg 7.0 Update: Use new channel layout #1626

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions misc/prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OPUS_VERSION=1.3.1
VPX_VERSION=1.11.0
FDKAAC_VERSION=2.0.2
NASM_VERSION=2.15.05
FFMPEG_VERSION=5.0.1
FFMPEG_VERSION=7.0
hashworks marked this conversation as resolved.
Show resolved Hide resolved
JEMALLOC_VERSION=5.3.0
PCRE2_VERSION=10.39
OPENH264_VERSION=2.4.0
Expand Down Expand Up @@ -316,8 +316,8 @@ install_ffmpeg()
--extra-ldflags="${ADDI_LDFLAGS} -L${PREFIX}/lib -Wl,-rpath,${PREFIX}/lib " \
--extra-libs=-ldl ${ADDI_EXTRA_LIBS} \
${ADDI_LICENSE} \
--disable-everything --disable-programs --disable-avdevice --disable-dwt --disable-lsp --disable-lzo --disable-faan --disable-pixelutils \
--enable-shared --enable-zlib --enable-libopus --enable-libvpx --enable-libfdk_aac --enable-libopenh264 --enable-openssl --enable-network --enable-libsrt --enable-dct --enable-rdft ${ADDI_LIBS} \
--disable-everything --disable-programs --disable-avdevice --disable-dwt --disable-lsp --disable-faan --disable-pixelutils \
--enable-shared --enable-zlib --enable-libopus --enable-libvpx --enable-libfdk_aac --enable-libopenh264 --enable-openssl --enable-network --enable-libsrt ${ADDI_LIBS} \
${ADDI_HWACCEL} \
--enable-ffmpeg \
--enable-encoder=libvpx_vp8,libopus,libfdk_aac,libopenh264,mjpeg,png${ADDI_ENCODER} \
Expand Down Expand Up @@ -348,7 +348,7 @@ install_jemalloc()
(DIR=${TEMP_PATH}/jemalloc && \
mkdir -p ${DIR} && \
cd ${DIR} && \
curl -sSLf https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2 | tar -jx --strip-components=1 && \
curl -sSLf https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2 | tar -jx --strip-components=1 --no-same-owner && \
./configure --prefix="${PREFIX}" && \
make -j$(nproc) && \
sudo make install_include install_lib && \
Expand Down
27 changes: 16 additions & 11 deletions src/projects/modules/ffmpeg/ffmpeg_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ namespace ffmpeg
case cmn::MediaType::Audio:
media_track->SetSampleRate(stream->codecpar->sample_rate);
media_track->GetSample().SetFormat(ffmpeg::Conv::ToAudioSampleFormat(stream->codecpar->format));
media_track->GetChannel().SetLayout(ffmpeg::Conv::ToAudioChannelLayout(stream->codecpar->channel_layout));
media_track->GetChannel().SetLayout(ffmpeg::Conv::ToAudioChannelLayout(stream->codecpar->ch_layout.u.mask));
break;
default:
break;
Expand Down Expand Up @@ -478,7 +478,7 @@ namespace ffmpeg
media_frame->SetHeight(frame->height);
media_frame->SetFormat(frame->format);
media_frame->SetPts((frame->pts == AV_NOPTS_VALUE) ? -1LL : frame->pts);
media_frame->SetDuration(frame->pkt_duration);
media_frame->SetDuration(frame->duration);

AVFrame* moved_frame = av_frame_alloc();
av_frame_move_ref(moved_frame, frame);
Expand All @@ -493,10 +493,10 @@ namespace ffmpeg
media_frame->SetMediaType(media_type);
media_frame->SetBytesPerSample(::av_get_bytes_per_sample(static_cast<AVSampleFormat>(frame->format)));
media_frame->SetNbSamples(frame->nb_samples);
media_frame->GetChannels().SetLayout(ffmpeg::Conv::ToAudioChannelLayout(frame->channel_layout));
media_frame->GetChannels().SetLayout(ffmpeg::Conv::ToAudioChannelLayout(frame->ch_layout.u.mask));
media_frame->SetSampleRate(frame->sample_rate);
media_frame->SetFormat(frame->format);
media_frame->SetDuration(frame->pkt_duration);
media_frame->SetDuration(frame->duration);
media_frame->SetPts((frame->pts == AV_NOPTS_VALUE) ? -1LL : frame->pts);

AVFrame* moved_frame = av_frame_alloc();
Expand Down Expand Up @@ -701,11 +701,11 @@ namespace ffmpeg
}
else
{
char channel_layout[16]{};
::av_get_channel_layout_string(channel_layout, OV_COUNTOF(channel_layout), parameters->channels, parameters->channel_layout);
char channel_layout_buf[16]{};
::av_channel_layout_describe(&parameters->ch_layout, channel_layout_buf, OV_COUNTOF(channel_layout_buf));

// 48000 Hz, stereo, fltp,
message.AppendFormat("%d Hz, %s(%d), %s, ", parameters->sample_rate, channel_layout, parameters->channels, ::av_get_sample_fmt_name(static_cast<AVSampleFormat>(parameters->format)));
message.AppendFormat("%d Hz, %s(%d), %s, ", parameters->sample_rate, channel_layout_buf, parameters->ch_layout.nb_channels, ::av_get_sample_fmt_name(static_cast<AVSampleFormat>(parameters->format)));
}

message.AppendFormat("%d kbps, ", (parameters->bit_rate / 1024));
Expand Down Expand Up @@ -789,10 +789,15 @@ namespace ffmpeg
break;

case cmn::MediaType::Audio: {
codecpar->channels = static_cast<int>(media_track->GetChannel().GetCounts());
codecpar->channel_layout = ToAVChannelLayout(media_track->GetChannel().GetLayout());
codecpar->sample_rate = media_track->GetSample().GetRateNum();
codecpar->frame_size = (media_track->GetAudioSamplesPerFrame()!=0)?media_track->GetAudioSamplesPerFrame():1024;
uint64_t channel_layout = ToAVChannelLayout(media_track->GetChannel().GetLayout());
codecpar->ch_layout = {
.order = AVChannelOrder::AV_CHANNEL_ORDER_NATIVE,
.nb_channels = static_cast<int>(media_track->GetChannel().GetCounts()),
.u = {.mask = channel_layout}
};

codecpar->sample_rate = media_track->GetSample().GetRateNum();
codecpar->frame_size = (media_track->GetAudioSamplesPerFrame()!=0)?media_track->GetAudioSamplesPerFrame():1024;
}
break;

Expand Down
8 changes: 6 additions & 2 deletions src/projects/modules/segment_writer/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,17 @@ bool Writer::FillCodecParameters(const std::shared_ptr<const Track> &track, AVCo
codec_parameters->codec_type = AVMEDIA_TYPE_AUDIO;
codec_parameters->codec_id = AvCodecIdFromMediaCodecId(media_track->GetCodecId());
codec_parameters->bit_rate = media_track->GetBitrate();
codec_parameters->channels = static_cast<int>(media_track->GetChannel().GetCounts());
codec_parameters->channel_layout = AvChannelLayoutFromAudioChannelLayout(media_track->GetChannel().GetLayout());
codec_parameters->sample_rate = media_track->GetSample().GetRateNum();
codec_parameters->frame_size = 1024;
codec_parameters->format = static_cast<int>(media_track->GetSample().GetFormat());
codec_parameters->codec_tag = 0;

codec_parameters->ch_layout = {
.order = AVChannelOrder::AV_CHANNEL_ORDER_NATIVE,
.nb_channels = static_cast<int>(media_track->GetChannel().GetCounts()),
.u = {.mask = static_cast<uint64_t>(AvChannelLayoutFromAudioChannelLayout(media_track->GetChannel().GetLayout()))}
};

std::shared_ptr<ov::Data> extra_data = nullptr;
if (media_track->GetCodecId() == cmn::MediaCodecId::Aac)
{
Expand Down
2 changes: 1 addition & 1 deletion src/projects/modules/segment_writer/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Writer
int DecideBufferSize() const;

int OnWrite(const uint8_t *buf, int buf_size);
static int OnWrite(void *opaque, uint8_t *buf, int buf_size)
static int OnWrite(void *opaque, const uint8_t *buf, int buf_size)
{
return (static_cast<Writer *>(opaque))->OnWrite(buf, buf_size);
}
Expand Down
6 changes: 3 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_aac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ void DecoderAAC::CodecThread()
}

// If there is no duration, the duration is calculated by timebase.
if (_frame->pkt_duration <= 0LL)
if (_frame->duration <= 0LL)
{
_frame->pkt_duration = ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Audio, GetRefTrack(), _frame);
_frame->duration = ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Audio, GetRefTrack(), _frame);
}


// If the decoded audio frame does not have a PTS, Increase frame duration time in PTS of previous frame
if(_frame->pts == AV_NOPTS_VALUE)
{
_frame->pts = _last_pkt_pts + _frame->pkt_duration;
_frame->pts = _last_pkt_pts + _frame->duration;
}

auto output_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Audio, _frame);
Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ bool DecoderAVC::InitCodec()

void DecoderAVC::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -270,9 +269,9 @@ void DecoderAVC::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}


Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_avc_nilogan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ bool DecoderAVCxNILOGAN::InitCodec()
it seems that dynamic resolution is supported
void DecoderAVCxNILOGAN::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -292,9 +291,9 @@ void DecoderAVCxNILOGAN::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_avc_nv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ bool DecoderAVCxNV::InitCodec()

void DecoderAVCxNV::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -271,9 +270,9 @@ void DecoderAVCxNV::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / (double) GetRefTrack()->GetTimeBase().GetExpr() );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / (double) GetRefTrack()->GetTimeBase().GetExpr() );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
4 changes: 2 additions & 2 deletions src/projects/transcoder/codec/decoder/decoder_avc_qsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ void DecoderAVCxQSV::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_avc_xma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ bool DecoderAVCxXMA::InitCodec()

void DecoderAVCxXMA::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -295,9 +294,9 @@ void DecoderAVCxXMA::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_hevc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ bool DecoderHEVC::InitCodec()

void DecoderHEVC::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -261,9 +260,9 @@ void DecoderHEVC::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ void DecoderHEVCxNILOGAN::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_hevc_nv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ bool DecoderHEVCxNV::InitCodec()

void DecoderHEVCxNV::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -260,9 +259,9 @@ void DecoderHEVCxNV::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
4 changes: 2 additions & 2 deletions src/projects/transcoder/codec/decoder/decoder_hevc_qsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ void DecoderHEVCxQSV::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
5 changes: 2 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_hevc_xma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ bool DecoderHEVCxXMA::InitCodec()

void DecoderHEVCxXMA::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -295,9 +294,9 @@ void DecoderHEVCxXMA::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
if(_frame->pkt_duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
if(_frame->duration <= 0LL && _context->framerate.num > 0 && _context->framerate.den > 0)
{
_frame->pkt_duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
_frame->duration = (int64_t)( ((double)_context->framerate.den / (double)_context->framerate.num) / ((double) GetRefTrack()->GetTimeBase().GetNum() / (double) GetRefTrack()->GetTimeBase().GetDen()) );
}

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
Expand Down
6 changes: 3 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ void DecoderMP3::CodecThread()
}

// If there is no duration, the duration is calculated by timebase.
if (_frame->pkt_duration <= 0LL)
if (_frame->duration <= 0LL)
{
_frame->pkt_duration = ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Audio, GetRefTrack(), _frame);
_frame->duration = ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Audio, GetRefTrack(), _frame);
}


// If the decoded audio frame does not have a PTS, Increase frame duration time in PTS of previous frame
if(_frame->pts == AV_NOPTS_VALUE)
{
_frame->pts = _last_pkt_pts + _frame->pkt_duration;
_frame->pts = _last_pkt_pts + _frame->duration;
}

auto output_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Audio, _frame);
Expand Down
6 changes: 3 additions & 3 deletions src/projects/transcoder/codec/decoder/decoder_opus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ void DecoderOPUS::CodecThread()
}

// If there is no duration, the duration is calculated by timebase.
if (_frame->pkt_duration <= 0LL)
if (_frame->duration <= 0LL)
{
_frame->pkt_duration = ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Audio, GetRefTrack(), _frame);
_frame->duration = ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Audio, GetRefTrack(), _frame);
}


// If the decoded audio frame does not have a PTS, Increase frame duration time in PTS of previous frame
if(_frame->pts == AV_NOPTS_VALUE)
{
_frame->pts = _last_pkt_pts + _frame->pkt_duration;
_frame->pts = _last_pkt_pts + _frame->duration;
}

auto output_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Audio, _frame);
Expand Down
3 changes: 1 addition & 2 deletions src/projects/transcoder/codec/decoder/decoder_vp8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ bool DecoderVP8::InitCodec()

void DecoderVP8::UninitCodec()
{
::avcodec_close(_context);
::avcodec_free_context(&_context);

_context = nullptr;
Expand Down Expand Up @@ -253,7 +252,7 @@ void DecoderVP8::CodecThread()
}

// If there is no duration, the duration is calculated by framerate and timebase.
_frame->pkt_duration = (_frame->pkt_duration <= 0LL) ? ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Video, GetRefTrack()) : _frame->pkt_duration;
_frame->duration = (_frame->duration <= 0LL) ? ffmpeg::Conv::GetDurationPerFrame(cmn::MediaType::Video, GetRefTrack()) : _frame->duration;

auto decoded_frame = ffmpeg::Conv::ToMediaFrame(cmn::MediaType::Video, _frame);
::av_frame_unref(_frame);
Expand Down
8 changes: 6 additions & 2 deletions src/projects/transcoder/codec/encoder/encoder_aac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ bool EncoderAAC::SetCodecParams()
_codec_context->bit_rate = GetRefTrack()->GetBitrate();
_codec_context->sample_fmt = (AVSampleFormat)GetSupportedFormat();
_codec_context->sample_rate = GetRefTrack()->GetSampleRate();
_codec_context->channel_layout = static_cast<uint64_t>(GetRefTrack()->GetChannel().GetLayout());
_codec_context->channels = GetRefTrack()->GetChannel().GetCounts();

_codec_context->ch_layout = {
.order = AVChannelOrder::AV_CHANNEL_ORDER_NATIVE,
.nb_channels = static_cast<int>(GetRefTrack()->GetChannel().GetCounts()),
.u = {.mask = static_cast<uint64_t>(GetRefTrack()->GetChannel().GetLayout())}
};

_bitstream_format = cmn::BitstreamFormat::AAC_ADTS;

Expand Down
Loading