NVIDIA / VideoProcessingFramework

Set of Python bindings to C++ libraries which provides full HW acceleration for video decoding, encoding and GPU-accelerated color space and pixel format conversions
Apache License 2.0
1.32k stars 233 forks source link

Reading video file provides incorrect PTS values #452

Open nrhodes opened 1 year ago

nrhodes commented 1 year ago

When I decode the enclosed video with PyNvCodec, I get 2 invalid PTS values for two frames in the middle of the video.

To Reproduce Steps to reproduce the behavior:

  1. Run the following test program:
    
    import PyNvCodec as nvc

if name == "main": gpu_id = 0

historical_pts = []
nvDec = nvc.PyNvDecoder('AndrewFailingBGMask.mp4', gpu_id)
out_pdata = nvc.PacketData()
frame_number = 0
HISTORY_LENGTH=4
while True:
    src_surface = nvDec.DecodeSingleSurface(out_pdata)
    if src_surface.Empty():
        break
    historical_pts.append(out_pdata.pts)
    historical_pts = historical_pts[-HISTORY_LENGTH:]
    if len(historical_pts) > 1 and historical_pts[-2] > historical_pts[-1]:
        print(f'Decreasing PTS at frame {frame_number}: {historical_pts}')
    frame_number += 1
2. You'll see the output:

Decreasing PTS frame 299: 258750 frame 300: 262500 frame 301: 266250 frame 302: 28713504 frame 303: 28713504 frame 304: 270000

**Expected behavior**
Nothing should be output (because the PTS should be monotonic non-decreasing).

**Desktop (please complete the following information):**
 - OS: Linux
 - Nvidia driver version: 520.61.05
 - CUDA Version: 11.8
 - Video Codec SDK Version: Commit b7cff07699204665ecbff5dc3bdc880e71bfec62
 - Python Version: 3.7.11

**Additional context**
The correct PTS values for this segment of the video (from `ffprobe -v error AndrewFailingBGMask.mp4 -select_streams v:0 -show_packets | grep "^pts=" | sed -e "s/^pts=//" | sort -n`):

frame 299: 258750 frame 300: 262500 frame 301: 262500 frame 302: 266250 frame 303: 266250 frame 304: 270000



https://user-images.githubusercontent.com/6276665/229596492-6fd8bd0a-1911-4992-879e-69b55fd32f96.mp4