| 360 | } |
| 361 | |
| 362 | bool FFmpegImportFileHandle::InitCodecs() |
| 363 | { |
| 364 | for (unsigned int i = 0; i < mAVFormatContext->GetStreamsCount(); i++) |
| 365 | { |
| 366 | const AVStreamWrapper* stream = mAVFormatContext->GetStream(i); |
| 367 | |
| 368 | if (stream->IsAudio()) |
| 369 | { |
| 370 | const AVCodecIDFwd id = mAVFormatContext->GetStream(i)->GetAVCodecID(); |
| 371 | |
| 372 | auto codec = mFFmpeg->CreateDecoder(id); |
| 373 | auto name = mFFmpeg->avcodec_get_name(id); |
| 374 | |
| 375 | if (codec == NULL) |
| 376 | { |
| 377 | wxLogError( |
| 378 | wxT("FFmpeg : CreateDecoder() failed. Index[%02d], Codec[%02x - %s]"), |
| 379 | i, id, name); |
| 380 | //FFmpeg can't decode this stream, skip it |
| 381 | continue; |
| 382 | } |
| 383 | |
| 384 | auto codecContextPtr = stream->GetAVCodecContext(); |
| 385 | |
| 386 | if ( codecContextPtr->Open( codecContextPtr->GetCodec() ) < 0 ) |
| 387 | { |
| 388 | wxLogError(wxT("FFmpeg : Open() failed. Index[%02d], Codec[%02x - %s]"),i,id,name); |
| 389 | //Can't open decoder - skip this stream |
| 390 | continue; |
| 391 | } |
| 392 | |
| 393 | const int channels = codecContextPtr->GetChannels(); |
| 394 | const sampleFormat preferredFormat = |
| 395 | codecContextPtr->GetPreferredAudacitySampleFormat(); |
| 396 | |
| 397 | auto codecContext = codecContextPtr.get(); |
| 398 | |
| 399 | mStreamContexts.emplace_back( |
| 400 | StreamContext { stream->GetIndex(), std::move(codecContextPtr), |
| 401 | channels, preferredFormat, true }); |
| 402 | |
| 403 | // Stream is decodeable and it is audio. Add it and its description to the arrays |
| 404 | int duration = 0; |
| 405 | if (stream->GetDuration() > 0) |
| 406 | duration = stream->GetDuration() * stream->GetTimeBase().num / stream->GetTimeBase().den; |
| 407 | else |
| 408 | duration = mAVFormatContext->GetDuration() / AUDACITY_AV_TIME_BASE; |
| 409 | |
| 410 | wxString bitrate; |
| 411 | if (codecContext->GetBitRate() > 0) |
| 412 | bitrate.Printf(wxT("%d"),(int)codecContext->GetBitRate()); |
| 413 | else |
| 414 | bitrate.Printf(wxT("?")); |
| 415 | |
| 416 | AVDictionaryWrapper streamMetadata = stream->GetMetadata(); |
| 417 | |
| 418 | auto lang = std::string(streamMetadata.Get("language", {})); |
| 419 |
nothing calls this directly
no test coverage detected