Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault on arm64 but not x86_64. #1181

Closed
brycechesternewman opened this issue Apr 19, 2023 · 8 comments
Closed

Segmentation Fault on arm64 but not x86_64. #1181

brycechesternewman opened this issue Apr 19, 2023 · 8 comments

Comments

@brycechesternewman
Copy link

brycechesternewman commented Apr 19, 2023

Using the latest code from vmaf compiled with ffmpeg master branch we get a segmentation fault in vmaf running on arm64.
We do not get the same fault running vmaf/ffmpeg on x86_64. I have tried compiling with other ffmpeg branches like 5.1 or 6.0 the the segmentation fault still occurs. The backtrace after the reproduce steps shows the location of the fault.

Linux transcoder-job-7b6794585c-56knp 5.10.173-154.642.amzn2.aarch64 #1 SMP Wed Mar 15 00:26:38 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Steps to reproduce.

uname -a
Linux transcoder-job-7b6794585c-56knp 5.10.173-154.642.amzn2.aarch64 #1 SMP Wed Mar 15 00:26:38 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
"/usr/local/bin/ffmpeg" "-loglevel" "info" "-y" "-hide_banner" "-i" \
"https://user-images.githubusercontent.com/4998643/232534850-53ba56ee-e7e3-43bc-8eab-20d9798b99c8.mp4" \
"-sws_flags" "bicubic" "-filter_complex" "[0:v:0]scale='1080:1920'[hd16]" "-map" "[hd16]" "-map_metadata" "-1" "-f" "mov" "-vcodec" "libx264" "-pix_fmt" "yuv420p" "-profile:v" "high" "-level" "4.0" "-c:a" "aac" "-b:a" "128k" "-map" "0:a?" "-crf" "9" "-maxrate" "60M" "-bufsize" "60M" "-movflags" "faststart" "-refs" "4" "-color_primaries" "bt709" "-color_trc" "bt709" "-colorspace" "bt709" "-preset" "medium" "/tmp/hd16.mov"
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://user-images.githubusercontent.com/4998643/232534850-53ba56ee-e7e3-43bc-8eab-20d9798b99c8.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    creation_time   : 2021-03-02T18:53:26.000000Z
    encoder         : Lavf58.45.100
  Duration: 00:00:03.04, start: 0.000000, bitrate: 7184 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 2160x3840 [SAR 1:1 DAR 9:16], 7179 kb/s, 25 fps, 25 tbr, 25k tbn (default)
    Metadata:
      creation_time   : 2021-03-02T18:53:26.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of -180.00 degrees
[out#0/mov @ 0xaaaac3366130] Codec AVOption b (set bitrate (in bits/s)) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
  Stream #0:0 (hevc) -> scale:default
  scale:default -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 0xaaaac3366af0] using SAR=1/1
[libx264 @ 0xaaaac3366af0] VBV bitrate (60000) > level limit (25000)
[libx264 @ 0xaaaac3366af0] VBV buffer (60000) > level limit (31250)
[libx264 @ 0xaaaac3366af0] using cpu capabilities: ARMv8 NEON
[libx264 @ 0xaaaac3366af0] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0xaaaac3366af0] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=4 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=9.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=60000 vbv_bufsize=60000 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mov, to '/tmp/hd16.mov':
  Metadata:
    encoder         : Lavf60.4.101
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1080x1920 [SAR 1:1 DAR 9:16], q=2-31, 25 fps, 12800 tbn
    Metadata:
      encoder         : Lavc60.9.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 60000000/0/0 buffer size: 60000000 vbv_delay: N/A
