adding choice for audio format
changed default format to mp3 sox now handles extraction (instead of ffmpeg)
This commit is contained in:
+29
-11
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
if (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {
|
||||
$config = parse_ini_file('/home/pi/BirdNET-Pi/thisrun.txt');
|
||||
} elseif (file_exists('/home/pi/BirdNET-Pi/firstrun.ini')) {
|
||||
$config = parse_ini_file('/home/pi/BirdNET-Pi/firstrun.ini');
|
||||
}
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(isset($_POST['submit'])) {
|
||||
$contents = file_get_contents("/home/pi/BirdNET-Pi/birdnet.conf");
|
||||
@@ -145,6 +145,14 @@ if(isset($_POST['submit'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST["audiofmt"])) {
|
||||
$audiofmt = $_POST["audiofmt"];
|
||||
if(strcmp($audiofmt,$config['AUDIOFMT']) !== 0) {
|
||||
$contents = preg_replace("/AUDIOFMT=.*/", "AUDIOFMT=$audiofmt", $contents);
|
||||
$contents2 = preg_replace("/AUDIOFMT=.*/", "AUDIOFMT=$audiofmt", $contents2);
|
||||
}
|
||||
}
|
||||
|
||||
$fh = fopen("/home/pi/BirdNET-Pi/birdnet.conf", "w");
|
||||
$fh2 = fopen("/home/pi/BirdNET-Pi/thisrun.txt", "w");
|
||||
fwrite($fh, $contents);
|
||||
@@ -225,7 +233,7 @@ label {
|
||||
width: 40%;
|
||||
font-weight:bold;
|
||||
}
|
||||
input {
|
||||
input,select {
|
||||
width: 60%;
|
||||
text-align:center;
|
||||
font-size:large;
|
||||
@@ -285,7 +293,17 @@ if (strcmp($newconfig['FULL_DISK'], "purge") == 0) {
|
||||
<p>Set Recording Length in seconds between 6 and 60. Multiples of 3 are recommended, as BirdNET analyzes in 3-second chunks.</p>
|
||||
<label for="extraction_length">Extraction Length: </label>
|
||||
<input name="extraction_length" type="number" min="3" max="<?php print($newconfig['RECORDING_LENGTH']);?>" value="<?php print($newconfig['EXTRACTION_LENGTH']);?>" /><br>
|
||||
<p>Set Extraction Length to something less than your Recording Length. Min=3 Max=Recording Length
|
||||
<p>Set Extraction Length to something less than your Recording Length. Min=3 Max=Recording Length</p>
|
||||
<label for="audiofmt">Extractions Audio Format</label>
|
||||
<select name="audiofmt">
|
||||
<option selected="<?php print($newconfig['AUDIOFMT']);?>"><?php print($newconfig['AUDIOFMT']);?></option>
|
||||
<?php
|
||||
$formats = array("8svx", "aif", "aifc", "aiff", "aiffc", "al", "amb", "amr-nb", "amr-wb", "anb", "au", "avr", "awb", "caf", "cdda", "cdr", "cvs", "cvsd", "cvu", "dat", "dvms", "f32", "f4", "f64", "f8", "fap", "flac", "fssd", "gsm", "gsrt", "hcom", "htk", "ima", "ircam", "la", "lpc", "lpc10", "lu", "mat", "mat4", "mat5", "maud", "mp2", "mp3", "nist", "ogg", "paf", "prc", "pvf", "raw", "s1", "s16", "s2", "s24", "s3", "s32", "s4", "s8", "sb", "sd2", "sds", "sf", "sl", "sln", "smp", "snd", "sndfile", "sndr", "sndt", "sou", "sox", "sph", "sw", "txw", "u1", "u16", "u2", "u24", "u3", "u32", "u4", "u8", "ub", "ul", "uw", "vms", "voc", "vorbis", "vox", "w64", "wav", "wavpcm", "wv", "wve", "xa", "xi");
|
||||
foreach($formats as $format){
|
||||
echo "<option value='$format'>$format</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<h3>Passwords</h3>
|
||||
<label for="caddy_pwd">Webpage: </label>
|
||||
<input name="caddy_pwd" type="text" value="<?php print($newconfig['CADDY_PWD']);?>" /><br>
|
||||
@@ -321,12 +339,12 @@ if (strcmp($newconfig['FULL_DISK'], "purge") == 0) {
|
||||
<br><br>
|
||||
<button type="submit" name="submit" class="block"><?php
|
||||
|
||||
if(isset($_SESSION['success'])){
|
||||
echo "Success!";
|
||||
unset($_SESSION['success']);
|
||||
} else {
|
||||
echo "Update Settings";
|
||||
}
|
||||
if(isset($_SESSION['success'])){
|
||||
echo "Success!";
|
||||
unset($_SESSION['success']);
|
||||
} else {
|
||||
echo "Update Settings";
|
||||
}
|
||||
?></button>
|
||||
<br>
|
||||
</form>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Exit when any command fails
|
||||
#set -x
|
||||
set -x
|
||||
set -e
|
||||
# Keep track of the last executed command
|
||||
#trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
|
||||
@@ -64,7 +64,8 @@ for h in "${SCAN_DIRS[@]}";do
|
||||
| awk -F\; '{print $5}' \
|
||||
| cut -d'.' -f2)""
|
||||
CONFIDENCE_SCORE="${CONFIDENCE:0:2}%"
|
||||
NEWFILE="${COMMON_NAME// /_}-${CONFIDENCE_SCORE}-${OLDFILE}"
|
||||
NEWFILE="${COMMON_NAME// /_}-${CONFIDENCE_SCORE}-${OLDFILE//.wav/.${AUDIOFMT}}"
|
||||
echo "NEWFILE=$NEWFILE"
|
||||
NEWSPECIES_BYDATE="${EXTRACTED}/By_Date/${DATE}/${COMMON_NAME// /_}"
|
||||
NEWSPECIES_BY_COMMON="${EXTRACTED}/By_Common_Name/${COMMON_NAME// /_}"
|
||||
NEWSPECIES_BY_SCIENCE="${EXTRACTED}/By_Scientific_Name/${SCIENTIFIC_NAME// /_}"
|
||||
@@ -102,7 +103,6 @@ for h in "${SCAN_DIRS[@]}";do
|
||||
# ls -1t . | tail -n +20 | xargs -r rm -vv
|
||||
# fi
|
||||
|
||||
echo "Extracting audio . . . "
|
||||
# If the above tests have passed, then the extraction happens.
|
||||
# After creating the extracted files by-date, and a directory tree
|
||||
# structured by-species, symbolic links are made to populate the new
|
||||
@@ -129,9 +129,11 @@ for h in "${SCAN_DIRS[@]}";do
|
||||
END=${RECORDING_LENGTH}
|
||||
fi
|
||||
|
||||
ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \
|
||||
-acodec copy -ss "${START}" -to "${END}"\
|
||||
"${NEWSPECIES_BYDATE}/${NEWFILE}"
|
||||
sox "${h}/${OLDFILE}" "${NEWSPECIES_BYDATE}/${NEWFILE}" \
|
||||
trim "${START}" "${END}"
|
||||
#ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \
|
||||
# -acodec copy -ss "${START}" -to "${END}"\
|
||||
# "${NEWSPECIES_BYDATE}/${NEWFILE}"
|
||||
|
||||
# Create spectrogram for extraction
|
||||
sox "${NEWSPECIES_BYDATE}/${NEWFILE}" -n remix 1 rate 24k spectrogram \
|
||||
@@ -183,7 +185,6 @@ for h in "${SCAN_DIRS[@]}";do
|
||||
|
||||
done < "${TMPFILE}"
|
||||
|
||||
echo -e "\n\n\nFINISHED!!! Processed extractions for ${h:19}"
|
||||
# Once each line of the TMPFILE has been processed, the TMPFILE is emptied
|
||||
# for the next iteration of the for loop.
|
||||
>"${TMPFILE}"
|
||||
@@ -201,8 +202,3 @@ echo "Linking Processed files to "${EXTRACTED}/Processed" web directory"
|
||||
if [[ ! -L ${EXTRACTED}/Processed ]] || [[ ! -e ${EXTRACTED}/Processed ]];then
|
||||
ln -sf ${PROCESSED} ${EXTRACTED}/Processed
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# That's all!
|
||||
echo "Finished -- the extracted sections are in ${EXTRACTED}"
|
||||
|
||||
Reference in New Issue
Block a user