Skip to content

Commit

Permalink
add support for "peaks" datastream for drawing waveforms
Browse files Browse the repository at this point in the history
  • Loading branch information
pautri committed May 6, 2021
1 parent 085a8c3 commit 6eb96f6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
7 changes: 7 additions & 0 deletions includes/admin.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ function islandora_video_admin(array $form, array &$form_state) {
),
),
);
// PEAKS derivatives.
$form['derivatives']['islandora_video_make_peaks_locally'] = array(
'#type' => 'checkbox',
'#title' => t('Create Peaks datastream locally'),
'#description' => t('Generate a peaks file for audio waveform display (not yet implemented).'),
'#default_value' => variable_get('islandora_video_make_archive', FALSE),
);

return system_settings_form($form);
}
Expand Down
21 changes: 21 additions & 0 deletions includes/derivatives.inc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ function islandora_video_create_mkv(AbstractObject $object, $force = FALSE) {
}
}

/**
* Creates the PEAKS derivative from the given video file.
*
* @param AbstractObject $object
* An AbstractObject representing an object in Fedora.
* @param bool $force
* Whether the derivative generation is being forced.
*
* @return array
* An array describing the outcome of the PEAKS creation.
*
* @see hook_islandora_derivative()
*/
function islandora_video_create_peaks(AbstractObject $object, $force = FALSE) {
// placeholder function, not yet implemented. Needs to generate peaks file in json format using
// "audiowaveform": https://github.com/bbc/audiowaveform
// see https://wavesurfer-js.org/faq/
// probably needs to be a 2-step process, first extracting the audio and then generating the peaks
return;
}

/**
* Create the thumbnail for the given file.
*
Expand Down
11 changes: 11 additions & 0 deletions islandora_video.module
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ function islandora_video_islandora_sp_videocmodel_islandora_derivative() {
'file' => drupal_get_path('module', 'islandora_video') . '/includes/derivatives.inc',
);
}
if (variable_get('islandora_video_make_peaks_locally', TRUE)) {
$derivatives[] = array(
'source_dsid' => NULL,
'destination_dsid' => 'PEAKS',
'weight' => 1,
'function' => array(
'islandora_video_create_peaks',
),
'file' => drupal_get_path('module', 'islandora_video') . '/includes/derivatives.inc',
);
}
return $derivatives;
}

Expand Down
8 changes: 8 additions & 0 deletions theme/theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ function template_preprocess_islandora_video(array &$variables) {

$mime = 'video/mp4';

if (isset($object['PEAKS'])) {
$peaks_url = url("islandora/object/{$object->id}/datastream/PEAKS", array('absolute' => TRUE));
}
else {
$peaks_url = null;
}

$video_params = array(
'pid' => $object->id,
);
Expand All @@ -61,6 +68,7 @@ function template_preprocess_islandora_video(array &$variables) {
$video_params += array(
'mime' => $mime,
'url' => $video_url,
'peaks' => $peaks_url,
);
}
// Thumbnail.
Expand Down
13 changes: 8 additions & 5 deletions xml/islandora_video_ds_composite_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@
<dsTypeModel ID="TECHMD">
<form MIME="application/xml"/>
</dsTypeModel>
<dsTypeModel ID="TN" optional="false">
<dsTypeModel ID="TN" optional="true">
<form MIME="image/jpeg"/>
<form MIME="image/png"/>
<form MIME="image/gif"/>
</dsTypeModel>
<dsTypeModel ID="OGG" optional="false">
<dsTypeModel ID="OGG" optional="true">
<form MIME="video/ogg"/>
</dsTypeModel>
<dsTypeModel ID="MKV" optional="false">
<dsTypeModel ID="MKV" optional="true">
<form MIME="video/x-matroska"/>
</dsTypeModel>
<dsTypeModel ID="TECHMD_FITS" optional="false">
<dsTypeModel ID="TECHMD_FITS" optional="true">
<form MIME="application/xml"/>
</dsTypeModel>
<dsTypeModel ID="MP4" optional="false">
<dsTypeModel ID="MP4" optional="true">
<form MIME="video/mp4"/>
</dsTypeModel>
<dsTypeModel ID="PEAKS" optional="true">
<form MIME="application/json"/>
</dsTypeModel>
</dsCompositeModel>

0 comments on commit 6eb96f6

Please sign in to comment.