gpt4 book ai didi

ffmpeg - AVFormatContext : interrupt callback proper usage?

转载 作者:行者123 更新时间:2023-12-04 23:11:07 25 4
gpt4 key购买 nike

AVFormatContext 的 interrupt_callback字段是一个

Custom interrupt callbacks for the I/O layer.


它的类型是 AVIOInterruptCB ,并在评论部分解释:

Callback for checking whether to abort blocking functions.

AVERROR_EXIT is returned in this case by the interrupted function. During blocking operations, callback is called with opaque as parameter. If the callback returns 1, the blocking operation will be aborted.

No members can be added to this struct without a major bump, if new elements have been added after this struct in AVFormatContext or AVIOContext.


我有两个问题:
  • 最后一段是什么意思?特别是“没有大的颠簸”?
  • 如果我将它与 RTSP 源一起使用,当我通过 avformat_close_input 关闭输入时,正在发送“TEARDOWN”消息,但它不会到达 RTSP 服务器。

  • 对于 2:这是演示的快速伪代码:
    int pkts = 0;
    bool early_exit = false;

    int InterruptCallback(void* ctx) {
    return early_exit ? 1 : 0;
    }

    void main() {
    ctx = avformat_alloc_context
    ctx->interrupt_callback.callback = InterruptCallback;

    avformat_open_input
    avformat_find_stream_info
    pkts=0;
    while(!early_exit) {
    av_read_frame

    if (pkts++ > 100) early_exit=true;
    }

    avformat_close_input
    }
    如果我根本不使用中断回调,则 TEARDOWN 被发送出去,并且它也到达 RTSP 服务器,因此它实际上可以断开连接。否则,它不会拆掉它,我必须等到 TCP 套接字超时。
    使用此中断回调的正确方法是什么?

    最佳答案

  • 这意味着他们不会更改此结构的任何内容 (AVIOInterruptCB)。但是,如果是这样的话,它将是一个重大的颠簸(从 4.4 到 5.0 的重大变化)
  • 您需要将有意义的参数传递给 void* ctx。任何你喜欢的东西,你都可以在静态函数中检查它。例如,您将设置为取消的 bool 值,因此您将中断 av_read_frame(这将返回一个 AVERROR_EXIT)。通常你会传递一个解码器上下文类或类似的东西,它还包含检查是否返回 1 以中断或 0 以正确继续请求所需的所有信息。一个真实的例子是您打开了一个错误的 rtsp,然后您想打开另一个(正确的),因此您需要取消之前的请求。
  • 关于ffmpeg - AVFormatContext : interrupt callback proper usage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68414179/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com