| import os | |
| import cv2 | |
| import numpy as np | |
| import tempfile | |
| import streamlit as st | |
| import time | |
| st.set_page_config(page_title="Exness Tempering App by Adil Khan") | |
| def overlay_image(background, overlay): | |
| background_resized = cv2.resize(background, (overlay.shape[1], overlay.shape[0])) | |
| alpha_channel = overlay[:, :, 3] / 255.0 | |
| for c in range(3): | |
| background_resized[:, :, c] = (1 - alpha_channel) * background_resized[:, :, c] + alpha_channel * overlay[:, :, c] | |
| return background_resized | |
| def image_tempering_app(): | |
| st.title("Exness Image Tempering App") | |
| cover_option = st.selectbox("Select Video Type:", ["With Banner", "With Multi-Banner", "Without Banner"], index=0) | |
| if cover_option == "Without Banner": | |
| cover_value = "cover.png" | |
| elif cover_option == "With Banner": | |
| cover_value = "cover2.png" | |
| else: | |
| cover_value = "cover3.png" | |
| screenshot_image = st.file_uploader("Upload Screenshot Image", type=["jpg", "jpeg", "png"]) | |
| if screenshot_image: | |
| file_bytes = np.asarray(bytearray(screenshot_image.read()), dtype=np.uint8) | |
| image = cv2.imdecode(file_bytes, cv2.IMREAD_UNCHANGED) | |
| cover = cv2.imread(cover_value, cv2.IMREAD_UNCHANGED) | |
| with st.spinner("Processing Image..."): | |
| result = overlay_image(image, cover) | |
| temp_filename = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name | |
| cv2.imwrite(temp_filename, result) | |
| st.success("Image Processing Complete!") | |
| st.download_button("Download Processed Image", data=open(temp_filename, "rb").read(), file_name="processed_image.png", mime="image/png") | |
| def process_video(video_path, output_path, cover_value): | |
| cap = cv2.VideoCapture(video_path) | |
| fourcc = cv2.VideoWriter_fourcc(*'mp4v') | |
| fps = int(cap.get(cv2.CAP_PROP_FPS)) | |
| width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
| height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
| total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) | |
| cover = cv2.imread(cover_value, cv2.IMREAD_UNCHANGED) | |
| out = cv2.VideoWriter(output_path, fourcc, fps, (cover.shape[1], cover.shape[0])) | |
| progress_bar = st.progress(0) | |
| status_text = st.empty() | |
| processed_frames = 0 | |
| start_time = time.time() | |
| while cap.isOpened(): | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| frame_resized = cv2.resize(frame, (cover.shape[1], cover.shape[0])) | |
| frame_processed = overlay_image(frame_resized, cover) | |
| out.write(frame_processed) | |
| processed_frames += 1 | |
| elapsed_time = time.time() - start_time | |
| estimated_total_time = (elapsed_time / processed_frames) * total_frames if processed_frames > 0 else 0 | |
| remaining_time = estimated_total_time - elapsed_time | |
| progress = int((processed_frames / total_frames) * 100) | |
| progress_bar.progress(progress) | |
| status_text.text(f"Processing: {progress}% | Estimated Remaining Time: {remaining_time:.2f} sec") | |
| cap.release() | |
| out.release() | |
| status_text.text("Processing Complete!") | |
| st.success("Video Processing Complete!") | |
| def video_tempering_app(): | |
| st.title("Exness Video Tempering App") | |
| cover_option = st.selectbox("Select Video Type:", ["With Banner", "With Multi-Banner", "Without Banner"], index=0) | |
| if cover_option == "Without Banner": | |
| cover_value = "cover.png" | |
| elif cover_option == "With Banner": | |
| cover_value = "cover2.png" | |
| else: | |
| cover_value = "cover3.png" | |
| screenshot_video = st.file_uploader("Upload Screen Recording", type=["mp4"]) | |
| if screenshot_video: | |
| temp_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") | |
| temp_video.write(screenshot_video.read()) | |
| output_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name | |
| with st.spinner("Processing video..."): | |
| process_video(temp_video.name, output_video, cover_value) | |
| st.download_button("Download Processed Video", data=open(output_video, "rb").read(), file_name="processed_video.mp4", mime="video/mp4") | |
| def main(): | |
| app_selection = st.sidebar.radio("Select App", ("Image Tempering", "Video Tempering")) | |
| if app_selection == "Image Tempering": | |
| image_tempering_app() | |
| elif app_selection == "Video Tempering": | |
| video_tempering_app() | |
| if __name__ == "__main__": | |
| main() | |