FFMPEG 用户代理不起作用



我已经在 CentOS 上安装了 ffmpeg,去年它一直在愉快地编码文件音频文件,没问题。

但是,我现在想使用它来访问音频流,以替换我当前使用的笨拙的 php 代码,但我想应用自定义用户代理,以便我的客户端识别传入的连接。

我已经尝试了-user-agent,-user_agent和-headers,但这三个都返回"无法识别的选项"。

我使用的代码(不包括用户代理)是:

ffmpeg -t 3600 -i http://my.radio.com:8000/1 -vn -ar 44100 -ac 2 -ab 128k -f mp3 /var/www/vhosts/mywebsite.com/httpdocs/test.mp3

这没有问题,但是当我尝试添加 -user_agent、-user-agent 或 -headers 时,它会失败并出现上述错误。

如果有帮助,版本信息为:

FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
  built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
  configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.11. 0 /  0.11. 0
  libpostproc   51. 2. 0 / 51. 2. 0
FFmpeg 0.6.5
libavutil     50.15. 1 / 50.15. 1
libavcodec    52.72. 2 / 52.72. 2
libavformat   52.64. 2 / 52.64. 2
libavdevice   52. 2. 0 / 52. 2. 0
libavfilter    1.19. 0 /  1.19. 0
libswscale     0.11. 0 /  0.11. 0
libpostproc   51. 2. 0 / 51. 2. 0

提前感谢!

您可以使用 -headers 选项:

ffmpeg -headers 'User-Agent: Mozilla' -i http://my.radio.com:8000/1

请注意,您将收到一条警告:

[http @ 00000000004795c0] No trailing CRLF found in HTTP header.

从 FFmpeg 版本 2.8 开始,如果需要,将添加 CRLF。您可以如果需要,请将警告静音:

ffmpeg -v error -stats

或者您可以自己包含 CRLF:

q=$(printf 'User-Agent: Mozillarnx')
ffmpeg -headers "${q%x}"

我正在回答我自己的问题,因为经过一个小时或更长时间的挖掘,似乎我正在运行的旧版本的 ffmpeg,我从一个众所周知的存储库获得,不支持 -user_agent 选项/开关,也不支持 -headers 开关(感谢 Steven Penny)。

因此,我从官方网站下载了ffmpeg的Linux静态版本。在通过 SSH 将其弹跳到服务器上并记住将权限更改为 755 之后,我设法让 -user_agent 选项/开关工作。

我希望我自己对我的问题的回答,将来能帮助其他人。

最新更新