Mix and trim 2 files with Sox - linux

I need a little bit help and hope to find that here.
I am using sox for tagging some music with voice tags on my server while user is uploading the file. This is my command which I was using. Everything is working fine.
sox -m {voice_tag_loop} {source_file} {output_file}
Now I want to change something, but don't know how to do that and find no solution.
So the {voice_tag_loop} will be uploaded by user and can have all length e.g. 30 seconds, 20s, 17s or 1 Minute. Don't know that before.
The {source_file} is the music file and can have also different length e.g. 3:13 Min, 4:20Min
How can I mix the {voice_tag_loop} with the {source_file} that the {output_file} has the length of {source_file} but has the {voice_tag_loop} is mixed and looped/ repeated into also with as long the length of the {source_file}
I hope I could explain that, that you can understand that.
Best regards

Just repeat until the source file is exhausted, e.g.:
sox -m "| sox {voice_tag_loop} -p repeat -" {source_file} trim 0 $(soxi -d {source_file})
NB, don't forget the trim bit, otherwise the repeat part will generate an infinite file.

OK I have now the answer for all you wants to mix short audio with long audio and the short one should repeated as long the long audio is.
In my case a small description. The short file will be changed to 44.1kHz and will be looped every 30 seconds. Max 100 times but as long as the long file is. And finally both files will be mixed. This all is one procedure.
sox {short_file} -r 44.1k -p pad 0 30 repeat 100 trim 0 $(sox --i -d {long_file}) | sox - -m {long_file} {output_file}
Regards

this did it for me
sox {short_file} -p repeat 100 trim 0 $(sox --i -d {long_file}) | sox - -m {long_file} {new_file}

Related

ffmpeg being inprecise when trimming mp3 files

I want to use ffmpeg to trim some mp3s without re-encoding. The command I used was
ffmpeg -i "inputfile.mp3" -t 00:00:12.414 -c copy out.mp3
However, out.mp3 has a length of 12.460s, and when I load the file in Audacity I can see that it was cut at the wrong spot, and not at 12.414s.
Why is this? I googled a bit and tried some other commands like ffmpeg -i "inputfile.mp3" -ss 0 -to 00:00:12.414 -c copy out.mp3 (which interestingly results in a different length of 12.434s) but could never get the milliseconds to be cut right.
PS. I wasn't sure whether SO was the right place to ask since it isn't technically programming related, however most of the stuff I found on ffmpeg for trimming audio files were stackoverflow questions, e. g. ffmpeg trimming videos with millisecond precision
You can't trim MP3 (nor most lossy codec output) with that level of precision. An MP3 frame or so of padding is added during encoding. (See also: https://wiki.hydrogenaud.io/index.php?title=Gapless, and all the hacks required to make this work.)
If you need precision timing, use something uncompressed like PCM in WAV, or a lossless compression like FLAC.
On Linux you can use mp3splt:
mp3splt -f mp3file.mp3 from to -o output file format
Example:
mp3splt -f "/home/audio folder/test.mp3" 0.11.89 3.25.48 -o #f_trimmed
this will create a "/home/audio folder/test_trimmed.mp3"
For more info to the parameters, check the mp3splt man page here
On Windows you can use mp3DirectCut
mp3DirectCut has a GUI, but it also have command line support

Mix audio files with an offset(at particular points) using SOX

I have two audio files one is 10 secs long and other is 17 secs long, I want to mix the files together so that the 17 sec file starts playing from the start, while the 10 sec file will start after 7 seconds into the 17seconds file.
How can I do this?
I followed this link, I also tried other commands mentioned in Sox FAQ, question number 7, but I am unable to mix two files by providing an offset, I also tried the command in command line and the error is same.
The error which I see is
option ` ' not recognized
and the command I used is
sox -m drums.wav "|sox beats.wav -p pad 1.5" out.wav
Edit: It seems to me that the pipe operator "|" is broken, how do I fix this?
My problem is exactly the same as mentioned in this forum
I think there's an issue with ".
Try
sox -m drums.wav '|sox beats.wav -p pad 1.5' out.wav

Delay audio for a few seconds at the start of audio files (using ffmpeg)

I have been trying to get lots of wav files delayed by 2 seconds at the start using ffmpeg. And so far, even though I have read the manual, I was not able to get it working. Here is my command:
for %%A in (*.wav) do (
ffmpeg -i "%%A" -itsoffset 00:00:02 "%%~NA"1.wav )
And nothing is being changed. Files are simply getting copied. I also tried the same with mp3 files. I also tried mkv and avi (to make sure it was not a container writing issue), but it gives the same result also.
Command is same here and here, but it does not work. Please, help.
You must put -itsoffset BEFORE you specify input. So:
ffmpeg -itsoffset 00:00:02 -i "%%A" "%%~NA"1.wav
Changing the input time offset like that isn't going to do anything noticeable for a single stream, it's meant for fixing out-of-sync issues between audio and video streams.
Do you want to tack on two seconds of silence at the start? If so, one simple way that'd work (although it may feel a bit hackish) is to simply tack on a 2 second WAV full of silence, before the actual input. This would be accomplished by simply adding another -i option before the actual file:
ffmpeg -i 2secsilence.wav -i "%%A" "%%~NA"1.wav
I know this question is over 9 months old, but I came across it and wanted to add some more information about '-itsoffset'. From the ffmpeg trouble ticket pages (https://ffmpeg.org/trac/ffmpeg/ticket/1349):
This command should display file1 content one second earlier than file2 content:
ffmpeg -itsoffset -1 -i file1.ts -i file2.ts -vcodec copy -acodec copy -map 0:0 -map 1:1 out.ts
1) What I see is that -itsoffset adds or subtracts from all the timestamps (both the video and audio streams) in a file. So this option is only going to be useful when remuxing from separate input files.
2) outfile has expected playback behavior with .ts and .mkv containers.
3) It does not work with .avi (no timestamps, so not a surprise)
4) It does not work with .mp4 container (a bug?)
And that is where this issue stands as of today.

alternate two wav files into 1 single one using sox and bash

I'm using linux and bash I have two files filea.wav and fileb.wav which are both 1 second long. I would like to join 4000 of them so I will get 1 large file that is an hour long that has the two files alternating.
Example: of what the 1 hour single file would look like
filea.wav fileb.wav filea.wav fileb.wav filea.wav fileb.wav .....
I know I can use sox to create and repeat a file
sox filea.wav file1hour.wav repeat 4000
but how can I have it so two files alternate back and forth and still get 1 single file using sox?
sox filea.wav fileb.wav long.wav
sox long.wav file1hour.wav repeat 1800
rm long.wav
More details on how to use sox(1): http://sox.sourceforge.net/sox.html

Linux images to video, double digit problem

i have a list of images which im trying to convert to a video.
the images are the following:
t2.jpg
t3.jpg
t4.jpg
I can convert those three images into a video with:
ffmpeg -r 5 -i t%d.jpg -y -an video.avi
but if i turn the names to t20.jpg,t30.jpg and t40.jpg, it doesn't work anymore.
and changing %d to %02d doesn't make any difference.
What am I doing wrong?
The user interface around ffmpeg seems to be very bad.
Is there any other way to turn a list of images into a video?
Hope this helps
For creating a video from many images:
ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi
The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.
Source

Resources