Skip to content

Commit

Permalink
Fix bug where audio metadata "timeReference"-samples aren't set corre…
Browse files Browse the repository at this point in the history
…ctly

Due to a wrong conditional they were always set to 0.
Additionally an interface for the emtadata field "audiosamplerate" is added.
  • Loading branch information
Agrarvolution committed Feb 2, 2024
1 parent 7297a15 commit 5781010
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/jsx/KBRG/ThumbnailMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,18 @@ ThumbnailMetadata.prototype.extractMetadata = function () {
* @returns {object} containing ending, samples, sample frequency and bitrate
*/
ThumbnailMetadata.extractAudioMetadata = function (xmp) {
var audioEncoding = xmp.getProperty(XMPConst.NS_BWF, "codingHistory").value || '';

var sampleFrequency = audioEncoding.match(/F=\d+/g);
if (sampleFrequency == null || sampleFrequency.length) {
sampleFrequency = 0;
} else {
sampleFrequency = Number(sampleFrequency[0].replace('F=', ''));
var sampleFrequency = 0;
if (xmp.doesPropertyExist(XMPConst.NS_DM, 'audioSampleRate')) {
sampleFrequency = xmp.getProperty(XMPConst.NS_DM, 'audioSampleRate').value || '';
} else if (xmp.doesPropertyExist(XMPConst.NS_BWF, 'codingHistory')) {
var audioEncoding = xmp.getProperty(XMPConst.NS_BWF, 'codingHistory').value || '';
audioEncoding = audioEncoding.match(/F=\d+/g).toString();

if (audioEncoding.length === 0) {
sampleFrequency = 0;
} else {
sampleFrequency = Number(audioEncoding.replace('F=', ''));
}
}

var bitRate = audioEncoding.match(/W=\d+/g);
Expand Down Expand Up @@ -142,7 +147,7 @@ ThumbnailMetadata.extractTimecodeMetadata = function (xmp) {

var prevFramerate = 0;
if (timecodeStruct !== '' && xmp.doesStructFieldExist(XMPConst.NS_DM, timecodeStruct, XMPConst.NS_DM, this.PREVIOUS_TIME_FORMAT)) {
prevFramerate = this.checkMetadataFramerate(xmp.getStructField(XMPConst.NS_DM, timecodeStruct, XMPConst.NS_DM, this.PREVIOUS_TIME_FORMAT).value || '');
prevFramerate = this.checkMetadataFramerate(xmp.getStructField(XMPConst.NS_DM, timecodeStruct, XMPConst.NS_DM, this.PREVIOUS_TIME_FORMAT).value || '');
}

var prevStartTime = new Timecode();
Expand Down Expand Up @@ -313,8 +318,10 @@ ThumbnailMetadata.prototype.updateTimecodeMetadata = function (newStartTime) {
ThumbnailMetadata.PREVIOUS_TIME_VALUE, this.timecodeMetadata.prevStartTime.toString());

if (this.audioMetadata) {
this.audioMetadata.samples = this.timecodeMetadata.startTime.toSamples(this.audioMetadata.sampleFrequency);

this.xmp.setProperty(XMPConst.NS_BWF, "timeReference",
this.timecodeMetadata.startTime.toSamples(this.audioMetadata.sampleFrequency).toString(), XMPConst.STRING);
this.audioMetadata.samples.toString(), XMPConst.STRING);
}
if (this.updateThumbnailMetadata()) {
return true;
Expand Down

0 comments on commit 5781010

Please sign in to comment.