Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to update audio codec of audiofile using ffmpeg
Forum Updated to NodeBB v4.3 + New Features

How to update audio codec of audiofile using ffmpeg

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jaswinder
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AttilaPethe
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved