centos 在PHP中从相机电影(MOV文件)获取方向?

lx0bsm1f  于 2022-11-07  发布在  PHP
关注(0)|答案(1)|浏览(292)

我已经从iPhone上传了我的照片和电影到我的CentOS网络服务器,现在我想在我的主页上显示它们(我希望它们在本地托管--而不是通过iCloud)。照片没有问题,因为我可以通过exif访问它们的数据,但电影文件似乎不那么容易。
我的服务器是CentOSApache,我正在使用PHP 8.1,现在我计划只包括我的iPhone的东西,但当然,它可以预期,我会从其他相机上传也稍后。
我需要这个方向的原因是我将把它封装到Bootstrap 4.6中,让它自动响应。我将这样做:
横向电影格式(注意16by9):

<div class='embed-responsive embed-responsive-16by9'>
<video poster='mythumbnail.jpg' controls preload='metadata'>
<source src='mymovie.mov' type='video/mp4' />
<span style='background-color:red;color:white;'>(your browser cannot show this video)</span>
</video>
</div>

人像电影格式(注意9by16):

<div class='embed-responsive embed-responsive-9by16'>
<video poster='mythumbnail.jpg' controls preload='metadata'>
<source src='mymovie.mov' type='video/mp4' />
<span style='background-color:red;color:white;'>(your browser cannot show this video)</span>
</video>
</div>

有没有人对如何从MOV文件中获得方向有什么好主意?:-)

jaql4c8m

jaql4c8m1#

直到有人提供了一个更好的,理想的本地PHP解决方案,那么我将接受这个答案的基础上@CBroe的评论。
PHP不容易提供查询视频文件的元数据的可能性,但在CentOS(和其他Linux发行版)中使用mediainfo应用程序是一种可能性,它将能够查询大量文件的媒体类型和一些元信息。这对于图片、视频和音频文件是如此,但也可以是PDF文件和其他文件。
要在PHP中实现这一点,可以使用exec--同时确保使用escapeshellarg转义命令参数,以确保shell的安全:

$param = escapeshellarg("myfile.mov"); // make sure the argument is safe to pass
exec("mediainfo $param", $outputArray); // store line-by-line output in an array

mediainfo将输出类似于以下内容的内容,其中的每一行都将位于$outputArray数组变量中:

Array
(
    [0] => General
    [1] => Complete name                            : /myfolder/MVI_0447.mov
    [2] => Format                                   : MPEG-4
    [3] => Format profile                           : QuickTime
    [4] => Codec ID                                 : qt   2007.09 (qt  /CAEP)
    [5] => File size                                : 163 MiB
    [6] => Duration                                 : 1 min 4 s
    [7] => Overall bit rate                         : 21.1 Mb/s
    [8] => Encoded date                             : UTC 2014-08-10 15:32:22
    [9] => Tagged date                              : UTC 2014-08-10 15:32:22
    [10] => CNTH                                     : ?^P??#?k??T???o?2p com.apple.quicktime.make                 : Canon
    [12] => com.apple.quicktime.model                : Canon IXUS 135
    [13] => com.apple.quicktime.rating.user          : 0.000
    [14] => 
    [15] => Video
    [16] => ID                                       : 1
    [17] => Format                                   : AVC
    [18] => Format/Info                              : Advanced Video Codec
    [19] => Format profile                           : Baseline@L4.1
    [20] => Format settings                          : 1 Ref Frames
    [21] => Format settings, CABAC                   : No
    [22] => Format settings, Reference frames        : 1 frame
    [23] => Format settings, GOP                     : M=1, N=12
    [24] => Codec ID                                 : avc1
    [25] => Codec ID/Info                            : Advanced Video Coding
    [26] => Duration                                 : 1 min 4 s
    [27] => Bit rate                                 : 19.5 Mb/s
    [28] => Width                                    : 1 280 pixels
    [29] => Height                                   : 720 pixels
    [30] => Display aspect ratio                     : 16:9
    [31] => Frame rate mode                          : Constant
    [32] => Frame rate                               : 25.000 FPS
    [33] => Color space                              : YUV
    [34] => Chroma subsampling                       : 4:2:0
    [35] => Bit depth                                : 8 bits
    [36] => Scan type                                : Progressive
    [37] => Bits/(Pixel*Frame)                       : 0.848
    [38] => Stream size                              : 151 MiB (93%)
    [39] => Language                                 : English
    [40] => Encoded date                             : UTC 2014-08-10 15:32:22
    [41] => Tagged date                              : UTC 2014-08-10 15:32:22
    [42] => Color range                              : Full
    [43] => Color primaries                          : BT.709
    [44] => Transfer characteristics                 : BT.709
    [45] => Matrix coefficients                      : BT.601
    [46] => Codec configuration box                  : avcC
    [47] => 
    [48] => Audio
    [49] => ID                                       : 2
    [50] => Format                                   : PCM
    [51] => Format settings                          : Little / Signed
    [52] => Codec ID                                 : sowt
    [53] => Duration                                 : 1 min 4 s
    [54] => Bit rate mode                            : Constant
    [55] => Bit rate                                 : 1 536 kb/s
    [56] => Channel(s)                               : 2 channels
    [57] => Channel layout                           : L R
    [58] => Sampling rate                            : 48.0 kHz
    [59] => Bit depth                                : 16 bits
    [60] => Stream size                              : 11.9 MiB (7%)
    [61] => Language                                 : English
    [62] => Encoded date                             : UTC 2014-08-10 15:32:22
    [63] => Tagged date                              : UTC 2014-08-10 15:32:22
    [64] => 
    [65] => 
)

然后,这是你解释-并处理坏元数据的许多可能性,当使用各种相机源或媒体:-)例如,对于图片文件,我只使用mediainfo来确定它是一个图片文件,然后我通过exif_read_data传递数据,因为这是更详细的。

不过有一个小注意-对于我的特定设置,exec似乎在丹麦国家字符方面有一些问题,因为它无法读取包含这些字符的文件。我希望这与一些字符编码问题有关,但从未发现这一点-查看PHP "exec" cannot access filenames which have national Danish characters?了解详细信息。

相关问题