Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
chenc29xpeng opened this issue Sep 11, 2024 · 9 comments
Open
1 task done
Assignees
Labels
question Further information is requested Video Video related feature/question

Comments

@chenc29xpeng
Copy link

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
@chenc29xpeng chenc29xpeng added the question Further information is requested label Sep 11, 2024
@chenc29xpeng
Copy link
Author

By the way, ffmpeg can decode this mp4 file normally using ffmpeg -i cut.mp4 '%04d.png'

@awolant awolant added the Video Video related feature/question label Sep 11, 2024
@awolant awolant assigned awolant and unassigned szalpal Sep 11, 2024
@JanuszL
Copy link
Contributor

JanuszL commented Sep 11, 2024

Hi @chenc29xpeng,

Indeed, DALI returns not the output we may expect. Let us investigate this and get back to you soon.

@chenc29xpeng
Copy link
Author

Hi @chenc29xpeng,

Indeed, DALI returns not the output we may expect. Let us investigate this and get back to you soon.

@JanuszL, Thank you very much. This problem has troubled me for a long time. I am looking forward to your reply!

@chenc29xpeng
Copy link
Author

@JanuszL @awolant Is there any progress on this issue? I would be very grateful if you could fix it.

@JanuszL
Copy link
Contributor

JanuszL commented Sep 16, 2024

Hi @chenc29xpeng,

I'm sorry to say that there is no progress. The issue seems to be not related to DLAI itself but the GPU video decoding capability. I reached out to a relevant team and await their response.

@bpleshakov
Copy link

Is it related to #4135?

@JanuszL
Copy link
Contributor

JanuszL commented Sep 17, 2024

@bpleshakov it could be but I cannot tell.

@chenc29xpeng
Copy link
Author

Hi @chenc29xpeng,

I'm sorry to say that there is no progress. The issue seems to be not related to DLAI itself but the GPU video decoding capability. I reached out to a relevant team and await their response.

@JanuszL Got it. If there is any progress, please contact me as soon as possible. Thank you.

@chenc29xpeng
Copy link
Author

Is it related to #4135?

@bpleshakov I think it's irrelevant because I only have one mp4 video spliced ​​from h265 files, and the fps is 12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Video Video related feature/question
Projects
None yet
Development

No branches or pull requests

5 participants