I'm trying to adapt output_example.c to work with libx264 and aac with a mp4
container. Everything seems to work up until the point when I call
avcodec_encode_video. The coded_frame's pts *always* has the value
AV_NOPTS_VALUE ... Actually, it always has the value of the AVFrame passed
into avcodec_encode_video (so if I set the pts of the input frame to 1000,
coded_frame->pts will be 1000). The code is very similar to output_example.c
except I'm initializing the AVCodecContext based on the hq preset:
videoContext = videoStream->codec;
videoContext->codec_id = CODEC_ID_H264;
videoContext->codec_type = CODEC_TYPE_VIDEO;
videoContext->bit_rate = 400000;
videoContext->bit_rate_tolerance = 400000;
videoContext->width = width;
videoContext->height = height;
videoContext->time_base = frameRate;
videoContext->pix_fmt = PIX_FMT_YUV420P;
videoContext->thread_count = 0; // let x264 decide the number of
threads
videoContext->coder_type = FF_CODER_TYPE_AC; // coder=1 **
videoContext->flags |= CODEC_FLAG_LOOP_FILTER |
CODEC_FLAG_GLOBAL_HEADER; // flags=+loop **
videoContext->me_cmp |= FF_CMP_CHROMA; // cmp=+chroma **
videoContext->partitions = X264_PART_I8X8 | X264_PART_I4X4 |
X264_PART_P8X8 | X264_PART_B8X8; //
partitions=+parti8x8+parti4x4+partp8x8+partb8x8
videoContext->me_method = 8; // me_method=umh
videoContext->me_subpel_quality = 8; // subq=8 **
videoContext->me_range = 16; // me_range=16
videoContext->gop_size = 250; // g=250 **
videoContext->keyint_min = 25; // keyint_min=25**
videoContext->scenechange_threshold = 40; // sc_threshold=40 **
videoContext->i_quant_factor = 0.71f; // i_qfactor=0.71 **
videoContext->b_frame_strategy = 2; // b_startegy=2 **
videoContext->qcompress = 0.6f; // qcomp=0.6 **
videoContext->qmin = 10; // qmin = 10*
videoContext->qmax = 51; //qmax = 51 **
videoContext->max_qdiff = 4; // qdiff=4 **
videoContext->max_b_frames = 3; // bf=3 **
videoContext->refs = 4; //refs=4 **
videoContext->directpred = 3; //directpred=3 **
videoContext->trellis = 1; //trellis=1 **
videoContext->flags2 |= CODEC_FLAG2_WPRED | CODEC_FLAG2_MIXED_REFS |
CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP; //
flags2=+wpred+mixed_refs+dct8x8+fastpskip
... And the encoding function looks like this:
int outSize = avcodec_encode_video(videoContext, videoOutbuf,
OUTBUF_SIZE, inFrame);
if(outSize > 0)
{
AVPacket pkt;
av_init_packet(&pkt);
if(videoContext->coded_frame->pts != AV_NOPTS_VALUE)
pkt.pts = av_rescale_q(videoContext->coded_frame->pts,
videoContext->time_base, videoStream->time_base);
if(videoContext->coded_frame->key_frame)
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index = videoStream->index;
pkt.data = videoOutbuf;
pkt.size = outSize;
int ret = av_write_frame(formatContext, &pkt);
assert(!ret && "Error writing video frame");
}
Thanks to anyone who can help!
All the best,
Robert
--
Hide the petals underneath that bedroom floorboard and they will wither
without fail or success;
Put the people in the hollow box they crafted, bolt the doors and watch them
perish.
- Circle Takes The Square
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user