Python How to get an image family code (YUV, RGB) from a video not using extensions

456 Views Asked by At

I would like to know the family code of the video to make a conversion to YUV, without using the extensions.

In general, .mp4 and .avi are in RGB and I would like to convert them to YUV and keep the Y (luma) with a .split() and if the video is already in .yuv or .mov, directly do the split()

Here is what I did but the .mp4 files are not always in RGB, the same for the .avi files etc, and I also need the structure of the video ( yuv4.2.2 , 4.2.0 ...)

Is there another way to get the family code of the video directly (fourCC ?) and the structure of YUV ? Thanks for your help

import cv2
import numpy
from os import listdir
from os.path import isfile, join
video = cv2.VideoCapture(FilePathEdit)
success,img = video.read()
onlyfiles = [f for f in listdir("./video") if isfile(join("./video", f))]
print(onlyfiles)

for fp in filepaths:
    # Split the extension from the path and normalise it to lowercase.
    ext = os.path.splitext(fp)[-1].lower()

    # Now we can simply use == to check for equality, no need for wildcards.
    while ((success)and(video.get(cv2.CAP_PROP_POS_MSEC)!= End)):
        if ext == ".mp4" or ext == ".avi":
            img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
            y, u, v = cv2.split(img_yuv)
            "..."
        elif ext == ".mov" or ext == ".yuv":
            y, u, v = cv2.split(img)
            "..."
        else:
            print(" Video extension is: " + ext + ", extraction not possible")
0

There are 0 best solutions below