Я создавал видеокомпрессор с использованием платформы .net 4.2.1, а также использую библиотеку ffmpeg для сжатия видео. Я не получаю точную проблему: на самом деле библиотека ffmpeg не работает или запрос не ждет сжатия видео. Кстати, когда я нажимаю кнопку сжатия, чтобы начать сжатие видео, он загружает файл mp4 размером 0 КБ. Пожалуйста, помогите, если кто-нибудь знаком с этой концепцией
Спасибо
using System;
using System.Diagnostics;
using System.IO;
namespace WebApplication16
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCompress_Click(object sender, EventArgs e)
{
if (fileUpload.HasFile)
{
string inputFilePath = Path.GetTempFileName();
string outputFilePath = Path.GetTempFileName();
fileUpload.SaveAs(inputFilePath);
CompressVideo(inputFilePath, outputFilePath, "640x480", "200k");
Response.ContentType = "video/mp4";
Response.AppendHeader("Content-Disposition", "attachment; filename=\"compressed_video.mp4\"");
Response.TransmitFile(outputFilePath);
Response.End();
}
else
{
Response.Write("No file uploaded");
}
}
static void CompressVideo(string inputFilePath, string outputFilePath, string resolution , string bitrate )
{
try
{
if (!File.Exists(inputFilePath))
{
Console.WriteLine($"Error: Input file '{inputFilePath}' does not exist.");
return;
}
if (!IsValidVideoFile(inputFilePath))
{
Console.WriteLine($"Error: Input file '{inputFilePath}' is not a valid video file.");
return;
}
string ffmpegPath = @"C:\Users\abhin\Downloads\ffmpeg-master-latest-win64-gpl-shared\bin\ffmpeg.exe"; // Assuming ffmpeg is in PATH
string args = $"-i \"{inputFilePath}\" -s {resolution} -b:v {bitrate} \"{outputFilePath}\" -y";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = ffmpegPath,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine($"Error: {e.Data}");
}
};
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine($"Output: {e.Data}");
}
};
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
Console.WriteLine($"Error: ffmpeg process exited with code {process.ExitCode}");
}
}
if (!File.Exists(outputFilePath))
{
Console.WriteLine($"Error: Output file '{outputFilePath}' was not generated.");
}
else
{
Console.WriteLine($"Output file '{outputFilePath}' generated successfully.");
FileInfo fileInfo = new FileInfo(outputFilePath);
Console.WriteLine($"Output file size: {fileInfo.Length} bytes");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error occurred: {ex.Message}");
}
}
static bool IsValidVideoFile(string filePath)
{
string extension = Path.GetExtension(filePath);
return extension.ToLower() == ".mp4" || extension.ToLower() == ".avi" || extension.ToLower() == ".mov";
}
}
}
Video Compression
Подробнее здесь: https://stackoverflow.com/questions/786 ... -net-frame
Проблемы при создании видеокомпрессора с использованием библиотеки ffmpeg в .net framework 4.7.1. ⇐ C#
Место общения программистов C#
1719301791
Anonymous
Я создавал видеокомпрессор с использованием платформы .net 4.2.1, а также использую библиотеку ffmpeg для сжатия видео. Я не получаю точную проблему: на самом деле библиотека ffmpeg не работает или запрос не ждет сжатия видео. Кстати, когда я нажимаю кнопку сжатия, чтобы начать сжатие видео, он загружает файл mp4 размером 0 КБ. Пожалуйста, помогите, если кто-нибудь знаком с этой концепцией
Спасибо
using System;
using System.Diagnostics;
using System.IO;
namespace WebApplication16
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCompress_Click(object sender, EventArgs e)
{
if (fileUpload.HasFile)
{
string inputFilePath = Path.GetTempFileName();
string outputFilePath = Path.GetTempFileName();
fileUpload.SaveAs(inputFilePath);
CompressVideo(inputFilePath, outputFilePath, "640x480", "200k");
Response.ContentType = "video/mp4";
Response.AppendHeader("Content-Disposition", "attachment; filename=\"compressed_video.mp4\"");
Response.TransmitFile(outputFilePath);
Response.End();
}
else
{
Response.Write("No file uploaded");
}
}
static void CompressVideo(string inputFilePath, string outputFilePath, string resolution , string bitrate )
{
try
{
if (!File.Exists(inputFilePath))
{
Console.WriteLine($"Error: Input file '{inputFilePath}' does not exist.");
return;
}
if (!IsValidVideoFile(inputFilePath))
{
Console.WriteLine($"Error: Input file '{inputFilePath}' is not a valid video file.");
return;
}
string ffmpegPath = @"C:\Users\abhin\Downloads\ffmpeg-master-latest-win64-gpl-shared\bin\ffmpeg.exe"; // Assuming ffmpeg is in PATH
string args = $"-i \"{inputFilePath}\" -s {resolution} -b:v {bitrate} \"{outputFilePath}\" -y";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = ffmpegPath,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine($"Error: {e.Data}");
}
};
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine($"Output: {e.Data}");
}
};
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
Console.WriteLine($"Error: ffmpeg process exited with code {process.ExitCode}");
}
}
if (!File.Exists(outputFilePath))
{
Console.WriteLine($"Error: Output file '{outputFilePath}' was not generated.");
}
else
{
Console.WriteLine($"Output file '{outputFilePath}' generated successfully.");
FileInfo fileInfo = new FileInfo(outputFilePath);
Console.WriteLine($"Output file size: {fileInfo.Length} bytes");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error occurred: {ex.Message}");
}
}
static bool IsValidVideoFile(string filePath)
{
string extension = Path.GetExtension(filePath);
return extension.ToLower() == ".mp4" || extension.ToLower() == ".avi" || extension.ToLower() == ".mov";
}
}
}
Video Compression
Подробнее здесь: [url]https://stackoverflow.com/questions/78665653/facing-issues-while-building-video-compressor-using-ffmpeg-library-in-net-frame[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия