【问题标题】:Screen capture WITH audio in ffmpegffmpeg 中带音频的屏幕截图
【发布时间】:2015-04-06 19:51:06
【问题描述】:

我在 Fedora 20 中使用从 this revision 的源代码构建的 ffmpeg。

我可以使用以下命令完美地录制音频:

FFmpeg/ffmpeg -f alsa -ac 2 -i pulse -- output.wav

但是,当我同时尝试屏幕捕获和音频时,像这样:

FFmpeg/ffmpeg -video_size 800x600 -framerate 25 -ac 2 -f x11grab -i :0.0+0,0 -ac 2 -f alsa -i pulse -ac 2 -acodec copy output.mpeg -ac 2

我得到一个有 0 个音频通道的视频,我可以检查它是否正在运行 FFmpeg/ffplay output.mpeg

Input #0, mpeg, from 'output.mpeg':
  Duration: 00:00:09.44, start: 0.540000, bitrate: 2743 kb/s
    Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 800x600 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Stream #0:1[0x1c0]: Audio: mp2, 0 channels, s16p
   7.26 M-V:  0.000 fd=   0 aq=    0KB vq=   33KB sq=    0B f=0/0   

并且没有播放声音。 -ac 2 的位置不会改变行为,也不会只重复一次。尽管 ffmpeg 声称用 2 个通道录制音频,但这是输入:

ffmpeg version N-71312-ga66dcfe Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-7)
  configuration: 
  libavutil      54. 22.100 / 54. 22.100
  libavcodec     56. 34.100 / 56. 34.100
  libavformat    56. 29.100 / 56. 29.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 13.101 /  5. 13.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
Trailing options were found on the commandline.
Input #0, x11grab, from ':0.0+0,0':
  Duration: N/A, start: 1428348285.201679, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 800x600, 25 fps, 25 tbr, 1000k tbn, 25 tbc
Guessed Channel Layout for  Input Stream #1.0 : stereo
Input #1, alsa, from 'pulse':
  Duration: N/A, start: 1428348285.225901, bitrate: 1536 kb/s
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
 File 'output.mpeg' already exists. Overwrite ? [y/N] y
[mpeg @ 0x2d079a0] VBV buffer size not set, using default size of 130KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, mpeg, to 'output.mpeg':
  Metadata:
    encoder         : Lavf56.29.100
    Stream #0:0: Video: mpeg1video, yuv420p, 800x600, q=2-31, 200     kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.34.100 mpeg1video
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg1video (native))
  Stream #1:0 -> #0:1 (copy)

我一无所知。如果有人能告诉我如何让这个工作:

  • 修复我在命令行标志中的错误
  • 如果是回归,则从哪个版本构建。
  • 任何其他方式

我给他/她买一品脱。

【问题讨论】:

标签: ffmpeg audio-recording screen-capture


【解决方案1】:

4.2.2 版

获取您的音频

ffmpeg -list_devices true -f dshow -i dummy

然后

ffmpeg -rtbufsize 1500M -f dshow -i audio="Microphone (Realtek High Definition Audio)" -f -y -rtbufsize 100M -f gdigrab -t 00:00:30 -framerate 30 -probesize 10M -draw_mouse 1 -i desktop -c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25 -pix_fmt yuv420p "d:\ffmpeg_testing.mp4"

【讨论】:

  • 该命令中有一些很棒的东西,但不幸的是它们所做的事情为零。到官方 ffmpeg 文档的外部链接,或者更好地快速解释一些特定设置/标志的作用会很棒。
【解决方案2】:

解决方案似乎是同时使用不同的视频和音频编码器。此行有效:

FFmpeg/ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -i pulse -acodec aac -strict experimental output.flv

没有-acodec aac -strict experimental,我无法让它工作,这与ffmpeg wiki 上的HOWTO 相反。

我得到的错误信息是:

Output #0, flv, to 'output.flv':
    Stream #0:0: Video: flv1 (flv), yuv420p, 1024x768, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.34.100 flv
    Stream #0:1: Audio: adpcm_swf, 0 channels
    Metadata:
      encoder         : Lavc56.34.100 adpcm_swf
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> flv1 (flv))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> adpcm_swf (native))
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height

我也无法使用:

FFmpeg/ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -i pulse -acodec copy output.mpeg

其中包含-ac 2 可能在正确的位置。我反复遇到的错误是:

[mp2 @ 0x7faffc007da0] Header missing

这很可能是错误/回归。

总而言之,我(可能)在 ffmpeg 中发现了 1 个错误,在 ffmpeg 的 wiki 中发现了 1 个错误。看来我得自己买承诺的啤酒了;)

【讨论】:

  • 什么是“x11grab”。我使用它时显示错误?
  • 谢谢。你知道任何命令如何停止我曾经开始的这个过程吗?实际上我在 C# 代码中使用它
  • 它显示错误未知输入格式 x11grab 有什么解决办法吗?
  • 抱歉,我不再使用 ffmpeg(我什至没有安装它)。你最好再问一个问题。
  • @Ahmad x11grab 适用于 Linux,而非 Windows
【解决方案3】:

这行得通:

ffmpeg -f x11grab -video_size 1280x1024 -framerate 24 -i $DISPLAY -f alsa -i default -af \
acompressor=threshold=0.089:ratio=9:attack=200:release=1000 -vf scale=1280x720 -c:v h264_nvenc -g 24 \
-b:v 2M -preset fast -c:a aac -pix_fmt yuv420p -f otut.flv  

取自:使用 FFMPEG Y.T. 流式传输到 Twitch

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 2019-06-17
    相关资源
    最近更新 更多