简体   繁体   中英

Output video with same settings as input video python OpenCV

I have a video I read in to detect opbjects and generate an video that will at a later time be used as an monotone alpha channel for the original video.

I get the current input video with:

cap = cv2.VideoCapture('file.mp4')

From here you are supposed to create a VideoWriter to output the edited frames with something to the effect of:

out = cv2.VideoWriter('output.mp4',fourcc, 20.0, (640,480))

but is there a way to directly tell the writer to just copy the initial videos formatting and configurations?

I haven't tested this but from here it seems that you can use the get method on the video capture to get various properties from the video capture. Using this you can get the properties from the initial stream and set them in your writer.

From the documentation the identifiers you require would be:

CV_CAP_PROP_FPS => Frame rate.

CV_CAP_PROP_FRAME_WIDTH => Width.

CV_CAP_PROP_FRAME_HEIGHT => Height,

CV_CAP_PROP_FOURCC => Codec Code

As far as I can tell you can use it as cap.get(CV_CAP_PROP_FRAME_WIDTH) and do that for each property.

You can convert the character fourcc to an int by using

cv.VideoWriter.fourcc(c1, c2, c3, c4 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM