NVIDIA / NVIDIA/DALI

All pixels are abnormal [0, 135, 0] after H265 MP4 is decoded into images

Open
#5,632 9 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

question Video
Dominant language
C++
Stars
5.8k
Forks
678
Avg merge
3d 1h
Merged PRs (30d)
27

Description

Describe the question.
All images are green after the video is decoded.

When I use fn.readers.video to decode my own h265 video, the decoded image size is normal, but the pixels are abnormal. The pixels are all [0, 135, 0], I think there is something wrong with my mp4, because the official video is decoded normally. But my mp4 can be played normally and can be decoded normally based on the cpu through opencv. Can anyone help me take a look?

video file

google cloud drive: https://drive.google.com/file/d/1VwnAq2sunrGkZIGgJgF1d-97CCZj51aO/view?usp=sharing
baidu cloud drive: https://pan.baidu.com/s/1AM-OSo2bjWg1pE6GRSAdSQ?pwd=1ram

Here is my code:

import cv2
import tempfile
import numpy as np
from PIL import Image
from typing import List, Optional
from nvidia.dali import pipeline_def
import nvidia.dali.fn as fn
from nvidia.dali.plugin.pytorch import DALIGenericIterator

def mp4_to_image_opencv(input_file: str) -> List[np.ndarray]:
    """
    Return: list
    """
    frame_list = []
    cap = cv2.VideoCapture(input_file)
    while(cap.isOpened()):
        ret, frame = cap.read()
        if ret == True:
            frame_list.append(frame)
        else:
            break
    cap.release()
    return frame_list

if __name__ == "__main__":
    video_filename = "cut.mp4"
    frame_list = mp4_to_image_opencv(video_filename)
    cv2.imwrite("debug_opencv.png", frame_list[10])
    save_path = "debug_dali.png"
    sequence_length = 64

    @pipeline_def
    def video_pipe(file_list):
        video, label = fn.readers.video(device="gpu", file_list=file_list, sequence_length=sequence_length, file_list_frame_num=True, name="my_reader", pad_sequences=True)
        return video, label

    my_file_list_str = f"{video_filename} 0 0 20\n" # label start_frame_num end_frame_num
    tf = tempfile.NamedTemporaryFile()
    tf.write(str.encode(my_file_list_str))
    tf.flush()
    pipe = video_pipe(batch_size=1, file_list=tf.name, num_threads=1, device_id=0)
    pipe.build()

    dali_iter = DALIGenericIterator([pipe], ["image", "label"], reader_name="my_reader")
    for data in dali_iter:
        label = data[0]['label'].cpu().numpy()[0][0]
        image = data[0]['image'][0]
        pil_image = Image.fromarray(image[10].cpu().numpy())
        pil_image.save(save_path)
        
dali decode

Image

opencv decode

Image

Check for duplicates
  • I have searched the open bugs/issues and have found no duplicates for this bug report

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.