Author Topic: New PTP Camera Controller App for Android  (Read 2192 times)

petabyte

  • Freshman
  • **
  • Posts: 89
New PTP Camera Controller App for Android
« on: September 16, 2022, 03:21:50 AM »
I've been working on a PTP (Picture Transfer Protocol) library in C lately, with the main intent of making a DSLR controller Android app out of it.

Features that will come in the first release:
- Get Live EOS viewfinder image (can't use while recording)
- Interface with ML - Live screen data (320x240, see all Canon menus and ML menus while recording RAW or MOV)
  Not a solid replacement for HDMI, but useful (in case you don't have a HDMI adapter, or it blocks the USB port)
  Currently 15fps - should be possible to optimize (see https://github.com/petabyt/ptpview)
- Scripting in Javascript (scripts can run on demand or in background)
- Get live aperture+ISO+shutter speed+image format+battery
- Raise flash
- Take pictures and do BULB shots
- Image/File explorer
- Extensive settings and customization
- Plugins/mods/scripts written in Javascript (run on demand or in background, can modify UI)
- Script generator (timelapse)

Here are features I'll probably add in the future, other than the typical features you'd expect in a camera app:
- Sync camera video start time with phone, use internal phone mic as camera mic
- ML Like overlays over live view
Looking for suggestions :) - I only do astrophotography with my camera, so the feature set will be biased.

- The app will not only run on Android, but Linux too (as a web server). It would be possible to connect a Raspberry Pi to your DSLR and control your camera from inside (or technically, anywhere in the world)
- iOS support is not out of the question, but it would be a learning curve. I've never used an modern Apple device apart from when I fixed them, and I don't know how iOS apps are made.
- It's worth noting that the PTP library I made is very portable (and open source, https://github.com/petabyt/camlib) and can easily be compiled and ported to different platforms.
- The user interface for the app is written in HTML/CSS/JS and is layered over a graphics canvas, where the liveview is drawn. The app is mostly C and Javascript. Under 500 lines of Java code is required the the entire app to work.

Skinny

  • Member
  • ***
  • Posts: 204
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #1 on: September 16, 2022, 09:41:46 AM »
I think it is a great idea. :) If you can make DSLR controller compatible with ML - it can replace hdmi monitors and remote control.

For extra features...
  • An option to see clearly if something is connected to the USB and if DSLR is detected, etc. so - detailed status information. Because with existing android apps it is really hard to tell if everything is connected and why it doesn't work sometimes.. Especially if I'm trying to use long cables and so on.
  • And if connection with the camera is lost, reconnect everything automatically..
  • Probably at least some compatibility with ML raw..
  • It could be very cool if the app can trick the phone to think that the DSLR is one of built-in android cameras, if it is possible at all. With this option it will be very fast and easy to take a picture with DSLR and immediately upload it on social media such an instagram for example, without saving and transfering the file. Like it is native phone camera.

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #2 on: September 16, 2022, 03:25:59 PM »
All great ideas. When I was testing, the PTP liveview cut off when I started recording RAW or MOV. There's a slim chance there's a way around this, but I'm not sure.
A packet transmission status was exactly what I was thinking of, maybe an icon in the bottom that lights up green when packets are being received or sent.

names_are_hard

  • Developer
  • Hero Member
  • *****
  • Posts: 582
  • 200D idiot
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #3 on: September 16, 2022, 05:30:33 PM »
Per cam profiles could be nice.  Assumes there is some unique cam ID you can get, I guess likely.  Not sure what people would use them for since it depends on what other features you implement :)

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #4 on: September 16, 2022, 05:47:16 PM »
That would be pretty easy, would just have to copy the device name and serial number.

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #5 on: September 16, 2022, 07:39:25 PM »
I'm also very slowly working on LibUSB and WinUSB backends for this lib, so chances are it might find it's way into https://github.com/petabyt/mlinstall/ someday

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #6 on: November 11, 2022, 03:21:02 AM »
Updates:
- Implemented screen liveview https://www.youtube.com/watch?v=daW97UECLEo
Very slow, ~5fps transferring 259k per frame, should eventually be improved to ~30fps (?)
- MOV recording is possible while transmitting screen data - haven't tested RAW yet
- Base code for the app is implemented - stable data transmission, connecting/disconnecting, working backend (hardest part finished)
- It's written mostly in C99, which communicates with some Java code via JNI. The frontend will be written in JS/HTML/CSS (WebView), which will be transparent over the graphical canvas element.
- The app will allow custom JS scripts to be run/loaded to provide extra functionality - this is where ML interconnectivity can be implemented.
- The app will be sold on Google Play.
- While I'm working on the Android/Java backend, I'm also working on a LibUSB backend (WinUSB soon, hopefully) and implementing a browser based version.
Eventually, a WiFi connected raspberry pi could be plugged into the camera, which would host a control panel that could be accessed by any device on the same network.

