Error VideoWriter - not writing anything

asked 2018-11-30 08:20:29 -0600

Nbb gravatar image

I want to read video then write to different video. Below is my code but video writer does not save anything. Help pls.

import numpy as np
import cv2
from tqdm import tqdm

inp = "./videos/a"
out = "b"

inpcap = cv2.VideoCapture(inp+".MP4")
outcap = cv2.VideoWriter(out+".MP4", cv2.VideoWriter_fourcc('H','2','6','4'), 30, (int(inpcap.get(3)),int(inpcap.get(4))))

print(inp)
print(out)
print(int(inpcap.get(3)),int(inpcap.get(4)))

i = 1
pbar = tqdm(total = 80000)
while(inpcap.isOpened()):
    pbar.update(1)
    ret, frame = inpcap.read()
    if(ret == False):
        break
    outcap.write(frame)

inpcap.release()
outcap.release()
edit retag flag offensive close merge delete

Comments

hello someone help

Nbb gravatar imageNbb ( 2018-11-30 17:00:18 -0600 )edit
supra56 gravatar imagesupra56 ( 2018-11-30 20:52:15 -0600 )edit

@Nbb windows or linux?

LBerger gravatar imageLBerger ( 2018-12-01 08:59:31 -0600 )edit

@LBerger linux

Nbb gravatar imageNbb ( 2018-12-01 19:01:16 -0600 )edit

Add this before release cv2.waitKey(0)

supra56 gravatar imagesupra56 ( 2018-12-01 22:20:47 -0600 )edit

@LBerger is it working for you ? I am not sure why it isnt saving anything on mine

Nbb gravatar imageNbb ( 2018-12-02 03:50:35 -0600 )edit

I removed pbar, pbar.update and it is working for me (windows 10 ). Try to use MJPG instead of H264. If it works it is codec problem

LBerger gravatar imageLBerger ( 2018-12-02 03:53:27 -0600 )edit

@Nbb. Are you using raspberry pi for linux?

supra56 gravatar imagesupra56 ( 2018-12-02 06:35:00 -0600 )edit