{"record":{"id":"f638a27353403b12","repo":"ATH-MaaS/Pixelle-Video","slug":"failed-to-create-video-from-image-error-msg","errorCode":null,"errorMessage":"Failed to create video from image: {error_msg}","messagePattern":"Failed to create video from image: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/video.py","lineNumber":675,"sourceCode":"                    t=audio_duration,  # Force video duration to match audio exactly\n                    vcodec='libx264',\n                    acodec='aac',\n                    pix_fmt='yuv420p',\n                    audio_bitrate='192k',\n                    preset='medium',\n                    crf=23,\n                    **{'b:v': '2M'}  # Video bitrate\n                )\n                .overwrite_output()\n                .run(capture_stdout=True, capture_stderr=True)\n            )\n            \n            logger.success(f\"Video created from image: {output} (duration: {audio_duration:.3f}s)\")\n            return output\n        except ffmpeg.Error as e:\n            error_msg = e.stderr.decode() if e.stderr else str(e)\n            logger.error(f\"FFmpeg error creating video from image: {error_msg}\")\n            raise RuntimeError(f\"Failed to create video from image: {error_msg}\")\n    \n    def add_bgm(\n        self,\n        video: str,\n        bgm: str,\n        output: str,\n        bgm_volume: float = 0.3,\n        loop: bool = True,\n        fade_in: float = 0.0,\n        fade_out: float = 0.0,\n    ) -> str:\n        \"\"\"\n        Add background music to video\n        \n        Args:\n            video: Video file path\n            bgm: Background music file path\n            output: Output video file path","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/video.py#L657-L693","documentation":"create_video_from_image builds a video track from a still image (looped for the audio's duration) via ffmpeg. An ffmpeg.Error is re-raised as this RuntimeError with decoded stderr. Failures usually stem from a bad image, bad audio, or encoder unavailability.","triggerScenarios":"Image file missing or in an unsupported format; audio duration probe failing so the loop/duration flags get bad values; libx264 not present in the ffmpeg build; invalid fps/size parameters; output container rejecting the chosen encoder.","commonSituations":"16-bit or CMYK PNGs the encoder rejects; WebP inputs unsupported by older ffmpeg builds; minimal ffmpeg installs (no libx264) in containers; zero-length audio making duration computation fail.","solutions":["Read the FFmpeg stderr in the message for the exact encoder/input error.","Verify the image exists and convert it to a standard RGB PNG/JPG.","Verify the audio file is valid (ffprobe shows an audio stream and finite duration).","Install an ffmpeg build with libx264 (`ffmpeg -encoders | grep 264`) and re-run."],"exampleFix":"// before\nservice.create_video_from_image('slide.webp', 'voice.mp3', 'out.mp4')  # decode/encoder error\n// after\nconvert_image('slide.webp', 'slide.png')  # standard RGB PNG\nassert get_audio_duration('voice.mp3') > 0\nservice.create_video_from_image('slide.png', 'voice.mp3', 'out.mp4')","handlingStrategy":"validation","validationCode":"import ffmpeg\nassert os.path.isfile(image) and os.path.getsize(image) > 0\nassert has_audio_stream(audio)\nassert '264' in subprocess.run(['ffmpeg','-encoders'],capture_output=True,text=True).stdout or True  # warn if libx264 missing","typeGuard":"def is_valid_audio(path: str) -> bool:\n    try:\n        probe = ffmpeg.probe(path)\n        dur = float(probe['format'].get('duration', 0))\n        return any(s.get('codec_type') == 'audio' for s in probe['streams']) and dur > 0\n    except Exception:\n        return False","tryCatchPattern":"try:\n    service.create_video_from_image(image, audio, out)\nexcept RuntimeError as e:\n    if 'Failed to create video from image' in str(e):\n        logger.error(f'image-to-video encode failed: {e}')\n        # convert image to RGB PNG, verify audio, retry\n    else:\n        raise","preventionTips":["Convert images to standard RGB PNG/JPG before use.","Ensure the audio duration is finite and > 0 (it drives the loop length).","Install an ffmpeg build with libx264 in containers.","Verify both inputs with ffprobe in CI before render jobs."],"tags":["ffmpeg","image","encoding"],"backgroundTag":"ffmpeg-encode-failed","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}