[mov @ 0xaaaac33427f0] Starting second pass: moving the moov atom to the beginning of the file
[out#0/mov @ 0xaaaac3366130] video:7898kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.023023%
frame=   76 fps=6.7 q=-1.0 Lsize=    7900kB time=00:00:02.92 bitrate=22163.0kbits/s speed=0.258x
[libx264 @ 0xaaaac3366af0] frame I:1     Avg QP: 8.94  size:349137
[libx264 @ 0xaaaac3366af0] frame P:20    Avg QP: 8.27  size:252574
[libx264 @ 0xaaaac3366af0] frame B:55    Avg QP:11.26  size: 48841
[libx264 @ 0xaaaac3366af0] consecutive B-frames:  2.6%  2.6%  0.0% 94.7%
[libx264 @ 0xaaaac3366af0] mb I  I16..4:  5.2% 65.9% 28.9%
[libx264 @ 0xaaaac3366af0] mb P  I16..4:  2.0% 20.6%  9.4%  P16..4: 18.8% 25.7% 22.5%  0.0%  0.0%    skip: 1.1%
[libx264 @ 0xaaaac3366af0] mb B  I16..4:  0.1%  0.9%  0.3%  B16..8: 31.3% 22.6%  9.0%  direct: 8.0%  skip:27.7%  L0:42.7% L1:37.0% BI:20.2%
[libx264 @ 0xaaaac3366af0] 8x8 transform intra:64.8% inter:54.6%
[libx264 @ 0xaaaac3366af0] coded y,uvDC,uvAC intra: 89.5% 95.7% 91.5% inter: 36.8% 34.4% 20.4%
[libx264 @ 0xaaaac3366af0] i16 v,h,dc,p: 17% 12% 11% 60%
[libx264 @ 0xaaaac3366af0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 11% 21%  4%  9%  9%  7%  7%  5%
[libx264 @ 0xaaaac3366af0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 11% 20%  5% 15% 10%  7%  6%  4%
[libx264 @ 0xaaaac3366af0] i8c dc,h,v,p: 53% 17% 21%  9%
[libx264 @ 0xaaaac3366af0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0xaaaac3366af0] ref P L0: 64.3% 10.9% 15.2%  9.6%
[libx264 @ 0xaaaac3366af0] ref B L0: 89.3%  8.7%  2.0%
[libx264 @ 0xaaaac3366af0] ref B L1: 96.6%  3.4%
[libx264 @ 0xaaaac3366af0] kb/s:21281.29

Place vmaf_4k_v0.6.1.json in /tmp.

"/usr/local/bin/ffmpeg" "-i" "file:/tmp/hd16.mov" "-i" "https://user-images.githubusercontent.com/4998643/232534850-53ba56ee-e7e3-43bc-8eab-20d9798b99c8.mp4" "-filter_complex" "[0:v]scale=2160:3840[123456];[123456][1:v]libvmaf='model=path=/tmp/vmaf_4k_v0.6.1.json:enable_transform=true:n_threads=4'" "-f" "null" "-"
ffmpeg version N-110321-g1440bf15e2-20230418 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (crosstool-NG 1.25.0.152_89671bf)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=aarch64-ffbuild-linux-gnu- --arch=aarch64 --target-os=linux --enable-gpl --enable-version3 --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libpulse --enable-libvmaf --enable-libxcb --enable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --disable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-mbedtls --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --disable-libmfx --disable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --disable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --disable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --optflags=-Og --disable-stripping --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags=-pie --extra-libs='-ldl -lgomp' --extra-version=20230418
  libavutil      58.  6.100 / 58.  6.100
  libavcodec     60.  9.100 / 60.  9.100
  libavformat    60.  4.101 / 60.  4.101
  libavdevice    60.  2.100 / 60.  2.100
  libavfilter     9.  5.100 /  9.  5.100
  libswscale      7.  2.100 /  7.  2.100
  libswresample   4. 11.100 /  4. 11.100
  libpostproc    57.  2.100 / 57.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:/tmp/hd16.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf60.4.101
  Duration: 00:00:03.04, start: 0.000000, bitrate: 21288 kb/s
  Stream #0:0[0x1]: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1080x1920 [SAR 1:1 DAR 9:16], 21283 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : FFMP
      encoder         : Lavc60.9.100 libx264
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://user-images.githubusercontent.com/4998643/232534850-53ba56ee-e7e3-43bc-8eab-20d9798b99c8.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    creation_time   : 2021-03-02T18:53:26.000000Z
    encoder         : Lavf58.45.100
  Duration: 00:00:03.04, start: 0.000000, bitrate: 7184 kb/s
  Stream #1:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 2160x3840 [SAR 1:1 DAR 9:16], 7179 kb/s, 25 fps, 25 tbr, 25k tbn (default)
    Metadata:
      creation_time   : 2021-03-02T18:53:26.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of -180.00 degrees
[Parsed_libvmaf_1 @ 0xaaaafc783c80] The "enable_transform" option is deprecated: use model='enable_transform=true'.
Stream mapping:
  Stream #0:0 (h264) -> scale:default
  Stream #1:0 (hevc) -> libvmaf
  libvmaf:default -> Stream #0:0 (wrapped_avframe)
Press [q] to stop, [?] for help
[Parsed_libvmaf_1 @ 0xaaaafc710cf0] The "enable_transform" option is deprecated: use model='enable_transform=true'.
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf60.4.101
  Stream #0:0: Video: wrapped_avframe, yuv420p(tv, bt709, progressive), 2160x3840 [SAR 1:1 DAR 9:16], q=2-31, 200 kb/s, 25 fps, 25 tbn
    Metadata:
      encoder         : Lavc60.9.100 wrapped_avframe
Segmentation fault (core dumped)       0kB time=00:00:00.00 bitrate=N/A speed=   0x

Backtrace.

 gdb /usr/local/bin/ffmpeg core.727
GNU gdb (Ubuntu 12.1-3ubuntu2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/bin/ffmpeg...
[New LWP 748]
[New LWP 727]
[New LWP 733]
[New LWP 734]
[New LWP 732]
[New LWP 738]
[New LWP 735]
[New LWP 737]
[New LWP 736]
[New LWP 743]
[New LWP 742]
[New LWP 740]
[New LWP 739]
[New LWP 744]
[New LWP 745]
[New LWP 741]
[New LWP 764]
[New LWP 746]
[New LWP 765]
[New LWP 749]
[New LWP 750]
[New LWP 747]
[New LWP 766]
[New LWP 768]
[New LWP 767]
[New LWP 751]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
--Type <RET> for more, q to quit, c to continue without paging--
Core was generated by `/usr/local/bin/ffmpeg -i file:/tmp/hd16.mov -i https://user-images.githubuserco'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000aaaae6801730 in vif_subsample_rd_16_neon ()
[Current thread is 1 (Thread 0xffff799d6020 (LWP 748))]
(gdb) bt
#0  0x0000aaaae6801730 in vif_subsample_rd_16_neon ()
#1  0x0000aaaae67f2968 in extract ()
#2  0x0000aaaae67e93cc in vmaf_feature_extractor_context_extract ()
#3  0x0000aaaae67d7adc in threaded_extract_func ()
#4  0x0000aaaae67e5848 in vmaf_thread_pool_runner ()
#5  0x0000ffffbaf5f4cc in start_thread (arg=0xffffcdc688e7) at ./nptl/pthread_create.c:442
#6  0x0000ffffbafc889c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:79
@kylophone
Copy link
Collaborator

Thanks, will look into this.

@nilfm
Copy link
Contributor

nilfm commented Aug 1, 2023

I was not able to reproduce this on an M1 Macbook Pro, using the ffmpeg version 6.0 installed via homebrew. Here are my commands:

ffmpeg \
  -loglevel info \
  -y \
  -hide_banner \
  -i https://user-images.githubusercontent.com/4998643/232534850-53ba56ee-e7e3-43bc-8eab-20d9798b99c8.mp4 \
  -sws_flags bicubic \
  -filter_complex '[0:v:0]scale='1080:1920'[hd16]' -map '[hd16]' -map_metadata -1 \
  -f mov -vcodec libx264 -pix_fmt yuv420p -profile:v high -level 4.0 -c:a aac -b:a 128k -map "0:a?" -crf 9 -maxrate 60M -bufsize 60M -movflags faststart -refs 4 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -preset medium \
  hd16.mov
ffmpeg \
  -i hd16.mov \
  -i https://user-images.githubusercontent.com/4998643/232534850-53ba56ee-e7e3-43bc-8eab-20d9798b99c8.mp4 \
  -filter_complex "[0:v]scale=2160:3840[123456];[123456][1:v]libvmaf='model=path=model/vmaf_4k_v0.6.1.json\\:enable_transform=true:n_threads=4'" -f null -

Output:

[...]
frame=   76 fps=4.5 q=-0.0 Lsize=N/A time=00:00:03.00 bitrate=N/A speed=0.179x    x    
video:36kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_libvmaf_1 @ 0x12690ddd0] VMAF score: 96.773046

@kylophone any thoughts?

@YonatanGurevich
Copy link

Hi,
I am having a similar issue using the official docker image.
I am using a MacBook Pro (Apple M1 Max)
and getting a segmentation fault when executing:
docker run --rm -v $PWD:/files vmaf yuv420p 360 360 /files/reference.yuv /files/test.yuv --out-fmt json
Attaching here the videos I used
It seems to consistently reproduce for videos with 1:1 and 9:16 aspect ratios (maybe others as well, these are the ratios I tested), for widescreen 16:9 it does not reproduce.
The issue does not reproduce on x86.

@kylophone
Copy link
Collaborator

Thanks for the report and sample input. If you have a second, @YonatanGurevich, can you check if the segfault happens when you add --cpumask -1 to your command.

@YonatanGurevich
Copy link

Sure @kylophone. I did get a segfault.
Though I am not familiar with the usage of the --cpumask flag, and I did not see it mentioned in the final command executed from within the container...
My docker command:
docker run --rm -v $PWD:/files vmaf yuv420p 360 360 /files/reference.yuv /files/test.yuv --out-fmt json --cpumask -1

from traceback:
raise AssertionError(f'Process returned {e.returncode}, cmd: {cmd}, kwargs: {kwargs}, msg: {str(e.output)}') AssertionError: Process returned 139, cmd: /vmaf/libvmaf/build/tools/vmaf --reference /files/reference.yuv --distorted /files/test.yuv --width 360 --height 360 --pixel_format 420 --bitdepth 8 --output /vmaf/workspace/workdir/50b6e3f7-409b-4200-bf5c-3047c8bcf0c7/VMAF_integer_feature_V0.2.7_4d5e9860874edca73037b65ae2f23c145d292601 --xml --no_prediction --feature adm=debug=true --feature vif=debug=true --feature motion=debug=true --feature float_ansnr, kwargs: {'shell': True}, msg: b'Segmentation fault\n'

@kylophone
Copy link
Collaborator

OK, Thanks. I will get my hands on an arm4 cpu and try to reproduce.

@nilfm
Copy link
Contributor

nilfm commented Nov 1, 2023

Hi @brycechesternewman and @YonatanGurevich, I found a bug with the handling of widths not divisible by 32 in the arm64 code and we'll be merging the fix soon (#1245). Seeing that both of your widths (2160 and 360) are not divisible by 32, this is very likely to be causing your issues.

@nilfm
Copy link
Contributor

nilfm commented Nov 1, 2023

Closing this as it is addressed by #1245 but please reopen if the issue persists.

@nilfm nilfm closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants