puhitaku / mtplvcap

Nikon to USB Webcam. Supports older models that Nikon WU does not. Windows/macOS/Linux. No HDMI capture dongle is needed. Ask me on Twitter @puhitaku
https://twitter.com/puhitaku
Other
258 stars 19 forks source link

Not working with D300 #31

Open mochihisa opened 3 years ago

mochihisa commented 3 years ago

I tried to use it on my D300, but it did not work.

[0000]  INFO usb: found: 04b0:041a
[0000]  INFO main: started  
[0002]  WARN lv: workerLV: failed to start live view: the camera is not ready  
[0003]  WARN lv: frameCaptor: failed to decode header  

The environment in which it was run is as follows.

OS : Ubuntu 20.10 Version : v1.2.0

puhitaku commented 3 years ago

Hi,

The shutter won't open if "the camera is not ready" error happens except you change the F value. I'd like to ask you to confirm that it opened after you changed it manually.

On the other hand, I pushed the experimental fix of this problem. Can you build this branch and run it with debug output enabled? mtplvcap -debug mtp,server

puhitaku commented 3 years ago

ping @mochihisa

mochihisa commented 3 years ago

I'm sorry for the late reply. I don't have time right now, so I'll reply later.

mochihisa commented 3 years ago

I'm getting different output than before. Is there any possibility?

[0000]  INFO usb: found: 04b0:041a
[0000] ERROR mtp: fatal error LIBUSB_ERROR_IO; closing connection.
[0000] FATAL mtp: failed to detect MTP devices: could not open 04b0:041a: mtp: no MTP extensions in ''
puhitaku commented 3 years ago

@mochihisa Sorry for inactivity, It looks like the camera is not responding in an earlier stage than the original error message (failed to decode header). no MTP extensions in '' indicates many types of fundamental problems like interfered USB communication, broken USB cables, etc. Please checkout the master branch and see if the problem persists or not.

mochihisa commented 3 years ago

I'm sorry, I'll be late in replying due to periodic exams.

mochihisa commented 3 years ago

Sorry for the late reply. The same result was obtained using the master branch. It seems that the cable is not damaged because it can be used for photo transfer.

yanorei32 commented 2 years ago

I found 4 problems with D300.

  1. Failed to parse 64-byte style header.
    • I think, same as #50
  2. Failed to set f-value (showup an error message).
  3. Failed to set ISO (w/o error message)
  4. Showup invalid resolution.

Environment

Nikon D300 firmware A: 1.01, B: 1.00 libusb 1.0.25-3 go 1.18 linux/amd64 Arch Linux 5.17.1-arch1-1

Issue: Failed to parse 64-byte style header.

Log (Release 1.5.0 and 3bc52d45 are showed same logs):

$ ./mtplvcap -debug mtp,server
[0000]  INFO usb: found: 05ac:821f
[0000]  INFO usb: found: 04b0:041a
[0000]  WARN mtp: detected more than 1 device
[0000]  INFO mtp: opening the detected Nikon DSLR: 04b0:041a
[0000]  INFO main: started
[0000] DEBUG lv: manufacturer = NIKON, product = NIKON DSC D300, serialnumber = 000002014808
[0000] DEBUG lv: model matched: D300
[0001] DEBUG lv: current recording media: SDRAM
[0002]  WARN lv: workerLV: failed to start live view: the camera is not ready
[0003]  WARN lv: frameCaptor: failed to decode header
[0004]  WARN lv: frameCaptor: failed to decode header
[0005]  WARN lv: frameCaptor: failed to decode header

When I change the header size 64 to 96, 128, 192, 256, 384 (mtp/nikon.go), the resolution and frame rate were displayed correctly on localhost:42389 and "failed to decode header" is not show up. But the image remained broken.

I dumped the raw byte array to binary file for debugging.

source code diff ```diff diff --git a/mtp/server.go b/mtp/server.go index 1bb11ba..e89892a 100644 --- a/mtp/server.go +++ b/mtp/server.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "net/http" "strconv" "sync" @@ -778,6 +779,7 @@ func (s *LVServer) getLiveViewImgInner() (LiveView, error) { } raw := buf.Bytes() + _ = ioutil.WriteFile("debug", raw, 0644) lvr := liveViewRaw{} err = binary.Read(bytes.NewReader(raw[8:hs]), binary.BigEndian, &lvr) ```
xxd ``` 0000000 8002 aa01 c010 200b c010 200b 6008 9005 0000010 6001 2001 8c09 9005 ffff ffff 0006 ff00 0000020 0100 0f00 e001 0f0e 0100 ffff ffff ffff 0000030 0000 0000 0000 0000 ffff ffff ffff ffff 0000040 d8ff dbff 8400 0400 0606 0607 0805 0707 0000050 0907 0809 0c0a 0d14 0b0c 0c0b 1219 0f13 0000060 1d14 1f1a 1d1e 1c1a 201c 2e24 2027 2c22 ```

I found SOI marker (ffd8) at 0x40 (64). And I tried get JPEG file with this script.

dd bs=1 skip=64 if=debug of=debug.jpg

This image is correct.

Download debug.zip

debug

I put some bytes (more than or equal 5) to binary.Read and I got works well, But it is dirty hack.

I think liveViewRaw has ommitable element(s).

I need accurate liveViewRaw struct for 64-byte style header.

diff --git a/mtp/server.go b/mtp/server.go
index 1bb11ba..0760695 100644
--- a/mtp/server.go
+++ b/mtp/server.go
@@ -780,7 +780,7 @@ func (s *LVServer) getLiveViewImgInner() (LiveView, error) {
        raw := buf.Bytes()

        lvr := liveViewRaw{}
-       err = binary.Read(bytes.NewReader(raw[8:hs]), binary.BigEndian, &lvr)
+       err = binary.Read(bytes.NewReader(raw[8:hs+5]), binary.BigEndian, &lvr)
        if err != nil {
                return LiveView{}, fmt.Errorf("failed to decode header")
        }

Issue: Failed to set f-value (showup an error message):

I tried to change f-number but I got ERROR (1.5.0 and 3bc52d45).

$ ./mtplvcap -debug mtp,server
...
[0010] DEBUG lv: HandleControl: set ISO: 2500
[0011]  WARN lv: frameCaptor: failed to decode header
[0015]  WARN lv: frameCaptor: failed to decode header
[0016] DEBUG lv: HandleControl: set f-number: 10
[0016] ERROR lv: HandleControl: failed to set f-number: failed to set f-number: RetCode a005
[0016] DEBUG lv: current recording media: SDRAM
[0017]  WARN lv: workerLV: failed to start live view: the camera is not ready
[0018]  WARN lv: frameCaptor: failed to decode header

Issue: Failed to set ISO (w/o error message)

ISO value does not affect the image w/o error message. (check on 3bc52d45 + dirtyhack)

Issue: Showup invalid resolution.

D300 reports original camera resolution (4288x2848) but image resolution is 640x426. (check on 3bc52d45 + dirtyhack) image

Note:

This model's ISO and F-value control does not affect to internal LiveView function's image. F-number and ISO may be out-of-control in LiveView mode.