Mux h264 and g711a ok.

This commit is contained in:
Fancy code 2024-06-21 21:05:39 +08:00
parent 8270c6ced2
commit e992b29e2d

View File

@ -191,7 +191,6 @@ void FfmpegMuxStream::GetVideoStream(const void *data, const size_t &size, const
} }
void FfmpegMuxStream::GetAudioStream(const void *data, const size_t &size, const StreamInfo &streamInfo) void FfmpegMuxStream::GetAudioStream(const void *data, const size_t &size, const StreamInfo &streamInfo)
{ {
return;
AVPacket *packet = nullptr; AVPacket *packet = nullptr;
packet = av_packet_alloc(); packet = av_packet_alloc();
packet->data = (unsigned char *)data; packet->data = (unsigned char *)data;
@ -212,8 +211,10 @@ void FfmpegMuxStream::GetAudioStream(const void *data, const size_t &size, const
LogInfo("Error during decoding\n"); LogInfo("Error during decoding\n");
break; break;
} }
ConvertAudioFrame(mFrameVideo, mCodecAudioContext, &mAudioSt); mFrameAudio->pts = mAudioSt.next_pts;
write_frame(mOc, mAudioSt.enc, mAudioSt.st, mFrameAudio, mAudioSt.tmp_pkt); mAudioSt.next_pts += mFrameAudio->nb_samples;
ConvertAudioFrame(mFrameVideo, mAudioSt.enc, &mAudioSt);
write_frame(mOc, mAudioSt.enc, mAudioSt.st, mAudioSt.frame, mAudioSt.tmp_pkt);
break; break;
} }
av_packet_unref(packet); av_packet_unref(packet);
@ -255,7 +256,7 @@ bool FfmpegMuxStream::add_stream(OutputStream *ost, AVFormatContext *oc, const A
case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_AUDIO:
c->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; c->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
c->bit_rate = 64000; c->bit_rate = 64000;
c->sample_rate = 44100; c->sample_rate = 8000;
if ((*codec)->supported_samplerates) { if ((*codec)->supported_samplerates) {
c->sample_rate = (*codec)->supported_samplerates[0]; c->sample_rate = (*codec)->supported_samplerates[0];
for (i = 0; (*codec)->supported_samplerates[i]; i++) { for (i = 0; (*codec)->supported_samplerates[i]; i++) {
@ -361,9 +362,9 @@ bool FfmpegMuxStream::open_video(AVFormatContext *oc, const AVCodec *codec, Outp
} }
bool FfmpegMuxStream::open_audio(AVFormatContext *oc, const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) bool FfmpegMuxStream::open_audio(AVFormatContext *oc, const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
{ {
AVCodecContext *c; AVCodecContext *c = nullptr;
int nb_samples; int nb_samples = 0;
int ret; int ret = 0;
AVDictionary *opt = nullptr; AVDictionary *opt = nullptr;
c = ost->enc; c = ost->enc;
@ -545,13 +546,7 @@ bool FfmpegMuxStream::InitCodecAudio(enum AVCodecID codecId, AVCodec **codec, AV
int FfmpegMuxStream::write_frame(AVFormatContext *fmt_ctx, AVCodecContext *c, AVStream *st, AVFrame *frame, int FfmpegMuxStream::write_frame(AVFormatContext *fmt_ctx, AVCodecContext *c, AVStream *st, AVFrame *frame,
AVPacket *pkt) AVPacket *pkt)
{ {
int ret; int ret = 0;
if (c == nullptr) {
LogError("c is null\n");
}
if (frame == nullptr) {
LogError("frame is null\n");
}
// send the frame to the encoder // send the frame to the encoder
ret = avcodec_send_frame(c, frame); ret = avcodec_send_frame(c, frame);
if (ret < 0) { if (ret < 0) {