Mux mp4 ok.
This commit is contained in:
parent
b748ccbfb2
commit
c88dbe1ecf
|
@ -20,10 +20,9 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME MediaBase)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} avformat avcodec avutil swresample avdevice avfilter swscale postproc fdk-aac StatusCode Log)
|
||||
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
target_link_libraries(${TARGET_NAME} avformat avcodec avutil swresample avdevice avfilter swscale postproc fdk-aac z StatusCode Log)
|
||||
else()
|
||||
target_link_libraries(${TARGET_NAME} avformat avcodec avutil swresample avdevice avfilter swscale postproc fdk-aac StatusCode Log)
|
||||
target_link_libraries(${TARGET_NAME} z)
|
||||
endif()
|
||||
|
||||
add_custom_target(
|
||||
|
|
|
@ -167,24 +167,23 @@ void inline FfmpegDecoder::AVParseData(const void *data, const size_t &size,
|
|||
}
|
||||
}
|
||||
}
|
||||
// static void save_code_stream_file(const void *data, const size_t &size)
|
||||
// {
|
||||
// char OutPath[16];
|
||||
// const void *pData = data;
|
||||
// FILE *file = NULL;
|
||||
|
||||
static void save_code_stream_file(const void *data, const size_t &size)
|
||||
{
|
||||
char OutPath[16];
|
||||
const void *pData = data;
|
||||
FILE *file = NULL;
|
||||
// sprintf(OutPath, "./test.pcm");
|
||||
// file = fopen(OutPath, "a+");
|
||||
|
||||
sprintf(OutPath, "./test.pcm");
|
||||
file = fopen(OutPath, "a+");
|
||||
// if (file) { // TODO: Don't open very time.
|
||||
// fwrite(pData, 1, size, file);
|
||||
// fflush(file);
|
||||
// }
|
||||
|
||||
if (file) { // TODO: Don't open very time.
|
||||
fwrite(pData, 1, size, file);
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
if (file)
|
||||
fclose(file);
|
||||
}
|
||||
// if (file)
|
||||
// fclose(file);
|
||||
// }
|
||||
void inline FfmpegDecoder::AVDecodeData(AVPacket *pkt, std::function<void(AVFrame *frame)> callback)
|
||||
{
|
||||
int ret = avcodec_send_packet(mCodecCtx, pkt);
|
||||
|
@ -209,7 +208,7 @@ void inline FfmpegDecoder::AVDecodeData(AVPacket *pkt, std::function<void(AVFram
|
|||
// for (ch = 0; ch < mCodecCtx->ch_layout.nb_channels; ch++)
|
||||
// // fwrite(frame->data[ch] + data_size * i, 1, data_size, outfile);
|
||||
// save_code_stream_file(mFrame->data[ch] + data_size * i, data_size);
|
||||
save_code_stream_file(mFrame->data[0], mFrame->linesize[0]);
|
||||
// save_code_stream_file(mFrame->data[0], mFrame->linesize[0]);
|
||||
callback(mFrame);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
#include <libavcodec/codec_id.h>
|
||||
#include <libavcodec/packet.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/avassert.h>
|
||||
// #include <libavutil/avassert.h>
|
||||
#include <libavutil/avutil.h>
|
||||
#include <libavutil/channel_layout.h>
|
||||
#include <libavutil/dict.h>
|
||||
|
@ -82,11 +82,11 @@ bool FfmpegEncoder::Init(int &outputFlags)
|
|||
mCodecCtx->sample_rate = 44100;
|
||||
}
|
||||
}
|
||||
mCodecCtx->sample_rate = SOURCE_AUDIO_SAMPEL_RATE;
|
||||
mCodecCtx->sample_rate = 16000;
|
||||
// mCodecCtx->time_base = (AVRational){1, mCodecCtx->sample_rate};
|
||||
mCodecCtx->ch_layout.nb_channels = 1;
|
||||
av_channel_layout_default(&mCodecCtx->ch_layout, 1);
|
||||
// av_channel_layout_copy(&mCodecCtx->ch_layout, &src);
|
||||
// mCodecCtx->ch_layout.nb_channels = 1;
|
||||
// av_channel_layout_default(&mCodecCtx->ch_layout, 1);
|
||||
av_channel_layout_copy(&mCodecCtx->ch_layout, &src);
|
||||
break;
|
||||
|
||||
case AVMEDIA_TYPE_VIDEO:
|
||||
|
@ -170,23 +170,23 @@ bool FfmpegEncoder::OpenEncoder(AVDictionary *optArg, AVStream *stream)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
static void save_code_stream_file(const void *data, const size_t &size)
|
||||
{
|
||||
char OutPath[16];
|
||||
const void *pData = data;
|
||||
FILE *file = NULL;
|
||||
LogInfo("save_code_stream_file: %d\n", size);
|
||||
sprintf(OutPath, "./test.aac");
|
||||
file = fopen(OutPath, "a+");
|
||||
// static void save_code_stream_file(const void *data, const size_t &size)
|
||||
// {
|
||||
// char OutPath[16];
|
||||
// const void *pData = data;
|
||||
// FILE *file = NULL;
|
||||
// LogInfo("save_code_stream_file: %d\n", size);
|
||||
// sprintf(OutPath, "./test.aac");
|
||||
// file = fopen(OutPath, "a+");
|
||||
|
||||
if (file) { // TODO: Don't open very time.
|
||||
fwrite(pData, 1, size, file);
|
||||
fflush(file);
|
||||
}
|
||||
// if (file) { // TODO: Don't open very time.
|
||||
// fwrite(pData, 1, size, file);
|
||||
// fflush(file);
|
||||
// }
|
||||
|
||||
if (file)
|
||||
fclose(file);
|
||||
}
|
||||
// if (file)
|
||||
// fclose(file);
|
||||
// }
|
||||
int FfmpegEncoder::EncodeData(AVFrame *frame, AVStream *stream, std::function<void(AVPacket *pkt)> callback)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -300,8 +300,8 @@ bool FfmpegEncoder::OpenAudio(AVDictionary *optArg, AVStream *stream)
|
|||
AVChannelLayout ch_layout;
|
||||
av_channel_layout_copy(&ch_layout, &src);
|
||||
/* set options */
|
||||
// av_opt_set_chlayout(mSwrCtx, "in_chlayout", &ch_layout, 0);
|
||||
av_opt_set_chlayout(mSwrCtx, "in_chlayout", &mCodecCtx->ch_layout, 0);
|
||||
av_opt_set_chlayout(mSwrCtx, "in_chlayout", &ch_layout, 0);
|
||||
// av_opt_set_chlayout(mSwrCtx, "in_chlayout", &mCodecCtx->ch_layout, 0);
|
||||
av_opt_set_int(mSwrCtx, "in_sample_rate", SOURCE_AUDIO_SAMPEL_RATE, 0);
|
||||
av_opt_set_sample_fmt(mSwrCtx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
|
||||
av_opt_set_chlayout(mSwrCtx, "out_chlayout", &mCodecCtx->ch_layout, 0);
|
||||
|
|
Loading…
Reference in New Issue
Block a user