2010-11-10 2 views

Répondre

1

Voici la commande pour convertir le fichier .mp3 en .flv (qui n'a aucune donnée vidéo).

ffmpeg -i test.mp3 -ab 32k -acodec libmp3lame -ac 1 -ar 44100 audio.flv.

Vous pouvez exécuter cette commande depuis votre programme.

Si vous avez besoin d'aide sur la façon d'installer et d'utiliser ffmpeg vous pouvez aller sur leur site:

http://ffmpeg.org

Merci,

Mahmud

+0

Pas de cmd mais de C++, s'il vous plaît. Et btw il semble réencoder si utilisé dans votre chemin ... – Rella

+1

Vous trouverez un exemple de programme dans le répertoire ffmpeg nommé ffmpeg.c si vous l'installez. Dans la fonction principale, ajoutez les codes suivants à la fin: opt_input_file ("in.mp3"); opt_audio_codec ("libmp3lame"); opt_audio_rate (NULL, "44100"); opt_audio_channels (NULL, "1"); opt_default ("ab", "32k"); opt_default ("ac", "1"); opt_output_file ("out.flv"); if (nb_output_files <= 0) { \t fprintf (erreur stderr, "erreur"); \t return -1; } if (nb_input_files == 0) { \t fprintf (erreur stderr, "erreur"); \t return -1; Av_encode (output_files, nb_output_files, input_files, nb_input_files, stream_maps, nb_stream_maps); –

+0

mais il semble que vous réencodiez - pas simplement mettre des paquets codés dans un autre conteiner ... – Rella

0
ffmpeg -i file.mp3 -acodec copy output.flv 
+0

Pas de cmd mais de C++, s'il vous plaît – Rella

0

Avez-vous envisagé juste en cours d'exécution ffmpeg à partir d'un appel popen()/system() à partir de C++? C'est beaucoup plus facile que de configurer la bibliothèque ffmpeg, cela rend trivial à multithread (pas vraiment un problème dans l'exemple) et vous libère de tout problème de liaison LGPL et dll-hell.

+0

J'apprécie vraiment l'idée, mais ce n'est pas mon genre - parce que je prévois de travailler en temps réel avec mes flux de programmes vidéo et mes flux vidéo en direct sur Internet ... – Rella

+0

Vous pouvez diriger les données de votre programme vers ffmpeg avec popen() –

0

Voici ce que vous voulez faire:

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); 
} 

Puis d'autres choses, plus d'importance si vous ne voulez pas réencoder ...

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.. 
    } 
} 

qui est utile espoir. Le code n'est cependant qu'un extrait et ne fonctionnera pas tout seul, mais cela vous aidera à avoir l'idée.

Questions connexes