Я пытаюсь ввести поток и уменьшить битрейт видео, не сохраняя его нигде, поэтому я надеюсь передать его как поток, получить выходные данные в виде потока и отправить его в цифровые океанские пространства для сохранения.
/>Но я пробовал много вещей, но мой выходной поток становится пустым. и файл пуст.
public async Task VideoOperationAsync(Stream inputStream)
{
try
{
// Ensure the input stream is at the beginning
inputStream.Position = 0;
// Create a memory stream to hold the output data
using (var outputStream = new MemoryStream())
{
var arguments = $"-i pipe:0 -b:v 2000k -f mp4 pipe:1";
Cli.Wrap("ffmpeg")
.WithArguments(arguments)
.WithStandardInputPipe(PipeSource.FromStream(inputStream))
.WithStandardOutputPipe(PipeTarget.ToStream(outputStream))
.ExecuteAsync();
// Ensure the output stream is at the beginning before reading
outputStream.Position = 0;
using (var fileStream = new FileStream(@"D:\Gremlin-data\VideoResized\output_cropped.mp4", FileMode.Create, FileAccess.Write))
{
await outputStream.CopyToAsync(fileStream);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
throw; // Re-throw the exception if needed
}
}
Я также ранее пробовал это:
public async Task VideoOperationAsync(Stream inputStream)
{
попробуй
{
// Убедитесь, что входной поток находится в начале
inputStream.Position = 0;
var ffmpegProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "ffmpeg", // Ensure ffmpeg is in your PATH or provide the full path
Arguments = $"-i pipe:0 -b:v 2000k -f mp4 pipe:1", // Correct bitrate format
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true, // Capture standard error
UseShellExecute = false,
CreateNoWindow = true
}
};
ffmpegProcess.Start();
// Write input stream to ffmpeg's standard input asynchronously
Task writingTask = Task.Run(async () =>
{
await inputStream.CopyToAsync(ffmpegProcess.StandardInput.BaseStream);
ffmpegProcess.StandardInput.BaseStream.Close();
});
// Read ffmpeg's standard output to a memory stream asynchronously
using (MemoryStream ms = new MemoryStream())
{
Task readingTask = Task.Run(async () =>
{
await ffmpegProcess.StandardOutput.BaseStream.CopyToAsync(ms);
});
Подробнее здесь: https://stackoverflow.com/questions/787 ... -in-ffmpeg
Использование каналов для потоковых данных в FFMPEG ⇐ C#
Место общения программистов C#
-
Anonymous
1721195667
Anonymous
Я пытаюсь ввести поток и уменьшить битрейт видео, не сохраняя его нигде, поэтому я надеюсь передать его как поток, получить выходные данные в виде потока и отправить его в цифровые океанские пространства для сохранения.
/>Но я пробовал много вещей, но мой выходной поток становится пустым. и файл пуст.
public async Task VideoOperationAsync(Stream inputStream)
{
try
{
// Ensure the input stream is at the beginning
inputStream.Position = 0;
// Create a memory stream to hold the output data
using (var outputStream = new MemoryStream())
{
var arguments = $"-i pipe:0 -b:v 2000k -f mp4 pipe:1";
Cli.Wrap("ffmpeg")
.WithArguments(arguments)
.WithStandardInputPipe(PipeSource.FromStream(inputStream))
.WithStandardOutputPipe(PipeTarget.ToStream(outputStream))
.ExecuteAsync();
// Ensure the output stream is at the beginning before reading
outputStream.Position = 0;
using (var fileStream = new FileStream(@"D:\Gremlin-data\VideoResized\output_cropped.mp4", FileMode.Create, FileAccess.Write))
{
await outputStream.CopyToAsync(fileStream);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
throw; // Re-throw the exception if needed
}
}
Я также ранее пробовал это:
public async Task VideoOperationAsync(Stream inputStream)
{
попробуй
{
// Убедитесь, что входной поток находится в начале
inputStream.Position = 0;
var ffmpegProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "ffmpeg", // Ensure ffmpeg is in your PATH or provide the full path
Arguments = $"-i pipe:0 -b:v 2000k -f mp4 pipe:1", // Correct bitrate format
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true, // Capture standard error
UseShellExecute = false,
CreateNoWindow = true
}
};
ffmpegProcess.Start();
// Write input stream to ffmpeg's standard input asynchronously
Task writingTask = Task.Run(async () =>
{
await inputStream.CopyToAsync(ffmpegProcess.StandardInput.BaseStream);
ffmpegProcess.StandardInput.BaseStream.Close();
});
// Read ffmpeg's standard output to a memory stream asynchronously
using (MemoryStream ms = new MemoryStream())
{
Task readingTask = Task.Run(async () =>
{
await ffmpegProcess.StandardOutput.BaseStream.CopyToAsync(ms);
});
Подробнее здесь: [url]https://stackoverflow.com/questions/78757844/using-pipes-for-stream-data-in-ffmpeg[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия