| | |
| | | {
|
| | | #include <libavcodec/avcodec.h>
|
| | | #include <libavutil/frame.h>
|
| | | #include <libavformat/avformat.h>
|
| | | #include <libavutil/imgutils.h>
|
| | | #include <libavutil/opt.h>
|
| | | #include <libavformat/avformat.h>
|
| | |
|
| | | #include <libyuv.h>
|
| | | }
|
| | |
| | | in->pAVCodecContext->height = 600;//#todo from config
|
| | | in->pAVCodecContext->time_base.num=1;
|
| | | in->pAVCodecContext->time_base.den=25;
|
| | | in->pAVCodecContext->gop_size = 25;
|
| | | in->pAVCodecContext->gop_size = 2;
|
| | | in->pAVCodecContext->max_b_frames = 0;
|
| | | //in->pAVCodecContext->profile = FF_PROFILE_H264_MAIN;
|
| | | in->pAVCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;
|
| | |
|
| | | //av_opt_set(c->priv_data, "preset", "superfast", 0); |
| | | av_opt_set(in->pAVCodecContext->priv_data, "preset", "superfast", 0); |
| | | //av_opt_set(c->priv_data, "tune", "zerolatency", 0);
|
| | |
|
| | | if(avcodec_open2(in->pAVCodecContext, avCodec, NULL) >= 0)
|
| | |
| | | return !(in->payError);
|
| | | }
|
| | |
|
| | | bool encodeH264(H264Encoder_Internal* in, uint8_t* buffer, timeval pts)
|
| | | {
|
| | | AVFrame avFrame;
|
| | | avFrame.width = 1920;//#todo
|
| | | avFrame.height = 1080;
|
| | | avFrame.data[0] = buffer;
|
| | | avFrame.data[1] = buffer + 1920*1080;
|
| | | avFrame.data[2] = buffer + 1920*1080 + 1920*1080/4;
|
| | | return encodeH264(in, &avFrame, pts);
|
| | | }
|
| | |
|
| | | bool PL_H264Encoder::pay(const PipeMaterial& pm)
|
| | | {
|
| | | H264Encoder_Internal* in = (H264Encoder_Internal*)internal;
|
| | |
| | | return false;
|
| | |
|
| | | MB_Frame* frame = (MB_Frame*)pm.buffer;
|
| | | if (frame->type != MB_Frame::MBFT_PTR_AVFRAME)
|
| | | |
| | | bool ret;
|
| | | |
| | | if (frame->type == MB_Frame::MBFT_PTR_AVFRAME)
|
| | | ret = encodeH264(in, (AVFrame*)(frame->buffer), frame->pts);
|
| | | else if (frame->type == MB_Frame::MBFT_YUV420)
|
| | | ret = encodeH264(in, (uint8_t*)(frame->buffer), frame->pts);
|
| | | else
|
| | | {
|
| | | printf("PL_H264Encoder::pay only support MBFT_PTR_AVFRAME\n");
|
| | | printf("PL_H264Encoder::pay only support MBFT_PTR_AVFRAME / MBFT_YUV420\n");
|
| | | in->payError = true;
|
| | | return false;
|
| | | }
|
| | | |
| | | bool ret = encodeH264(in, (AVFrame*)(frame->buffer), frame->pts);
|
| | |
|
| | | in->payError = !ret;
|
| | |
|
| | | if (ret)
|