たとえば、私は file.mp3 を持っています。目的の形式でビデオ (FLV など) なしでサウンドを再生できることがわかっているので、mp3 コンテナーから ffmpeg を使用してエンコードされた mp3 データを flv に配置する方法 (記事/コードサンプルを取得する場所)これ)?
cmd からではなく、ffmpeg をライブラリとして使用する C++ からという意味です。(タグを参照)
たとえば、私は file.mp3 を持っています。目的の形式でビデオ (FLV など) なしでサウンドを再生できることがわかっているので、mp3 コンテナーから ffmpeg を使用してエンコードされた mp3 データを flv に配置する方法 (記事/コードサンプルを取得する場所)これ)?
cmd からではなく、ffmpeg をライブラリとして使用する C++ からという意味です。(タグを参照)
.mp3 ファイルを .flv (動画データを含まない) に変換するコマンドは次のとおりです。
ffmpeg -i test.mp3 -ab 32k -acodec libmp3lame -ac 1 -ar 44100 audio.flv.
このコマンドは、プログラムから実行できます。
ffmpeg のインストール方法と使用方法についてヘルプが必要な場合は、次のサイトにアクセスしてください。
ありがとう、
マフムード
ffmpeg -i file.mp3 -acodec copy output.flv
c++ からの popen() / system() 呼び出しから ffmpeg を実行することを検討しましたか?
ffmpeg ライブラリをセットアップするよりもはるかに簡単で、マルチスレッド化が簡単になり (この例では実際には問題になりません)、LGPL リンクや dll 地獄の問題から解放されます。
やりたいことは次のとおりです。
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..
}
}
お役に立てば幸いです。ただし、コードは抜粋であり、単独では機能しませんが、アイデアを得るのに役立ちます。