ffmpeg-如何传递HTTP标头?

利佐佐姆

我需要将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" 

然后,我运行本地的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);

我不断收到错误消息:“在HTTP标头中找不到结尾的CRLF。” 并且请求被卡住。

如果我放下标题,则一切正常。

我还尝试将两个标头都放在一个字符串中,但是我使用的任何换行符(\ r \ n,\ r \ n等)均无效。

有人可以帮我弄清楚如何正确地使用附带的标题来编写此命令吗?

詹姆森

简短答案

确保您使用的是最新版本ffmpeg,然后使用该-user-agent选项。

更长的答案

为了调试,我设置一个BaseHTTPSever在运行127.0.0.1:8080do_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)

运行该命令后,我可以像这样运行您的命令:

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

执行此操作时,我从中看到以下相关输出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'.

在服务器上,我看到了:

User-Agent: Lavf/56.40.101
X-Forwarded-For: 13.14.15.66

所以看起来好像ffmpeg是设置它自己的。但是,有一个选项-user-agentffmpeg,当我换成-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

最后一点。关于Trac for中的标头错误有很多讨论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

因此,下一步可能是确保您使用的是最新版本ffmpeg

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章