Reputation: 2478
I have a gnuplot script (plot.script) that is invoked like
C:> ffmpeg -i '.\my_awesome_audio_file.wav' -filter_complex aformat=channel_layouts=mono -acodec pcm_s16le -ar 4000 -f data - | gnuplot -e "fileout='plot';fileformat='png';wid=500;" .\plot.script
Now I'd want to default filein variable to stdin if it is not passed as argument. This because I want to be able to call this script as a 1-liner command with ffmpeg data generation and also as step-by-step procedure
My idea was to use
if(!exists('filein')){
filein = '-';
}
but this throws warning: Skipping data file with no valid points
if i print the variable datafile I got -
(I expected something like stdin).
this is the plot.script
script:
if(!exists('filein')){
filein = '-';
}
if (!exists("hei")){
hei = 4444;
}
if (!exists("wid")){
wid = 5555;
}
if(!exists("fileformat")){
fileformat = 'png';
}
if(!exists("fileout")){
fileout = 'risultato';
}
fileout = fileout . '.' . fileformat;
if(!exists("dataformat")){
dataformat = '%int16';
}
if(fileformat eq 'png'){
set terminal png transparent size larghezza,altezza;
}else{
set terminal fileformat size wid,hei;
}
set output fileout;
unset key;
unset tics;
unset border;
set lmargin 0;
set rmargin 0;
set tmargin 0;
set bmargin 0;
print filein;
plot filein binary filetype=bin format=dataformat endian=little array=1:0 with lines linecolor "0x009900";
But I also want to call this command-by-command: generate the data-file:
c:> ffmpeg -i '.\my_awesome_audio_file.wav' -filter_complex aformat=channel_layouts=mono -acodec pcm_s16le -ar 4000 -f data audio.dat
plot the data:
c:> gnuplot -e "filein='audio.dat';fileout='plot';fileformat='png';wid=500;" .\plot.script
Upvotes: 0
Views: 238
Reputation: 15118
There are probably a lot of ways you might deal with this, but my suggestion is to have gnuplot plot from a pipe opened by the shell command that calls it. It is then up to the shell to fill that pipe either via cat
from an existing file or by directing a stream to it. Here is the relevant section from the documentation (see help pipes
)
On systems with an fdopen() function, data can be read from an arbitrary file
descriptor attached to either a file or pipe. To read from file descriptor
`n` use `'<&n'`. This allows you to easily pipe in several data files in a
single call from a POSIX shell:
$ gnuplot -p -e "plot '<&3', '<&4'" 3<data-3 4<data-4
$ ./gnuplot 5< <(myprogram -with -options)
gnuplot> plot '<&5'
Upvotes: 0