Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: --until rejects files shorter than the given time; how to work around? (Read 5405 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

--until rejects files shorter than the given time; how to work around?

I am running the following command as part of a script to process a wav to flac

flac --best --sample-rate=8000 --until=0:15.00 stream.part3.wav -f -o audio.flac

The issue I have is that I only want the first 15 seconds of the stream.part3.wav file (this file can vary in length)
However if the original file is less than 15 seconds flac returns an error and does not process the file
Does anyone know a way I could get around this
Thanks !!

--until rejects files shorter than the given time; how to work around?

Reply #1
You should be able to use something like shntool (http://www.etree.org/shnutils/shntool/) in order to see the length of the WAV file you're about to transcode. Afterwards, you can act accordingly -- if length < 15 seconds, transcode the entire file, else use --until=0:15.00 and transcode only the first 15 seconds.

If using other tools is not an option, perhaps you can infer the length by looking at the file size (use the stat GNU utility). Then, you can obtain the length (in seconds) like so (provided the the file size is given in bytes, which is what the  stat utility gives you):
length = (file_size * 8) / (sample_rate * bit_depth * channel_count)

--until rejects files shorter than the given time; how to work around?

Reply #2
Thank you for the reply
It is a quite a bit above my pay grade so I have been trying to understand
So far I have added this to my script without success I figured I could adjust the 5000 number once I had a general idea of size:

SIZE =`stat %s stream.part3.wav | grep 'Size'`
if [ "$SIZE" !> "5000" ]
then
flac --best --sample-rate=8000 stream.part3.wav -f -o audio.flac
else
flac --best --sample-rate=8000 --until=0:14.00 stream.part3.wav -f -o audio.flac


In place of the original:
flac --best --sample-rate=8000 --until=0:15.00 stream.part3.wav -f -o audio.flac

Don't want to be a pest so I will keep trying unless you see an easy fix
Thanks again

--until rejects files shorter than the given time; how to work around?

Reply #3
Code: [Select]
sox -V input.wav -r 8000 output.flac trim 0 15

--until rejects files shorter than the given time; how to work around?

Reply #4
Thanks for your response
I guess the reason I am having the issue in the first place was my inability to get flac file handler to work in sox


sox FAIL formats: no handler for file extension `flac'


--until rejects files shorter than the given time; how to work around?

Reply #5
Sweet your post gave me an idea
I used  sox to trim the file as a wav file (since the flac portion of my sox is not working)
Then I used flac to convert the trimmed wav file to a trimmed flac file
Now it is working for me
thank you all for your help !

--until rejects files shorter than the given time; how to work around?

Reply #6
Check your package manager. In deb based distributions and most likely in rpm based ones like centos sox formats are in separate packages:

Code: [Select]
aptitude search sox
p   libsox-dev                                             - Development files for the SoX library                          
i   libsox-fmt-all                                         - All SoX format libraries                                        
i A libsox-fmt-alsa                                        - SoX alsa format I/O library                                    
i A libsox-fmt-ao                                          - SoX Libao format I/O library                                    
i A libsox-fmt-base                                        - Minimal set of SoX format libraries                            
i A libsox-fmt-ffmpeg                                      - SoX ffmpeg format library                                      
i A libsox-fmt-mp3                                         - SoX MP3 format library                                          
i A libsox-fmt-oss                                         - SoX OSS format I/O library                                      
i A libsox-fmt-pulse                                       - SoX PulseAudio format I/O library                              
i A libsox1a                                               - SoX library of audio effects and processing                    
i   sox                                                    - Swiss army knife of sound processing


I always install libsox-fmt-all after installing sox.