the histogram was made with Preview (macOS).
I also think there is something wrong with the ranges. I have reproduced the error in my application with the sample applications. The test file is a any 1920x1080 jpg file input.jpg. First i decode the jpg with 06_jpeg_decode to yuv(V4L2_PIX_FMT_YUV420M) and then encode it to jpg with 05_jpeg_encode, then i copy multiple test.yuv files to video.yuv to get a video, after this step i encode the video.yuv with 01_video_encode to a h264 video, ffmpeg is used to convert the h264 to a mp4 file. Then you have to open the file test.jpg and video.mp4 with a web browser in 2 taps and switch between the taps, then you can see the difference in the shadows and highlights.
I have also checked the input formatfor 05_jpeg_encode and 01_video_encode, which are both V4L2_PIX_FMT_YUV420M.
./jpeg_decode num_files 1 input.jpg test.yuv
../05_jpeg_encode/jpeg_encode test.yuv 1920 1080 test.jpg -f 1 -crop 0 0 1920 1080
cat tes.yuv >> video.yuv (multiple(30-40) times to get a video, my video.yuv is 306MB big)
../01_video_encode/video_encode video.yuv 1920 1080 H264 video.h264
ffmpeg -i video.h264 -vcodec copy -an video.mp4
I hope you can reproduce my problem with this steps!