MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / UpdateAudioInfo

Method UpdateAudioInfo

src/FFmpegReader.cpp:917–1029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

915}
916
917void FFmpegReader::UpdateAudioInfo() {
918 int codec_channels =
919#if HAVE_CH_LAYOUT
920 AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->ch_layout.nb_channels;
921#else
922 AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->channels;
923#endif
924
925 // Set default audio channel layout (if needed)
926#if HAVE_CH_LAYOUT
927 AVChannelLayout audio_ch_layout = ffmpeg_get_valid_channel_layout(
928 AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->ch_layout, codec_channels);
929 if (audio_ch_layout.nb_channels > 0) {
930 av_channel_layout_uninit(&(AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->ch_layout));
931 av_channel_layout_copy(&(AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->ch_layout), &audio_ch_layout);
932 codec_channels = audio_ch_layout.nb_channels;
933 }
934#else
935 if (codec_channels > 0 && AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->channel_layout == 0)
936 AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->channel_layout = av_get_default_channel_layout(AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->channels);
937#endif
938
939 if (info.sample_rate > 0) {
940 // Skip init - if info struct already populated
941 return;
942 }
943
944 auto record_duration = [](double &target, double seconds) {
945 if (seconds > 0.0)
946 target = std::max(target, seconds);
947 };
948
949 // Set values of FileInfo struct
950 info.has_audio = true;
951 info.file_size = pFormatCtx->pb ? avio_size(pFormatCtx->pb) : -1;
952 info.acodec = aCodecCtx->codec->name;
953#if HAVE_CH_LAYOUT
954 info.channels = audio_ch_layout.nb_channels;
955 info.channel_layout = static_cast<ChannelLayout>(ffmpeg_channel_layout_mask(audio_ch_layout));
956#else
957 info.channels = AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->channels;
958 info.channel_layout = (ChannelLayout) AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->channel_layout;
959#endif
960
961 // If channel layout is not set, guess based on the number of channels
962 if (info.channel_layout == 0) {
963 if (info.channels == 1) {
964 info.channel_layout = openshot::LAYOUT_MONO;
965 } else if (info.channels == 2) {
966 info.channel_layout = openshot::LAYOUT_STEREO;
967 }
968 }
969
970 info.sample_rate = AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->sample_rate;
971 info.audio_bit_rate = AV_GET_CODEC_ATTRIBUTES(aStream, aCodecCtx)->bit_rate;
972 if (info.audio_bit_rate <= 0) {
973 // Get bitrate from format
974 info.audio_bit_rate = pFormatCtx->bit_rate;

Callers

nothing calls this directly

Calls 4

ToDoubleMethod · 0.80
ParentTimelineMethod · 0.45

Tested by

no test coverage detected