Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Unable to save a video file (encoder not found)

$
0
0
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 tried to set the fourcc manualy by using H264 MPG4 ..., but I always get this error : `encoder not found` 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 tried -1 so I can choose from available codec but I don't get any choice 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 ? Originally I intended to use cv2.CAP_PROP_XXXX to get the properties from my file and use this information to create my new file, and thus use the same codec to open my first file and write my second. 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 found two way to do this in C++ unfortunately I'm not experienced enough to figure out how to do this in python **EDIT :** it seems I am now
 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 :** 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 still need some help on that part

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>