【问题标题】:Gnuplot how to set a variable to standard-input if not passed如果未通过,Gnuplot如何将变量设置为标准输入
【发布时间】:2020-12-16 03:11:00
【问题描述】:

我有一个 gnuplot 脚本 (plot.script),可以像这样调用

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        

现在我想将 filein 变量默认为 stdin,如果它没有作为参数传递。这是因为我希望能够将此脚本调用为具有 ffmpeg 数据生成的 1-liner 命令以及分步过程

我的想法是使用

if(!exists('filein')){
filein = '-';
}

但这会抛出 warning: Skipping data file with no valid points

如果我打印我得到- 的变量数据文件(我期望像标准输入这样的东西)。

这是plot.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";

但我也想逐个调用这个命令: 生成数据文件:

c:> ffmpeg -i '.\my_awesome_audio_file.wav' -filter_complex aformat=channel_layouts=mono -acodec pcm_s16le -ar 4000 -f data audio.dat

绘制数据:

c:> gnuplot -e "filein='audio.dat';fileout='plot';fileformat='png';wid=500;" .\plot.script

【问题讨论】:

    标签: windows ffmpeg gnuplot stdin


    【解决方案1】:

    您可能有很多方法可以处理这个问题,但我的建议是从调用它的 shell 命令打开的管道中获取 gnuplot 绘图。然后由 shell 通过cat 从现有文件或通过将流定向到它来填充该管道。这是文档中的相关部分(请参阅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'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多