FFMPEG: Как поставить закодированные медиа-данные из одного контейнера в другую без реконструкции?

StackOverflow https://stackoverflow.com/questions/4144033

Вопрос

Так что, например: у меня есть file.mp3, я знаю, что мой желаемый формат может воспроизводить звук без видео (например, FLV), так как поставить закодированные данные MP3, используя FFMPEG из контейнера MP3 в FLV (где можно получить образцы / кода это)?

Я имею в виду не из CMD, а от C ++ с помощью FFMPEG в качестве библиотеки. (см. теги)

Это было полезно?

Решение

Вот команда для преобразования файла .mp3 на .flv (у которого нет видеоданных).

FFMPEG -I TEST.MP3 -AB 32K -ACODEC LIBMP3LAME -AC 1 -AR 44100 AUDIO.FLV.

Вы можете выполнить эту команду из вашей программы.

Если вам нужна помощь о том, как установить и использовать FFMPEG, вы можете перейти на их сайт:

http://ffmpeg.org.

Спасибо,

Махмуд

Другие советы

Вы считаете просто запустив FFMPEG от POPON () / System () Call из C ++?

Это намного проще, чем настройку библиотеки FFMPEG, она делает его тривиальным для многопотативной (не на самом деле в примере) и освобождает вас от любых ссылок LGPL и проблем DLL-ALL.

Вот что вы хотите сделать:

AVFormatContext *ptrFormatContext;
int i, videoStream, audioStream;
AVCodecContext *ptrCodecCtxt;
AVCodec *ptrCodec;
AVFrame *ptrFrame;
AVPacket ptrPacket;
int frameFinished;
float aspect_ratio;

AVCodecContext  *aCodecCtx;
AVCodec         *aCodec;

AVCodecContext  *aTargetCodecCtxt;
AVCodecContext  *vTargetCodecCtxt;
AVCodec         *aTargetCodec;
AVCodec         *vTargetCodec;
AVSampleFormat  ptrSampleFormats[2] = {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32};



audioStream = videoStream = -1;

av_register_all();
avcodec_register_all();

ptrFormatContext = avformat_alloc_context();

if(avformat_open_input(&ptrFormatContext, filename, NULL, NULL) != 0 )
{
    qDebug("Error opening the input");
    exit(-1);
}
if(av_find_stream_info( ptrFormatContext) < 0)
{
    qDebug("Could not find any stream info");
    exit(-2);
}
dump_format(ptrFormatContext, 0, filename, (int) NULL);

for(i=0; i<ptrFormatContext->nb_streams; i++)
{
    switch(ptrFormatContext->streams[i]->codec->codec_type)
    {
    case AVMEDIA_TYPE_VIDEO:
    {
        if(videoStream < 0) videoStream = i;
        break;
    }
    case AVMEDIA_TYPE_AUDIO:
    {
        if(audioStream < 0) audioStream = i;
    }
    }
}
if(audioStream == -1)
{
    qDebug("Could not find any audio stream");
    exit(-3);
}
if(videoStream == -1)
{
    qDebug("Could not find any video stream");
    exit(-4);
}

aCodecCtx = ptrFormatContext->streams[audioStream]->codec;
if( (aCodec = avcodec_find_decoder(aCodecCtx->codec_id)) == NULL)
{
    qDebug("Could not find the audio decoder");
    exit(-5);
}
if( (avcodec_open(aCodecCtx, aCodec)) != 0 )
{
    qDebug("Could not open the audio decoder");
    exit(-6);
}

ptrCodecCtxt = ptrFormatContext->streams[videoStream]->codec;
if( (ptrCodec = avcodec_find_decoder(ptrCodecCtxt->codec_id)) == NULL )
{
    qDebug("Could not find the video decoder");
    exit(-7);
}
if((avcodec_open(ptrCodecCtxt, ptrCodec)) != 0)
{
    qDebug("Could not find any video stream");
    exit(-8);
}

Тогда некоторые другие вещи, в основном неактуальные, если вы не хотите реконструировать ...

ptrFrame = avcodec_alloc_frame();

while(av_read_frame(ptrFormatContext,&ptrPacket) >= 0)
{
    if(ptrPacket.stream_index == videoStream)
    {
       //do stuff with the package, for eg transcribe it into another output stream..

    }
    else if (ptrPacket.stream_index == audioStream)
    {
       //do stuff with the package, for eg transcribe it into another output stream..
    }
}

Надеюсь, это полезно. Кодекс - однако только выдержка и не будет работать самостоятельно, но он поможет вам получить идею.

ffmpeg -i file.mp3 -acodec copy output.flv
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top