[FFmpeg-trac] #9458(ffmpeg:reopened): ffmpeg's outputs differ a lot when compiled with gcc and clang

FFmpeg trac at avcodec.org
Mon Oct 18 23:29:58 EEST 2021

#9458: ffmpeg's outputs differ a lot when compiled with gcc and clang
             Reporter:  Shaohua Li  |                    Owner:  (none)
                 Type:  defect      |                   Status:  reopened
             Priority:  normal      |                Component:  ffmpeg
              Version:  git-master  |               Resolution:
             Keywords:              |               Blocked By:
             Blocking:              |  Reproduced by developer:  0
Analyzed by developer:  0           |
Changes (by Shaohua Li):

 * status:  closed => reopened
 * resolution:  invalid =>


 Well, I would insist that this issue is important as clang and gcc both
 are top popular compilers. It's harmful to have inconsistent program
 results across compilers or compiler optimisations (as I have explained in
 my last comment). Inconsistent results mean that at least one (potentially
 multiple) compiled binary has incorrect semantics.

 Since I reported this issue, I've been trying to debug ffmpeg to find the
 root cause of such difference. I used gdb (with rr) to debug gcc11 and
 clang13 compiled ffmpeg_g with optflags=-O0.

 I found that in ''libavcodec/motion_est.c:914'',
 ''s->mpvencdsp.pix_sum(pix, s->linesize)'' would be evaluated differently
 by these two ffmpegs. This difference only appeared when analysing some of
 the streams. Because "pix_sum" seems to be in the form of assembly code, I
 was not able to continue my analysis. I provided detailed reproduce
 procedures below in case you're interested in.

 1) run gdb :
 % gdb --args ffmpeg_g  -threads  1 -y -i   input_diff_1  -f mp4 output

 2) set breakpoint at ffmpeg.c:4817:
 % b ffmpeg.c:4817

 3) start the program and continue until you hit the breakpoint '''11'''

 4) set breakpoint at motion_est.c:914 and continue; Note that, you need to
 make sure that when you hit this breakpoint, ''mb_x'' and ''mb_y'' should
 both be 0. This is important since ffmpeg is by default multi-threading
 and somehow ''-threads 1'' cannot make it single-threaded in gdb.

 5) check the value of ''sum''. For clang13 compiled ffmpeg, it was
 ''60160'' while for gcc11, it was ''57751''.
Ticket URL: <https://trac.ffmpeg.org/ticket/9458#comment:3>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list