-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformats_h33.py
More file actions
1 lines (1 loc) · 2.04 KB
/
formats_h33.py
File metadata and controls
1 lines (1 loc) · 2.04 KB
1
import numpy as np\nimport cv2\nimport os\nimport subprocess\n\ndef read_input_file(file_path):\n with open(file_path, 'rb') as f:\n return f.read()\n\ndef byte_to_color(byte):\n return (byte, byte, byte)\n\ndef generate_video_frames(data, frame_size=(640, 640), grid_size=(16, 16)):\n square_size = frame_size[0] // grid_size[0]\n frames = []\n for i in range(0, len(data), grid_size[0] * grid_size[1]):\n frame = np.zeros((frame_size[0], frame_size[1], 3), dtype=np.uint8)\n for j in range(grid_size[0]):\n for k in range(grid_size[1]):\n byte_index = i + j * grid_size[1] + k\n if byte_index < len(data):\n color = byte_to_color(data[byte_index])\n cv2.rectangle(frame, (k * square_size, j * square_size), ((k + 1) * square_size, (j + 1) * square_size), color, -1)\n frames.append(frame)\n return frames\n\ndef create_video(frames, output_path, fps=30):\n height, width, _ = frames[0].shape\n fourcc = cv2.VideoWriter_fourcc(*'mp4v')\n video_writer = cv2.VideoWriter(output_path, fourcc, fps, (width, height))\n for frame in frames:\n video_writer.write(frame)\n video_writer.release()\n\ndef combine_video_with_audio(video_path, audio_path, output_path):\n command = ['ffmpeg', '-i', video_path, '-i', audio_path, '-c:v', 'copy', '-c:a', 'aac', '-strict', 'experimental', output_path]\n subprocess.run(command)\n\ndef main(input_file, audio_file, output_video, output_combined):\n data = read_input_file(input_file)\n frames = generate_video_frames(data)\n create_video(frames, output_video)\n combine_video_with_audio(output_video, audio_file, output_combined)\n\nif __name__ == '__main__':\n input_file = 'input.bin' # Adjust this path to your needs\n audio_file = 'audio.mp3' # Adjust this path to your needs\n output_video = 'output.mp4' # Output video file name\n output_combined = 'output_combined.mp4' # Combined output file name\n main(input_file, audio_file, output_video, output_combined)\n