Exploring the PTP/IP Protocol

Remote Live View using PTP/IP on Canon EOS Cameras

In the final post of the Exploring the PTP/IP Protocol series, you will learn how to use Canon EOS cameras’ remote live view feature, including touch to focus.

Change Live View Output Mode

To change the live view output mode, use a SetPropValue operation with property code 0xd1b0.

Live View Output Modes
0x0: none
0x1: camera
0x2: host
0x3: cameraAndHost

For my use case, I set the output mode to cameraAndHost so the camera’s screen remains functional while the CineRemote app is connected.

Poll Live View Image

When the camera is in host or cameraAndHost live view mode, you can poll a preview image using the GetLiveViewImage (0x9153) operation.

GetLiveViewImage Operation

The GetLiveViewImage request takes three arguments whose meanings I am unaware of, but the values (0x00200000, 0x0, 0x0) captured from a packet sent by the EOS Utility do the trick.

GetLiveViewImage Operation
1e
00
00
00
06
00
00
00
01
00
00
00
53
91
14
00
00
00
00
00
20
00
00
00
00
00
00
00
00
00
Offset
Type
Description
0
Uint32
Length: 30 bytes
4
Uint32
Packet Type: Operation Request (0x06)
8
Uint32
Data Phase: No Data
12
Uint16
Operation: GetLiveViewImage (0x9153)
14
Uint32
Transaction Id: 20
18
Uint32
Unknown Property (0x00200000)
22
Uint32
Unknown Property (0x0)
26
Uint32
Unknown Property (0x0)

Like the GetEvent data operation discussed in a previous post, the camera responds with a StartDataPacket indicating the data size and an EndDataPacket containing a live view image.

Extracting the Live View Payload

The response payload comprises multiple segments containing the image bytes and additional data. Like the GetEventData response, a payload segment starts with length and ID, followed by its content.

Live view payload segment codes
  const image = 0x1;
  const touchAutofocus = 0x8;
  const sensorResolution = 0xe;
  const histogram = 0x11;

The image segment from the Canon EOS 70D is about 160 kb in size and represents a jpeg-encoded image with a resolution of 960x540px. In the CineRemote app, I use an interval of 200ms to poll the live view image, which results in a choppy 5fps preview.

Canon EOS PTP/IP sample live view image
Sample live view image

Touch Autofocus

When using a Canon EOS camera in live view mode, it supports touch to focus. After touching the screen, the camera tracks the subject and attempts to keep it in focus. While active, the display shows a rectangle around the tracked target. Additionally, the camera provides the tracking data within the live view payload.

Parse Touch Autofocus Segment

The TouchAutofocus segment contains a status field and the tracking area.

Touch Autofocus Live View Segment
24
00
00
00
08
00
00
00
01
00
00
00
30
00
00
00
01
00
00
00
50
11
00
00
06
02
00
00
ae
01
00
00
ae
01
00
00
Offset
Type
Description
0
Uint32
Length: 36 bytes
4
Uint32
Segment ID: TouchAutofocus
8
Uint32
Unknown Value
12
Uint32
Autofocus Status: Tracking
16
Uint32
Unknown Value
20
Uint32
X Coordinate
24
Uint32
Y Coordinate
28
Uint32
Autofocus rect width
32
Uint32
Autofocus rect height

The status field describes the tracking mode, e. g. 0x30 for tracking or 0x20 for face tracking.

The tracking area is described by its top left corner coordinates, width, and height. The X and Y coordinates range between zero and the sensor width or height, respectively. Width and height are also represented as a length in pixels since the tracking rectangle can vary in size.

Set Touch Autofocus

Using a 0x915b operation (SetTouchAfPosition), you can alter the position of the touch autofocus rectangle.

SetTouchAutofocus Operation
1e
00
00
00
06
00
00
00
01
00
00
00
5b
91
14
00
00
00
03
00
00
00
ae
03
00
00
03
02
00
00
Offset
Type
Description
0
Uint32
Length: 30 bytes
4
Uint32
Packet Type: Operation Request (0x06)
8
Uint32
Data Phase: No Data
12
Uint16
Operation: SetTouchAfPosition (0x915b)
14
Uint32
Transaction Id: 20
18
Uint32
Unknown Constant (0x03)
22
Uint32
X Coordinate (0x03ae)
26
Uint32
Y Coordinate Property (0x0203)

As parameters, the operation takes a constant of unknown meaning (0x03) and the center of the new tracking point as X and Y coordinates. The bounds of the tracking point coordinates are between zero and the sensor width or height, respectively.

With the information of the current and previous posts at your disposal, you should be able to wirelessly remote control a Canon EOS camera using PTP/IP.

Unless I stumble on another interesting operation, this has been the last post of the series. Next, I want to integrate support for Canon EOS R cameras into the CineRemote app. Luckily, these cameras support Canon’s modern and well-documented wireless API CCAPI.