File size: 2,179 Bytes
3772102
a1bec20
dc10d60
ded77bf
3772102
 
 
 
 
dc10d60
 
3772102
 
 
dc10d60
3772102
 
 
ded77bf
3772102
dc10d60
3772102
dc10d60
 
 
 
3772102
 
 
dc10d60
 
 
3772102
 
 
 
 
 
 
dc10d60
3772102
 
 
 
 
 
 
 
 
 
ded77bf
3772102
dc10d60
3772102
 
 
ded77bf
3772102
 
 
ded77bf
3772102
 
ded77bf
dc10d60
3772102
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gradio as gr
import cv2
import numpy as np

def process_video(video_path, frame_difference, brightness_value):
    # Read the video
    cap = cv2.VideoCapture(video_path)
    if not cap.isOpened():
        return "Error: Unable to open video."

    # Get video properties
    frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = int(cap.get(cv2.CAP_PROP_FPS))
    
    # Create a VideoWriter object to write the output video
    output_path = "output_video.mp4"
    out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, frame_height))

    # Initialize a list to store frames for frame shifting
    frames = []
    
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        # Invert the pixel values of the frame
        inverted_frame = cv2.bitwise_not(frame)
        frames.append((frame, inverted_frame))

    cap.release()

    # Process video by applying frame difference and overlaying
    num_frames = len(frames)
    for i in range(num_frames):
        # Get the original and shifted frames
        orig_frame = frames[i][0]
        shifted_index = (i + frame_difference) % num_frames
        shifted_frame = frames[shifted_index][1]  # Use the inverted frame of shifted frame

        # Overlay the frames with 50% opacity
        overlay_frame = cv2.addWeighted(orig_frame, 0.5, shifted_frame, 0.5, 0)

        # Increase the brightness
        overlay_frame = np.clip(overlay_frame * brightness_value, 0, 255).astype(np.uint8)

        # Write the resulting frame to the output video
        out.write(overlay_frame)

    out.release()
    
    return output_path

# Gradio Interface
iface = gr.Interface(
    fn=process_video,
    inputs=[
        gr.Video(label="Input Video"),  # Video input
        gr.Slider(0, 50, value=1, label="Frame Difference"),  # Frame difference input
        gr.Slider(0.0, 1.0, value=1.0, label="Brightness Adjustment"),  # Brightness adjustment input
    ],
    outputs=gr.Video(label="Output Video"),  # Video output
    title="Motion Amplification with Frame Difference"
)

iface.launch()