提取音频片段

此处整理,从完整的音频文件中,提取其中一段,即提取音频片段。

从mp3中提取某个时间段的mp3

  1. ffmpeg -i show_14322648_audio.mp3 -acodec copy -ss 00:00:03.110 -to 00:00:06.110 show_14322648_audio_000003110_000006110.mp3
  • 参数解释
    • -i:input 输入文件
    • -acodec copy
      • -acodec = audio codec:音频编码器
      • == -c copy
        • 等价于:
          1. ffmpeg -i show_14322648_audio.mp3 -c copy -ss 00:00:03.110 -to 00:00:06.110 show_14322648_audio_000003110_000006110_cCopy.mp3

官网文档

  • Stream-copy ffmpeg Documentation

    3.2 Stream copy

        Stream copy is a mode selected by supplying the copy parameter to the -codec option. It makes ffmpeg omit the decoding and encoding step for the specified stream, so it does only demuxing and muxing. It is useful for changing the container format or modifying container-level metadata

  • toc-Main-options

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

    -to position (input/output)

        Stop writing the output or reading the input at position. position 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.

    -ss position (input/output)

        When used as an input option (before -i), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved.

        When used as an output option (before an output url), decodes but discards input until the timestamps reach position.

        position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

输出举例

  1. splitAudio git:(master) ffmpeg -i show_14322648_audio.mp3 -c copy -ss 00:00:03.110 -to 00:00:06.110 show_14322648_audio_000003110_000006110_cCopy.mp3
  2. ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
  3. built with Apple LLVM version 10.0.0 (clang-1000.11.45.2)
  4. configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-nonfree
  5. libavutil 56. 14.100 / 56. 14.100
  6. libavcodec 58. 18.100 / 58. 18.100
  7. libavformat 58. 12.100 / 58. 12.100
  8. libavdevice 58. 3.100 / 58. 3.100
  9. libavfilter 7. 16.100 / 7. 16.100
  10. libavresample 4. 0. 0 / 4. 0. 0
  11. libswscale 5. 1.100 / 5. 1.100
  12. libswresample 3. 1.100 / 3. 1.100
  13. libpostproc 55. 1.100 / 55. 1.100
  14. Input #0, mp3, from 'show_14322648_audio.mp3':
  15. Metadata:
  16. major_brand : isom
  17. minor_version : 0
  18. compatible_brands: isomiso2avc1
  19. encoder : Lavf58.12.100
  20. Duration: 00:00:48.27, start: 0.025057, bitrate: 128 kb/s
  21. Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
  22. Metadata:
  23. encoder : Lavc58.18
  24. Output #0, mp3, to 'show_14322648_audio_000003110_000006110_cCopy.mp3':
  25. Metadata:
  26. major_brand : isom
  27. minor_version : 0
  28. compatible_brands: isomiso2avc1
  29. TSSE : Lavf58.12.100
  30. Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
  31. Metadata:
  32. encoder : Lavc58.18
  33. Stream mapping:
  34. Stream #0:0 -> #0:0 (copy)
  35. Press [q] to stop, [?] for help
  36. size= 47kB time=00:00:02.97 bitrate= 129.5kbits/s speed=1.76e+03x
  37. video:0kB audio:47kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.173211%