0

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?

Vineet Yadav
  • 305
  • 1
  • 4
  • 13
  • 1
    mp4 uses lossy compression which slightly alters your frame pixels. It might be possible to still use mp4, but you'd have to hide the during while encoding the video to mp4 **after** the lossy step. – Reti43 May 09 '18 at 07:09
  • [Here](https://stackoverflow.com/questions/35396977/lsb-dct-based-image-steganography/35398127#35398127)'s an analogy with using jpeg for image steganography – Reti43 May 09 '18 at 07:15
  • To minimize the loss of quality and preserve the integrity of the modified frames, you can use lossless codecs, such as FFV1 or HuffYUV: fourcc = cv2.VideoWriter_fourcc(*'FFV1') OR fourcc = cv2.VideoWriter_fourcc(*'HuffYUV') – Vince Calo May 12 '23 at 04:19

0 Answers0