[英]Unable to encode single frame h264 (.mp4) video with FFmpeg. No video stream present
I have achieved this with ffmpeg command line tool using the command.我使用该命令通过 ffmpeg 命令行工具实现了这一点。 The folder had only one image.
该文件夹只有一张图片。
ffmpeg -r 24 -i image%03d.bmp -c:v libx264 -pix_fmt yuv420p oneframex.mp4
ffmpeg -r 24 -i 图像%03d.bmp -c:v libx264 -pix_fmt yuv420p oneframex.mp4
I would like to do the same with C++.我想用 C++ 做同样的事情。 If I encode a video of three or more frames, video encodes correctly, but the result of encoding a one or two frames video never has a video stream, as reported by ffprobe and some media players.
如果我编码一个三帧或更多帧的视频,视频编码正确,但编码一帧或两帧视频的结果永远不会有视频流,正如 ffprobe 和一些媒体播放器所报告的那样。
Comparing with ffprobe, my video (the one with three or more frames) and the one generated by the command tool show almost the same information.与ffprobe相比,我的视频(具有三帧或更多帧的视频)和命令工具生成的视频显示的信息几乎相同。 Only bitrate and encoder version are different.
只有比特率和编码器版本不同。
I have tried adding force_key_frames to 1, tried with many encoding options and have be unsuccessful.我曾尝试将 force_key_frames 添加到 1,尝试使用许多编码选项但都没有成功。
The application output gives me this information:应用程序输出为我提供了以下信息:
[libx264 @ 20d1b840] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 20d1b840] 使用 CPU 功能:MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 20d1b840] profile High, level 4.0
[libx264 @ 20d1b840] 配置文件高,级别 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 analyse=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
[libx264 @ 20d1b840] 264 - 核心 142 r2431 ac76440 - H.264/MPEG-4 AVC 编解码器 - Copyleft 2003-2014 - http://www.videolan.org/x264.html - 选项:cabac=0 ref=1 deblock =1:0:0 分析=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 线程=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 blueay_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(¶m, "preset", "slow", 0);
av_dict_set(¶m, "profile", "high", 0);
av_dict_set(¶m, "crf", "10", 0); //this gave me quality
av_dict_set(¶m, "force_key_frames", "1", 0);
In my encoding I just added在我的编码中,我刚刚添加了
ppicture->pts = pCodecCtx->frame_number
to avoid non-strictly-monotonic PTS message.避免非严格单调的 PTS消息。 And tried the methods from this question in case it had something to do.
并尝试了这个问题中的方法,以防万一。
I'm sure I must be missing some important parameter to be able to create such a small video.我确定我必须遗漏一些重要参数才能创建这么小的视频。 I will take any suggestion.
我会接受任何建议。
After sending the single frame to encoder, a null frame must be sent to flush encoders.将单帧发送到编码器后,必须将空帧发送到刷新编码器。
avcodec_send_frame(enc, nullptr);
avcodec_receive_packet(enc, pkt);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.