Top Banner
Ruby Meets Sony Camera Remote API 簡煒航 Jian Weihang @tonytonyjan
83

Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Aug 06, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby Meets Sony Camera Remote API

簡煒航 Jian Weihang @tonytonyjan

Page 2: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Bonjour

Page 3: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

About me

Page 4: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.
Page 5: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

簡煒航 Jian, Weihang

Page 6: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan.net

Page 7: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan

Page 8: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan

Page 9: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan

Page 10: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan

Page 11: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan

Page 12: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

tonytonyjan

Page 13: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Double Keyboard Player

Page 14: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby

Page 15: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Postgraduate

Page 16: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Freelancer

Page 17: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Book Writer

Page 18: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Coach of Rails Girls Taipei

Page 19: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Startupbrainana.com

5xruby.tw

Page 20: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Taiwan

Page 21: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

臺灣(Taiwan)

Page 22: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

臺灣(Taiwan)

Page 23: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

2015-02-18

Montreal Taipei

-18°C 19°C

Page 24: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Happy Chinese New YearIt’s Year of the RAM Ram

Page 25: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby Meets Sony Camera Remote API

簡煒航 Jian Weihang @tonytonyjan

Page 26: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

6 months ago…

Page 27: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Taipei City New Recreation Center

Page 28: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.
Page 29: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Photo Truck

Page 30: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

CameraScreen

Page 31: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Flow

1. Play a short film.

2. Display camera live preview.

3. Take a picture.

4. Freeze the picture for 5 min

5. Repeat.

Page 32: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.
Page 33: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Â

• ˜

Page 34: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Solutions

Page 35: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Solution to Display

• How about VLC API?

• Easy to control over TCP (gem install vli-client)

• Impossible to add effects (Countdown images, sounds)

• HTML5 over browser seems the first choice.

Page 36: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Solution to Camera Control

• How about gphoto2?

• Supports more than1,800 cameras.

• There is CLI mode.

• Have to repeat capturing preview to stream.

• It’s surprising.

Page 37: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Sony Remote Camera

DSC-QX100

Page 38: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Sony Camera Remote API

• It’s free, and it’s open.

• It’s SSDP + UPnP over Wi-Fi, and it’s open.

• It’s easy (JSON-RPC over HTTP), and it’s open.

• It’s well documented, and it’s open.

Because opening matters

Page 39: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

3 Steps to Access Camera

Page 40: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Device Discovery

Page 41: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Get the API URL

Page 42: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

SSDP

Request

Response

Mandatory

Search Target

Page 43: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Get API URL

Page 44: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

API ExamplesThere are more than 90 APIs

Page 45: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

JSON-RPC 1.0Request Response

Camera Remote API uses JSON-PRC over HTTP POST request.

Page 46: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Take PictureRequest Response

Page 47: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Zoom inRequest Response

Page 48: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Set ExposureRequest Response

Available Modes“Program Auto”, “Aperture, Shutter”,

“Manual”, “Intelligent Auto”, “Superior Auto”

Page 49: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby TimeIntegrate Remote API with Ruby.

Page 50: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Discover Device - 1/2

Page 51: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Discover Device - 2/2

Parse XML to get API URL (using nokogiri or rexml).

Page 52: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Calling API

Page 53: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Live Preview

Page 54: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Get Liveview URLRequest Response

Page 55: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Packet Data Format

Page 56: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Packet Format• Comen Header: 8 bytes

• Payload Header: 128 bytes

• Fist 4 bytes are fixed start code: ”\x24\x35\x68\x79”

• The following 3 bytes is JPEG data size.

• Payload data: depends on JPEG data size.

Page 57: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby TimeProcessing Stream using Ruby

Page 58: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

HTTP Streaming (1/2)

Page 59: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

HTTP Streaming (2/2)

Page 60: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

String#unpackDecodes string, returning array of each value extracted.

Page 61: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Common Header

Page 62: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Common Header (1/2)

Page 63: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Common Header (2/2)

Page 64: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Payload Header

Page 65: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Payload Header (1/2)

Page 66: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Payload Header (2/2)

Page 67: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

gem install bindata

Page 68: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby gem?

Page 69: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

$ gem install sonycamhttps://github.com/tonytonyjan/sonycam

Page 70: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby Usage

Page 71: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

CLI Usage

Page 72: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

CLI Usage

`sonycam liveview` prints streaming data to STDOUT

Page 73: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Record to mp4

Page 74: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Live Streaming

Page 75: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Demo

Page 76: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Friendly Reminder

Page 77: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Secrets in DSC-RX100M2

• Others

• http://10.0.0.1:10000/sony/camera

• DSC-RX 100M2

• http://10.0.0.1:10000/camera

It’s not mentioned in any official document.

Page 78: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Mandatory Extensions (1/2)

Page 79: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Mandatory Extensions (2/2)

MAN REQUIRED by HTTP Extension Framework. Unlike the NTS and ST field values, the field value of the MAN header field is enclosed in double quotes; it defines the scope (namespace) of the extension. MUST be “ssdp:discover".

- Quoted from “UPnP Device Architecture 1.1”

Page 80: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Conclusion

Page 81: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Sony’s Cameras are friendly for developers

Page 82: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Ruby is easy to write even in handling binary

Page 83: Ruby Meets Sony Camera Remote API - tonytonyjan.net · Flow 1. Play a short film. 2. Display camera live preview. 3. Take a picture. 4. Freeze the picture for 5 min 5. Repeat.

Thank You