Извлечение аудио из видео с помощью autogen ffmpeg C# в UnityC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Извлечение аудио из видео с помощью autogen ffmpeg C# в Unity

Сообщение Anonymous »

Привет, я использую ffmpeg autogen для извлечения аудио из видео в Unity, но когда я следую этому коду, запись в файл невозможна, его размер 0 КБ, так в чем проблема, или у кого-то есть примеры извлечения аудио с использованием этой библиотеки , извините за мой английский. Это github библиотеки:
https://github.com/Ruslan-B/FFmpeg.AutoGen

Код: Выделить всё

unsafe void TestExtractAudio()
{

string inFile = Application.streamingAssetsPath + "/" + strFileName;
string outFile = Application.streamingAssetsPath + "/" + strFileNameAudio;

AVOutputFormat* outFormat = null;
AVFormatContext* inFormatContext = null;
AVFormatContext* outFormatContext = null;
AVPacket packet;

ffmpeg.av_register_all();

inFormatContext = ffmpeg.avformat_alloc_context();
outFormatContext = ffmpeg.avformat_alloc_context();

if (ffmpeg.avformat_open_input(&inFormatContext, inFile, null, null) < 0)
{
throw new ApplicationException("Could not open input file.");
}

if (ffmpeg.avformat_find_stream_info(inFormatContext, null) < 0)
{
throw new ApplicationException("Failed to retrieve input stream info.");
}

ffmpeg.avformat_alloc_output_context2(&outFormatContext, null, null, outFile);
if (outFormatContext == null)
{
throw new ApplicationException("Could not create output context");
}

outFormat = outFormatContext->oformat;

AVStream* inStream = inFormatContext->streams[1];
AVStream* outStream = ffmpeg.avformat_new_stream(outFormatContext, inStream->codec->codec);
if (outStream == null)
{
throw new ApplicationException("Failed to allocate output stream.");
}

if (ffmpeg.avcodec_copy_context(outStream->codec, inStream->codec) < 0)
{
throw new ApplicationException("Couldn't copy input stream codec context to output stream codec context");
}

outFormatContext->audio_codec_id = AVCodecID.AV_CODEC_ID_MP3;

int retcode = ffmpeg.avio_open(&outFormatContext->pb, outFile, ffmpeg.AVIO_FLAG_WRITE);
if (retcode < 0)
{
throw new ApplicationException("Couldn't open output file");
}

int returnCode = ffmpeg.avformat_write_header(outFormatContext, null);

if (returnCode < 0)
{
throw new ApplicationException("Error occurred opening output file.");
}

while (true)
{
if (ffmpeg.av_read_frame(inFormatContext, &packet) < 0)
{
break;
}

if (packet.stream_index == 1)
{

inStream = inFormatContext->streams[1];
outStream = outFormatContext->streams[0];

// TODO: Replicate log packet functionality to print out what's inside the packet.

packet.pts = ffmpeg.av_rescale_q_rnd(packet.pts, inStream->time_base, outStream->time_base,
AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX);
packet.dts = ffmpeg.av_rescale_q_rnd(packet.dts, inStream->time_base, outStream->time_base,
AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX);

packet.duration = ffmpeg.av_rescale_q(packet.duration, inStream->time_base, outStream->time_base);

int returncode = ffmpeg.av_interleaved_write_frame(outFormatContext, &packet);

}

ffmpeg.av_packet_unref(&packet);
}

ffmpeg.av_write_trailer(outFormatContext);

ffmpeg.avformat_close_input(&inFormatContext);

ffmpeg.avformat_free_context(outFormatContext);

Console.WriteLine("Press any key to continue...");

Console.ReadKey();
}
значение returnCode возвращает меньше 0, так что кто-нибудь может это исправить, большое спасибо за это

Подробнее здесь: https://stackoverflow.com/questions/474 ... p-in-unity
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как использовать CUDA для декодирования видео в FFmpeg.AutoGen?
    Anonymous » » в форуме C#
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous
  • Декодирование нескольких видео на графическом процессоре (FFmpeg.autogen + C#)
    Anonymous » » в форуме C#
    0 Ответы
    61 Просмотры
    Последнее сообщение Anonymous
  • Видео FFMPEG.Autogen rtsp часто ломается
    Anonymous » » в форуме C#
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous
  • У меня есть проблема с моим аудиокодиком FFMPEG FFMPEG FFMPEG
    Anonymous » » в форуме C++
    0 Ответы
    27 Просмотры
    Последнее сообщение Anonymous
  • Как декодировать файл MP4 с помощью графического процессора, используя ffmpeg.autogen?
    Anonymous » » в форуме C#
    0 Ответы
    12 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C#»