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