简体   繁体   English

使用文件输入时无法设置ffmpeg标头

[英]Can't set ffmpeg header when using file for input

I'm attempting to set headers ( as suggested here ) for my ffmpeg concat command like so: 我正在尝试为ffmpeg concat命令设置标头( 如此处建议 ),如下所示:

ffmpeg \
    -f concat \
    -safe 0 \
    -protocol_whitelist file,http,https,tcp,tls \
    -headers $'Content-Type: audio/wav\r\n' \
    -i 'inputs.txt' \
    -c 'copy' 'output.wav' \
    -v trace

where my input file is structured as such: 我的输入文件的结构如下:

file 'https://path/to/file1'
file 'https://path/to/file2'
file 'https://path/to/file3'

However, when I run the command, ffmpeg doesn't set the headers, as seen by the output of -v: 但是,当我运行命令时,ffmpeg不会设置标头,如-v的输出所示:

[http @ 0x7fa133d01080] request: GET / HTTP/1.1
User-Agent: Lavf/58.20.100
Accept: */*
Range: bytes=0-
Connection: close
Host: localhost:3001
Icy-MetaData: 1

What's strange is if I set my input not through an input txt and just through -i /path/to file (as seen below) it works just fine. 奇怪的是,如果我不通过输入txt而是仅通过-i /path/to file设置输入(如下所示),则效果很好。

ffmpeg \
    -f concat \
    -safe 0 \
    -protocol_whitelist file,http,https,tcp,tls \
    -headers $'Content-Type: audio/wav\r\n' \
    -i 'https://google.com' \
    -c 'copy' 'output.wav' \
    -v trace

Output of -v: -v的输出:

[https @ 0x7fed3ac03940] request: GET / HTTP/1.1
User-Agent: Lavf/58.20.100
Accept: */*
Range: bytes=0-
Connection: close
Host: google.com
Icy-MetaData: 1
Content-Type: audio/wav

Not sure why reading the inputs through a file would affect the headers getting sent. 不确定为什么通过文件读取输入会影响标题发送。 For now the workaround is to use a string concatenating all of the inputs (a bit messier than I'd like), but I'm curious if anyone might know why this is happening. 现在,解决方法是使用一个字符串将所有输入连接起来(比我想要的还乱一些),但是我很好奇是否有人知道为什么会这样。

UPDATE : According to this post I have to read inputs through a text file, so I'm back to square one.... 更新 :根据这篇文章,我必须通过一个文本文件读取输入内容,所以我回到正题。

When a single input is directed fed to ffmpeg ( -i ), various options can be set on it, depending on what the input reader allows and recognizes. 当将单个输入直接输入到ffmpeg( -i )时,可以在其上设置各种选项,具体取决于输入阅读器允许和识别的内容。

However, FFmpeg does not natively read an input list from a text file. 但是,FFmpeg本身不会从文本文件中读取输入列表。 There's a bespoke module called the concat demuxer , invoked by -f concat , which parses the input list, opens each file and concatenates them. 有一个名为concat demuxer的定制模块,由-f concat调用,该模块解析输入列表,打开每个文件并将其串联。 To the main ffmpeg pipeline, this is presented as a single input, generated by the concat module. 对于主要的ffmpeg管道,这是由concat模块生成的单个输入。 And the concat module does not recognize or carry over options meant for the individual files listed within the text file. 而且concat模块不会识别或保留用于文本文件中列出各个文件的选项。 All listed files can only be opened with default parameters of their respective demuxers/decoders/protocols..etc. 所有列出的文件只能使用其各自的解复用器/解码器/协议..etc的默认参数打开。 This is a limitation. 这是一个限制。 You may open a feature request at trac.ffmpeg.org to change this. 您可以在trac.ffmpeg.org上打开功能请求以进行更改。

What you could do is read all inputs directly. 您可以做的是直接读取所有输入。

ffmpeg \
    -headers $'Content-Type: audio/wav\r\n' \
    -i 'https://google1.com' \
    -headers $'Content-Type: audio/wav\r\n' \
    -i 'https://google2.com' \
    -headers $'Content-Type: audio/wav\r\n' \
    -i 'https://google3.com' \
    -headers $'Content-Type: audio/wav\r\n' \
    -i 'https://google4.com' \
    -filter_complex "[0][1][2][3]concat=n=4:v=0:a=1" \
    'output.wav'

For WAV inputs, re-encoding to WAV won't lose quality. 对于WAV输入,重新编码为WAV不会失去质量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM