I am trying to implement steganography on videos.For that i have to extract each video frame and hide secret message inside them.Now i have successfully extract frames, hide message inside them and save it using OpenCv cv2. But when i again extract frames from the stego video, the frames are completely different in their pixel values.
Even if i am not applying steganography and just extract and save frame back as new video,the frames are completely different when i extract them again.
Here is my code that i use to extract and save frames using OpenCv2
import cv2
def get_frame_count(cap):
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) - 1
return frame_count
def get_fps_rate(cap):
fps = cap.get(cv2.CAP_PROP_FPS)
return fps
video_input_path = "./sample4.mp4"
cap = cv2.VideoCapture(video_input_path)
width = (int)(cap.get(cv2.CAP_PROP_FRAME_WIDTH ))
height = (int)(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
frame_count = get_frame_count(cap)
fps = get_fps_rate(cap)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter('newVideo.mp4', fourcc, fps, (width, height))
count = 0
while cap.isOpened():
ret, frame = cap.read()
video.write(frame)
count = count + 1
if (count >= (frame_count)):
cap.release()
break
video.release
cv2.destroyAllWindows()
To check the equality of first frame in both videos (sample4.mp4 and newVideo.mp4) i use this code:
import cv2
def get_frame_count(cap):
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) - 1
return frame_count
video_input_path = "./sample4.mp4"
cap = cv2.VideoCapture(video_input_path)
frame_count = get_frame_count(cap)
width = (int)(cap.get(cv2.CAP_PROP_FRAME_WIDTH ))
height = (int)(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
ret, frame = cap.read()
print frame
cap.release()
video_input_path = "./newVideo.mp4"
cap = cv2.VideoCapture(video_input_path)
frame_count = get_frame_count(cap)
width = (int)(cap.get(cv2.CAP_PROP_FRAME_WIDTH ))
height = (int)(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
ret, frame = cap.read()
print frame
cap.release()
and frame data of both frames are completely different. How is that possible?