简体   繁体   English

如何从ffmpeg中的流中检索HTTP标头?

[英]How to retrieve HTTP headers from a stream in ffmpeg?

I'm currently makeing an audio streaming app on Android. 我目前正在Android上制作音频流媒体应用。 I'm using Android NDK combined with ffmpeg to perform that it's working pretty well so far. 我正在使用Android NDK与ffmpeg相结合来执行它迄今为止运行良好。

Right now I would like to retrieve the shoutcast metadata contained in the headers stream while streaming. 现在我想在流式传输时检索标题流中包含的shoutcast元数据。 Apparently ffmpeg doesn't provide a direct way to do that but I'm pretty sure it's technically possible to retrieve HTTP headers from the stream as we are receiving all the bytes while streaming. 显然ffmpeg没有提供直接的方法来做到这一点,但我很确定技术上可以从流中检索HTTP标头,因为我们在流式传输时接收所有字节。

Does anyone know how to retrieve HTTP headers from a stream using ffmpeg? 有谁知道如何使用ffmpeg从流中检索HTTP标头?

In case you are looking for shoutcast metadata ... 如果您正在寻找shoutcast元数据 ...
Since FFmpeg 2.0 there is built-in support for them. 自FFmpeg 2.0以来,它们内置了支持。 Here's the http protocol that exposes the relevant AVOptions. 这是公开相关AVOptions的http协议

Implementation 履行

Set the icy AVOption to 1 when calling avformat_open_input . 调用avformat_open_input时,将icy AVOption设置为1。 This will set the Icy-MetaData HTTP header when opening the stream: 这将在打开流时设置Icy-MetaData HTTP标头:

AVDictionary *options = NULL;
av_dict_set(&options, "icy", "1", 0);
AVFormatContext* container = avformat_alloc_context();
int err = avformat_open_input(&container, url, NULL, &options);

Then poll the icy_metadata_packet or icy_metadata_headers AVOption on your context to retrieve the current metadata: 然后轮询上下文中的icy_metadata_packeticy_metadata_headers AVOption以检索当前元数据:

char* metadata = NULL;
av_opt_get(container, "icy_metadata_packet", AV_OPT_SEARCH_CHILDREN, (uint8_t**) &metadata);
printf("icy_metadata_packet: %s\n", metadata);
av_free(metadata);
metadata = NULL;
av_opt_get(container, "icy_metadata_headers", AV_OPT_SEARCH_CHILDREN, (uint8_t**) &metadata);
printf("\nicy_metadata_headers:\n%s\n", metadata);
av_free(metadata);

Next you'll probably want to get the metadata information up to the Java layer of your Android app. 接下来,您可能希望将元数据信息提供到Android应用程序的Java层。 I'm not familiar with the NDK, so you'll have to figure this out for yourself ;) 我不熟悉NDK,所以你必须自己解决这个问题;)

Example Output 示例输出

icy_metadata_packet: StreamTitle='Zelda Reorchestrated - Twilight Symphony - Gerudo Desert';

icy_metadata_headers:
icy-br: 192
icy-description: Radio Hyrule
icy-genre: Remix
icy-name: Radio Hyrule
icy-pub: 1
icy-url: http://radiohyrule.com/

More Information 更多信息

Find out more on the mailing list where the patch was proposed. 在提出补丁的邮件列表中找到更多信息。
The options are defined on the AVClass for the HTTP and HTTPS context ( code ). 这些选项在AVClass为HTTP和HTTPS上下文( 代码 )定义。

This involves 2 separate operations on the http response and has not much to do with android-ffmpeg. 这涉及对http响应的两个单独操作,与android-ffmpeg没什么关系。

see sections '1.1.3' , '1.1.6' here 请参阅此处的 “1.1.3”,“1.1.6”部分

Assuming you are using default implementation of HttpClient in android, the apis are very similar. 假设你在android中使用HttpClient的默认实现,api非常相似。 There is a bridge package in use for android that wraps the apache httpclient libs used in my example. 有一个用于android的桥接包,包装了我的示例中使用的apache httpclient库。

When you get the response, you do one thing to get the response headers ( see links ) and then another thing to get the stream object in the ENTITY and then use JNI to pass a ptr to that stream over to the I/O from ffmpeg. 当你得到响应时,你做一件事来获取响应头(参见链接)然后另一件事来获取ENTITY中的流对象,然后使用JNI将ptr传递给ffmpeg的I / O 。

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

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