File tree Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -42,9 +42,8 @@ def __init__(
42
42
decoder = self ._decoder , stream_index = stream_index , media_type = "audio"
43
43
)
44
44
assert isinstance (self .metadata , core .AudioStreamMetadata ) # mypy
45
- self ._source_sample_rate = self .metadata .sample_rate
46
45
self ._desired_sample_rate = (
47
- sample_rate if sample_rate is not None else self ._source_sample_rate
46
+ sample_rate if sample_rate is not None else self .metadata . sample_rate
48
47
)
49
48
50
49
def get_samples_played_in_range (
Original file line number Diff line number Diff line change @@ -1431,9 +1431,9 @@ UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormatAndSampleRate(
1431
1431
if (sourceSampleRate != desiredSampleRate) {
1432
1432
// Note that this is an upper bound on the number of output samples.
1433
1433
// `swr_convert()` will likely not fill convertedAVFrame with that many
1434
- // samples, it will buffer the last few ones because those require future
1435
- // samples. That's also why we reset nb_samples after the call to
1436
- // `swr_convert()`.
1434
+ // samples if sample rate conversion is needed. It will buffer the last few
1435
+ // ones because those require future samples. That's also why we reset
1436
+ // nb_samples after the call to `swr_convert()`.
1437
1437
convertedAVFrame->nb_samples = av_rescale_rnd (
1438
1438
swr_get_delay (streamInfo.swrContext .get (), sourceSampleRate) +
1439
1439
srcAVFrame->nb_samples ,
@@ -1464,7 +1464,6 @@ UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormatAndSampleRate(
1464
1464
1465
1465
// See comment above about nb_samples
1466
1466
convertedAVFrame->nb_samples = numConvertedSamples;
1467
- // TODO need to flush properly to retrieve the last few samples.
1468
1467
1469
1468
return convertedAVFrame;
1470
1469
}
Original file line number Diff line number Diff line change @@ -1104,8 +1104,11 @@ def test_format_conversion(self):
1104
1104
def test_sample_rate_conversion (self , start_seconds , stop_seconds ):
1105
1105
# When start_seconds is not exactly 0, we have to increase the tolerance
1106
1106
# a bit. This is because sample_rate conversion relies on a sliding
1107
- # window of samples: if we start a stream in the middle, the first few
1108
- # samples aren't able to take advantage of the preceeding samples.
1107
+ # window of samples: if we start decoding a stream in the middle, the
1108
+ # first few samples we're decoding aren't able to take advantage of the
1109
+ # preceeding samples for sample-rate conversion. This leads to a
1110
+ # slightly different sample-rate conversion that we would otherwise get,
1111
+ # had we started the stream from the beginning.
1109
1112
atol = 1e-4 if start_seconds == 0 else 1e-2
1110
1113
rtol = 1e-6
1111
1114
You can’t perform that action at this time.
0 commit comments