Unable to save a video file (encoder not found)

asked 2015-12-23 03:28:39 -0500

John_Mdo gravatar image

updated 2015-12-24 04:29:16 -0500

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 ...
(more)
edit retag flag offensive close merge delete

Comments

may be this post could help you

LBerger gravatar imageLBerger ( 2015-12-23 10:08:26 -0500 )edit

thx but it doesn't this post is in C++ and as I said, i'm not really comfortable translating something from one language to the other , yet

John_Mdo gravatar imageJohn_Mdo ( 2015-12-23 11:07:02 -0500 )edit

try to use this codec CV_FOURCC('P','I','M','1')

LBerger gravatar imageLBerger ( 2015-12-24 04:46:00 -0500 )edit

thank's for your answer

I get this error now : MPEG1/2 does not support 12/1 fps

Just to see what happens when i change the fps to 20 24 or 30

i get this error Tag PIM1/0x314d4950 incompatible with outpout codec id '1' (j[0][0][0])

by the way I get the FPS from my source file and I'd like to create a file with the same properties

John_Mdo gravatar imageJohn_Mdo ( 2015-12-24 06:31:37 -0500 )edit

may be this post would help you

Try to change extension with PIM1 I use avi. I don't think that if you have got an encoder to decode video you've got an encoder.

LBerger gravatar imageLBerger ( 2015-12-24 06:37:51 -0500 )edit

Thx again, indeed it's working with PIM1 and .avi so that's that

but now how do I make it work with ACV1 and .mp4

John_Mdo gravatar imageJohn_Mdo ( 2015-12-24 09:04:39 -0500 )edit

have you try to download cisco encoder ?

LBerger gravatar imageLBerger ( 2015-12-24 09:19:12 -0500 )edit

thx, i'll test it and edit my post if it work

John_Mdo gravatar imageJohn_Mdo ( 2015-12-24 10:12:08 -0500 )edit

@John_Mdo afaik, Videowriter only works with .avi containers

LorenaGdL gravatar imageLorenaGdL ( 2015-12-26 10:46:33 -0500 )edit

@LBerger I installed cisco encoder but I don't see any change in application behaviour @LorenaGdL Ok, thanks for the info, I still have issue opening avi file I'll post the error message if I find a way to get it

John_Mdo gravatar imageJohn_Mdo ( 2015-12-28 04:14:05 -0500 )edit