accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.46k stars 2k forks source link

use `VideoFileWriter` to generate H264/MP4 incorrectly #2138

Open waleswood opened 4 years ago

waleswood commented 4 years ago

What would you like to submit? (put an 'x' inside the bracket that applies)

Issue description

v3.8.2-alpha、v3.8.1-alpha

the H264/MP4,The video is displayed for one minute, but it can be played for two minutes, and the playing speed is twice as slow.

 _videoWriter = new VideoFileWriter();
_videoWriter.VideoCodec = VideoCodec.H264;
_videoWriter.BitRate = 1000 * 1024;
_videoWriter.FrameRate = 30;
_videoWriter.PixelFormat = AVPixelFormat.FormatYuv420P;
_videoWriter.Open(fileName, "mp4");
//....
_videoWriter.WriteVideoFrame(bitmap);

v3.6.0

Generating MP4 video for H264 is not supported

v3.7

Can be generated normally when images resolution 160x120 or 320x240. but 640x480 and 1280x720 Still not working properly

this is console output

[libx264 @ 076456c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 076456c0] profile Constrained Baseline, level 4.1
[libx264 @ 076456c0] 264 - core 148 r2744 b97ae06 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=0 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=4 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=12 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=12 rc=abr mbtree=1 bitrate=20480 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[swscaler @ 08dcfea0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0cae2000] deprecated pixel format used, make sure you did set range correctly
[mp4 @ 07644ce0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
[mp4 @ 07644ce0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
_videoWriter.Open(fileName, sImgInfo.Width,sImgInfo.Height, 25, VideoCodec.H264);
//....
_videoWriter.WriteVideoFrame(bitmap);