发布网友
共2个回答
热心网友
这个简单。大致的思路是
1.打开wav文件
2.打开要输出的wma文件
3.不停的读取数据帧
4.读取以后解码并写入wma
5.关闭wav文件
6.关闭wma文件
重新写例子太麻烦贴点代码吧
#include "Debug.h"
#include "FFMpegAVFileReader.h"
#include "FFMpegAVFileReaderFactory.h"
#include <sstream>
#include "yk_convert.h"
static char h2_head[4] = {(char)0x00,(char)0x00,(char)0x00,(char)0x01};
namespace YK
{
FFMpegAVFileReader::FFMpegAVFileReader()
{
ffmpeg_avcodec_init();
ffmpeg_av_register_all();
av_log_set_callback(ffmpeg_log_callback);
m_format_context = 0;
m_input_format = 0;
m_format_parameters = 0;
m_packet = (AVPacket*)av_mallocz(sizeof(AVPacket));
}
FFMpegAVFileReader::~FFMpegAVFileReader()
{
Close();
av_free(m_packet);
}
avfile_reader_param_t* FFMpegAVFileReader::GetParam()
{
//YK::AutoLock l(m_lock);
return &m_param;
}
void FFMpegAVFileReader::Seek(int pts)
{
YK::AutoLock l(m_lock);
int ret = av_seek_frame(m_format_context,-1,(YK::int_t)pts * (YK::int_t)1000,AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY);
//if(ret >= 0)
//{
// for(int i = 0; i < m_format_context->nb_streams; i++)
// {
// avcodec_flush_buffers( m_format_context->streams[i]->codec );
// }
//}
//std::stringstream ss;
//ss << "pts = " << pts
// << " ret = " << ret << std::endl;
//OutputDebugString(ss.str().data());
}
void FFMpegAVFileReader::GetDuration(double& start,double& end)
{
//YK::AutoLock l(m_lock);
start = (double)(m_start_time / 1000000);
end = start + (double)(m_ration / 1000000);
}
service_error_t FFMpegAVFileReader::Open(int time_out)
{
YK::AutoLock l(m_lock);
service_error_t service_error;
// 打开文件
if (av_open_input_file(&m_format_context,TToANSI(m_param.input_file_path).data(),m_input_format,0,m_format_parameters) < 0)
{
service_error.init(service_error_type_failed,"av_open_input_file failed");
return service_error;
}
// 查询流信息
if(av_find_stream_info(m_format_context) < 0)
{
service_error.init(service_error_type_failed,"av_find_stream_info failed");
return service_error;
}
m_start_time = m_format_context->start_time;
m_ration = m_format_context->ration;
#ifdef _DEBUG
pFile = fopen("D:/1.out","w+b");
#endif
// 保存流信息
av_stream_info_t av_stream_info;
for(unsigned int i = 0; i < m_format_context->nb_streams; i++)
{
AVStream *st = m_format_context->streams[i];
AVCodecContext *enc = st->codec;
if(enc->codec_type == AVMEDIA_TYPE_AUDIO)
{
// 音频
av_stream_info.av_stream_info_type = av_stream_info_type_audio;
av_stream_info.codec_id = codec_id_none;
//channel_layout = enc->channel_layout;
av_stream_info.audio_channels = enc->channels;
av_stream_info.audio_samplepersec = enc->sample_rate;
av_stream_info.audio_bitpersample = yk_sample_format(enc->sample_fmt);
//audio_sample_fmt = enc->sample_fmt;
//input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(audio_codec_name);
av_stream_info.codec_id = yk_code_id(enc->codec_id);
av_stream_info.extradata_size = enc->extradata_size;
if(av_stream_info.extradata_size)
memcpy(av_stream_info.extradata,enc->extradata,enc->extradata_size);
if(av_stream_info.codec_id == codec_id_mp3)
{
av_stream_info.extradata_size = sizeof(mpeg1_waveformat_extradata);
mpeg1_waveformat_extradata* pMpeg1WaveFormat = (mpeg1_waveformat_extradata*)av_stream_info.extradata;
pMpeg1WaveFormat->dwHeadBitrate = enc->bit_rate;
pMpeg1WaveFormat->dwPTSHigh = 0;
pMpeg1WaveFormat->dwPTSLow = 0;
pMpeg1WaveFormat->fwHeadFlags = 25;
pMpeg1WaveFormat->fwHeadLayer = ACM_MPEG_LAYER3;
pMpeg1WaveFormat->fwHeadMode = ACM_MPEG_STEREO;
pMpeg1WaveFormat->fwHeadModeExt = 1;
pMpeg1WaveFormat->wHeadEmphasis = 1;
}
AddStreamInfo(av_stream_info);
m_stream_audio_index = i;
}
else if(enc->codec_type == AVMEDIA_TYPE_VIDEO)
{
// 视频
av_stream_info.av_stream_info_type = av_stream_info_type_video;
av_stream_info.codec_id = codec_id_none;
av_stream_info.video_width = enc->width;
av_stream_info.video_height = enc->height;
av_stream_info.video_profile = enc->profile;
av_stream_info.video_level = enc->level;
if(av_stream_info.video_profile < 0)
{
av_stream_info.video_profile = 77;
}
if(av_stream_info.video_level < 0)
{
av_stream_info.video_level = 30;
}
av_stream_info.extradata_size =
热心网友
?图形界面的还是命令行工具,我知道有个命令行工具ffmpeg,不过解码swf不怎么方便,起码不能是压缩的swf
还有一篇文章希望有用:
另外:flash 8自带的Flash 8 Video Encoder能把别的影片转变成flv格式的,至于把swf转变成flv???就得你用flash 8将SWF导入然后变换成FLV
-----------------------下面方法仅供参考-------------
《MP4/RM转换专家》是梦幻科技的又一优秀专业力作。MP4/RM转换专家支持将几乎所有视频格式如:RM/RMVB/VOB/AVI/MPEG/DAT/VCD/SVCD/DVD/ASF/WMV/MOV/QT/MP4/3GP/3GPP2/DV/YUV等视频文件转换为普通MP4机、SONY PSP机、iPod Video、3GP/3GPP2/MP4手机或DVD影碟机等硬件支持的AVI/MPEG4/3GP/3GPP2/MP4视频格式!软件更是支持Flash的SWF/FLV文件的导出,同时还允许将多种格式转换为RM和RMVB格式。