Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Python cv2.CAP_PROP_FOURCC conversion from double to char

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 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';

So if anyone can translate the c++ in python or show my any other way to do this please let me know

Python cv2.CAP_PROP_FOURCC conversion from double to char

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 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)

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';

So if anyone can translate the c++ in python or show my any other way to do this please let me know

Beginner need help : Python cv2.CAP_PROP_FOURCC conversion from double to char

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 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';

So if anyone can translate the c++ in python or show my any other way to do this please let me know

Beginner need help : Python cv2.CAP_PROP_FOURCC conversion from double to charUnable to save a video file

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 I always get an error like : encoder not found

I tried -1 so i can choose from available codec but i don't get any choice

i don't get it, I can open a video file but not create a new one ?

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';

So if anyone can translate the c++ in python or show my any other way to do this please let me knowanyway i'm stuck and i need some help

Unable to save a video file

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 I always get an error like : encoder not found

I tried -1 so i can choose from available codec but i don't get any choice

i don't get it, I can open a video file but not create a new one ?

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

Unable to save a video file

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 I always get an error like : encoder not found

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 a my source video file but not create a new one 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: 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

Unable to save a video filefile (encoder not found)

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

Unable to save a video file (encoder not found)

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 ..., but I always get this error : encoder not found I tried -1 so i I can choose from available codec but i I don't get any choice

When i 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 I don't get it, if I can open my source video file doesn't it mean that i I got the right codec for it ?

originaly i 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. 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 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 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

Unable to save a video file (encoder not found)

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 ..., but I always get this error : encoder not found I tried -1 so I can choose from available codec but I don't get any choice

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 ?

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

Unable to save a video file (encoder not found)

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 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

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 ?

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 : *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