Код: Выделить всё
gst-launch-1.0 rtspsrc location="rtsp://:@:
" ! rtph264depay ! h264parse ! mpegtsmux ! hlssink max-files=0 playlist-length=0 location="%05d.ts" playlist-location="list.m3u8" target-duration=15
Захват консоли CMD
ЧТО ПРОИСХОДИТ В VISUAL STUDIO:
Захват консоли Visual Studio
Не могу запустить потоковую передачу с помощью этого конвейера. Когда я пытаюсь запустить конвейер через CMD, он работает отлично, но когда я запускаю процесс через код C#, он зависает в «Перераспределить задержку...» и потоковая передача не происходит. Не начну. Я пытался увеличить задержку, но это тоже не сработало.
Это весь мой серверный код C#, который я написал. Я получаю от него веб-запросы и запускаю Gst-launch-1.0.
Код: Выделить всё
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:
/");
listener.Start();
Console.WriteLine("Server Running...");
try
{
while (true)
{
HttpListenerContext context = await listener.GetContextAsync();
string rtspUrl = context.Request.QueryString["url"];
string cameraIp = context.Request.QueryString["ip"];
if (!string.IsNullOrEmpty(rtspUrl) && !string.IsNullOrEmpty(cameraIp) &&
Uri.IsWellFormedUriString(rtspUrl, UriKind.Absolute) &&
IPAddress.TryParse(cameraIp, out _))
{
string directoryPath = Path.Combine("C:", "Users", "FEFDEVNOC", "source", "repos", "GStreamerServer", "GStreamerServer", "bin", "Debug", "net6.0", "Streams", cameraIp);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
string hlsOutputPath = Path.Combine(directoryPath, "output.m3u8");
//string command = $"rtspsrc location=\"{rtspUrl}\" latency=200 ! rtph264depay ! h264parse ! mpegtsmux ! hlssink location=\"{directoryPath}\\%06d.ts\" target-duration=5 playlist-location=\"{hlsOutputPath}\"";
string command = "rtspsrc name =myrtsp location=rtsp://:@:´ ! queue ! rtph264depay ! h264parse ! mpegtsmux name=mymux ! hlssink max-files=5 playlist-location=playlist.m3u8 location=segment%05d.ts target-duration=10 myrtsp. ! queue ! rtpmp4adepay ! aacparse ! mymux.";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C gst-launch-1.0 {command}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine("Output: " + e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine("Error: " + e.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await Task.Run(() => process.WaitForExit());
if (process.ExitCode != 0)
{
Console.WriteLine("GStreamer falhou com código de saída: " + process.ExitCode);
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
using (var writer = new StreamWriter(context.Response.OutputStream))
{
await writer.WriteLineAsync("Falha ao iniciar o streaming.");
}
continue;
}
}
context.Response.StatusCode = (int)HttpStatusCode.OK;
using (var writer = new StreamWriter(context.Response.OutputStream))
{
Console.WriteLine($"Requisição: {rtspUrl} IP: {cameraIp}");
await writer.WriteLineAsync($"Streaming iniciado para {cameraIp}");
}
}
else
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
context.Response.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Erro: " + ex.Message);
}
finally
{
listener.Stop();
}
}
}
Код: Выделить всё
location /start-stream {
proxy_pass http://localhost:
/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /streams {
alias
add_header 'Access-Control-Allow-Origin' '*';
}
Может ли кто-нибудь мне помочь?Я пробовал изменить конвейер, запустить Visual Studio 2022 в режиме администратора, изменить PATH среды, попробовать GStreamer с gs-inpect-1.0, и у меня есть все плагины... Я уже проверил.< /п>
Подробнее здесь: https://stackoverflow.com/questions/791 ... ot-working