Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8037

Camera board • Re: "Or Better"?

$
0
0
Here's a script that attempts to create synchronized videos using the PIP method combined with my original script. Let me know if it works for you. (My Pi5 should be here in a few days)
Doesn't work. There seems to be no section of code where video recordings are initiated?
Also, the 'synchronizer' routine appears to be designed to synchronise pairs of images, not video streams, so isn't directly suitable 'as-is'.

Busy time ahead, when the Pi5 arrives.
Good Luck!
Got the Pi5 and 2 cameras.
So, I'm using this code

Code:

import subprocessimport threadingimport os# Set parameters for video capturewidth, height = 1500, 1500fps = 15record_time = 10  # seconds# Output file pathsoutput1 = "camera1.h264"output2 = "camera2.h264"mp4_output1 = "camera1.mp4"mp4_output2 = "camera2.mp4"merged_output = "merged_output.mp4"# Function to record video from one camera using libcamera-viddef record_camera(camera_index, output_file):    libcamera_cmd = [        "libcamera-vid",        "-t", str(record_time * 1000),  # Convert seconds to milliseconds        "-o", output_file,        "--width", str(width),        "--height", str(height),        "--framerate", str(fps),        "--camera", str(camera_index)    ]    subprocess.run(libcamera_cmd)# Record from both cameras in paralleldef record_both_cameras():    thread1 = threading.Thread(target=record_camera, args=(0, output1))  # First camera    thread2 = threading.Thread(target=record_camera, args=(1, output2))  # Second camera    # Start recording    thread1.start()    thread2.start()    # Wait for both threads to finish    thread1.join()    thread2.join()# Convert raw h264 files to mp4 using ffmpegdef convert_to_mp4(input_file, output_file):    ffmpeg_cmd = [        "ffmpeg", "-i", input_file, "-c:v", "copy", output_file    ]    subprocess.run(ffmpeg_cmd)# Merge the two MP4 videos side-by-side using ffmpegdef merge_videos():    ffmpeg_cmd = [        "ffmpeg", "-i", mp4_output1, "-i", mp4_output2,        "-filter_complex", "hstack", "-c:v", "libx264",        "-crf", "23", "-preset", "veryfast", merged_output    ]    subprocess.run(ffmpeg_cmd)# Remove temporary MP4 filesdef clean_up():    try:        os.remove(mp4_output1)        os.remove(mp4_output2)        print(f"Removed {mp4_output1} and {mp4_output2}")    except OSError as e:        print(f"Error: {e.filename} - {e.strerror}")if __name__ == "__main__":    # Record videos from both cameras    record_both_cameras()    # Convert the raw h264 videos to mp4    convert_to_mp4(output1, mp4_output1)    convert_to_mp4(output2, mp4_output2)    # Merge the two mp4 videos side by side    merge_videos()    # Clean up by removing the temporary MP4 files    #clean_up()    print(f"Recording completed and videos merged into {merged_output}")
The problem is all mp4 files have a time of 0, thus the "merged" video, while side by side has a play length of 0.

Statistics: Posted by MRV — Fri Oct 11, 2024 9:09 am



Viewing all articles
Browse latest Browse all 8037

Trending Articles