save console output of programm to file - not simplte 2>&1 - linux

i want to analyze multiple mp3 files and get the bpm of the files. Therefore i'm using soundstretch. At first i'm converting the mp3 files using sox
sox -t mp3 -r 44100 -c 2 file.mp3 -t wav file3.wav
after this i want to analyze the track with soundstretch
soundstretch file.wav -bpm
this also gives me the result in the console. But i'm not able to redirect the printed response to a file. i already tried stuff like
soundstretch file.wav -bpm > file.mp3.bpm
soundstretch file.wav -bpm 2>&1 > file.mp3.bpm
the only result is, that the messages are displayed in the console and there is a empty file

Switch it around if you want one file
soundstretch file.wav -bpm > file.mp3.bpm 2>&1
or use two file two files:
soundstretch file.wav -bpm 2> file.mp3.err > file.mp3.bpm

I think you should use the soundstretch as
soundstretch inputFile outputFile options
ex. : soundstretch Sample.waw out.txt -bpm

Related

remove audio from mp4 file ffmpeg

I am on a Mac using Python 3.6. I am trying to remove audio from an mp4 file using ffmpeg but unfortunately it does not give me the "silenced" mp4 file I look for. Code I use is:
ffmpeg_extract_audio("input_file.mp4", "output_file.mp4", bitrate=3000, fps=44100)
It gives me a new output file with a low-quality video image, but still the audio. Any suggestion?
ok thank you #sascha. I finally put all my mp4 files in the same folder and run the following code:
for file in *.mp4; do ffmpeg -i "$file" -c copy -an "noaudio_$file"; done
If, like me, one uses Sublime Text or any other text editor (already using Python language), it run with the following:
import subprocess
command = 'for file in *.mp4; do ffmpeg -i "$file" -c copy -an "noaudio_$file"; done'
subprocess.call(command, shell=True)

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 ...

Concatenate two or more songs

I tried three different methods in order to concatenate songs
Audacity: Works, but it adds a "click" sound between the first and second song
cat command: I tried cat *.wma > result.wma and cat second.wma >> first.wma. Both have the same problem, the resulting file is just the first one.
ffmpeg: ffmpeg -i "concat:uno.wma|dos.wma" -acodec copy result.wma, same problem as cat command, the file result.wma is a copy of uno.wma
Any help?
You should use ">>" operator instead of ">", because ">" overrides the result of first operation. But, I'm not sure about the correctness of this operation on audio files.
Example:
$ echo "1" > output
$ echo "2" > output
$ cat output
2
$ echo "1" >> output2
$ echo "2" >> output2
$ cat output2
1
2
If you write: cat *.wma > result.wma, actually you do:
cat 1.wma > result.wma
cat 2.wma > result.wma
So, you'll get 2.wma in result.wma, without 1.wma in it.
The ffmpeg concat protocol you're using (the "concat:" pattern) does not work for concatenating some media files like WMA and WAV.
https://trac.ffmpeg.org/wiki/Concatenate
Likely because they have some headers at the beginning of their files. At least, WAV files have a 46 byte file header if made with ffmpeg. These headers are likely also tripping up the playback of files concatenated with the cat command.
So try this for generic concatenation instead:
ffmpeg -i "first.wma" -i "second.wma" -filter_complex '[0:0][1:0]concat=n=2:v=0:a=1[out]' -map '[out]' result.wma
See related question and answer (for WAV files):
https://superuser.com/q/587511/192525
Try this:
cat song1.wma song2.wma > bothsongs.wma

Redirecting ffmpeg result into another file

I'm trying to get the size of an input video using ffmpeg, below is the code that I use, what I'm trying to do is to first store the result into a txt file and then do some parsing to get the size of the video:
$ ffmpeg -i TheNorth.mp4
The terminal says "At least one output file must be specified"
Then I tried this:
$ ffmpeg -i TheNorth.mp4 result.txt
The terminal says "Unable to find a suitable output format for 'size.txt'"
So how could I get the result and save it to the specified file?
You can store the output ffmpeg generates with piping:
ffmpeg -i TheNorth.mp4 2> result.txt
You need to use 2> here, as ffmpeg writes to StdErr (and not StdOut).
ffprobe
If you just want to get the size of the video then you can get that, and other info, directly with ffprobe. This will avoid redirection, temporary output files, and the additional parsing.
$ ffprobe -v error -select_streams v:0 -show_entries stream=height,width -of csv=p=0:s=x input.mkv
1280x720
See FFmpeg Wiki: FFprobe Tips for more examples.
tee
For users who want to encode and capture the resulting console output, I recommend using tee. The problem with pure redirection is that important messages such as error messages, failures, and prompts can be missed.
You can avoid this by including tee to show the output in the console and to save it to a file:
ffmpeg -i input … output |& tee console.txt
ffmpeg outputs to stderr instead of the more typical stdout, so the & is added to the | pipe to deal with that. This is only for Bash 4+. If you're using something else then change |& to 2>&1 which redirects stderr to stdout before it is sent to the pipe.
Somewhat better idea is to use ffprobe
ffprobe -show_format -print_format json TheNorth.mp4
that will output JSON formated info about video. Guess it is easier to parse than raw output. To redirect output to file use just ordinary pipe > result.txt similar to accepted answer but without two.

Print output into a text file in linux

Hello I am trying to get the difference between to text files. There are a lot of differences and viewing them in terminal is making it volatile since I cannot save them. I want to view and save the diff. How would I catch the output and print it to a text file??
Code I am using for getting the diff is diff -i -w -B file1.txt file2.txt
Save to text file:
diff -i -w -B file1.txt file2.txt > diff.txt
Write directly to printer:
diff -i -w -B file1.txt file2.txt | lpr
Write saved text file to printer
lpr diff.txt
'Hope that helps .. PSM
PS:
Here's a link on Linux command-line printing:
http://tldp.org/HOWTO/Printing-Usage-HOWTO-2.html
Generally speaking,
command > output.txt
and in your case
diff -i -w -B file1.txt file2.txt > output.txt
and if you want to append the result
command >> output.txt
Just redirect it to a file:
diff -i -w -B file1.txt file2.txt > output.diff
If you'd like to know more about redirecting output, the advanced details vary shell-to-shell, but here's a reference for bash and a cheat-sheet for the common stdout/stderr redirects.

Resources