diff --git a/misc/prerequisites.sh b/misc/prerequisites.sh index a647558d3..5d11048a1 100755 --- a/misc/prerequisites.sh +++ b/misc/prerequisites.sh @@ -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 JEMALLOC_VERSION=5.3.0 PCRE2_VERSION=10.39 OPENH264_VERSION=2.4.0 @@ -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} \ @@ -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 && \ diff --git a/src/projects/modules/ffmpeg/ffmpeg_conv.h b/src/projects/modules/ffmpeg/ffmpeg_conv.h index 115864a05..f67932f63 100644 --- a/src/projects/modules/ffmpeg/ffmpeg_conv.h +++ b/src/projects/modules/ffmpeg/ffmpeg_conv.h @@ -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; @@ -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); @@ -493,10 +493,10 @@ namespace ffmpeg media_frame->SetMediaType(media_type); media_frame->SetBytesPerSample(::av_get_bytes_per_sample(static_cast(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(); @@ -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(¶meters->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(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(parameters->format))); } message.AppendFormat("%d kbps, ", (parameters->bit_rate / 1024)); @@ -789,10 +789,15 @@ namespace ffmpeg break; case cmn::MediaType::Audio: { - codecpar->channels = static_cast(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(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; diff --git a/src/projects/modules/segment_writer/writer.cpp b/src/projects/modules/segment_writer/writer.cpp index 1fb8fd94d..6e2dc42b7 100644 --- a/src/projects/modules/segment_writer/writer.cpp +++ b/src/projects/modules/segment_writer/writer.cpp @@ -256,13 +256,17 @@ bool Writer::FillCodecParameters(const std::shared_ptr &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(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(media_track->GetSample().GetFormat()); codec_parameters->codec_tag = 0; + codec_parameters->ch_layout = { + .order = AVChannelOrder::AV_CHANNEL_ORDER_NATIVE, + .nb_channels = static_cast(media_track->GetChannel().GetCounts()), + .u = {.mask = static_cast(AvChannelLayoutFromAudioChannelLayout(media_track->GetChannel().GetLayout()))} + }; + std::shared_ptr extra_data = nullptr; if (media_track->GetCodecId() == cmn::MediaCodecId::Aac) { diff --git a/src/projects/modules/segment_writer/writer.h b/src/projects/modules/segment_writer/writer.h index ca06dcf37..c87b25b0d 100644 --- a/src/projects/modules/segment_writer/writer.h +++ b/src/projects/modules/segment_writer/writer.h @@ -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(opaque))->OnWrite(buf, buf_size); } diff --git a/src/projects/transcoder/codec/decoder/decoder_aac.cpp b/src/projects/transcoder/codec/decoder/decoder_aac.cpp index c1302d50a..1fbefdae3 100644 --- a/src/projects/transcoder/codec/decoder/decoder_aac.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_aac.cpp @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_avc.cpp b/src/projects/transcoder/codec/decoder/decoder_avc.cpp index 1ec6f185e..760f02622 100644 --- a/src/projects/transcoder/codec/decoder/decoder_avc.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_avc.cpp @@ -92,7 +92,6 @@ bool DecoderAVC::InitCodec() void DecoderAVC::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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()) ); } diff --git a/src/projects/transcoder/codec/decoder/decoder_avc_nilogan.cpp b/src/projects/transcoder/codec/decoder/decoder_avc_nilogan.cpp index 50b829a93..7c6bbcd0d 100644 --- a/src/projects/transcoder/codec/decoder/decoder_avc_nilogan.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_avc_nilogan.cpp @@ -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; @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_avc_nv.cpp b/src/projects/transcoder/codec/decoder/decoder_avc_nv.cpp index d6a444901..83c3da39e 100644 --- a/src/projects/transcoder/codec/decoder/decoder_avc_nv.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_avc_nv.cpp @@ -99,7 +99,6 @@ bool DecoderAVCxNV::InitCodec() void DecoderAVCxNV::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_avc_qsv.cpp b/src/projects/transcoder/codec/decoder/decoder_avc_qsv.cpp index 541040a2d..595065866 100644 --- a/src/projects/transcoder/codec/decoder/decoder_avc_qsv.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_avc_qsv.cpp @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_avc_xma.cpp b/src/projects/transcoder/codec/decoder/decoder_avc_xma.cpp index b4bc8b896..22d8fdfe9 100644 --- a/src/projects/transcoder/codec/decoder/decoder_avc_xma.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_avc_xma.cpp @@ -111,7 +111,6 @@ bool DecoderAVCxXMA::InitCodec() void DecoderAVCxXMA::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_hevc.cpp b/src/projects/transcoder/codec/decoder/decoder_hevc.cpp index eea80b21b..88d0d5e6a 100755 --- a/src/projects/transcoder/codec/decoder/decoder_hevc.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_hevc.cpp @@ -84,7 +84,6 @@ bool DecoderHEVC::InitCodec() void DecoderHEVC::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_hevc_nilogan.cpp b/src/projects/transcoder/codec/decoder/decoder_hevc_nilogan.cpp index e5868db24..60a68ef87 100644 --- a/src/projects/transcoder/codec/decoder/decoder_hevc_nilogan.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_hevc_nilogan.cpp @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_hevc_nv.cpp b/src/projects/transcoder/codec/decoder/decoder_hevc_nv.cpp index 76f7f5ed1..36dab687d 100644 --- a/src/projects/transcoder/codec/decoder/decoder_hevc_nv.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_hevc_nv.cpp @@ -93,7 +93,6 @@ bool DecoderHEVCxNV::InitCodec() void DecoderHEVCxNV::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_hevc_qsv.cpp b/src/projects/transcoder/codec/decoder/decoder_hevc_qsv.cpp index c7ec0d137..c8531e0ba 100644 --- a/src/projects/transcoder/codec/decoder/decoder_hevc_qsv.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_hevc_qsv.cpp @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_hevc_xma.cpp b/src/projects/transcoder/codec/decoder/decoder_hevc_xma.cpp index 521dc12ef..2c1e27a78 100644 --- a/src/projects/transcoder/codec/decoder/decoder_hevc_xma.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_hevc_xma.cpp @@ -111,7 +111,6 @@ bool DecoderHEVCxXMA::InitCodec() void DecoderHEVCxXMA::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_mp3.cpp b/src/projects/transcoder/codec/decoder/decoder_mp3.cpp index a53c2f831..c7301a1cf 100644 --- a/src/projects/transcoder/codec/decoder/decoder_mp3.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_mp3.cpp @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_opus.cpp b/src/projects/transcoder/codec/decoder/decoder_opus.cpp index 031db5f06..2d43143e9 100644 --- a/src/projects/transcoder/codec/decoder/decoder_opus.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_opus.cpp @@ -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); diff --git a/src/projects/transcoder/codec/decoder/decoder_vp8.cpp b/src/projects/transcoder/codec/decoder/decoder_vp8.cpp index c52edb977..464b1c27d 100644 --- a/src/projects/transcoder/codec/decoder/decoder_vp8.cpp +++ b/src/projects/transcoder/codec/decoder/decoder_vp8.cpp @@ -83,7 +83,6 @@ bool DecoderVP8::InitCodec() void DecoderVP8::UninitCodec() { - ::avcodec_close(_context); ::avcodec_free_context(&_context); _context = nullptr; @@ -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); diff --git a/src/projects/transcoder/codec/encoder/encoder_aac.cpp b/src/projects/transcoder/codec/encoder/encoder_aac.cpp index 238de1541..91e5eefd3 100644 --- a/src/projects/transcoder/codec/encoder/encoder_aac.cpp +++ b/src/projects/transcoder/codec/encoder/encoder_aac.cpp @@ -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(GetRefTrack()->GetChannel().GetLayout()); - _codec_context->channels = GetRefTrack()->GetChannel().GetCounts(); + + _codec_context->ch_layout = { + .order = AVChannelOrder::AV_CHANNEL_ORDER_NATIVE, + .nb_channels = static_cast(GetRefTrack()->GetChannel().GetCounts()), + .u = {.mask = static_cast(GetRefTrack()->GetChannel().GetLayout())} + }; _bitstream_format = cmn::BitstreamFormat::AAC_ADTS; diff --git a/src/projects/transcoder/codec/encoder/encoder_ffopus.cpp b/src/projects/transcoder/codec/encoder/encoder_ffopus.cpp index c70021b18..3c0a53812 100644 --- a/src/projects/transcoder/codec/encoder/encoder_ffopus.cpp +++ b/src/projects/transcoder/codec/encoder/encoder_ffopus.cpp @@ -15,9 +15,13 @@ bool EncoderFFOPUS::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(GetRefTrack()->GetChannel().GetLayout()); - _codec_context->channels = GetRefTrack()->GetChannel().GetCounts(); - + + _codec_context->ch_layout = { + .order = AVChannelOrder::AV_CHANNEL_ORDER_NATIVE, + .nb_channels = static_cast(GetRefTrack()->GetChannel().GetCounts()), + .u = {.mask = static_cast(GetRefTrack()->GetChannel().GetLayout())} + }; + // Support Frequency // 4000 - OPUS_BANDWIDTH_NARROWBAND (8kHz) (2~8 kbps) // 6000 - OPUS_BANDWIDTH_MEDIUMBAND (12kHz) diff --git a/src/projects/transcoder/filter/filter_resampler.cpp b/src/projects/transcoder/filter/filter_resampler.cpp index beda3b993..9bf3f33fd 100644 --- a/src/projects/transcoder/filter/filter_resampler.cpp +++ b/src/projects/transcoder/filter/filter_resampler.cpp @@ -248,7 +248,7 @@ void FilterResampler::WorkerThread() if (ret < 0) { logte("An error occurred while feeding the audio filtergraph: pts: %lld, linesize: %d, srate: %d, layout: %d, channels: %d, format: %d, rq: %d", - _frame->pts, _frame->linesize[0], _frame->sample_rate, _frame->channel_layout, _frame->channels, _frame->format, _input_buffer.Size()); + _frame->pts, _frame->linesize[0], _frame->sample_rate, _frame->ch_layout.u.mask, _frame->ch_layout.nb_channels, _frame->format, _input_buffer.Size()); continue; } diff --git a/src/projects/transcoder/transcoder_context.h b/src/projects/transcoder/transcoder_context.h index a34a635a9..a1e198e22 100644 --- a/src/projects/transcoder/transcoder_context.h +++ b/src/projects/transcoder/transcoder_context.h @@ -78,7 +78,7 @@ class MediaFrame if (_priv_data) { - _priv_data->pkt_duration = duration; + _priv_data->duration = duration; } }