您的位置:首页 > 文旅 > 旅游 > ffmpeg中的超时控制

ffmpeg中的超时控制

2024/10/5 20:34:51 来源:https://blog.csdn.net/melonbo/article/details/140502465  浏览:    关键词:ffmpeg中的超时控制

在FFmpeg库中,很多函数没有直接的参数可以设置超时。

那么有哪些函数可以通过设置 AVFormatContext 的 interrupt_callback 来实现超时控制?

  • avformat_open_input: 打开输入文件或流。这个函数会阻塞,尤其是在网络流的情况下,可能会因为等待服务器响应而长时间阻塞。

  • avformat_find_stream_info: 读取流信息。这个函数会尝试读取更多的数据来获得流的详细信息,如果数据源响应缓慢,也会阻塞。

  • av_read_frame: 读取数据包。这个函数会读取下一帧的数据包,如果数据源响应缓慢或者网络连接不稳定,也会阻塞。

  • avio_read: 从输入缓冲区读取数据,这个函数也会阻塞。

  • avio_open: 打开文件或网络资源以进行读取或写入的函数。

  • av_seek_frame avformat_seek_file用于在媒体流中进行跳转操作

  • 等等

总之在打开、关闭、读写网络流的时候都有可能遇到阻塞的问题。

avformat_find_stream_info函数为例,函数的调用关系如下:

avformat_find_stream_inforead_frame_internalff_read_packets->iformat->read_packetread_packet(rpsp.c)ff_sdp_demuxer.read_packet = ff_rtsp_fetch_packetff_rtsp_fetch_packetread_packetff_rtsp_tcp_read_packetff_rtsp_read_replyffurl_read_completeretry_transfer_wrapperff_check_interrupt

ff_check_interrupt函数用于检测中断回调函数是否应该触发中断操作。

调用ff_check_interrupt函数的函数包括:

async_check_interrupt in async.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
retry_transfer_wrapper in avio.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
get_current_fragment in dashdec.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
read_data in dashdec.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
reopen_demux_for_component in dashdec.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
dash_read_packet in dashdec.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
failing_write_packet in fifo_test.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
read_data in hls.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
read_data in hls.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
read_data in hls.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
hls_read in hlsproto.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
hls_read in hlsproto.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
libsrt_network_wait_fd_timeout in libsrt.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
libsrt_listen_connect in libsrt.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
ff_network_wait_fd_timeout in network.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
ff_network_sleep_interruptible in network.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
ff_poll_interrupt in network.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
ff_listen_connect in network.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
start_connect_attempt in network.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
rtp_read in rtpproto.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 
udp_read_packet in rtsp.c (ffmpeg\ffmpeg-4.1.4\libavformat) : 

以上函数被进一步调用的关系如下:

retry_transfer_wrapperffurl_readwrapped_url_readio_read_packetcache_readconcat_readcrypto_readftp_getcftp_readftp_read_dirgopher_readhls_readhttp_getchttp_buf_readhttp_shutdownrtmpe_readrtmp_http_send_cmdrtmp_http_readrtmp_http_openff_rtmp_packet_readff_rtmp_packet_read_internalrtmp_writeudp_read_packetrtp_read_headersap_read_headersap_fetch_packetsrtp_readsubfile_readgnutls_url_pulltls_read_callbackmbedtls_recvurl_bio_breadtls_client_handshake_looptls_readtls_read_cbffurl_read_completeget_chunk_headerread_data_packetget_http_header_dataget_tcp_server_responsertmp_packet_read_one_chunkrtmp_calc_swfhashrtmp_handshakertmp_receive_hs_packetrtmp_server_handshakeff_rtsp_skip_packetff_rtsp_read_replyread_linertsp_read_announceff_rtsp_tcp_read_packetffurl_writeio_write_packetcrypto_writecrypto_closeftp_send_commandftp_writegopher_writehttp_write_replyhttp_connecthttp_writeff_rtmp_packet_writeff_rtp_check_and_send_back_rrff_rtp_send_punch_packetsff_rtp_send_rtcp_feedbackff_rtsp_read_replyff_rtsp_tcp_write_packetgnutls_url_pushhttp_proxy_openhttp_proxy_writehttp_shutdownicecast_writeism_writembedtls_sendmd5_closeprompeg_write_fecrtmp_handshakertmp_send_hs_packetrtmp_server_handshakertmpe_writertp_writertsp_send_cmd_with_content_asyncrtsp_send_replysap_write_closesap_write_packetsend_command_packetsrtp_writetee_writetls_client_handshaketls_client_handshake_looptls_shutdown_clienttls_writetls_write_callbacktls_write_cburl_bio_bwriteasync_check_interruptasync_buffer_taskasync_openasync_read_internalasync_seekff_listen_connectsctp_openunix_openff_network_sleep_interruptiblehttp_read_streamff_network_wait_fd_timeouttcp_readtcp_writeff_poll_interruptff_listen_connectff_connect_parallelget_current_fragmentread_datalibsrt_listen_connectlibsrt_setuplibsrt_network_wait_fd_timeoutlibsrt_listenlibsrt_listen_connectlibsrt_readlibsrt_writeread_datahls_read_headerpulse_read_packetreopen_demux_for_componenttls_client_handshake_loopreopen_demux_for_componentopen_demux_for_componentrecheck_discard_flagsdash_read_packetdash_seekstart_connect_attemptff_connect_paralleludp_read_packetread_packetdash_read_packetAVInputFormat ff_dash_demuxer = {.name           = "dash",.long_name      = NULL_IF_CONFIG_SMALL("Dynamic Adaptive Streaming over HTTP"),.priv_class     = &dash_class,.priv_data_size = sizeof(DASHContext),.read_probe     = dash_probe,.read_header    = dash_read_header,.read_packet    = dash_read_packet,.read_close     = dash_close,.read_seek      = dash_read_seek,.flags          = AVFMT_NO_BYTE_SEEK,};failing_write_packetAVOutputFormat ff_fifo_test_muxer = {.name           = "fifo_test",.long_name      = NULL_IF_CONFIG_SMALL("Fifo test muxer"),.priv_data_size = sizeof(FailingMuxerContext),.write_header   = failing_write_header,.write_packet   = failing_write_packet,.write_trailer  = failing_write_trailer,.deinit         = failing_deinit,.priv_class     = &failing_muxer_class,.flags          = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH,};hls_readconst URLProtocol ff_hls_protocol = {.name           = "hls",.url_open       = hls_open,.url_read       = hls_read,.url_close      = hls_close,.flags          = URL_PROTOCOL_FLAG_NESTED_SCHEME,.priv_data_size = sizeof(HLSContext),};rtp_readconst URLProtocol ff_rtp_protocol = {.name                      = "rtp",.url_open                  = rtp_open,.url_read                  = rtp_read,.url_write                 = rtp_write,.url_close                 = rtp_close,.url_get_file_handle       = rtp_get_file_handle,.url_get_multi_file_handle = rtp_get_multi_file_handle,.priv_data_size            = sizeof(RTPContext),.flags                     = URL_PROTOCOL_FLAG_NETWORK,.priv_data_class           = &rtp_class,};

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com