![](/img/trans.png)
[英]Media Foundation video re-encoding producing audio stream sync offset
[英]FFmpeg: How to put encoded media data from one container to another with out re-encoding?
因此,例如:我有file.mp3,我知道我想要的格式可以在没有视频的情况下播放声音(例如FLV),因此如何使用ffmpeg将经过编码的mp3数据从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-hell问题。
这是您想做的:
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..
}
}
希望对您有所帮助。 但是,该代码仅是摘录,不能单独使用,但可以帮助您理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.