### Install LTX-Video Source: https://context7.com/lightricks/ltx-video/llms.txt Clone the repository, set up a virtual environment, and install the package with inference dependencies. ```bash git clone https://github.com/Lightricks/LTX-Video.git cd LTX-Video # Create virtual environment python -m venv env source env/bin/activate python -m pip install -e .[inference] ``` -------------------------------- ### Install LTX-Video with Inference Dependencies Source: https://github.com/lightricks/ltx-video/blob/main/README.md Sets up a Python virtual environment and installs the LTX-Video package with optional inference dependencies. ```bash python -m venv env source env/bin/activate python -m pip install -e .[inference] ``` -------------------------------- ### Clone LTX-Video Repository Source: https://github.com/lightricks/ltx-video/blob/main/README.md Use this command to clone the LTX-Video repository to your local machine. Ensure you have Git installed. ```bash git clone https://github.com/Lightricks/LTX-Video.git cd LTX-Video ``` -------------------------------- ### Image-to-Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt Generate video from a starting image by specifying conditioning media paths and frame positions. The image is used as the first frame. ```python from ltx_video.inference import InferenceConfig, infer # Image-to-video configuration config = InferenceConfig( prompt="The woman slowly turns her head and smiles warmly at the camera. " "Her hair gently moves in the breeze.", pipeline_config="configs/ltxv-13b-0.9.8-distilled.yaml", height=704, width=1216, num_frames=121, frame_rate=30, seed=42, output_path="outputs/", # Conditioning settings conditioning_media_paths=["input_image.jpg"], conditioning_start_frames=[0], # Apply image at frame 0 conditioning_strengths=[1.0], # Full conditioning strength image_cond_noise_scale=0.15, # Noise for motion continuity ) infer(config) ``` -------------------------------- ### Image-to-Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt Use this command for generating video from a single input image and a text prompt. Specify conditioning media paths, start frames, dimensions, number of frames, seed, and pipeline configuration. ```bash python inference.py \ --prompt "The woman turns and smiles warmly" \ --conditioning_media_paths input.jpg \ --conditioning_start_frames 0 \ --height 704 \ --width 1216 \ --num_frames 121 \ --seed 42 \ --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` -------------------------------- ### LTXVideoPipeline with Advanced Generation Options Source: https://context7.com/lightricks/ltx-video/llms.txt Utilize LTXVideoPipeline for fine-grained control over video generation, including spatiotemporal guidance (STG), classifier-free guidance, and custom timestep schedules. This example demonstrates advanced parameters for precise control. ```python from ltx_video.inference import create_ltx_video_pipeline, get_device from ltx_video.utils.skip_layer_strategy import SkipLayerStrategy import torch device = get_device() pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device=device, ) generator = torch.Generator(device=device).manual_seed(12345) # Advanced generation with STG (Spatiotemporal Guidance) result = pipeline( prompt="A vintage car drives along a winding mountain road at golden hour.", negative_prompt="worst quality, inconsistent motion, blurry", height=704, width=1216, num_frames=121, frame_rate=30, num_inference_steps=40, guidance_scale=3.5, # CFG scale (recommended: 3-3.5) stg_scale=1.0, # Spatiotemporal guidance strength rescaling_scale=0.7, # STG rescaling factor skip_layer_strategy=SkipLayerStrategy.AttentionValues, skip_block_list=[19], # Transformer blocks for STG decode_timestep=0.05, # VAE decode timestep decode_noise_scale=0.025, # Noise scale for VAE decoding generator=generator, output_type="pt", vae_per_channel_normalize=True, is_video=True, mixed_precision=False, offload_to_cpu=False, ) video = result.images # (B, C, F, H, W) tensor ``` -------------------------------- ### Multi-Keyframe Conditioning Source: https://context7.com/lightricks/ltx-video/llms.txt Generate video using multiple conditioning media (images or videos) at specified start frames. This allows for more complex temporal control over the generated video. ```bash python inference.py \ --prompt "A dancer performs an elegant spin" \ --conditioning_media_paths start.jpg middle.mp4 end.jpg \ --conditioning_start_frames 0 40 112 \ --height 704 \ --width 1216 \ --num_frames 121 \ --seed 42 \ --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` -------------------------------- ### Set Inference Timesteps for Scheduler Source: https://context7.com/lightricks/ltx-video/llms.txt Set the inference timesteps for the scheduler based on the desired number of inference steps and the shape of the latent samples. This example uses a CUDA device. ```python # Set inference timesteps scheduler.set_timesteps( num_inference_steps=40, samples_shape=(1, 128, 16, 88, 152), # (B, C, F, H, W) latent shape device="cuda", ) print(f"Timesteps: {scheduler.timesteps[:5]}...") # Output: Timesteps: tensor([0.9875, 0.9750, 0.9625, 0.9500, 0.9375], device='cuda:0')... ``` -------------------------------- ### Basic Text-to-Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt Configure and run text-to-video generation using InferenceConfig. Ensure sufficient VRAM or enable offloading to CPU. ```python from ltx_video.inference import InferenceConfig, infer # Basic text-to-video configuration config = InferenceConfig( prompt="A young woman with wavy hair stands outdoors on a foggy day. " "She wears a cozy pink sweater with a serene expression.", negative_prompt="worst quality, inconsistent motion, blurry, jittery, distorted", pipeline_config="configs/ltxv-13b-0.9.8-distilled.yaml", height=704, width=1216, num_frames=121, frame_rate=30, seed=171198, output_path="outputs/", offload_to_cpu=False, # Enable for GPUs with <30GB VRAM ) # Run inference infer(config) # Output: Video saved to outputs/video_output_0_a-young-woman-with-wavy_171198_704x1216x121_0.mp4 ``` -------------------------------- ### Initialize LTXMultiScalePipeline Source: https://context7.com/lightricks/ltx-video/llms.txt Set up the LTXMultiScalePipeline by creating a base pipeline and a latent upsampler. Ensure the correct checkpoint paths and device are specified. ```python from ltx_video.inference import create_ltx_video_pipeline, create_latent_upsampler, get_device from ltx_video.pipelines.pipeline_ltx_video import LTXMultiScalePipeline import torch device = get_device() # Create base pipeline base_pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device=device, ) # Create latent upsampler latent_upsampler = create_latent_upsampler( latent_upsampler_model_path="ltxv-spatial-upscaler-0.9.8.safetensors", device=device, ) # Create multi-scale pipeline pipeline = LTXMultiScalePipeline(base_pipeline, latent_upsampler=latent_upsampler) ``` -------------------------------- ### Basic Text-to-Video Generation via CLI Source: https://context7.com/lightricks/ltx-video/llms.txt Generate a video from a text prompt using the LTX-Video command-line interface. Specify prompt, dimensions, number of frames, seed, and pipeline configuration. ```bash # Basic text-to-video python inference.py \ --prompt "A serene lake at sunset with gentle ripples" \ --height 704 \ --width 1216 \ --num_frames 121 \ --seed 42 \ --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` -------------------------------- ### Create LTXVideoPipeline for Direct Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt Create a configured LTXVideoPipeline instance for programmatic control over video generation. This factory function allows for detailed parameter tuning and batch processing. Ensure the correct device is selected. ```python from ltx_video.inference import create_ltx_video_pipeline, get_device import torch device = get_device() # Returns "cuda", "mps", or "cpu" # Create pipeline with full configuration pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", # Options: "bfloat16", "float8_e4m3fn" text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", sampler="from_checkpoint", # Options: "uniform", "linear-quadratic", "from_checkpoint" device=device, enhance_prompt=False, prompt_enhancer_image_caption_model_name_or_path="MiaoshouAI/Florence-2-large-PromptGen-v2.0", prompt_enhancer_llm_model_name_or_path="unsloth/Llama-3.2-3B-Instruct", ) # Generate video directly generator = torch.Generator(device=device).manual_seed(42) result = pipeline( prompt="A serene lake at sunset with gentle ripples on the water surface.", negative_prompt="worst quality, blurry, jittery", height=704, width=1216, num_frames=121, frame_rate=30, num_inference_steps=40, guidance_scale=3.5, stg_scale=1.0, rescaling_scale=0.7, generator=generator, output_type="pt", # Returns PyTorch tensor vae_per_channel_normalize=True, is_video=True, ) video_tensor = result.images # Shape: (batch, channels, frames, height, width) print(f"Generated video shape: {video_tensor.shape}") # Output: Generated video shape: torch.Size([1, 3, 121, 704, 1216]) ``` -------------------------------- ### Command Line Interface for Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt LTX-Video provides a CLI for quick video generation without writing Python code. ```APIDOC ## Command Line Interface ### Description LTX-Video provides a CLI for quick video generation without writing Python code. ### Method CLI Command ### Endpoint N/A ### Parameters #### Command Line Arguments - **--prompt** (string) - Required - The text prompt for video generation. - **--height** (integer) - Required - The height of the output video. - **--width** (integer) - Required - The width of the output video. - **--num_frames** (integer) - Required - The number of frames in the output video. - **--seed** (integer) - Optional - The random seed for reproducible results. - **--pipeline_config** (string) - Required - Path to the pipeline configuration YAML file. ### Request Example ```bash python inference.py \ --prompt "A serene lake at sunset with gentle ripples" \ --height 704 \ --width 1216 \ --num_frames 121 \ --seed 42 \ --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` ### Response #### Success Response - **Output**: Generated video file saved to disk. ``` -------------------------------- ### Generate Video with Conditioning Media Source: https://context7.com/lightricks/ltx-video/llms.txt Prepare conditioning media tensors and create conditioning items for video generation. Ensure media items are loaded with appropriate dimensions and conditioning strength. ```python media_tensor = load_media_file( media_path="keyframe.jpg", height=height, width=width, max_frames=1, padding=padding, ) # Create conditioning items conditioning_items = [ ConditioningItem( media_item=media_tensor, # Shape: (1, 3, frames, H, W) media_frame_number=0, # Target frame in output conditioning_strength=1.0, # 1.0 = hard conditioning ), ConditioningItem( media_item=load_media_file("end_frame.jpg", height, width, 1, padding), media_frame_number=112, # Near end of video conditioning_strength=0.8, # Softer conditioning ), ] # Generate with conditioning generator = torch.Generator(device=device).manual_seed(42) result = pipeline( prompt="A person walks through a park, birds fly overhead.", height=height_padded, width=width_padded, num_frames=121, frame_rate=30, conditioning_items=conditioning_items, image_cond_noise_scale=0.15, generator=generator, output_type="pt", vae_per_channel_normalize=True, is_video=True, ) ``` -------------------------------- ### create_ltx_video_pipeline - Pipeline Factory Source: https://context7.com/lightricks/ltx-video/llms.txt Create a configured LTXVideoPipeline instance for direct programmatic control over video generation. This provides access to all pipeline parameters and allows batch processing. ```APIDOC ## create_ltx_video_pipeline - Pipeline Factory Create a configured LTXVideoPipeline instance for direct programmatic control over video generation. This provides access to all pipeline parameters and allows batch processing. ### Method POST (implied by `create_ltx_video_pipeline` function usage) ### Endpoint Not explicitly defined, assumed to be an internal function call. ### Parameters #### Request Body (Inferred from `create_ltx_video_pipeline` arguments) - **ckpt_path** (string) - Required - Path to the checkpoint file. - **precision** (string) - Required - Inference precision. Options: "bfloat16", "float8_e4m3fn". - **text_encoder_model_name_or_path** (string) - Required - Name or path of the text encoder model. - **sampler** (string) - Optional - Sampler to use. Options: "uniform", "linear-quadratic", "from_checkpoint". Defaults to "from_checkpoint". - **device** (string) - Required - Device to run the pipeline on (e.g., "cuda", "mps", "cpu"). - **enhance_prompt** (boolean) - Optional - Whether to enhance the prompt. Defaults to False. - **prompt_enhancer_image_caption_model_name_or_path** (string) - Optional - Name or path of the prompt enhancer image caption model. - **prompt_enhancer_llm_model_name_or_path** (string) - Optional - Name or path of the prompt enhancer LLM model. #### Generation Parameters (passed to the pipeline call) - **prompt** (string) - Required - The text prompt for video generation. - **negative_prompt** (string) - Optional - The negative prompt to guide generation away from. - **height** (integer) - Required - The height of the generated video. - **width** (integer) - Required - The width of the generated video. - **num_frames** (integer) - Required - The number of frames in the generated video. - **frame_rate** (integer) - Required - The frame rate of the generated video. - **num_inference_steps** (integer) - Required - Number of diffusion inference steps. - **guidance_scale** (float) - Required - Classifier-free guidance scale (recommended: 3-3.5). - **stg_scale** (float) - Optional - Spatiotemporal guidance strength. - **rescaling_scale** (float) - Optional - STG rescaling factor. - **generator** (torch.Generator) - Optional - PyTorch generator for reproducibility. - **output_type** (string) - Optional - Output type. Options: "pt" (PyTorch tensor). - **vae_per_channel_normalize** (boolean) - Optional - Whether to normalize VAE per channel. - **is_video** (boolean) - Required - Indicates video generation. ### Request Example ```python from ltx_video.inference import create_ltx_video_pipeline, get_device import torch device = get_device() # Returns "cuda", "mps", or "cpu" # Create pipeline with full configuration pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", # Options: "bfloat16", "float8_e4m3fn" text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", sampler="from_checkpoint", # Options: "uniform", "linear-quadratic", "from_checkpoint" device=device, enhance_prompt=False, prompt_enhancer_image_caption_model_name_or_path="MiaoshouAI/Florence-2-large-PromptGen-v2.0", prompt_enhancer_llm_model_name_or_path="unsloth/Llama-3.2-3B-Instruct", ) # Generate video directly generator = torch.Generator(device=device).manual_seed(42) result = pipeline( prompt="A serene lake at sunset with gentle ripples on the water surface.", negative_prompt="worst quality, blurry, jittery", height=704, width=1216, num_frames=121, frame_rate=30, num_inference_steps=40, guidance_scale=3.5, stg_scale=1.0, rescaling_scale=0.7, generator=generator, output_type="pt", # Returns PyTorch tensor vae_per_channel_normalize=True, is_video=True, ) video_tensor = result.images # Shape: (batch, channels, frames, height, width) print(f"Generated video shape: {video_tensor.shape}") # Output: Generated video shape: torch.Size([1, 3, 121, 704, 1216]) ``` ### Response #### Success Response (200) - **images** (torch.Tensor) - The generated video as a PyTorch tensor with shape (batch, channels, frames, height, width). ``` -------------------------------- ### Image-to-Video Generation Inference Source: https://github.com/lightricks/ltx-video/blob/main/README.md Command-line script to generate a video from a given prompt and conditioning image. Ensure to replace placeholders with actual paths and values. ```bash python inference.py --prompt "PROMPT" --conditioning_media_paths IMAGE_PATH --conditioning_start_frames 0 --height HEIGHT --width WIDTH --num_frames NUM_FRAMES --seed SEED --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` -------------------------------- ### Video-to-Video Transformation with InferenceConfig Source: https://context7.com/lightricks/ltx-video/llms.txt Use InferenceConfig to set up parameters for transforming an existing video using img2img/vid2vid techniques. Specify input media path, output directory, and inference settings. ```python from ltx_video.inference import InferenceConfig, infer # Video-to-video configuration config = InferenceConfig( prompt="Transform the scene into a vibrant anime style with " "dramatic lighting and bold colors.", pipeline_config="configs/ltxv-2b-0.9.6-distilled.yaml", height=704, width=1216, num_frames=25, frame_rate=30, seed=42, output_path="outputs/", input_media_path="source_video.mp4", # Video to transform ) infer(config) ``` -------------------------------- ### LTX-Video Inference as a Library Source: https://github.com/lightricks/ltx-video/blob/main/README.md Python code snippet demonstrating how to use the LTX-Video model as a library for inference. Requires importing `infer` and `InferenceConfig`. ```python from ltx_video.inference import infer, InferenceConfig infer( InferenceConfig( pipeline_config="configs/ltxv-13b-0.9.8-distilled.yaml", prompt=PROMPT, height=HEIGHT, width=WIDTH, num_frames=NUM_FRAMES, output_path="output.mp4", ) ) ``` -------------------------------- ### Perform Multi-Scale Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt Generate video using the LTXMultiScalePipeline with two-pass refinement. Configure parameters for both the first and second passes, including timesteps and guidance scales. ```python generator = torch.Generator(device=device).manual_seed(42) # Multi-scale generation with two-pass refinement result = pipeline( prompt="Cinematic shot of ocean waves crashing on rocky cliffs at sunset.", height=704, width=1216, num_frames=121, frame_rate=30, downscale_factor=0.6666666, # First pass at 2/3 resolution first_pass={ "timesteps": [1.0, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250], "guidance_scale": 1, "stg_scale": 0, "rescaling_scale": 1, "skip_block_list": [42], }, second_pass={ "timesteps": [0.9094, 0.7250, 0.4219], "guidance_scale": 1, "stg_scale": 0, "rescaling_scale": 1, "skip_block_list": [42], "tone_map_compression_ratio": 0.6, }, generator=generator, output_type="pt", vae_per_channel_normalize=True, is_video=True, ) ``` -------------------------------- ### LTXVideoPipeline - Direct Pipeline Usage Source: https://context7.com/lightricks/ltx-video/llms.txt The `LTXVideoPipeline` class provides fine-grained control over the diffusion process including spatiotemporal guidance, classifier-free guidance, and custom timestep schedules. ```APIDOC ## LTXVideoPipeline - Direct Pipeline Usage The `LTXVideoPipeline` class provides fine-grained control over the diffusion process including spatiotemporal guidance, classifier-free guidance, and custom timestep schedules. ### Method POST (implied by `LTXVideoPipeline` call) ### Endpoint Not explicitly defined, assumed to be an internal class method call. ### Parameters #### Pipeline Creation Parameters (passed to `create_ltx_video_pipeline`) - **ckpt_path** (string) - Required - Path to the checkpoint file. - **precision** (string) - Required - Inference precision. Options: "bfloat16", "float8_e4m3fn". - **text_encoder_model_name_or_path** (string) - Required - Name or path of the text encoder model. - **device** (string) - Required - Device to run the pipeline on (e.g., "cuda", "mps", "cpu"). #### Generation Parameters (passed to the pipeline call) - **prompt** (string) - Required - The text prompt for video generation. - **negative_prompt** (string) - Optional - The negative prompt to guide generation away from. - **height** (integer) - Required - The height of the generated video. - **width** (integer) - Required - The width of the generated video. - **num_frames** (integer) - Required - The number of frames in the generated video. - **frame_rate** (integer) - Required - The frame rate of the generated video. - **num_inference_steps** (integer) - Required - Number of diffusion inference steps. - **guidance_scale** (float) - Required - Classifier-free guidance scale (recommended: 3-3.5). - **stg_scale** (float) - Optional - Spatiotemporal guidance strength. - **rescaling_scale** (float) - Optional - STG rescaling factor. - **skip_layer_strategy** (SkipLayerStrategy) - Optional - Strategy for skipping layers in STG. - **skip_block_list** (list[int]) - Optional - List of transformer blocks to skip for STG. - **decode_timestep** (float) - Optional - VAE decode timestep. - **decode_noise_scale** (float) - Optional - Noise scale for VAE decoding. - **generator** (torch.Generator) - Optional - PyTorch generator for reproducibility. - **output_type** (string) - Optional - Output type. Options: "pt" (PyTorch tensor). - **vae_per_channel_normalize** (boolean) - Optional - Whether to normalize VAE per channel. - **is_video** (boolean) - Required - Indicates video generation. - **mixed_precision** (boolean) - Optional - Whether to use mixed precision. - **offload_to_cpu** (boolean) - Optional - Whether to offload to CPU. ### Request Example ```python from ltx_video.inference import create_ltx_video_pipeline, get_device from ltx_video.utils.skip_layer_strategy import SkipLayerStrategy import torch device = get_device() pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device=device, ) generator = torch.Generator(device=device).manual_seed(12345) # Advanced generation with STG (Spatiotemporal Guidance) result = pipeline( prompt="A vintage car drives along a winding mountain road at golden hour.", negative_prompt="worst quality, inconsistent motion, blurry", height=704, width=1216, num_frames=121, frame_rate=30, num_inference_steps=40, guidance_scale=3.5, # CFG scale (recommended: 3-3.5) stg_scale=1.0, # Spatiotemporal guidance strength rescaling_scale=0.7, # STG rescaling factor skip_layer_strategy=SkipLayerStrategy.AttentionValues, skip_block_list=[19], # Transformer blocks for STG decode_timestep=0.05, # VAE decode timestep decode_noise_scale=0.025, # Noise scale for VAE decoding generator=generator, output_type="pt", vae_per_channel_normalize=True, is_video=True, mixed_precision=False, offload_to_cpu=False, ) video = result.images # (B, C, F, H, W) tensor ``` ### Response #### Success Response (200) - **images** (torch.Tensor) - The generated video as a PyTorch tensor with shape (batch, channels, frames, height, width). ``` -------------------------------- ### Multi-Condition Video Generation Inference Source: https://github.com/lightricks/ltx-video/blob/main/README.md Command-line script for generating video conditioned on multiple images or video segments. Specify paths and target frame numbers for each condition. Conditioning strength can also be adjusted. ```bash python inference.py --prompt "PROMPT" --conditioning_media_paths IMAGE_OR_VIDEO_PATH_1 IMAGE_OR_VIDEO_PATH_2 --conditioning_start_frames TARGET_FRAME_1 TARGET_FRAME_2 --height HEIGHT --width WIDTH --num_frames NUM_FRAMES --seed SEED --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` -------------------------------- ### Prompt Enhancement for Video Generation Source: https://context7.com/lightricks/ltx-video/llms.txt Enable automatic prompt enhancement using image captioning and LLM models. This expands short prompts into detailed cinematic descriptions for richer video generation. ```python from ltx_video.inference import create_ltx_video_pipeline, InferenceConfig, infer import torch # Create pipeline with prompt enhancement models pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device="cuda", enhance_prompt=True, # Enable enhancement prompt_enhancer_image_caption_model_name_or_path="MiaoshouAI/Florence-2-large-PromptGen-v2.0", prompt_enhancer_llm_model_name_or_path="unsloth/Llama-3.2-3B-Instruct", ) # Short prompt will be automatically enhanced generator = torch.Generator(device="cuda").manual_seed(42) result = pipeline( prompt="A cat on a windowsill", # Short prompt height=704, width=1216, num_frames=121, frame_rate=30, num_inference_steps=40, guidance_scale=3.5, generator=generator, output_type="pt", enhance_prompt=True, # Will expand to detailed cinematic description vae_per_channel_normalize=True, is_video=True, ) # The prompt is enhanced to include details like: # "A fluffy orange tabby cat sits gracefully on a white windowsill, # bathed in warm afternoon sunlight streaming through the glass..." ``` -------------------------------- ### Video Extension Inference Source: https://github.com/lightricks/ltx-video/blob/main/README.md Command-line script to extend an existing video. Input video segments must have a specific frame count (multiple of 8 plus 1), and the target frame number should be a multiple of 8. Replace placeholders with actual values. ```bash python inference.py --prompt "PROMPT" --conditioning_media_paths VIDEO_PATH --conditioning_start_frames START_FRAME --height HEIGHT --width WIDTH --num_frames NUM_FRAMES --seed SEED --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml ``` -------------------------------- ### Multi-Keyframe Conditioning Source: https://context7.com/lightricks/ltx-video/llms.txt Control video generation using multiple keyframes at specific positions. This allows for precise control over scene transitions and character movements. ```python from ltx_video.inference import InferenceConfig, infer # Multi-keyframe configuration config = InferenceConfig( prompt="A dancer performs a graceful spin, starting slow and accelerating. " "The lighting transitions from warm to cool tones.", pipeline_config="configs/ltxv-13b-0.9.8-distilled.yaml", height=704, width=1216, num_frames=121, frame_rate=30, seed=42, output_path="outputs/", # Multiple conditioning items conditioning_media_paths=[ "start_pose.jpg", # Starting frame "mid_sequence.mp4", # Middle sequence (must be 8n+1 frames) "end_pose.jpg", # Ending frame ], conditioning_start_frames=[0, 40, 112], conditioning_strengths=[1.0, 0.8, 1.0], ) infer(config) ``` -------------------------------- ### Video Extension Source: https://context7.com/lightricks/ltx-video/llms.txt Extend existing videos forward or backward by conditioning on video segments. Input video segments must have a specific frame count (8n+1). ```python from ltx_video.inference import InferenceConfig, infer # Video extension configuration config = InferenceConfig( prompt="The scene continues as the camera slowly pans right, " "revealing a mountain landscape in golden hour light.", pipeline_config="configs/ltxv-13b-0.9.8-distilled.yaml", height=704, width=1216, num_frames=121, frame_rate=30, seed=42, output_path="outputs/", # Extend from existing video conditioning_media_paths=["existing_video.mp4"], # Must be 8n+1 frames conditioning_start_frames=[0], ) infer(config) ``` -------------------------------- ### Initialize RectifiedFlowScheduler Source: https://context7.com/lightricks/ltx-video/llms.txt Create a RectifiedFlowScheduler with specified sampler and shifting options. Configure the scheduler for uniform sampling and resolution-dependent timestep shifting. ```python from ltx_video.schedulers.rf import RectifiedFlowScheduler import torch # Create scheduler with uniform sampling scheduler = RectifiedFlowScheduler( num_train_timesteps=1000, sampler="Uniform", # Options: "Uniform", "LinearQuadratic", "Constant" shifting="SD3", # Resolution-dependent timestep shift target_shift_terminal=0.1, ) ``` -------------------------------- ### LTXMultiScalePipeline - High-Quality Multi-Scale Rendering Source: https://context7.com/lightricks/ltx-video/llms.txt The multi-scale pipeline generates videos in two passes: a lower-resolution first pass followed by latent upsampling and refinement for higher quality output. ```APIDOC ## LTXMultiScalePipeline - High-Quality Multi-Scale Rendering ### Description The multi-scale pipeline generates videos in two passes: a lower-resolution first pass followed by latent upsampling and refinement for higher quality output. ### Method POST ### Endpoint /generate/video ### Parameters #### Query Parameters - **prompt** (string) - Required - The text prompt to guide video generation. - **height** (integer) - Required - The height of the output video. - **width** (integer) - Required - The width of the output video. - **num_frames** (integer) - Required - The total number of frames in the output video. - **frame_rate** (integer) - Required - The frame rate of the output video. - **downscale_factor** (float) - Optional - Factor to downscale the video for the first pass. - **first_pass** (object) - Optional - Configuration for the first generation pass. - **timesteps** (list of float) - Optional - Specific timesteps to use. - **guidance_scale** (float) - Optional - Guidance scale for the first pass. - **stg_scale** (float) - Optional - STG scale for the first pass. - **rescaling_scale** (float) - Optional - Rescaling scale for the first pass. - **skip_block_list** (list of integer) - Optional - Blocks to skip during the first pass. - **second_pass** (object) - Optional - Configuration for the second refinement pass. - **timesteps** (list of float) - Optional - Specific timesteps to use. - **guidance_scale** (float) - Optional - Guidance scale for the second pass. - **stg_scale** (float) - Optional - STG scale for the second pass. - **rescaling_scale** (float) - Optional - Rescaling scale for the second pass. - **skip_block_list** (list of integer) - Optional - Blocks to skip during the second pass. - **tone_map_compression_ratio** (float) - Optional - Compression ratio for tone mapping. - **generator** (torch.Generator) - Optional - PyTorch generator for reproducible results. - **output_type** (string) - Optional - The format of the output ('pt' for PyTorch tensors). - **vae_per_channel_normalize** (boolean) - Optional - Whether to normalize VAE per channel. - **is_video** (boolean) - Required - Indicates that video generation is intended. ### Request Example ```python from ltx_video.inference import create_ltx_video_pipeline, create_latent_upsampler, get_device from ltx_video.pipelines.pipeline_ltx_video import LTXMultiScalePipeline import torch device = get_device() base_pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device=device, ) latent_upsampler = create_latent_upsampler( latent_upsampler_model_path="ltxv-spatial-upscaler-0.9.8.safetensors", device=device, ) pipeline = LTXMultiScalePipeline(base_pipeline, latent_upsampler=latent_upsampler) generator = torch.Generator(device=device).manual_seed(42) result = pipeline( prompt="Cinematic shot of ocean waves crashing on rocky cliffs at sunset.", height=704, width=1216, num_frames=121, frame_rate=30, downscale_factor=0.6666666, first_pass={ "timesteps": [1.0, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250], "guidance_scale": 1, "stg_scale": 0, "rescaling_scale": 1, "skip_block_list": [42], }, second_pass={ "timesteps": [0.9094, 0.7250, 0.4219], "guidance_scale": 1, "stg_scale": 0, "rescaling_scale": 1, "skip_block_list": [42], "tone_map_compression_ratio": 0.6, }, generator=generator, output_type="pt", vae_per_channel_normalize=True, is_video=True, ) ``` ### Response #### Success Response (200) - **result** (object) - The generated video data, typically as PyTorch tensors. ``` -------------------------------- ### FP8 Quantized Model Inference Source: https://context7.com/lightricks/ltx-video/llms.txt Utilize an FP8 quantized model for faster inference. This configuration is suitable for scenarios where speed is critical and can be run on consumer hardware. ```bash python inference.py \ --prompt "Ocean waves crash against rocky cliffs" \ --height 704 \ --width 1216 \ --num_frames 121 \ --seed 42 \ --pipeline_config configs/ltxv-13b-0.9.8-distilled-fp8.yaml ``` -------------------------------- ### Perform Scheduler Step During Denoising Source: https://context7.com/lightricks/ltx-video/llms.txt Execute a single step of the scheduler during the denoising loop. This involves providing the model output, current timestep, and sample latents. ```python # Scheduler step during denoising loop noise_pred = torch.randn(1, 128, 16, 88, 152, device="cuda") latents = torch.randn(1, 128, 16, 88, 152, device="cuda") timestep = scheduler.timesteps[0] output = scheduler.step( model_output=noise_pred, timestep=timestep, sample=latents, return_dict=True, stochastic_sampling=False, ) denois ed_latents = output.prev_sample ``` -------------------------------- ### Video-to-Video Transformation Source: https://context7.com/lightricks/ltx-video/llms.txt Transform an existing video using img2img/vid2vid techniques by providing an input media path and adjusting inference steps. ```APIDOC ## Video-to-Video Transformation Transform an existing video using img2img/vid2vid techniques by providing an input media path and adjusting inference steps. ### Method POST (implied by `infer` function usage) ### Endpoint Not explicitly defined, assumed to be an internal function call. ### Parameters #### Request Body (Inferred from `InferenceConfig`) - **prompt** (string) - Required - The text prompt to guide the transformation. - **pipeline_config** (string) - Required - Path to the pipeline configuration file. - **height** (integer) - Required - The height of the output video. - **width** (integer) - Required - The width of the output video. - **num_frames** (integer) - Required - The number of frames in the output video. - **frame_rate** (integer) - Required - The frame rate of the output video. - **seed** (integer) - Required - The random seed for reproducibility. - **output_path** (string) - Required - The directory to save the output video. - **input_media_path** (string) - Required - The path to the input video file for transformation. ### Request Example ```python from ltx_video.inference import InferenceConfig, infer config = InferenceConfig( prompt="Transform the scene into a vibrant anime style with dramatic lighting and bold colors.", pipeline_config="configs/ltxv-2b-0.9.6-distilled.yaml", height=704, width=1216, num_frames=25, frame_rate=30, seed=42, output_path="outputs/", input_media_path="source_video.mp4", # Video to transform ) infer(config) ``` ### Response No explicit response defined, the output is saved to `output_path`. ``` -------------------------------- ### ConditioningItem - Frame Conditioning Source: https://context7.com/lightricks/ltx-video/llms.txt The `ConditioningItem` dataclass defines individual conditioning frames or sequences for precise control over generated video content. ```APIDOC ## ConditioningItem - Frame Conditioning The `ConditioningItem` dataclass defines individual conditioning frames or sequences for precise control over generated video content. ### Method Not applicable, this is a data structure definition. ### Endpoint Not applicable. ### Parameters (for `ConditioningItem`) - **media_path** (string) - Path to the conditioning media file. - **conditioning_scale** (float) - Scale of the conditioning. - **conditioning_frames** (list[int]) - Specific frames to use for conditioning. - **conditioning_type** (str) - Type of conditioning (e.g., 'image', 'video'). ### Request Example (Illustrative, as `ConditioningItem` is part of a larger process) ```python from ltx_video.pipelines.pipeline_ltx_video import ConditioningItem, LTXVideoPipeline from ltx_video.inference import create_ltx_video_pipeline, load_media_file, calculate_padding import torch device = "cuda" pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device=device, ) height, width, num_frames = 704, 1216, 121 height_padded = ((height - 1) // 32 + 1) * 32 width_padded = ((width - 1) // 32 + 1) * 32 padding = calculate_padding(height, width, height_padded, width_padded) # Example of how ConditioningItem might be used (details depend on pipeline implementation) # conditioning_items = [ # ConditioningItem( # media_path="conditioning_frame_0.png", # conditioning_scale=0.8, # conditioning_frames=[0], # conditioning_type='image' # ) # ] # result = pipeline( # prompt="...", # conditioning_items=conditioning_items, # # ... other parameters # ) ``` ### Response Not applicable for a data structure definition. ``` -------------------------------- ### ConditioningItem for Frame Conditioning Source: https://context7.com/lightricks/ltx-video/llms.txt Define individual conditioning frames or sequences using the ConditioningItem dataclass for precise control over generated video content. This is part of setting up precise frame conditioning. ```python from ltx_video.pipelines.pipeline_ltx_video import ConditioningItem, LTXVideoPipeline from ltx_video.inference import create_ltx_video_pipeline, load_media_file, calculate_padding import torch device = "cuda" pipeline = create_ltx_video_pipeline( ckpt_path="ltxv-13b-0.9.8-distilled.safetensors", precision="bfloat16", text_encoder_model_name_or_path="PixArt-alpha/PixArt-XL-2-1024-MS", device=device, ) height, width, num_frames = 704, 1216, 121 height_padded = ((height - 1) // 32 + 1) * 32 width_padded = ((width - 1) // 32 + 1) * 32 padding = calculate_padding(height, width, height_padded, width_padded) ``` -------------------------------- ### Set Custom Timesteps for Distilled Models Source: https://context7.com/lightricks/ltx-video/llms.txt Override the default timesteps with a custom list, suitable for distilled models. Ensure the device is specified. ```python # Custom timesteps for distilled models scheduler.set_timesteps( timesteps=[1.0, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250, 0.4219], device="cuda", ) ``` -------------------------------- ### VAE Encoding and Decoding Source: https://context7.com/lightricks/ltx-video/llms.txt Encode videos into latent space and decode them back to pixel space using the VAE. Ensure the video tensor is normalized to [-1, 1] and specify device and data type. ```python from ltx_video.models.autoencoders.vae_encode import vae_encode, vae_decode from ltx_video.models.autoencoders.causal_video_autoencoder import CausalVideoAutoencoder import torch # Load VAE from checkpoint vae = CausalVideoAutoencoder.from_pretrained("ltxv-13b-0.9.8-distilled.safetensors") vae = vae.to("cuda").to(torch.bfloat16) # Video tensor: (batch, channels, frames, height, width) # Values normalized to [-1, 1] video = torch.randn(1, 3, 121, 704, 1216, device="cuda", dtype=torch.bfloat16) # Encode to latent space latents = vae_encode( media_items=video, vae=vae, vae_per_channel_normalize=True, ) print(f"Latent shape: {latents.shape}") # Output: Latent shape: torch.Size([1, 128, 16, 88, 152]) # Decode back to pixel space decoded_video = vae_decode( latents=latents, vae=vae, is_video=True, vae_per_channel_normalize=True, timestep=torch.tensor([0.05], device="cuda"), # For timestep-conditioned decoder ) print(f"Decoded shape: {decoded_video.shape}") # Output: Decoded shape: torch.Size([1, 3, 121, 704, 1216]) ```