Skip to content

Commit

Permalink
Support for additional video metadata (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
gino0631 committed Feb 11, 2018
1 parent 6c017ed commit adafb10
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Added
- Support for additional video metadata
[#12](https://github.com/gino0631/nextcloud-metadata/issues/12)

### Changed
- Display of image metadata improved
- Error handling improved
Expand Down
71 changes: 65 additions & 6 deletions lib/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class MetadataController extends Controller {
255 => 'Other'
);

const FOUR_CC = array(
'avc1' => 'H.264 - MPEG-4 AVC (part 10)'
);

protected $language;

public function __construct($appName, IRequest $request) {
Expand Down Expand Up @@ -80,7 +84,7 @@ public function get($source) {
case 'video/x-matroska':
case 'video/x-msvideo':
if ($sections = $this->readId3($file)) {
$metadata = $this->getAvMetadata($sections);
$metadata = $this->getAvMetadata($sections, $lat, $lon);
// $this->dump($sections, $metadata);
}
break;
Expand Down Expand Up @@ -245,7 +249,7 @@ protected function unpackInt($intel, $data) {
return unpack(($intel? 'V' : 'N').'d', $data)['d'];
}

protected function getAvMetadata($sections) {
protected function getAvMetadata($sections, &$lat, &$lon) {
$return = array();

$audio = $this->getVal('audio', $sections) ?: array();
Expand Down Expand Up @@ -284,8 +288,31 @@ protected function getAvMetadata($sections) {
$this->addValT('Bit rate', $this->language->t('%s kbps', array(floor($v/1000))), $return);
}

if ($v = $this->getVal('author', $quicktime)) {
$this->addValT('Author', $v, $return);
}

if ($v = $this->getVal('copyright', $quicktime)) {
$this->addValT('Copyright', $v, $return);
}

if ($v = $this->getVal('make', $quicktime)) {
$this->addValT('Camera used', $v, $return);
}

if ($v = $this->getVal('model', $quicktime)) {
$this->addValT('Camera used', $v, $return);
}

if ($v = $this->getVal('com.android.version', $quicktime)) {
$this->addValT('Android version', $v, $return);
}

if ($v = $this->getVal('codec', $video)) {
$this->addValT('Video codec', $v, $return);

} else if ($v = $this->getVal('fourcc', $video)) {
$this->addValT('Video codec', $this->formatFourCc($v), $return);
}

if ($v = $this->getVal('bits_per_sample', $video)) {
Expand Down Expand Up @@ -341,6 +368,16 @@ protected function getAvMetadata($sections) {
$this->addValT('Encoding tool', $v, $return);
}

if ($v = $this->getVal('gps_latitude', $quicktime)) {
$lat = $v[0];
$this->addValT('GPS coordinates', $this->formatGpsDegree($lat, 'N', 'S'), $return);
}

if ($v = $this->getVal('gps_longitude', $quicktime)) {
$lon = $v[0];
$this->addValT('GPS coordinates', $this->formatGpsDegree($lon, 'E', 'W'), $return, null, ' ');
}

return $return;
}

Expand Down Expand Up @@ -458,13 +495,13 @@ protected function getImageMetadata($sections, &$lat, &$lon) {

if ($v = $this->getVal('GPSLatitude', $gps)) {
$ref = $this->getVal('GPSLatitudeRef', $gps);
$this->addValT('GPS coordinates', $ref . ' ' . $this->formatGpsCoord($v), $return);
$this->addValT('GPS coordinates', $this->formatGpsCoord($v, $ref), $return);
$lat = $this->gpsToDecDegree($v, $ref == 'N');
}

if ($v = $this->getVal('GPSLongitude', $gps)) {
$ref = $this->getVal('GPSLongitudeRef', $gps);
$this->addValT('GPS coordinates', $ref . ' ' . $this->formatGpsCoord($v), $return, null, ' ');
$this->addValT('GPS coordinates', $this->formatGpsCoord($v, $ref), $return, null, ' ');
$lon = $this->gpsToDecDegree($v, $ref == 'E');
}

Expand Down Expand Up @@ -514,8 +551,12 @@ protected function formatFlashMode($mode) {
}
}

protected function formatGpsCoord($coord) {
$return = $this->evalRational($coord[0]) . '°';
protected function formatFourCc($code) {
return array_key_exists($code, MetadataController::FOUR_CC) ? MetadataController::FOUR_CC[$code] . ' (' . $code .')' : $code;
}

protected function formatGpsCoord($coord, $ref) {
$return = $ref . ' ' . $this->evalRational($coord[0]) . '°';

if (($coord[1] != '0/1') || ($coord[2] != '0/1')) {
$return .= ' ' . $this->evalRational($coord[1]) . '\'';
Expand All @@ -528,6 +569,24 @@ protected function formatGpsCoord($coord) {
return $return;
}

protected function formatGpsDegree($deg, $posRef, $negRef) {
$return = ($deg >= 0) ? $posRef : $negRef;
$deg = abs($deg);

$v = floor($deg);
$return .= ' ' . $v . '°';

$deg = ($deg - $v) * 60;
$v = floor($deg);
$return .= ' ' . $v . '\'';

$deg = ($deg - $v) * 60;
$v = round($deg, 2);
$return .= ' ' . $v . '"';

return $return;
}

protected function gpsToDecDegree($coord, $pos) {
$return = round($this->evalRational($coord[0]) + ($this->evalRational($coord[1]) / 60) + ($this->evalRational($coord[2]) / 3600), 8);

Expand Down

0 comments on commit adafb10

Please sign in to comment.