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>
    extern"C"
    {
    #include "avformat.h"
    #include "avcodec.h"

    #include <swscale.h>
    }

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

    AVFrame* frame = avcodec_alloc_frame();
    
    
    av_register_all();
    
    AVFormatContext *formatContext = avformat_alloc_context();
    if(avformat_open_input(&formatContext,"/Users/local/abc.avi",NULL,NULL)!= 0)
    {
        av_free(frame);
    }
    
    QHash<QString, QString> ap;
    av_find_stream_info(formatContext);
    av_read_play(formatContext);
    
    if(!formatContext)
    {
    
        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()<<"duration"<<text;
    qDebug()<<"bitrate"<&lt;formatContext-&gt;bit_rate/1000;
    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
        pCodec=avcodec_find_decoder(c->codec_id);
        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.


  • Moderators

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.