Change the length of wav files - audio

I have multiple wav files with the duration of 2.2 - 2.8 seconds.
I want to modify (stretch/squeeze) them, such that all of them will be with the exact duration of 2.5 seconds.
I mean slightly stretch the actual data and not just add leading/trailing zeros.
Is it possible?
Thanks

Yes, you can use https://github.com/waywardgeek/sonic like this:
sonic -s 3.2 book.wav book_fast.wav

I haven't found a simple solution with ffmpeg, but you can use RubberBand:
rubberband --duration d input.wav output.wav
(thanks to https://superuser.com/a/1132229/807246)
Example:
$ duration=2.5; for file in *.wav; do rubberband -D $duration $file out_${file}; done;
$ sox --info -D file.wav
2.390875
$ sox --info -D out_file.wav
2.500000

Related

Piping sox output into aplay

I need to concat multiple mp3 files together then adjust there volume then play via aplay. I currently do this using the following 3 commands
sox file1.mp3 file2.mp3 file3.mp3 out1.wav
sox -v 0.5 out1.wav out2.wav
aplay -D plughw:1,0 out2.wav
This works correctly the only minor issue is it creates temporary files and I know it can be done by piping all these commands together somehow. Sort of like.
sox file1.mp3 file2.mp3 file3.mp3 | sox -v 0.5 | aplay -D plughw:1,0
But can't appear to get the piping to work (I am not really a linux user) Any help would be much appreciated :)

insert audio into another audio file (eg a censor bleep)

I need to insert a short beep into another audio file (similar to a censorship bleep) using linux and/or php.
I'm thinking there should be some way to do it with ffmpeg (with some combination of -t, concat, map, async, adelay, itsoffset?) or avconv or mkvmerge - but haven't found anyone doing this. Maybe I need to do it in 2 stages somehow?
For example if I have a 60 second mp3 and want to beep out 2 seconds at 2 places the desired result would be:
0:00-0:15 from original
0:15-0:17 beep (overwrites the 2 secs of original)
0:17-0:40 from original
0:40-0:42 beep
0:42-0:60 from original
I have a 2 second beep.mp3, but can use something else instead like -i "sine=frequency=1000:duration=2"
You can use the concat demuxer.
Create a text file, e.g.
file main.wav
inpoint 0
outpoint 15
file beep.wav
file main.wav
inpoint 17
outpoint 40
file beep.wav
file main.wav
inpoint 40
outpoint 42
and then
ffmpeg -f concat -i list.txt out.mp3
Convert the beep file to have the same sampling rate and channel count as the main audio.
First, you need to have beep.mp3 time equal to 60 seconds or little bit less than your mp3 file time.
Then, you can use ffmpeg code -ss <start_time> -t <duration> -i <your_file>.mp3
ffmpeg -ss 00:00:00 -t 15 -i ./original.mp3 -ss 00:15:00 -t 2 -i ./beep.mp3 -ss 00:17:00 -t 23 -i ./original.mp3 -ss 00:40:00 -t 2 -i ./beep.mp3 -ss 00:42:00 -i ./original.mp3 -filter_complex '[0:0][1:0] concat=n=2:v=0:a=1[out]' -map '[out]' ./output.mp3
at the end you will get output.mp3 file as you needed.

Linux: How to combine multiple FLAC audio files into 1 file, with differing sample rates, but not changing pitch

I've looked everywhere to try to combine a bunch of FLAC files with differing sample rates into 1 file. What I've tried so far is:
ffmpeg concat with a wildcard:
ffmpeg -f concat -i <( for f in *.flac; do echo "file '$(pwd)/$f'"; done ) -safe 0 output.flac
I get for every filename, (even if I change pwd to './' for relative):
ffmpeg unsafe filename
Regardless of the file's filename.
I've tried sox:
sox *.flac output.flac
Which leads to:
sox FAIL sox: Input files must have the same sample-rate
I've even tried combining the two:
#!/usr/bin/env bash
set -eu
for i in *.flac *.ogg *.mp3
do
ffmpeg -i "$i" "$i.wav"
done
sox *.wav combined.wav
Same error as above.
Anyone have any tips? I'm sure that in some Windows program you can drag in 5 differing sound files and combine them with ease. Is there not a simple way to do this on linux cmdline?
safe 0 is a private option for the concat demuxer, so it has to appear before the input i.e. -f concat -safe 0 -i ...

is there a way to control the extraction of key frame using ffmpeg

the situation is i get 8 frames with the default threshold for scenecut detection.as the key frames i get is not representive enough .so i want to turn down the threhold to get more key-frames.but i use the -g and -sc_threshold arguments in my command(reference:How to control key-frame generation of ffmpeg?) ,it donot work well.i still get the same 8 frames without any change.any ideas?
You could output an iframes list and use it with some script.
$ ffprobe -show_packets -print_format compact input.mkv 2>/dev/null | egrep -n flags=K | cut -d: -f 1 > iframes

How to generate video screencaps of video files via linux commandline

Is there a command line program for linux (ubuntu) which can generate a large image containing say 6 caps from a given video (e.g. WMV) laid out storyboard style (I know on Windows media player classic can do this)? I need this for part of a script I am writing.
I pulled the answer from this site: http://blog.prashanthellina.com/2008/03/29/creating-video-thumbnails-using-ffmpeg/
ffmpeg -itsoffset -4 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
Where -4 is the number of seconds into the file to grab the screenshot, 320x240 is the screenshot size, and test.jpg is the output file.
Hope this helps.
Use SlickSlice
./slickslice.sh -x video.avi -s 5x3 -e
I've used MPlayer to save frames as images and ImageMagick to combine them:
mplayer -nosound -sstep 15 -vo png video.mkv
montage *.png -tile 3x3 -geometry 300x+0+0 screencaps.png
vcsi can do this. It is a command-line tool written in Python. Example:
vcsi video.mkv -o output.jpg

Resources