zoukankan      html  css  js  c++  java
  • 使用ffmpeg录音

    官方教程:http://ffmpeg.org/ffmpeg.html

    录音方法:

    开始找到了这个方法,但是不行呀,好像是没有这个oss吧。

    oss 是linux 下的声音相关的东西,与alsa 一样,不过oss 是商业的, 而/dev/dsp 是oss 用到的麦克的设备吧

    ffmpeg -f oss -i /dev/dsp wheer.mp3
    
    ffmpeg -f oss -i /dev/dsp -ar 8000 -ab 10200 wheer.amr

    采用 alsa-oss 录制,就可以啦

    ffmpeg -f alsa -ac 2 -i hw:0,0 out.mp3
    
    ffmpeg -f alsa -ac 2 -i hw:0,0 out.wav

    科大讯飞的合成或者识别,保存成的音频文件格式是16k或者8k,16bit,单声道pcm格式的音频。采用以下方式录音

     ffmpeg -f alsa  -ar 16000 -ac 1 -i hw:0 lib.wav

    q——停止

    但是 我使用以上命令时,提示说

    cannot set channel count to 1 (Invalid argument)
    hw:0: Input/output error

    最后查阅资料,发现以下参数设置:

    复制代码
    -ab bitrate 设置音频码率
    
    -ar freq 设置音频采样率
    
    -ac channels 设置通道 缺省为1
    
    -an 不使能音频纪录
    
    -acodec codec 使用codec编解码
    复制代码

    如此按理说,去掉 -ac通道设置即可,运行以下命令:

     ffmpeg -f alsa  -ar 16000 -i hw:0 lib.wav
    -acodec pcm_s16le

    但还是无法识别,最后问了一下,是这样录音的:
    ffmpeg -y -f alsa -i pluse -t 00:00:06 -ar 16000 -ac 1 lib.wav

    其中

    复制代码
    -y (global)
      Overwrite output files without asking.
    
    -f fmt (input/output)
       Force input or output file format. The format is normally auto detected for input files and guessed from the file extension
       for output files, so this option is not needed in most cases.
    
    -i url (input)
       input file url
    
    -t duration (input/output)
    
       When used as an input option (before -i), limit the duration of data read from the input file.
    
       When used as an output option (before an output url), stop writing the output after its duration reaches duration.
    
       duration must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.
    
       -to and -t are mutually exclusive and -t has priority.

    复制代码
    //试试改改他的用法
    ffmpeg -y -f alsa -i hw:0 -t 00:00:06 -ar 16000 -ac 1 lib.wav

     这个可以了。

    感谢

    出处:http://www.cnblogs.com/farewell-farewell/p/6111756.html

  • 相关阅读:
    JVM | JVM的核心技术
    性能测试 | 服务器CPU使用率高分析实例
    VIM | vim操作大全
    数据库 | SQL查询&LIMIT的用法
    性能测试 | Linux系统top命令中的io使用率,很多人都误解了它的具体含义
    团队游戏的那些事
    细说内测
    PropertyPlaceHolderConfigurer中的location是不是用错了?
    foreach写失效的问题
    如何优雅的写单元测试?
  • 原文地址:https://www.cnblogs.com/mq0036/p/6541804.html
Copyright © 2011-2022 走看看