-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds test for BARLT metadata parsing
FLAC custom metadata fields are output as is by ffprobe. Because they did not have an `=` character the `Substring` call in `GetInfo` threw an exception because the `IndexOf` call returned `-1` and that was not a valid index for a string. I've added test audio for a BARLT and a test dedicated to parsing that metadata. At this stage we have no actual use for the metadata.
- Loading branch information
Showing
9 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// <copyright file="FfmpegUtilityTests.cs" company="QutEcoacoustics"> | ||
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group). | ||
// </copyright> | ||
|
||
namespace Acoustics.Test.Tools | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Acoustics.Test.TestHelpers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class FfmpegUtilityTests | ||
{ | ||
[TestMethod] | ||
public void FfmpegGracefullyIgnoresMetadataLinesOfUnexpectedFormat() | ||
{ | ||
var utility = TestHelper.GetAudioUtilityFfmpeg(); | ||
var testFilename = "20190401T000000+1000_REC [19.21440152.8811].flac"; | ||
var testFile = PathHelper.ResolveAsset("BARLT", testFilename); | ||
var testInfo = TestHelper.AudioDetails[testFilename]; | ||
|
||
// this used to fail because FLAC custom fields are not output in the standard | ||
// ffmpeg `key=value` format. | ||
var info = utility.Info(testFile); | ||
|
||
Assert.IsNotNull(info); | ||
|
||
// and we should be able to parse the data | ||
|
||
var raw = @"Metadata: | ||
SENSORUID : 000010 | ||
: | ||
MICROPHONEBUILDDATE2: unknown | ||
MICROPHONEUID2 : unknown | ||
MICROPHONEUID1 : 000629 | ||
SENSORFIRMWAREVERSION: Firmware: V3.08 | ||
SENSORLOCATION : +19.2144 +152.8811 | ||
SDCARDCID : 9E42453531324742100000004D012BE5 | ||
MICROPHONEBUILDDATE1: 2019-02-22 | ||
MICROPHONETYPE2 : unknown | ||
CHANNELGAIN1 : 50dB | ||
MICROPHONETYPE1 : STD AUDIO MIC | ||
BATTERYLEVEL : 100p 12.83V | ||
RECORDINGEND : 2019-04-01 01:59:56 | ||
RECORDINGSTART : 2019-04-01 00:00:01 | ||
CHANNELGAIN2 : 0dB"; | ||
|
||
IEnumerable<(string Key, string Value)> Clean(string line) | ||
{ | ||
var parts = line.Split(new[] { ':', ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
if (parts.Length != 2) | ||
{ | ||
yield break; | ||
} | ||
|
||
yield return (parts[0], parts[1]); | ||
} | ||
|
||
var values = raw.SplitOnAnyNewLine().SelectMany(Clean); | ||
|
||
foreach (var keyAndValue in values) | ||
{ | ||
string ffmpegKey = "FORMAT TAG:" + keyAndValue.Key; | ||
Assert.IsTrue(info.RawData.ContainsKey(ffmpegKey)); | ||
Assert.AreEqual(keyAndValue.Value, info.RawData[ffmpegKey]); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/Fixtures/BARLT/20190401T000000+1000_REC [19.21440152.8811].flac
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
20190401T000000+1000_REC [19.21440152.8811].flac: | ||
Is a trimmed down version of an originally 2 hour long file. | ||
It's not a true output of a BAR LT sensor because we've modified it with | ||
audacity. It's enough though for us to test the metadata parsing. |