IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
--until rejects files shorter than the given time; how to work around?, [was “Centos Command line help”/TOS #6]
6string
post Sep 3 2013, 17:05
Post #1





Group: Members
Posts: 4
Joined: 3-September 13
Member No.: 109943



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 !!
Go to the top of the page
+Quote Post
d125q
post Sep 3 2013, 17:59
Post #2





Group: Members
Posts: 57
Joined: 4-May 13
Member No.: 107966



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)

This post has been edited by d125q: Sep 3 2013, 18:01
Go to the top of the page
+Quote Post
6string
post Sep 3 2013, 19:15
Post #3





Group: Members
Posts: 4
Joined: 3-September 13
Member No.: 109943



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
Go to the top of the page
+Quote Post
phofman
post Sep 3 2013, 20:31
Post #4





Group: Members
Posts: 300
Joined: 14-February 12
Member No.: 97162



CODE
sox -V input.wav -r 8000 output.flac trim 0 15
Go to the top of the page
+Quote Post
6string
post Sep 4 2013, 03:17
Post #5





Group: Members
Posts: 4
Joined: 3-September 13
Member No.: 109943



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'

Go to the top of the page
+Quote Post
6string
post Sep 4 2013, 04:22
Post #6





Group: Members
Posts: 4
Joined: 3-September 13
Member No.: 109943



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 !
Go to the top of the page
+Quote Post
phofman
post Sep 4 2013, 05:47
Post #7





Group: Members
Posts: 300
Joined: 14-February 12
Member No.: 97162



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

CODE
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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 3rd September 2014 - 09:45