This commit is contained in:
cxh 2025-10-16 17:11:40 +08:00
parent a48b2ef917
commit c592e1b7cb

View File

@ -95,6 +95,7 @@ GstElement *RTMPManager::create_pipeline(const Camera &cam, StreamType type)
}
std::string stream_name = cam.name + stream_type_suffix(type);
std::string pipeline_str = "v4l2src device=" + cam.device +
" ! video/x-raw,format=NV12,width=" + std::to_string(width) +
",height=" + std::to_string(height) + ",framerate=" + std::to_string(fps) +
@ -103,10 +104,7 @@ GstElement *RTMPManager::create_pipeline(const Camera &cam, StreamType type)
std::to_string(bitrate) + " gop=" + std::to_string(fps) +
" ! h264parse ! flvmux streamable=true name=mux "
"! rtmpsink location=\"rtmp://127.0.0.1/live/" +
stream_name +
" live=1\" sync=false"
" timeout=5000000 " // 5秒超时微秒单位
"async-handling=true"; // 异步错误处理,防止阻塞
stream_name + " live=1\" sync=false async-handling=true do-timestamp=true";
LOG_INFO("[RTMP] Creating pipeline for '" + stream_name + "': " + pipeline_str);
@ -328,6 +326,8 @@ void RTMPManager::stream_loop(Camera cam, StreamType type, StreamContext *ctx)
status.running = false;
status.last_result = StreamResult::CONNECTION_FAIL;
status.last_error = err ? err->message : "GStreamer error";
LOG_ERROR("[RTMP] Stream error from '" + cam.name + "': " + status.last_error);
gst_element_set_state(pipeline, GST_STATE_NULL); // ✅ 防止卡死
if (err) g_error_free(err);
try_set_start(status);
break;