mobileoverlord

mobileoverlord

Co-author of Nerves

This year I decided to take an impromptu trip to New York to visit the World Maker Faire with my two daughters. Of all the attractions there, the one my youngest daughter (2 years old) can’t stop talking about is The Hand of Man, a 26-foot long hydraulically-actuated hand that picks up cars and drops them. While there, we captured our own video and now all she wants to do is watch it over and over again.

Lately I’ve been doing some testing on the Raspberry Pi Zero with @fhunleth when he mentioned that he put together a simple video player using some demo code from Raspberry Pi. This simple video player would play back video with no sound and boasts 1080p buttery smooth playback. So I decided to create a device that would play back the video on repeat.

Creating a new project

Lets start by generating a new project:

mix nerves.new video_pi --init-gadget
cd video_pi
export MIX_TARGET=rpi0

Next, we will edit the mix.exs file and add a dependency to our target deps

defp deps(target) do
  [
    {:nerves_runtime, "~> 0.6"},
    {:nerves_init_gadget, "~> 0.4"},
    {:rpi_video, github: "fhunleth/rpi_video"}
  ] ++ system(target)
end

Then, fetch out dependencies

mix deps.get

Finally, lets create some firmware and boot it up. Insert an SD card and run:

mix do firmware, firmware.burn

When fwup is finished writing to the SD card, remove it from your computer (fwup automatically ejects the disk) and insert it into your Raspberry Pi Zero. Then, connect a micro USB cable to the USB port labeled: ‘USB’ and not the one labeled: PWR IN. This will allow your computer to interface with the Raspberry Pi. Plug the other end of the USB cable into your computer and wait a bit for it to power up. After a few seconds you should be able to ssh to the device by running:

ssh nerves.local

If successful, you will receive an iex> prompt. To exit the ssh connection and return back to your host, type ~.. See the nerves_init_gadget documentation for more information.

Preparing the video

My video was shot on an iPhone and needed to be transcoded in order to be played back by the video player code. On Mac, you will need ffmpeg which you can install through homebrew.

brew install ffmpeg

Then transcode the video

ffmpeg -i input.mov output.h264

Copying the video to the Pi

With the Raspberry Pi Zero still connected to our machine we need to copy the movie to the device for playback. We can do this using sftp. The reason we are copying the movie using sftp instead of including it in the rootfs_overlay is because of its size. The application data partition has a much larger partition size than the rootfs partitions. Also, if we want to change the video we are playing back, it would be nice to not have to recompile and deploy. Okay, lets put the file on the device. In the following example, you are going to replace /path/to/output_video with the actual path to where your transcoded video is.

cd /path/to/output_video
sftp nerves.local

You should now be connected to the Raspberry Pi with an sftp> prompt. To upload the file:

put output.h264 /root/
bye

Playing the video

To play the video you simply need to call RpiVideo.play("/root/output.h264"). In my case, I simply added a loop to the application start.

spawn(fn -> play_video("/root/output.h264") end)

# later in the file

def play_video(video) do
  RpiVideo.play(video)
  play_video(video)
end

There is a slight blip of the console session that you can see when the video goes to replay. It would be nice to have an option to look the video which would require additional work. If anyone is interested, you can find more about the code at the rpi_video source.

This project is a great way to get up and running quickly with Nerves. With Halloween right around the corner, it is also a neat way to add video to costumes and decorations. Please share any enhancements and ways that you’ve used this in the comments.

Showing Posts 1 to 4

AstonJ

AstonJ

Aww sounds like she really enjoyed the day and it inspired and captured her imagination. Mine is running wild too; I have visions of her creating robots powered by Nerves when she’s older :003: Has she shown an interest in coding yet? :lol:

Thanks for the guide too! Do you think we should create a nerves-guides or nerves-how-to tag (or both!) for threads like this? I think we discussed it somewhere else on the forum but I can’t remember where now :icon_redface:

GregMefford

GregMefford

That’s awesome, @mobileoverlord! :rocket:

@AstonJ I think it would be cool to have a “Project Updates” section or something, where people could maintain a thread for their project as they work on it.

AstonJ

AstonJ

Do you mean like this one #your-libraries-projects:projects :003:

GregMefford

GregMefford

Ah, yeah that seems good, and just put a nerves tag on your project to categorize it. :+1:

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews