0

我正在做一个创建照相亭的项目。我有一台相机(佳能 550d)和一台显示我写的网页的触摸屏电脑(运行 ubuntu)。

我正在使用gphoto2从网页中控制我的 DSLR exec(),我可以轻松拍照。

我的问题是我还想在人们拍照之前显示相机的实时预览。现在,我准备好了一个脚本,它在一个无边界窗口中打开一个 MPlayer 实例,该窗口也位于所有内容之上,代码在一个名为的文件中live.sh

#!/bin/bash
gphoto2 --capture-movie --stdout > fifo.mjpg & mplayer -cache 32 -demuxer 35 -noborder -geometry 50%:100 -ontop 1 fifo.mjpg

基本上 gphoto2 流到 fifo.mjpg 然后 MPlayer 播放该文件。

当我从终端运行它时,一切都很好:

bash live.sh

如果我从 php 中运行相同的命令,它不起作用

exec("bash live.sh", $output);

看看我从这两个环境运行时得到的输出

从终端运行(此工作)

MPlayer 1.2.1 (Debian), built with gcc-5.3.1 (C) 2000-2016 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing 1.
File not found: '1'
Failed to open 1.


Playing fifo.mjpg.


libavformat version 56.40.101 (external)
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.

*** Error ***             
An error occurred in the io-library ('Could not claim the USB device'):    Could not claim interface 0 (Device or resource busy). Make sure no other program (gvfs-gphoto2-volume-monitor) or kernel module (such as sdc2xx, stv680, spca50x) is using the device and you have read/write access to the device.
ERROR: Movie capture error... Exiting.
Movie capture finished (0 frames)
libavformat file format detected.
Cannot seek backward in linear streams!
Seek failed
[mjpeg @ 0x7f9cffecb540]Found EOI before any SOF, ignoring
[mjpeg @ 0x7f9cffecb540]Changeing bps to 8
[lavf] stream 0: video (mjpeg), -vid 0
VIDEO:  [MJPG]  1056x704  0bpp  25.000 fps    0.0 kbps ( 0.0 kbyte/s)
Load subtitles in ./
Failed to open VDPAU backend libvdpau_va_gl.so: cannot open shared object file: No such file or directory
[vdpau] Error when calling vdp_device_create_x11: 1
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 56.60.100 (external)
Selected video codec: [ffmjpeg] vfm: ffmpeg (FFmpeg MJPEG)
==========================================================================
Audio: no sound
Starting playback...
[mjpeg @ 0x7f9cffecb540]Found EOI before any SOF, ignoring
[mjpeg @ 0x7f9cffecb540]Changeing bps to 8
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
Movie-Aspect is undefined - no prescaling applied.
[swscaler @ 0x7f9d00c36fa0]bicubic scaler, from yuv422p to yuyv422 using     MMXEXT
[swscaler @ 0x7f9d00c36fa0]using unscaled yuv422p -> yuyv422 special converter
VO: [xv] 1056x704 => 1056x704 Packed YUY2
Movie-Aspect is undefined - no prescaling applied.
VO: [xv] 1056x704 => 1056x704 Packed YUY2
V:   0.5   0/  0 37% 14%  0.0% 0 0 50%

MPlayer interrupted by signal 2 in module: enable_cache



MPlayer interrupted by signal 2 in module: video_read_frame
[mjpeg @ 0x7f9cffecb540]overread 8
[mjpeg @ 0x7f9cffecb540]EOI missing, emulating
V:   0.6   0/  0 36% 13%  0.0% 0 0 50%

Exiting... (Quit)

尽管存在所有错误,但一切都运行得非常好。

这是我从 PHP 中的 exec() 运行时得到的输出(这不起作用):

array(16) {
  [0]=>
    string(71) "MPlayer 1.2.1 (Debian), built with gcc-5.3.1 (C) 2000-2016 MPlayer Team"
  [1]=>
    string(39) "Terminal type `unknown' is not defined."
  [2]=>
    string(0) ""
  [3]=>
    string(10) "Playing 1."
  [4]=>
    string(0) ""
  [5]=>
    string(0) ""
  [6]=>
    string(18) "Playing fifo.mjpg."
  [7]=>
    string(29) "
  Cache fill:  0.00% (0 bytes)"
  [8]=>
    string(0) ""
  [9]=>
    string(40) "libavformat version 56.40.101 (external)"
  [10]=>
    string(33) "libavformat file format detected."
  [11]=>
    string(39) "Cannot seek backward in linear streams!"
  [12]=>
    string(42) "[mjpeg @ 0x7fb771bec540]Changeing bps to 8"
  [13]=>
    string(38) "[lavf] stream 0: video (mjpeg), -vid 0"
  [14]=>
    string(69) "VIDEO:  [MJPG]  1056x704  0bpp  25.000 fps    0.0 kbps ( 0.0 kbyte/s)"
  [15]=>
    string(20) "Load subtitles in ./"
}

如果有人对如何使这项工作有任何想法,我将不胜感激。

谢谢!

4

1 回答 1

0

尝试替换exec脚本popen调用并将其作为后台脚本调用。

pclose(popen("bash live.sh > /dev/null &", 'r'));

这样,代码在与 php.ini 分离的 shell 中执行。这可能有助于 MPlayer 工作。

于 2016-06-26T13:02:28.823 回答