TODO List:
- Design modern user interface, find icons
- Implement ~10 PTP opcodes
- Implement ~30 canon/eos opcodes
- Implement parsing/packing of object structures + into/from JSON
- Ensure LibUSB backend is reliable/stable
- Design a PTP API for Javascript
- Implement PTP/IP support - I think it's less complicated than USB, but painfully unreliable
- Sort out JPEG decoding/encoding
- Decide on a good name... currently "CamControl"

koljanych

  • New to the forum
  • *
  • Posts: 8
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #7 on: November 12, 2022, 10:11:18 PM »
what do you think about Canon XC Protocol ?

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #8 on: November 12, 2022, 11:58:37 PM »
what do you think about Canon XC Protocol ?
Never heard of it

Johnny78

  • Just arrived
  • *
  • Posts: 1
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #9 on: November 15, 2022, 08:25:28 AM »
what do you think about Canon XC Protocol ?

What is this protocol ? Like @petabyte, I've never heard of it.

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #10 on: November 15, 2022, 03:58:43 PM »
Quick google search shows it's a completely new IP based protocol created by Canon, for their very high end cameras.
Has nothing to do with PTP, so this app will never support it. Even if I could support it, I'm nowhere near getting my hands on a $2000 cinema camera.

Whr

  • New to the forum
  • *
  • Posts: 25
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #11 on: December 01, 2022, 04:28:36 PM »
I have an idea
Is it possible to write GPS information to the photo EXIF via the phone GPS? I think this would be useful for travel photography
500D 1.1.1 & X-T3

domasa

  • Member
  • ***
  • Posts: 112
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #12 on: December 01, 2022, 05:08:08 PM »
+ date and time synchronization

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #13 on: December 01, 2022, 07:35:59 PM »
Time sync is possible I think. GPS - I don't know. Would be vendor specific I guess.
Still working on this consistently - just a time consuming and difficult project.

optikus

  • New to the forum
  • *
  • Posts: 5
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #14 on: December 01, 2022, 07:47:39 PM »
Hello,

it would be very useful to implement "B" (in B-mode) with unlimited time via USB/Wifi on those cameras, which cannot perform "B" correctly as the "M" and others where it is blocked in EOS-Utility-software.

Kind regards
Jöerg

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #15 on: December 01, 2022, 11:32:55 PM »
Bulb mode is easy to implement, at least for Canon. Trying to design everything so a Nikon/Sony/Fuji extension would be as easy as possible.

Whr

  • New to the forum
  • *
  • Posts: 25
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #16 on: December 02, 2022, 11:36:53 AM »
Time sync is possible I think. GPS - I don't know. Would be vendor specific I guess.
Still working on this consistently - just a time consuming and difficult project.

Maybe there's some other way to achieve the GPS function. It just works as a GPS logger, recording phone location every minute(or at a specific time). When users use their phone to output photos from the camera, the app will automatically write the location to EXIF. At the same time, the software can export the location information for a time period as a separate file and the user can write the photo location information in batches on the computer using ExifTool.
500D 1.1.1 & X-T3

