Skip to content

Commit eada8b2

Browse files
committed
Make sure that the proper video stream index is used by the GPU decoder
- fixes the use of 0 index stream inside the GPU decoder by properly obtained index Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
1 parent ef604c4 commit eada8b2

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

dali/operators/reader/loader/video/frames_decoder.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ class DLL_PUBLIC FramesDecoder {
219219

220220
std::optional<bool> zero_latency_ = {};
221221

222+
// False when the file doesn't have any correct content or doesn't have valid video stream
223+
bool is_valid_ = false;
224+
222225
private:
223226
/**
224227
* @brief Gets the packet from the decoder and reads a frame from it to provided buffer. Returns
@@ -275,8 +278,6 @@ class DLL_PUBLIC FramesDecoder {
275278
int channels_ = 3;
276279
bool flush_state_ = false;
277280
bool is_vfr_ = false;
278-
// False when the file doesn't have any correct content or doesn't have valid video stream
279-
bool is_valid_ = false;
280281

281282
const std::string filename_ = {};
282283
std::optional<MemoryVideoFile> memory_video_file_ = {};

dali/operators/reader/loader/video/frames_decoder_gpu.cc

+9-4
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ void FramesDecoderGpu::InitBitStreamFilter() {
331331
}
332332

333333
DALI_ENFORCE(
334-
avcodec_parameters_copy(bsfc_->par_in, av_state_->ctx_->streams[0]->codecpar) >= 0,
334+
avcodec_parameters_copy(bsfc_->par_in,
335+
av_state_->ctx_->streams[av_state_->stream_id_]->codecpar) >= 0,
335336
"Unable to copy bit stream filter parameters");
336337
DALI_ENFORCE(
337338
av_bsf_init(bsfc_) >= 0,
@@ -364,7 +365,11 @@ void FramesDecoderGpu::InitGpuParser() {
364365
InitBitStreamFilter();
365366

366367
filtered_packet_ = av_packet_alloc();
367-
DALI_ENFORCE(filtered_packet_, "Could not allocate av packet");
368+
if (!filtered_packet_) {
369+
DALI_WARN(make_string("Could not allocate av packet for \"", Filename(), "\""));
370+
is_valid_ = false;
371+
return;
372+
}
368373

369374
auto codec_type = GetCodecType();
370375

@@ -380,8 +385,8 @@ void FramesDecoderGpu::InitGpuParser() {
380385
parser_info.pfnDecodePicture = frame_dec_gpu_impl::process_picture_decode;
381386
parser_info.pfnDisplayPicture = nullptr;
382387

383-
auto extradata = av_state_->ctx_->streams[0]->codecpar->extradata;
384-
auto extradata_size = av_state_->ctx_->streams[0]->codecpar->extradata_size;
388+
auto extradata = av_state_->ctx_->streams[av_state_->stream_id_]->codecpar->extradata;
389+
auto extradata_size = av_state_->ctx_->streams[av_state_->stream_id_]->codecpar->extradata_size;
385390

386391
memset(&parser_extinfo, 0, sizeof(parser_extinfo));
387392
parser_info.pExtVideoInfo = &parser_extinfo;

dali/test/python/input/test_video.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import glob
16+
import os
1617
import itertools
1718
import numpy as np
1819
import nvidia.dali.fn as fn
@@ -22,7 +23,8 @@
2223
from nvidia.dali import pipeline_def
2324
from test_utils import get_dali_extra_path, to_array
2425

25-
filenames = glob.glob(f"{get_dali_extra_path()}/db/video/[cv]fr/*.mp4")
26+
test_data_root = get_dali_extra_path()
27+
filenames = glob.glob(f"{test_data_root}/db/video/[cv]fr/*.mp4")
2628
# filter out HEVC because some GPUs do not support it
2729
filenames = filter(lambda filename: "hevc" not in filename, filenames)
2830
# mpeg4 is not yet supported in the CPU operator
@@ -254,3 +256,26 @@ def test_video_input_input_queue(device, n_test_files):
254256
glob="No data was provided to the InputOperator. Make sure to feed it properly.",
255257
):
256258
input_pipe.run()
259+
260+
261+
@params(*device_values)
262+
def test_video_input_audio_stream(device):
263+
"""
264+
Checks if video decoding when audio stream is present
265+
"""
266+
input_name = "VIDEO_INPUT"
267+
268+
input_pipe = video_input_pipeline(
269+
input_name=input_name,
270+
batch_size=3,
271+
sequence_length=4,
272+
device=device,
273+
**common_pipeline_params,
274+
)
275+
276+
filename = os.path.join(test_data_root, "db", "video", "sintel", "sintel_trailer-720p.mp4")
277+
test_file = np.fromfile(filename, dtype=np.uint8)
278+
input_pipe.build()
279+
input_pipe.feed_input(input_name, np.array([[test_file]]))
280+
281+
input_pipe.run()

0 commit comments

Comments
 (0)