Cannot encode single frame h264 (.mp4) video using FFmpeg. No video stream

I achieved this with the ffmpeg command line using the command. There was only one image in the folder.

ffmpeg -r 24 -i image% 03d.bmp -c: v libx264 -pix_fmt yuv420p oneframex.mp4

I would like to do the same with C ++. If I encode a video of three or more frames, the video is encoded correctly, but the result of encoding one or two frames of the video never has a video stream, as reported by ffprobe and some media players.

Comparing to ffprobe, my video (one with three or more frames) and one generated by the command tool shows almost the same information. Only the bitrate and encoder version is different.

I tried adding force_key_frames to 1, tried with many encoding options and with no success.

The application output gives me the following information:

[libx264 @ 20d1b840] using processor capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX

Profile

[libx264 @ 20d1b840] High, level 4.0

[libx264 @ 20d1b840] 264 - core 142 r2431 ac76440 - H.264 / MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac = 0 ref = 1 deblock = 1: 0: 0 anal = 0x3: 0x113 me = dia subme = 8 psy = 1 psy_rd = 1.00: 0.00 mixed_ref = 0 me_range = 16 chroma_me = 0 trellis = 0 8x8dct = 1 cqm = 0 deadzone = 21.11 fast_pskip = 1 chroma_qp_offset = -2 threads = 1 lookahead_threads = 1 sliced_threads = 0 nr = 0 decimate = 1 interlaced = 0 bluray_compat = 0 constrained_intra = 0 bframes = 0 weightp = 0 keyint = 1 keyint_min = 1 scenecut = 0 intra_refresh = 0 rc = crf mbtree = 0 crf = 10.0 qcomp = 0.60 qpmin = 0 qpmax = 25 qpstep = 4 ip_ratio = 1.40 aq = 1: 1.00

These are my main parameters:

pCodecCtx->codec_id = AV_CODEC_ID_H264;
pCodecCtx->pix_fmt= AV_PIX_FMT_YUV420P; 
pCodecCtx->gop_size = 1;
pCodecCtx->bit_rate = 400000;
pCodecCtx->me_range = 16;
pCodecCtx->max_qdiff = 4;
pCodecCtx->qcompress = 0.6;
pCodecCtx->qmin = 0;
pCodecCtx->qmax = 25;
pCodecCtx->time_base.den = 24;
pCodecCtx->time_base.num = 1;

AVDictionary *param = 0;
            av_dict_set(&param, "preset", "slow", 0);
            av_dict_set(&param, "profile", "high", 0);
            av_dict_set(&param, "crf", "10", 0); //this gave me quality
            av_dict_set(&param, "force_key_frames", "1", 0);

      

In my encoding, I just added

ppicture->pts = pCodecCtx->frame_number

      

to avoid a not strictly monotonous PTS message. And tried the methods from this question in case he had something to do.

I'm sure I must be missing an important parameter in order to create such a small video. I will make any suggestion.

+3


source to share





All Articles