I'm trying to convert an MP4 video, created using OpenCV, to HLS format using FFmpeg. However, I keep encountering the following error:
moov atom not found [in#0 @ 0x62ea0f9fb500] Error opening input: Invalid data found when processing input.FFmpeg Command:
ffmpeg -i input_file_path -r 30 -g 60 -keyint_min 60 -sc_threshold 0
-c:v libx264 -preset veryfast -profile:v main -level 4.0
-hls_time 2 -hls_list_size 0 -hls_flags delete_segments+append_list+split_by_time+omit_endlist
-hls_segment_filename segment_%03d.ts hls_output_path
Python Code for Creating MP4:
import cv2import tempfileimport osfrom subprocess import callwith tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_file: raw_filename = temp_file.name fourcc = cv2.VideoWriter_fourcc(*'H264') out = cv2.VideoWriter(raw_filename, fourcc, fps, (width, height), True) out.write(cv2.cvtColor(first_frame, cv2.COLOR_RGB2BGR)) for frame in frame_generator: out.write(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)) out.release()with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_file: final_filename = temp_file.namecommand = ['ffmpeg','-y', '-i', raw_filename, final_filename]call(command)with open(final_filename, 'rb') as file: video_bytes = file.read()os.remove(raw_filename)os.remove(final_filename)
Environment:
OS: UbuntuCloud: AWS EC2FFmpeg Version: 6.1.1-3ubuntu5