我正在尝试使用-headers
ffmpeg 中的命令,但使用以下命令时出现错误No trailing CRLF found in HTTP header
。
ffmpeg -headers "$(printf '\n%s\n%s\n%s\n%s\n%s\n%s\n\n' 'Cookie: GPS=1; PREF=f1=50000000&hl=en; VISITOR_INFO1_LIVE=YYVg5wZlZM4; YSC=nqFTzbjynHk; s_gl=1d69aac621b2f9c0a25dade722d6e24bcwIAAABVUw==' 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0' 'Accept-Encoding: gzip, deflate' 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' 'Accept-Language: en-us,en;q=0.5')" -i http://localhost:8000 -v trace
这是 ffmpeg输出(注意,-v
我也尝试过\r\n
,,而不是只是仍然得到相同的错误(printf 转义的双重情况)\\r\\n
\\n
\n
ffmpeg -headers "$(printf '\n%s\n%s\n%s\n%s\n%s\n%s\n\n' 'Cookie: GPS=1; PREF=f1=50000000&hl=en; VISITOR_INFO1_LIVE=YYVg5wZlZM4; YSC=nqFTzbjynHk; s_gl=1d69aac621b2f9c0a25dade722d6e24bcwIAAABVUw==' 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0' 'Accept-Encoding: gzip, deflate' 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' 'Accept-Language: en-us,en;q=0.5')" -i http://localhost:8000 -v trace
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Splitting the commandline.
Reading option '-headers' ... matched as AVOption 'headers' with argument '
Cookie: GPS=1; PREF=f1=50000000&hl=en; VISITOR_INFO1_LIVE=YYVg5wZlZM4; YSC=nqFTzbjynHk; s_gl=1d69aac621b2f9c0a25dade722d6e24bcwIAAABVUw==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en-us,en;q=0.5'.
Reading option '-i' ... matched as input url with argument 'http://localhost:8000'.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url http://localhost:8000.
Successfully parsed a group of options.
Opening an input file: http://localhost:8000.
[NULL @ 0x556cf5231a60] Opening 'http://localhost:8000' for reading
[http @ 0x556cf5232780] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[http @ 0x556cf5232780] No trailing CRLF found in HTTP header.
[http @ 0x556cf5232780] request: GET / HTTP/1.1
User-Agent: Lavf/57.83.100
Accept: */*
Range: bytes=0-
Connection: close
Host: localhost:8000
Icy-MetaData: 1
Cookie: GPS=1; PREF=f1=50000000&hl=en; VISITOR_INFO1_LIVE=YYVg5wZlZM4; YSC=nqFTzbjynHk; s_gl=1d69aac621b2f9c0a25dade722d6e24bcwIAAABVUw==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en-us,en;q=0.5
[http @ 0x556cf5232780] header='HTTP/1.0 200 OK'
[http @ 0x556cf5232780] http_code=200
答案1
这条评论说得对:
这是一个警告,而不是错误。
ffmpeg
自行附加尾随的 CRLF 并继续。
我的回答解释为什么即使您\r\n
在 中使用,该工具也无法“看到” CRLF printf
。这是因为$()
。POSIX 规范说[强调我的]:
$(command)
[...]
shell 应通过在子 shell 环境中执行 [...] 来扩展命令替换,并用命令的标准输出
command
替换命令替换(command
加上括起来的或反引号的文本),$()
删除替换末尾的一个或多个 <newline> 字符序列。
因此没有办法\n
从中获得尾随$()
。
你可以让你的 shell 添加尾随换行符,尽管并非所有的 shell 都支持此功能。在 Bash 中,
foo "$(printf '\n%s\r\n' 'bar')"
使用
foo "$(printf '\n%s' 'bar')"$'\r\n'
答案2
我发现的最佳解决方案是:
ffmpeg …
-method PUT \
-headers "Cookie: GPS=1;"$'\r\n'
或者对于多个标题:
ffmpeg …
-method PUT \
-headers "Cookie: GPS=1;"$'\r\n'"PREF=f1=50000000"$'\r\n'