美文网首页
FFmpeg滤镜(7)

FFmpeg滤镜(7)

作者: Goning | 来源:发表于2019-03-18 10:23 被阅读0次

    FFmpeg音频音量探测

    本文介绍音频音量与音频波形相关的滤镜操作。


    1、音频音量获得
    ffmpeg -i input.aac -filter_complex volumedetect -c:v copy -f null /dev/null
    
    Input #0, aac, from 'input.aac':
      Duration: 00:00:32.14, bitrate: 154 kb/s
        Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 154 kb/s
    [Parsed_volumedetect_0 @ 0x7faa895027c0] n_samples: 0
    Stream mapping:
      Stream #0:0 (aac) -> volumedetect
      volumedetect -> Stream #0:0 (pcm_s16le)
    Press [q] to stop, [?] for help
    Output #0, null, to '/dev/null':
      Metadata:
        encoder         : Lavf58.20.100
        Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
        Metadata:
          encoder         : Lavc58.35.100 pcm_s16le
    size=N/A time=00:00:30.32 bitrate=N/A speed= 519x    
    video:0kB audio:5224kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    [Parsed_volumedetect_0 @ 0x7faa895027c0] n_samples: 2674688
    [Parsed_volumedetect_0 @ 0x7faa895027c0] mean_volume: -20.7 dB
    [Parsed_volumedetect_0 @ 0x7faa895027c0] max_volume: -4.2 dB
    [Parsed_volumedetect_0 @ 0x7faa895027c0] histogram_4db: 33
    [Parsed_volumedetect_0 @ 0x7faa895027c0] histogram_5db: 289
    [Parsed_volumedetect_0 @ 0x7faa895027c0] histogram_6db: 609
    [Parsed_volumedetect_0 @ 0x7faa895027c0] histogram_7db: 1242
    [Parsed_volumedetect_0 @ 0x7faa895027c0] histogram_8db: 2697
    

    从如上信息可知,mean_volume为获得的音频的平均大小,即-20.7 dB。


    2、绘制音频波形

    使用FFmpeg可以通过showwavespic滤镜来绘制音频的波形图,例如:

    ffmpeg -i input.aac -filter_complex "showwavespic=s=640x120" -frames:v 1 output.png
    

    命令执行后将会生成一个宽高为640x120大小的output.png图片,图片内容为音频波形。

    Input #0, aac, from 'input.aac':
      Duration: 00:00:32.14, bitrate: 154 kb/s
        Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 154 kb/s
    Stream mapping:
      Stream #0:0 (aac) -> showwavespic
      showwavespic -> Stream #0:0 (png)
    Press [q] to stop, [?] for help
    Output #0, image2, to 'output.png':
      Metadata:
        encoder         : Lavf58.20.100
        Stream #0:0: Video: png, rgba, 640x120 [SAR 1:1 DAR 16:3], q=2-31, 200 kb/s, 68.91 fps, 68.91 tbn, 68.91 tbc
        Metadata:
          encoder         : Lavc58.35.100 png
    frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.01 bitrate=N/A speed=0.201x    
    video:3kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    

    上图显示的为音频波形的全部信息,即stereo的多声道音频,如果希望看到每个声道的音频波形图,可以使用showwavespic与split_channel滤镜配合绘制出不同声道的波形图:

    ffmpeg -i input.aac -filter_complex "showwavespic=s=640x120:split_channels=1" -frames:v 1 output.png
    
    Input #0, aac, from 'input.aac':
      Duration: 00:00:32.14, bitrate: 154 kb/s
        Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 154 kb/s
    Stream mapping:
      Stream #0:0 (aac) -> showwavespic
      showwavespic -> Stream #0:0 (png)
    Press [q] to stop, [?] for help
    Output #0, image2, to 'output.png':
      Metadata:
        encoder         : Lavf58.20.100
        Stream #0:0: Video: png, rgba, 640x120 [SAR 1:1 DAR 16:3], q=2-31, 200 kb/s, 68.91 fps, 68.91 tbn, 68.91 tbc
        Metadata:
          encoder         : Lavc58.35.100 png
    frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.01 bitrate=N/A speed=0.214x    
    video:3kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    

    上图显示的是双声道的左右声道的波形图。


    相关文章

      网友评论

          本文标题:FFmpeg滤镜(7)

          本文链接:https://www.haomeiwen.com/subject/rfjbpqtx.html