Write cv2 frames in MPEG-TS format

asked 2020-08-28 02:45:59 -0600

I am processing a video file created by GStreamer (.ts, MPEG-TS) format. After processing I want to save the fames to another segment file (*.ts, MPEG-TS) format. I couldn't find any option to do so.

import cv2

vs = cv2.VideoCapture("video.ts")
fourcc = cv2.VideoWriter_fourcc(*'mpegts')
writer = cv2.VideoWriter("result.ts", fourcc, 30.0, (W, H), True) 

while True:
    ret, frame = vs.read()
    if ret:
        writer.write(frame)
    else:
        break

vs.release()
writer.release()

Is there a way to achieve this? I tried writing to mp4 and rename it to .ts extension but that doesn't work in hls streaming.

edit retag flag offensive close merge delete