petabyte

  • Freshman
  • **
  • Posts: 89
Re: Brainstorming features for a PTP/USB/IP Android App
« Reply #17 on: December 02, 2022, 08:00:17 PM »
Maybe there's some other way to achieve the GPS function. It just works as a GPS logger, recording phone location every minute(or at a specific time). When users use their phone to output photos from the camera, the app will automatically write the location to EXIF. At the same time, the software can export the location information for a time period as a separate file and the user can write the photo location information in batches on the computer using ExifTool.
I can say this: whatever the EOS apps can do, I can do.

petabyte

  • Freshman
  • **
  • Posts: 89
Re: New PTP Camera Controller App for Android
« Reply #18 on: December 19, 2022, 04:24:42 AM »
Update:
I've made a lot of progress - bulb works, focus works, mirror flipping works, live get/set ISO/aperture/shutter speed/image format is almost done, and liveview works (on Linux and Android)
Now I need to make the HTML/CSS/JS user interface a little better. This is what I'm currently working on:
https://eggnog.theres.life/f/63-sacuojn5xehdxje3rmoz321iachj5c.png
https://eggnog.theres.life/f/64-mkgly30jykmfbj14yh6wq3fah4qi7t.png
Currently I've been testing it mostly in portrait mode, but I think users will be in landscape mode the most (with a phone mounted to the flash mount).
Having both won't be impossible, but it might require a lot of planning and CSS magic (and likely some JS stuff too) to make everything fit properly and not overlap.

So I'm asking a bunch of camera nerds, what UI layout would be optimal? Would you ever use portrait mode? What should I tweak in my current design?

Skinny

  • Member
  • ***
  • Posts: 204
Re: New PTP Camera Controller App for Android
« Reply #19 on: December 19, 2022, 11:05:08 AM »
I think an option to turn the display 90 and 180 degrees as well as mirroring it could be useful in some situations.. What about RAW recording while using your app?

petabyte

  • Freshman
  • **
  • Posts: 89
Re: New PTP Camera Controller App for Android
« Reply #20 on: December 19, 2022, 06:44:24 PM »
I think an option to turn the display 90 and 180 degrees as well as mirroring it could be useful in some situations.. What about RAW recording while using your app?
PTP while recording MOV/MLV is possible. I've hardly tested my custom liveview module (for liveview while recording) but it works while recording both formats. Unstable currently, but works.

petabyte

  • Freshman
  • **
  • Posts: 89
Re: New PTP Camera Controller App for Android
« Reply #21 on: January 29, 2023, 03:08:07 AM »
And finally, after 4 months... I'm still not finished yet.

I've finished most of the features I planned for v0.1.0. ML + EOS Liveview, remote capture/bulb, get/set WB, ISO, shutter speed, aperture, focus lens, basic file manager, etc. I've also got about a dozen other small things I need to implement and test.

I decided to build a new app on top of my existing camlib/camcontrol code. It's a very basic intervalometer app, with a section for JS scripting, standard and bulb capture.
This is mainly a basic tech demo to test my current implementation of PTP, and my understanding of Android USB communication. I've tested it as much as I can, but I haven't fuzz/stress tested it yet, so there's a slight chance it may have some bugs. After stress testing, I will upload it to the play store.

APK Download: https://github.com/petabyt/camlib/releases/tag/caminterv-1


dpjpandone

  • Senior
  • ****
  • Posts: 402
Re: New PTP Camera Controller App for Android
« Reply #22 on: Yesterday at 02:09:51 AM »
This has potential to be very useful. Most timelapses I am interested in recording end up with the camera in a very uncomfortable position to have to program the damn intervalometer from the LCD

petabyte

  • Freshman
  • **
  • Posts: 89
Re: New PTP Camera Controller App for Android
« Reply #23 on: Yesterday at 07:48:26 PM »
Thanks. Hopefully will have WiFi support for the next release. I know how to do it, but it would be tedious. iOS support is also theoretically possible, just need to get my hands on a mac and iphone.