FirstLastFrame
A simple Elixir library for extracting the first and last frames from video files. Provides a convenient way to programmatically access key visual elements within your video processing workflows.
Installation
Add first_last_frame to your list of dependencies in mix.exs:
elixir
def deps do
[
{:first_last_frame, "~> 0.1.0"} # Replace with the actual version] end
Then, run mix deps.get to fetch the dependency.
Usage
This library leverages ffmpeg under the hood. Ensure that ffmpeg is installed and accessible in your system's PATH.
Here are some example usages:
1. Extracting frames and saving them to default locations: elixir FirstLastFrame.extract("path/to/your/video.mp4") #=> {:ok, %{first_frame: "path/to/your/video_first.jpg", last_frame: "path/to/your/video_last.jpg"}}
This will extract the first and last frames as JPEG images, saving them in the same directory as the video file, with _first.jpg and _last.jpg suffixes.
2. Extracting frames and specifying output directories: elixir FirstLastFrame.extract("path/to/your/video.mp4", output_dir: "/tmp/frames") #=> {:ok, %{first_frame: "/tmp/frames/video_first.jpg", last_frame: "/tmp/frames/video_last.jpg"}}
This saves the extracted frames to the /tmp/frames directory.
3. Handling errors: elixir case FirstLastFrame.extract("invalid/path/video.mp4") do {:ok, frame_paths} ->
IO.puts "Frames extracted: #{inspect(frame_paths)}"->
IO.puts "Error extracting frames: #{reason}"end
This example demonstrates how to handle potential errors during the extraction process.
4. Piping for streamlined processing: elixir "path/to/your/video.mp4" |> FirstLastFrame.extract(output_dir: "/tmp/frames") |> case do {:ok, frame_paths} ->
IO.puts "Frames extracted: #{inspect(frame_paths)}"->
IO.puts "Error extracting frames: #{reason}"end
This demonstrates using the pipe operator for a more readable and concise workflow.
5. Custom filename suffixes: elixir FirstLastFrame.extract("path/to/your/video.mp4", first_frame_suffix: "_start", last_frame_suffix: "_end") #=> {:ok, %{first_frame: "path/to/your/video_start.jpg", last_frame: "path/to/your/video_end.jpg"}}
Customize the suffixes appended to the base filename for better organization.
Feature Summary
- Easy Extraction: Simplifies the process of extracting the first and last frames from video files.
- Customizable Output: Allows specifying the output directory and filename suffixes for better organization.
- Error Handling: Provides clear error messages for debugging.
- Clean API: Offers a straightforward and easy-to-use API.
- Dependency-Light: Relies on
ffmpeg, a widely available and powerful video processing tool.
License
MIT
This package is part of the first-last-frame ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/video/first-last-frame/