Liz*_*zom 13 video command-line ffmpeg http http-headers
我需要将http标头(用户代理和IP)传递给ffmpeg命令.
我使用以下命令:
ffmpeg -y -timeout 5000000 -map 0:0 -an -sn -f md5 - -headers "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36" -headers "X-Forwarded-For: 13.14.15.66" -i "http://127.0.0.1"
Run Code Online (Sandbox Code Playgroud)
我运行一个本地node.js服务器来查看我得到的标头:
'use strict';
var express = require('express');
var server = express();
server.all('/*', function(req, res) {
console.log(JSON.stringify(req.headers));
res.sendFile('SampleVideo_1080x720_1mb.mp4', {root: '.'});
});
server.listen(80);
Run Code Online (Sandbox Code Playgroud)
我不断收到错误消息"在HTTP标头中找不到尾随CRLF".并且请求被卡住了.
如果我删除标题 - 一切正常.
我也尝试将两个标题放在一个字符串中,但我使用的任何换行符(\ r \n,\ r \n等)都不起作用.
有人可以帮我弄清楚如何使用包含的头文件正确编写此命令吗?
Jam*_*son 13
确保您使用的是最新版本ffmpeg
,然后使用该-user-agent
选项.
为了调试,我设置一个BaseHTTPSever
在运行127.0.0.1:8080
有do_GET()
如下:
def do_GET(self):
try:
f = open(curdir + sep + self.path, 'rb')
self.send_response(200)
self.end_headers()
print("GET: "+ str(self.headers))
self.wfile.write(f.read())
f.close()
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
Run Code Online (Sandbox Code Playgroud)
通过该运行,这使我能够运行您的命令,如:
ffmpeg \
-y \
-timeout 5000000 \
-map 0:0 \
-an \
-sn \
-f md5 - \
-headers "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36" \
-headers "X-Forwarded-For: 13.14.15.66" \
-i "http://127.0.0.1:8080/some_video_file.mp4" \
-v trace
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我看到以下相关输出ffmpeg
:
Reading option '-headers' ... matched as AVOption 'headers' with argument 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'.
Reading option '-headers' ... matched as AVOption 'headers' with argument 'X-Forwarded-For: 13.14.15.66'.
Run Code Online (Sandbox Code Playgroud)
在服务器上,我看到:
User-Agent: Lavf/56.40.101
X-Forwarded-For: 13.14.15.66
Run Code Online (Sandbox Code Playgroud)
所以它看起来ffmpeg
就是设置它自己的.但是,有一个选项-user-agent
来ffmpeg
,当我换成-headers "User-Agent: <foo>"
用-user-agent "<foo>"
,我再没有看到过它的服务器上,旁边的X-Forwarded-For
标题:
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
最后一点.关于trac中的头文件bug有很多讨论ffmpeg
.我上面观察到的(基本上它正在工作,可能是一个小的命令更改)是一个相当新的版本:
ffmpeg version 2.8.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --enable-libx264 --enable-gpl --prefix=/usr/local --enable-shared --cc='gcc -fPIC'
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Run Code Online (Sandbox Code Playgroud)
所以,你的下一步行动可能是确保你有最新版本的ffmpeg
.
对于设置x:1
和y:2
标头 ffmpeg 请求,请使用以下命令:
ffmpeg -headers $'x:1\r\ny:2\r\n' -i 'http://sample.com' -y 'sample.mp4' -v debug
Run Code Online (Sandbox Code Playgroud)
结果:
[http @ 0x358be00] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[http @ 0x358be00] request: GET / HTTP/1.1
User-Agent: Lavf/57.76.100
Accept: */*
Range: bytes=0-
Connection: close
Host: example.com
Icy-MetaData: 1
x:1
y:2
Run Code Online (Sandbox Code Playgroud)
小智 7
好吧,ffmpeg手册说要通过CRLF分割多个http-header.问题是你用第二个"-header"覆盖你的第一个"-header"参数,因为只能有一个"-header"参数.
对于您的示例,您需要通过有效的CRLF 加入User-Agent
并X-Forwarded
加入一个参数,如下所示:
-header "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"$'\r\n'"X-Forwarded-For: 13.14.15.66"$'\r\n'
归档时间: |
|
查看次数: |
19784 次 |
最近记录: |