mcguirepr89 / BirdNET-Pi

A realtime acoustic bird classification system for the Raspberry Pi 4B, 3B+, and 0W2 built on the TFLite version of BirdNET.
Other
1.3k stars 140 forks source link

Feature request: extractions of same length as recordings #106

Closed DD4WH closed 2 years ago

DD4WH commented 2 years ago

Hi Patrick, I am still very happy with BirdNET-Pi and it is a very valuable tool for me in monitoring Pygmy Owls, as you know. I discovered they are more active in Janauary than in March (where most of the monitoring is regularly done) . . . :-) and my remote BirdNET-pi has been running successfully since November 2021 now!

This is a request for a "new"/modified feature:

This would be awesome, if you could implement it! I tried to fiddle with the script file extract_new_birdsound.sh line 115ff., but my knowledge in shell script language is very poor, so your help would be very much appreciated !

Best regards, Frank DD4WH

mcguirepr89 commented 2 years ago

@DD4WH Hi, Frank! So great to hear from you and to get the update on your long-running setup! November! That's great! It is also really gratifying to hear that you have learned new behavioral patterns for the Pygmy Owls from using BirdNET-Pi -- what a wonderful outcome.

Thank you also for this thoughtful and, as always, very clear and manageable request. I should be able to implement this for you. I am still away from my installation and forgot to arrange remote SSH access to it, so I cannot reach it for testing at this time. But here is what I'm thinking:

The method above may work (it may not, but I think it will), though I know it is not the request you put forward. Likewise, I would like to devise a method that retains the highest confidence score per species per recording so that you know what the most confident detection score was for a given species within a recording.

I'm going to keep this open as I tinker with possibilities. In the meantime, if you are able to make the adjustment above to test, it would be really helpful. If you are unable to test that, please don't worry as I should be back with my installation later this evening or tomorrow.

My best regards as always! Patrick

DD4WH commented 2 years ago

Hi Patrick, thanks a lot for your very quick and very helpful answer. I tried that and it worked ! I now get one extraction each for every recorded file. However, the length of the files differ, they are shorter than the original files . . . What I would like is to extract the original file with its original length. Maybe you also have a quick fix for that ? Maybe set START = 0 and END = EXTRACTION_LENGTH permanently ?

mcguirepr89 commented 2 years ago

Hey, that's great news! Thanks for testing that out.

However, the length of the files differ, they are shorter than the original files . . . What I would like is to extract the original file with its original length. Maybe you also have a quick fix for that ? Maybe set START = 0 and END = EXTRACTION_LENGTH permanently ?

That would certainly work as a short-term solution. Starting at line 127:

    ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \
      -acodec copy -ss "${START}" -to "${END}"\
        "${NEWSPECIES_BYDATE}/${NEWFILE}"

You can change that to:

    ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \
      -acodec copy -ss "0" -to "30"\
        "${NEWSPECIES_BYDATE}/${NEWFILE}"

And you should always get an extraction of 30 seconds. I'm able to tinker with my installation, now, so I will circle back with a more elegant and permanent solution for you that can be set in birdnet.conf instead of hard-coding in the extraction script.

Thanks again for testing that out for me -- super helpful!

DD4WH commented 2 years ago

Yes, that hard-coded 0 to 30s works well! Thank you, it already runs on my remote BirdNET-Pi :-) Of course, you are right, would be good to be able to set this behaviour in birdnet.conf

mcguirepr89 commented 2 years ago

Quick small update: This is built into extract_new_birdsounds.sh now, so anytime the ${RECORDING_LENGTH} == ${EXTRACTION_LENGTH}, ${START} will =0 and ${END} will =${RECORDING_LENGTH}

I am still working on having only 1 extraction per recording with the highest confidence score as the keeper.

mcguirepr89 commented 2 years ago

I think this was addressed -- please let me know if I am wrong about that, but it seems now that you should be able to set the extraction length to equal the recording length to achieve the desired results. I'll reopen if this is not the case.