|
@@ -99,7 +99,7 @@ static bool add_stream(LogApi* pLogApi, OutputStream *ost, AVFormatContext *oc,
|
|
|
/* find the encoder */
|
|
|
*codec = avcodec_find_encoder(codec_id);
|
|
|
if (!(*codec)) {
|
|
|
- pLogApi->Debug("add_stream failed for Could not find encoder for %s", avcodec_get_name(codec_id));
|
|
|
+ pLogApi->Debug("add_stream failed for Could not find encoder for %s.", avcodec_get_name(codec_id));
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -343,7 +343,7 @@ static int write_audio_frame(LogApi* pLogApi, AVFormatContext *oc, OutputStream
|
|
|
*/
|
|
|
ret = av_frame_make_writable(audio_ost->frame);
|
|
|
if (ret < 0) {
|
|
|
- pLogApi->Debug("write_audio_frame failed for av_frame_make_writable: %d", ret);
|
|
|
+ pLogApi->Debug("write_audio_frame failed for av_frame_make_writable: %d.", ret);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -358,7 +358,7 @@ static int write_audio_frame(LogApi* pLogApi, AVFormatContext *oc, OutputStream
|
|
|
audio_ost->frame->data, dst_nb_samples,
|
|
|
(const uint8_t **)frame->data, frame->nb_samples);
|
|
|
if (ret < 0) {
|
|
|
- pLogApi->Debug("write_audio_frame failed for Error while converting");
|
|
|
+ pLogApi->Debug("write_audio_frame failed for Error while converting.");
|
|
|
return -1;
|
|
|
}
|
|
|
frame = audio_ost->frame;
|
|
@@ -392,7 +392,7 @@ static int write_audio_frame(LogApi* pLogApi, AVFormatContext *oc, OutputStream
|
|
|
//pLogApi->Debug("write_audio_frame got_packet");
|
|
|
ret = write_frame(oc, &enc_ctx->time_base, audio_ost->st, &pkt, pLogApi);
|
|
|
if (ret < 0) {
|
|
|
- pLogApi->Debug("write_audio_frame failed for Error while writing audio frame: %d", ret);
|
|
|
+ pLogApi->Debug("write_audio_frame failed for Error while writing audio frame: %d.", ret);
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -448,14 +448,14 @@ static bool open_video(LogApi* pLogApi, AVFormatContext *oc, AVCodec *codec, Out
|
|
|
ret = avcodec_open2(enc_ctx, codec, &opt);
|
|
|
av_dict_free(&opt);
|
|
|
if (ret < 0) {
|
|
|
- pLogApi->Debug("open_video failed for Could not open video codec: %s, ret :%d", avcodec_get_name(codec->id), ret);
|
|
|
+ pLogApi->Debug("open_video failed for Could not open video codec: %s, ret :%d.", avcodec_get_name(codec->id), ret);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/* allocate and init a re-usable frame */
|
|
|
video_ost->frame = alloc_picture(enc_ctx->pix_fmt, enc_ctx->width, enc_ctx->height);
|
|
|
if (!video_ost->frame) {
|
|
|
- pLogApi->Debug("open_video failed for Could not allocate video frame");
|
|
|
+ pLogApi->Debug("open_video failed for Could not allocate video frame.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -466,7 +466,7 @@ static bool open_video(LogApi* pLogApi, AVFormatContext *oc, AVCodec *codec, Out
|
|
|
if (enc_ctx->pix_fmt != input_pix_fmt) {
|
|
|
video_ost->tmp_frame = alloc_picture(input_pix_fmt, enc_ctx->width, enc_ctx->height);
|
|
|
if (!video_ost->tmp_frame) {
|
|
|
- pLogApi->Debug("Could not allocate temporary picture");
|
|
|
+ pLogApi->Debug("Could not allocate temporary picture.");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -474,7 +474,7 @@ static bool open_video(LogApi* pLogApi, AVFormatContext *oc, AVCodec *codec, Out
|
|
|
/* copy the stream parameters to the muxer */
|
|
|
ret = avcodec_parameters_from_context(video_ost->st->codecpar, enc_ctx);
|
|
|
if (ret < 0) {
|
|
|
- pLogApi->Debug("open_video failed for Could not copy the stream parameters");
|
|
|
+ pLogApi->Debug("open_video failed for Could not copy the stream parameters.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -603,7 +603,7 @@ static int write_video_frame(LogApi* pLogApi, AVFormatContext *oc, OutputStream
|
|
|
}
|
|
|
|
|
|
if (ret < 0) {
|
|
|
- pLogApi->Debug("open_video failed for Error while writing video frame: %d", ret);
|
|
|
+ pLogApi->Debug("open_video failed for Error while writing video frame: %d.", ret);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -631,15 +631,15 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
bool result = true;
|
|
|
|
|
|
if (nBitPerSample != 8 && nBitPerSample != 16 && nBitPerSample != 32){
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for BitPerSample = %d", nBitPerSample);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for BitPerSample = %d.", nBitPerSample);
|
|
|
return false;
|
|
|
}
|
|
|
if (nchannels != 1 && nchannels != 2){
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for channels = %d", nchannels);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for channels = %d.", nchannels);
|
|
|
return false;
|
|
|
}
|
|
|
if (colorbit != 24){
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for colorbit = %d", colorbit);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for colorbit = %d.", colorbit);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -651,7 +651,7 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
/* allocate the output media context */
|
|
|
avformat_alloc_output_context2(&m_formatctx, NULL, NULL, filename);
|
|
|
if (!m_formatctx) {
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for avformat_alloc_output_context2, filename = %s", filename);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for avformat_alloc_output_context2, filename = %s.", filename);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -669,7 +669,7 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
result = add_stream(m_pLogApi, m_video_st, m_formatctx, &m_video_codec, m_outfmt->video_codec, width, height, colorbit, nfps, nSamplePsec, nchannels);
|
|
|
if (result == false){
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for add_stream, video_codec = %d", m_outfmt->video_codec);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for add_stream, video_codec = %d.", m_outfmt->video_codec);
|
|
|
return result;
|
|
|
}
|
|
|
m_bhave_video = true;
|
|
@@ -678,7 +678,7 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
result = add_stream(m_pLogApi, m_audio_st, m_formatctx, &m_audio_codec, m_outfmt->audio_codec, width, height, colorbit, nfps, nSamplePsec, nchannels);
|
|
|
if (result == false){
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for add_stream, audio_codec = %d", m_outfmt->audio_codec);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for add_stream, audio_codec = %d.", m_outfmt->audio_codec);
|
|
|
return result;
|
|
|
}
|
|
|
m_bhave_audio = true;
|
|
@@ -690,7 +690,7 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
result = open_video(m_pLogApi, m_formatctx, m_video_codec, m_video_st, opt, m_input_pix_fmt);
|
|
|
if (result == false){
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for open_video, video_codec = %d", m_outfmt->video_codec);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for open_video, video_codec = %d.", m_outfmt->video_codec);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
@@ -699,21 +699,21 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
result = open_audio(m_pLogApi, m_formatctx, m_audio_codec, m_audio_st, opt, AV_SAMPLE_FMT_U8);
|
|
|
if (result == false){
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for open_audio, AV_SAMPLE_FMT_U8");
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for open_audio, AV_SAMPLE_FMT_U8.");
|
|
|
return result;
|
|
|
}
|
|
|
}else if (nBitPerSample == 16){
|
|
|
result = open_audio(m_pLogApi, m_formatctx, m_audio_codec, m_audio_st, opt, AV_SAMPLE_FMT_S16);
|
|
|
if (result == false){
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for open_audio, AV_SAMPLE_FMT_S16");
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for open_audio, AV_SAMPLE_FMT_S16.");
|
|
|
return result;
|
|
|
}
|
|
|
}else if (nBitPerSample == 32) {
|
|
|
result = open_audio(m_pLogApi, m_formatctx, m_audio_codec, m_audio_st, opt, AV_SAMPLE_FMT_FLT);
|
|
|
if (result == false) {
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for open_audio, AV_SAMPLE_FMT_FLT");
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for open_audio, AV_SAMPLE_FMT_FLT.");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
@@ -726,13 +726,13 @@ bool FFmpegWriter::InitWriter(char* filename, int width, int height, int colorbi
|
|
|
iret = avio_open(&m_formatctx->pb, filename, AVIO_FLAG_WRITE);
|
|
|
if (iret < 0) {
|
|
|
Close();
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter Failed for avio_open, %s", filename);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter Failed for avio_open, %s.", filename);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
m_audio_input_buffer = new ByteBuffer(3*nBitPerSample/8 * nchannels* nSamplePsec);
|
|
|
- m_pLogApi->Debug("Init FFmpegWriter success, audio_input_buffer:%d", 3 * nBitPerSample / 8 * nchannels * nSamplePsec);
|
|
|
+ m_pLogApi->Debug("Init FFmpegWriter success, audio_input_buffer:%d.", 3 * nBitPerSample / 8 * nchannels * nSamplePsec);
|
|
|
|
|
|
m_bstart = false;
|
|
|
|
|
@@ -747,11 +747,11 @@ bool FFmpegWriter::StartWrite()
|
|
|
/* Write the stream header, if any. */
|
|
|
int ret = avformat_write_header(m_formatctx, &opt);
|
|
|
if (ret < 0) {
|
|
|
- m_pLogApi->Debug("StartWrite Failed when opening output file: %d", ret);
|
|
|
+ m_pLogApi->Debug("StartWrite Failed when opening output file: %d.", ret);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- m_pLogApi->Debug("FFmpegWriter StartWrite success");
|
|
|
+ m_pLogApi->Debug("FFmpegWriter StartWrite success.");
|
|
|
|
|
|
m_bstart = true;
|
|
|
|
|
@@ -765,7 +765,7 @@ bool FFmpegWriter::StopWrite() {
|
|
|
* av_write_trailer() may try to use memory that was freed on
|
|
|
* av_codec_close(). */
|
|
|
if (m_formatctx == NULL){
|
|
|
- m_pLogApi->Debug("End Failed when oc is null");
|
|
|
+ m_pLogApi->Debug("End Failed when oc is null.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -779,7 +779,7 @@ bool FFmpegWriter::StopWrite() {
|
|
|
|
|
|
m_bstart = false;
|
|
|
|
|
|
- m_pLogApi->Debug("FFmpegWriter End success");
|
|
|
+ m_pLogApi->Debug("FFmpegWriter End success.");
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -820,13 +820,13 @@ void FFmpegWriter::Close()
|
|
|
m_audio_input_buffer = NULL;
|
|
|
}
|
|
|
|
|
|
- m_pLogApi->Debug("FFmpegWriter Close success");
|
|
|
+ m_pLogApi->Debug("FFmpegWriter Close success.");
|
|
|
}
|
|
|
|
|
|
bool FFmpegWriter::ReceiveAudioData(unsigned char* pData, unsigned long len)
|
|
|
{
|
|
|
if (m_formatctx == NULL || m_audio_st == NULL || !m_bhave_audio){
|
|
|
- m_pLogApi->Debug("ReceiveAudioData Failed when oc is null");
|
|
|
+ m_pLogApi->Debug("ReceiveAudioData Failed when oc is null.");
|
|
|
return false;
|
|
|
}
|
|
|
//插入audio_input_buffer
|
|
@@ -842,7 +842,7 @@ bool FFmpegWriter::ReceiveAudioData(unsigned char* pData, unsigned long len)
|
|
|
//m_pLogApi->Debug("ReceiveAudioData available_data_len:%d", audio_input_buffer->bytesRemaining());
|
|
|
int result = write_audio_frame(m_pLogApi, m_formatctx, m_audio_st, m_audio_input_buffer);
|
|
|
if (result < 0) {
|
|
|
- m_pLogApi->Debug("write_audio_frame Failed, %d", result);
|
|
|
+ m_pLogApi->Debug("write_audio_frame Failed, %d.", result);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -861,14 +861,14 @@ bool FFmpegWriter::ReceiveAudioData(unsigned char* pData, unsigned long len)
|
|
|
bool FFmpegWriter::ReceiveVideoData(unsigned char* pData, unsigned long len)
|
|
|
{
|
|
|
if (m_formatctx == NULL || m_video_st == NULL || !m_bhave_video){
|
|
|
- m_pLogApi->Debug("ReceiveVideoData Failed when oc is null");
|
|
|
+ m_pLogApi->Debug("ReceiveVideoData Failed when oc is null.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//m_pLogApi->Debug("ReceiveVideoData len:%d", len);
|
|
|
int result = write_video_frame(m_pLogApi, m_formatctx, m_video_st, (char*)pData, len, m_input_pix_fmt);
|
|
|
if (result < 0){
|
|
|
- m_pLogApi->Debug("write_video_frame Failed, %d", result);
|
|
|
+ m_pLogApi->Debug("write_video_frame Failed, %d.", result);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|