胡斌

support rotate 180,use preset superfast for h264 encoding

... ... @@ -157,7 +157,7 @@ int CAVTranscoder::open_output_file(const char *filename)
enc_ctx->height = _nOutputHeight;
enc_ctx->width = _nOutputWidth;
enc_ctx->sample_aspect_ratio.den = 1;
enc_ctx->sample_aspect_ratio.num = 1;
enc_ctx->sample_aspect_ratio.num = 0;
/* take first format from list of supported formats */
enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
/* video time_base can be set to whatever is handy and supported by encoder */
... ... @@ -169,6 +169,11 @@ int CAVTranscoder::open_output_file(const char *filename)
enc_ctx->qmin = 10;
enc_ctx->qmax = 30;
enc_ctx->qcompress = 0.6;
AVDictionary * d = NULL;
char *k = av_strdup("preset"); // if your strings are already allocated,
char *v = av_strdup("ultrafast"); // you can avoid copying them like this
av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
/* Third parameter can be used to pass settings to encoder */
ret = avcodec_open2(enc_ctx, encoder, NULL);
if (ret < 0) {
... ... @@ -292,13 +297,14 @@ int CAVTranscoder::open_output_file(const char *filename)
if (!pSrcFrame){
return 0;
}
for (int i = 0; i < pSrcFrame->height; i++) {
memcpy(pDstFrame->data[0] + (y + i)*pDstFrame->linesize[0] + x, pSrcFrame->data[0] + i * pSrcFrame->linesize[0], pSrcFrame->linesize[0]);
memcpy(pDstFrame->data[0] + (y + i)*pDstFrame->linesize[0] + x, pSrcFrame->data[0] + i * pSrcFrame->linesize[0], pSrcFrame->linesize[0]>0 ? pSrcFrame->linesize[0] : -pSrcFrame->linesize[0]);
}
for (int i = 0; i < pSrcFrame->height / 2; i++){
memcpy(pDstFrame->data[1] + (y / 2)*pDstFrame->linesize[1] + x / 2, pSrcFrame->data[1] + i * pSrcFrame->linesize[1], pSrcFrame->linesize[1]);
memcpy(pDstFrame->data[2] + (y / 2)*pDstFrame->linesize[2] + x / 2, pSrcFrame->data[2] + i * pSrcFrame->linesize[2], pSrcFrame->linesize[2]);
memcpy(pDstFrame->data[1] + (y / 2 + i)*pDstFrame->linesize[1] + x / 2, pSrcFrame->data[1] + i * pSrcFrame->linesize[1], pSrcFrame->linesize[1]>0 ? pSrcFrame->linesize[1] : -pSrcFrame->linesize[1]);
memcpy(pDstFrame->data[2] + (y / 2 + i)*pDstFrame->linesize[2] + x / 2, pSrcFrame->data[2] + i * pSrcFrame->linesize[2], pSrcFrame->linesize[2]>0 ? pSrcFrame->linesize[2] : -pSrcFrame->linesize[2]);
}
return 0;
}
... ... @@ -310,6 +316,8 @@ int CAVTranscoder::open_output_file(const char *filename)
int nDstSize = avpicture_get_size(AV_PIX_FMT_YUV420P,_nOutputWidth, _nOutputHeight);
uint8_t *dstbuf = new uint8_t[nDstSize];
avpicture_fill((AVPicture*)pDstFrame, dstbuf, AV_PIX_FMT_YUV420P, _nOutputWidth, _nOutputHeight);
memset(dstbuf, 0x80, nDstSize);
if (decoders_got_frame.size() == 2){
fillDestFrame(pDstFrame, decoders_got_frame[0]->_cur_v_frame, 0, decoders_got_frame[0]->_media_role == mr_teacher ? 0 : 240);
decoders_got_frame[0]->free_cur_v_frame();
... ...
... ... @@ -20,6 +20,7 @@ int CVideoDecoder::add(media_info &info)
_uid = info.uid;
}
_info.push_back(info);
_rotate = info.rotate;
int ret;
... ... @@ -300,7 +301,14 @@ int CVideoDecoder::filter_encode_write_frame(AVFrame *frame, unsigned int stream
}
filt_frame->pict_type = AV_PICTURE_TYPE_NONE;
//todo: callback filted frame
if (_rotate == 180) {
filt_frame->data[0] += filt_frame->linesize[0] * (filt_frame->height - 1);
filt_frame->linesize[0] = -filt_frame->linesize[0];
filt_frame->data[1] += filt_frame->linesize[1] * (filt_frame->height / 2 - 1);
filt_frame->linesize[1] = -filt_frame->linesize[1];
filt_frame->data[2] += filt_frame->linesize[2] * (filt_frame->height / 2 - 1);
filt_frame->linesize[2] = -filt_frame->linesize[2];
}
_decoded_frames.push_back(filt_frame);
}
... ...
... ... @@ -31,5 +31,6 @@ protected:
bool _is_finished;
AVRational _codec_timebase;
unsigned int _uid;
int _rotate;
};
... ...
... ... @@ -40,7 +40,7 @@
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="merge_pip.cpp">
<Filter>源文件</Filter>
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
... ...