Congratulations to our 2022 Qt Champions!

How to update audio codec of audiofile using ffmpeg

  • I want to convert abc.avi file to abc.mp3 by using ffmpeg i am able to get existing codec of this file by using this code.
    @#include <QtCore/QCoreApplication>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <QDebug>
    #include <QHash>
    #include "avformat.h"
    #include "avcodec.h"

    #include <swscale.h>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    AVFrame* frame = avcodec_alloc_frame();
    AVFormatContext *formatContext = avformat_alloc_context();
    if(avformat_open_input(&formatContext,"/Users/local/abc.avi",NULL,NULL)!= 0)
    QHash<QString, QString> ap;
        qDebug()<<"not return";
    QString text = QString("%1").arg(int(formatContext->duration/AV_TIME_BASE)/60);
    text +=":"+QString("%1").arg(int(formatContext->duration/AV_TIME_BASE)`,2,10,QChar('0'));
    qDebug()<<"File Size"<&lt;formatContext-&gt;file_size/1024;
    AVCodecContext *c = 0;
    uint wma_idx;
    for (wma_idx = 0; wma_idx &lt; formatContext-&gt;nb_streams; wma_idx++)
        c = formatContext->streams[wma_idx]->codec;
        if (c->codec_type == AVMEDIA_TYPE_VIDEO)
            qDebug()<<"vedio Type" <<c->codec_type;
        if (c->codec_type == AVMEDIA_TYPE_AUDIO)
            qDebug()<<"Audio" <<c->codec_type;
        AVCodec *pCodec;
        // Find the decoder for the video stream
        if(pCodec==NULL) {
            qDebug()<<"code not read";
        qDebug()<<"codec name"<<pCodec->name;
    return a.exec&#40;&#41;;


    By this code i can get the existing codec of this file like audio codec mp3 and vedio codec mpeg4.
    Now i want to convert this vedio file to mp3 file with mp3 codec . i want to update codec of this file can any one address me how to do this task.
    Thanks in advance.

  • Have you considered asking the ffmpeg people? I am sure they have more experience working their library than the people here.

  • Did you manage to do the project? I am interested too!

Log in to reply