Skip to content
GitHub no longer supports this web browser. Learn more about the browsers we support.
libjpeg-turbo bindings for Elixir
Elixir C
Branch: master
Clone or download
Latest commit c1d9c6b Jan 31, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
c_src/turbojpeg_native Initial commit Jan 31, 2020
fixture Initial commit Jan 31, 2020
lib Remove unnecessary File.write/2 call Jan 31, 2020
test
.formatter.exs Initial commit Jan 31, 2020
.gitignore Initial commit Jan 31, 2020
LICENSE Initial commit Jan 31, 2020
README.md Updated link to hex package Feb 3, 2020
bundlex.exs Initial commit Jan 31, 2020
mix.exs Release v0.1.1 Feb 3, 2020
mix.lock Initial commit Jan 31, 2020

README.md

TurboJPEG

Fast JPEG encoding from raw YUV data using libjpeg-turbo

Installation

This library requires libjpeg-turbo to be installed

Arch linux

sudo pacman -S libjpeg-turbo

Ubuntu/Debian

sudo apt-get install libjpeg-turbo

OSX

brew install libjpeg-turbo

If available in Hex, the package can be installed by adding turbojpeg to your list of dependencies in mix.exs:

def deps do
  [
    {:shmex, "~> 0.2.0"},
    {:turbojpeg, "~> 0.1.0"}
  ]
end

Basic Usage

iex(1)> {:ok, native} = Turbojpeg.Native.create(1920, 1080, 90, :I420)
{:ok, #Reference<0.938325095.2990669826.234059>}
iex(2)> frame = File.read!("fixture/i420.yuv")
<<0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 2, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>
iex(3)> Turbojpeg.Native.to_jpeg(Shmex.new(frame), native)
{:ok,
 %Shmex{
   capacity: 203783,
   guard: #Reference<0.938325095.2990669827.232440>,
   name: "/shmex-00000005607042890133#000",
   size: 203783
 }}
iex(4)> Shmex.to_binary(jpeg)
<<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255,
  219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5,
  10, 7, 7, 6, ...>>
iex(5)> File.write!("test.jpg", Shmex.to_binary(jpeg))
:ok

Membrane Sink Usage

Pleas See the membrane guide before using this.

defmodule Your.Module.Pipeline do
  use Membrane.Pipeline

  @impl true
  def handle_init(location) do
    children = %{
      source: %SomeMembraneSourceModule{location: location},
      decoder: Membrane.Element.FFmpeg.H264.Decoder,
      jpeg_converter: %Turbojpeg.Sink{filename: "/tmp/frame.jpeg", quality: 100},
    }

    links = [
      link(:source) 
      |> to(:decoder) 
      |> to(:jpeg_converter) 
    ]

    spec = %ParentSpec{
      children: children,
      links: links
    }

    {{:ok, spec: spec}, %{}}
  end

end

Copyright and License

Copyright 2020, Binary Noggin

You can’t perform that action at this time.