# PhotoToVideoAI
A lightweight Elixir library for programmatically creating simple videos from images using the photo-to-video-ai service. This package provides a convenient way to integrate image-to-video conversion into your Elixir applications.
## Installation
Add `photo_to_video_ai` to your list of dependencies in `mix.exs`:
elixir
def deps do
[
{:photo_to_video_ai, "~> 0.1.0"} # Replace with the latest version
]
end
Then, run `mix deps.get` to fetch the dependencies. You will also need to configure your API key. The recommended approach is to set it as an environment variable:
bash
export PHOTO_TO_VIDEO_AI_API_KEY="YOUR_API_KEY"
Alternatively, you can configure it directly in your application configuration, but this is not recommended for production environments:
elixir
config :photo_to_video_ai, api_key: "YOUR_API_KEY"
## Usage
Here are a few examples of how to use the `PhotoToVideoAI` library.
**Example 1: Basic Video Creation**
elixir
alias PhotoToVideoAI
image_path = "/path/to/your/image.jpg"
case PhotoToVideoAI.create_video(image_path) do
{:ok, video_url} ->
IO.puts("Video created successfully! URL: #{video_url}")
{:error, reason} ->
IO.puts("Error creating video: #{reason}")
end
**Example 2: Specifying Video Duration**
elixir
alias PhotoToVideoAI
image_path = "/path/to/your/image.png"
options = %{duration: 5} # Duration in seconds
case PhotoToVideoAI.create_video(image_path, options) do
{:ok, video_url} ->
IO.puts("Video created successfully! URL: #{video_url}")
{:error, reason} ->
IO.puts("Error creating video: #{reason}")
end
**Example 3: Handling Errors with Pattern Matching**
elixir
alias PhotoToVideoAI
image_path = "/invalid/path/image.gif"
PhotoToVideoAI.create_video(image_path)
|> case do
{:ok, video_url} ->
IO.puts("Video URL: #{video_url}")
{:error, :invalid_image} ->
IO.puts("The provided image is invalid or unsupported.")
{:error, :api_error} ->
IO.puts("An error occurred while communicating with the API.")
{:error, reason} ->
IO.puts("An unexpected error occurred: #{reason}")
end
**Example 4: Using with `with` statement**
elixir
alias PhotoToVideoAI
defmodule MyModule do
def create_and_process_video(image_path) do
with {:ok, video_url} <- PhotoToVideoAI.create_video(image_path),
{:ok, processed_data} <- fetch_processed_data(video_url) do
IO.puts("Processed Data: #{processed_data}")
else
{:error, reason} -> IO.puts("Error: #{reason}")
end
end
defp fetch_processed_data(video_url) do
# Simulate fetching processed data from the video
{:ok, "Data from #{video_url}"}
end
end
MyModule.create_and_process_video("/path/to/image.jpg")
**Example 5: Using pipes for concise code**
elixir
alias PhotoToVideoAI
"/path/to/another_image.jpeg"
|> PhotoToVideoAI.create_video(%{duration: 10})
|> case do
{:ok, video_url} -> IO.puts("Video URL: #{video_url}")
{:error, reason} -> IO.puts("Error: #{reason}")
end
## Features
* **Simple Image-to-Video Conversion:** Easily convert images into short videos.
* **Duration Control:** Specify the desired duration of the generated video.
* **Error Handling:** Robust error handling with informative error messages.
* **API Key Authentication:** Securely authenticate with the photo-to-video-ai service using an API key.
## License
MIT
This package is part of the photo-to-video-ai ecosystem. For advanced features and enterprise-grade tools, visit: https://pvid.app/
Official site links:
- [Photo To Video AI](https://pvid.app/)