Hang on pipe.run()
I run the following code - it hangs when i reaches 461 on the line pipe_out = pipe.run().
Note that to eliminate possible sources of error, I set the values of batch_size, sequence_length, num_threads all to 1 (ideally I need them to be batch_size=2, sequence_length=8, num_threads=2 - these settings gave the same error).
The video I am processing is the following one: https://www.youtube.com/watch?v=5r0dWxy17C8. I downloaded the video using https://yt1s.com/en5.
This happens on a fresh installation of dali - nvidia-dali-cuda100==1.1.0
import os
import numpy as np
from nvidia.dali import pipeline_def
import nvidia.dali.fn as fn
batch_size=1
sequence_length=1
video_directory = "/home/nikhil/code/FaceMorph/"
video_files=["yt1s.com - Eartha Kitt Emotional interview Part 2_480p.mp4"]
@pipeline_def
def video_pipe(filenames):
videos = fn.readers.video(device="gpu", filenames=filenames, sequence_length=sequence_length,
shard_id=0, num_shards=1)
return videos
pipe = video_pipe(batch_size=batch_size, num_threads=1, device_id=0, filenames=video_files, seed=123456)
pipe.build()
i = 0
while(True):
print(i)
i += 1
pipe_out = pipe.run()
print(pipe_out)
step1 = pipe_out[0].as_cpu()
print(step1)
sequences_out = step1.as_array()
print(sequences_out.shape)
print('\n')
Hi,
It looks that after seeking a certain keyframe preceding the required one, the decoder is not able to resume decoding because the key data is missing in that frame. We need to figure out where the problem is and how to address it.
Just adding another observation in case it's helpful :
That video has ~(591s * 25fps) frames, so if one specifies a batch_size=1, sequence_length=64 and stride=230. Only one valid batch can be produced and the pipeline will not hang. Output timestamps:
tensor([[ 0.0000, 9.2000, 18.4000, 27.6000, 36.8000, 46.0000, 55.2000,
64.4000, 73.6000, 82.8000, 92.0000, 101.2000, 110.4000, 119.6000,
128.8000, 138.0000, 147.2000, 156.4000, 165.6000, 174.8000, 184.0000,
193.2000, 202.4000, 211.6000, 220.8000, 230.0000, 239.2000, 248.4000,
257.6000, 266.8000, 276.0000, 285.2000, 294.4000, 303.6000, 312.8000,
322.0000, 331.2000, 340.4000, 349.6000, 358.8000, 368.0000, 377.2000,
386.4000, 395.6000, 404.8000, 414.0000, 423.2000, 432.4000, 441.6000,
450.8000, 460.0000, 469.2000, 478.4000, 487.6000, 496.8000, 506.0000,
515.2000, 524.4000, 533.6000, 542.8000, 552.0000, 561.2000, 570.4000,
579.6000]], device='cuda:0', dtype=torch.float64)
I've observed similar behavior in terms of what does and doesn't hang on other videos downloaded from youtube. (I used https://github.com/ytdl-org/youtube-dl if that matters.)
Hi,
After a bit of the investigation of this problem, it seems that the decoder can decode consecutive frames starting from most of the keyframes. However, when seeked to a certain keyframe N it is not able to resume decoding. It is either the way we use av_bsf_send_packet or how the video SDK works.
We need to investigate further this problem and keep you posted.
Hi @SiftingSands, I have dived deeper into this problem. It seems that the video hangs on frame 461 it may be just corrupted. What the DALI video reader does before decoding any sequence is seeking to the preceding keyframe before the sequence start, start decoding, collect required frames that fall into a defined sequence and drop the remaining one between the keyframe and the last frame requested in the sequence. In the mentioned case, when DALI wants to decode frame 461, it seeks the preceding keyframes which happen to be 461 as well, and tries to decode from there. However, it seems that this frame despite being IDR doesn't have the parameter set necessary for the decoder to start it works. In effect, the decoder is not able to provide any frames between frame 461 and the next key one. As we wait for frame 461 it ends up as hang. When I downloaded the mentioned video with a different resolution it works fine, so I think this variant is just corrupted. I don't think we can do much in this case now.
Hello @JanuszL, My initial thought was some type of video incompatibility or corruption as well. However, I never encountered similar playback issues with OpenCV on videos extracted from youtube.
Here's a simple script that I used to read and save frames of a video using OpenCV : https://gist.github.com/SiftingSands/2163907225deb8cd009f61b631669689
OpenCV seems to read frame 461 without an issue, but I'm cognizant that DALI and OpenCV have different video decoding schemes. I'll be testing out OpenCV with a CUDA backend for video decoding, and I'll report those results if they're of interest.
Hi @SiftingSands, The difference between your code and DALI is that OpenCV reads frames sequentially, while DALI access containers randomly using seek operation that erases the previous decoding context. In the case, I described if the decoder has a context from the previous frames it works fine, but if you seek, you need to drop the context and in this particular case the context cannot be properly build using the 461 keyframes, and DALI decoder needs to wait until it sees another keyframe.
Leaving this note here in case anyone else encounters similar issues with video loading : VPF is another project that does hardware accelerated video transcoding and supports PyTorch tensors. It's able to seek to frame 461 (also tested adjacent frames in case of slight counting differences) in the originally mentioned video. Of course, users would have to write their own sharding, batching, etc. functionalities.
The same problem was reported here.
I hope this PR may help https://github.com/NVIDIA/DALI/pull/3858. Please check the nightly/weekly build after it is merged to see if it resolves your problem.
1.14 is available and should address this issue.