Pineapple Pinephone pic

Nothing new in base software today, so had some time to put up a quick hack for using the camera on the phone itself, via the local web browser.  Slow, and still cannot see what you are taking a picture of, until you hit the URL

using tmux, run an INSECURE local python http.server with cgi in one session:

python3 -m http.server --cgi

then in a cgi-bin directory execute the shell scripts to execute commands (again using my fire tablet to take picture of the phone).  Got to http://127.0.0.1:8000/cgi-bin/testpic

Note: this is all local to system, as the documentation says: Not For Production
especially if you have data enabled.  Once the camera app is working, will be unnecessary.  Also, have noticed sometimes the python server will get “stuck”, and need to go back to the tmux session and hit CTRL-C a couple of times to “unstick”.  Is a linux machine, so assume one could install a “real” http server.

Added side effect (**insecure**), you can see and take pictures from your laptop, if you are on the same network, change 127.0.0.1 to whatever ip the phone is on.

the cgi-bin/testpic script (or whatever you called it) looks something like this

#!/usr/bin/env python3

import os
import subprocess
from datetime import datetime

cmd='/home/phablet/bin/preview >> /tmp/pic.log 2>>/tmp/pic.err'
subprocess.call([cmd], shell=True)

print("Content-type: text/html")
print("")
print("""<html><body>
<h1>PinePhone</h1>
<a href="/Pictures">Pictures</a>
<br />
<hr />
<br />
<a href="/">Root</a>
<br />
<hr />
<br />
<center>
    <img src='/Pictures/preview.jpg' >
    <br />
    <form action="/cgi-bin/pictest">
        <button type="submit" style="font-size : 20px; width: 100%; height: 50px;">pictest</button>
   </form>
   <br />
      """)
timenow = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(timenow,"</center></body></html>")

and the preview script, in the bin dir.

#!/bin/bash
fname=$(date +"%Y%m%dT%H%M%S")
media-ctl -d /dev/media1 --set-v4l2 '"ov5640 3-004c":0[fmt:UYVY2X8/320x240]'
ffmpeg -f rawvideo -pixel_format yuv420p -s 320x240 -f video4linux2 -i /dev/video1 -vframes 1 ~/Pictures/$fname.jpg
convert ~/Pictures/$fname.jpg -rotate 90 ~/Pictures/preview.jpg 

before the script above will run, need to give permissions to read/write the camera

sudo chmod 777 /dev/media1
sudo chmod 777 /dev/video1

and as previously mentioned, need to update the ffmpeg libraries, and install the utilities

sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt update
sudo apt install ffmpeg
sudo apt install v4l-utils
sudo apt install imagemagick
This entry was posted in tech. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s