Hi everyone, first time here so please be gentle ;) Here it goes
I try to open a video file, do some detection inside, draw contours and then save everything in a new file with the same properties
, everything works as intended except the creating and writing in a new file part
I try to set the fourcc manualy by using H264 MPG4 etc
..., but I always get an this error like :
encoder not found
I tried -1 so i can choose from available codec but i don't get any choicechoice
When i use
out.isOpened()
it's always False so I have no idea what I do wrong here but I really can't find a wait to create a new file
i don't get it, if I can open my source video file doesn't it mean that i got the right codec for it ?
when i use
out.isOpened()
it's always False so I have no idea what I do wrong here but I really can't find a wait to create a new file
originaly i intended to use cv2.CAP_PROP_XXXX to get the properties from my file and use this information to create my new file.
After reading and trying , a lot, i'm stuck with a FOURCC in double format and i really don't know how to convert it in char format
fps = int(cap.get(cv2.CAP_PROP_FPS))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cap.get(cv2.CAP_PROP_FOURCC)
out = cv2.VideoWriter('C:\Users\John\Desktop\Test\output.mp4',fourcc, fps, (width,height))
I find two way to do this in C++ unfortunately I'm not experienced enough to figure out how to do this in python
char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0};
union { int v; char c[5];} uEx ;
uEx.v = ex; // From Int to char via union
uEx.c[4]='\0';
anyway i'm stuck and i need some help
EDIT: EDIT : I continued to search and try , here what I got so far, I did it step by step so I could see what was happening
fourcc = cap.get(cv2.CAP_PROP_FOURCC)
fourcc is a float and has a value of 828601953.0
fourcc= int(fourcc)
now fourcc is an int an has a value of 828601953
fourcc = chr((fourcc & 0XFF)) + chr((fourcc & 0XFF00) >> 8)+ chr((fourcc & 0XFF0000) >> 16)+ chr((fourcc & 0XFF000000) >> 24) + chr(0)
now fourcc is a string of 5 char 'a' 'v' 'c' '1' '\0'
fourcc = cv2.VideoWriter_fourcc(fourcc[0],fourcc[1],fourcc[2],fourcc[3])
now fourcc is an int again with the value 828601953
in the end what I have found out is that cv2.VideoWriter_fourcc() doesn't need maj charactere to work
and the second is that I don't have to change my fourcc in a string to use it and I can simplify my code
from this:
fourcc = cap.get(cv2.CAP_PROP_FOURCC)
fourcc = int(fourcc)
fourcc = chr((fourcc & 0XFF)) + chr((fourcc & 0XFF00) >> 8)+ chr((fourcc & 0XFF0000) >> 16)+ chr((fourcc & 0XFF000000) >> 24) + '\0'
fourcc = cv2.VideoWriter_fourcc(fourcc[0],fourcc[1],fourcc[2],fourcc[3])
out = cv2.VideoWriter('output.mp4',fourcc, fps, (width,height))
to this:
fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
out = cv2.VideoWriter('C:\Users\John\Desktop\Test\output.mp4',fourcc, fps, (width,height))
now all I have to figure out is why I can open my source video file with AVC1 codec but can't create a new file with the same codec, so for now i I still need some help on that part