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

FFmpeg only using one thread for transcoding. #67

Open
Matias314 opened this issue Dec 27, 2023 · 7 comments
Open

FFmpeg only using one thread for transcoding. #67

Matias314 opened this issue Dec 27, 2023 · 7 comments

Comments

@Matias314
Copy link

Hello, sorry if this isn't the right place to open an issue but I really can't wrap my head around it.
I've adjusted the amount of threads for transcoding in settings, saved and restarted my jail countless times to no avail.
I'm running TrueNAS on a server with 32 threads but only one thread is used which isn't nearly enough for fluid playback of higher resolution files when transcoded. Does anyone have any suggestions? Is there any way to troubleshoot this or see which flags are actually getting passed down to FFmpeg? Thank you in advance.

@Thefrank
Copy link
Owner

What do you have set for transcoding thread count? From the admin panel -> Playback -> Transcoding thread count. Try setting this manually.

What does top/htop report as "WCPU" for ffmpeg?
htop will give you a better idea by show core-by-core usage along with the full command being used by the encoder.

Does ffmpeg use the correct number of threads when run by hand with -threads 0? Does it work correctly for threads*1.5?

@Matias314
Copy link
Author

Matias314 commented Dec 27, 2023

Thanks for the response. I did change the thread count a few times to no avail. The last time I changed it to 16, and looking at the long command it htop it looks like the amount of threads is getting passed correctly:

ffmpeg -analyzeduration 200M -f matroska,webm -autorotate 0 -i file:/usr/local/share/Media/Movies/input.mkv -map_metadata -1 -map_chapters -1 -threads 16 -map 0:0 -map 0:1 -map -0:s -codec:v:0 libx264 -preset veryfast -crf 23 -maxrate 59616000 -bufsize 119232000 -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -sc_threshold:v:0 0 -vf setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,format=yuv420p -codec:a:0 aac -ac 2 -ab 384000 -af volume=2 -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename /var/db/jellyfin/transcodes/output%d.ts -hls_playlist_type vod -hls_list_size 0 -y /var/db/jellyfin/transcodes/output.m3u8

However WCPU never goes above 250%. So I guess it is using more than one thread but not nearly as much as specified.
When I manually kick off a simple transcode with ffmpeg -i ./input.mkv -map 0 -c copy -c:v libx264 ./output.mkv -threads 0, it utilizes all 32 threads with around 1200% WCPU.

When I manually run the long command from Jellyfin in my terminal I get the same roughly 250% WCPU and framerate as indicated in Jellyfin Playback Info. -threads 32 or 48 doesn't matter. FFmpeg is all black magic to me but this leads me to believe there's some bottleneck in the way Jellyfin commands FFmpeg to transcode video?

@Thefrank
Copy link
Owner

It appears FFmpeg will use roughly the correct amount of threads where it can. The issue seems to be when converting an x264(?) file into an HLS (MPEG_TS segments) stream file it only uses 1-2 threads resulting in the buffering. I am unsure if this is because the library does not support multi-threading for that file-type (x264?->HLS). The command issued appears correct. -threads only works for libraries that support it.

Does adjusting the preset it uses change anything? It should change the quality but does it increase/reduce the buffering?

@Matias314
Copy link
Author

Changing the preset from auto (which seemed to result to veryfast) to ultrafast does seem to reduce the buffering a little bit but it's still very much bottlenecked by the only 1-2 utilized threads.

@Thefrank
Copy link
Owner

Thefrank commented Dec 29, 2023

I currently have Windows and FreeBSD machines so to test the x264->HLS encoding I tried using the version of FFmpeg from WinGet. Using the command given to you by Jellyfin.

PS C:\Downloads\> ffmpeg -version
ffmpeg version 6.1-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100

Mediainfo from FFmpeg (not something like MediaInfo.exe)

Input #0, matroska,webm, from 'file:input.mkv':
  Metadata:
    encoder         : libebml v1.4.4 + libmatroska v1.7.1
    creation_time   : 2023-11-24T00:02:45.000000Z
  Duration: 00:46:49.50, start: 0.000000, bitrate: 4030 kb/s
  Chapters:
CHAPTERS...
  Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn (default)
    Metadata:
      BPS             : 3383587
      DURATION        : 00:46:49.474000000
      NUMBER_OF_FRAMES: 67360
      NUMBER_OF_BYTES : 1188262540
      _STATISTICS_WRITING_APP: mkvmerge v80.0 ('Roundabout') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2023-11-24 00:02:45
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(eng): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s (default)
    Metadata:
      BPS             : 640000
      DURATION        : 00:46:49.504000000
      NUMBER_OF_FRAMES: 87797
      NUMBER_OF_BYTES : 224760320
      _STATISTICS_WRITING_APP: mkvmerge v80.0 ('Roundabout') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2023-11-24 00:02:45
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
OTHER STREAMS/SUBS...

Parameters:

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (eac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000001cfcb07a300] using SAR=1/1
[libx264 @ 000001cfcb07a300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001cfcb07a300] profile Main, level 5.0, 4:2:0, 8-bit
[libx264 @ 000001cfcb07a300] 264 - core 164 r3161 a354f11 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=4 chroma_me=0 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=16 lookahead_threads=2 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=1 keyint=250 keyint_min=23 scenecut=0 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=59616 vbv_bufsize=119232 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, hls, to 'output.m3u8':
  Metadata:
    encoder         : Lavf60.16.100
  Stream #0:0: Video: h264, yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 90k tbn (default)
    Metadata:
      encoder         : Lavc60.31.102 libx264
    Side data:
      cpb: bitrate max/min/avg: 59616000/0/0 buffer size: 119232000 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 384 kb/s (default)
    Metadata:
      encoder         : Lavc60.31.102 aac

Results:

[out#0/hls @ 000001cfcb8ad1c0] video:604718kB audio:104106kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
frame=67360 fps=194 q=-1.0 Lsize=N/A time=00:46:48.78 bitrate=N/A speed=8.08x
[libx264 @ 000001cfcb07a300] frame I:937   Avg QP:14.42  size: 93427
[libx264 @ 000001cfcb07a300] frame P:19777 Avg QP:19.00  size: 20686
[libx264 @ 000001cfcb07a300] frame B:46646 Avg QP:20.26  size:  2628
[libx264 @ 000001cfcb07a300] consecutive B-frames:  4.1%  8.8%  5.7% 81.4%
[libx264 @ 000001cfcb07a300] mb I  I16..4: 57.7%  0.0% 42.3%
[libx264 @ 000001cfcb07a300] mb P  I16..4: 16.0%  0.0%  0.0%  P16..4: 20.6%  0.0%  0.0%  0.0%  0.0%    skip:63.3%
[libx264 @ 000001cfcb07a300] mb B  I16..4:  0.9%  0.0%  0.0%  B16..8:  5.4%  0.0%  0.0%  direct: 2.8%  skip:90.9%  L0:40.5% L1:51.1% BI: 8.4%
[libx264 @ 000001cfcb07a300] coded y,uvDC,uvAC intra: 28.5% 38.0% 18.0% inter: 2.3% 4.4% 0.3%
[libx264 @ 000001cfcb07a300] i16 v,h,dc,p: 52% 28% 10% 10%
[libx264 @ 000001cfcb07a300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 25% 16%  7%  5%  5%  5%  4%  6%
[libx264 @ 000001cfcb07a300] i8c dc,h,v,p: 51% 24% 19%  6%
[libx264 @ 000001cfcb07a300] Weighted P-Frames: Y:2.0% UV:1.6%
[libx264 @ 000001cfcb07a300] kb/s:1763.26
[aac @ 000001cfcb558f00] Qavg: 52341.137

On a 6-core CPU (12 threads), Windows 10 reported ~40% CPU usage across the whole task. Similar results reported when using FFmpeg 6.0.

Under Windows it heavy loads 6 threads (~80% utilization per) and almost ignores the other 6 (~10%). Changing -threads does appear to impact the transcode speed given the input and output settings provided for the sample I had. -threads 0 and -threads auto finish around the same time as -threads 4 or higher. -threads 1 to 3 still use more than 1,2, or 3 threads from a CPU load perspective but take longer to finish than -threads 4 or higher.

Neither FreeBSD nor Windows use ALL of the resources available when doing this type of transcode even when -threads appears to be supported for this. Windows is able to transcode the file faster than playback speed (~5-~8x).

I am trying the same test on FreeBSD with both the ports version and my static version. I will edit this post with my results

EDIT:

[libx264 @ 0x808b80c00] using SAR=1/1
[libx264 @ 0x808b80c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x808b80c00] profile Main, level 5.0, 4:2:0, 8-bit
[libx264 @ 0x808b80c00] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=4 chroma_me=0 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=2 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=1 keyint=250 keyint_min=23 scenecut=0 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=59616 vbv_bufsize=119232 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, hls, to 'output.m3u8':
  Metadata:
    encoder         : Lavf60.3.100
  Stream #0:0: Video: h264, yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 90k tbn (default)
    Metadata:
      encoder         : Lavc60.3.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 59616000/0/0 buffer size: 119232000 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 384 kb/s (default)
    Metadata:
      encoder         : Lavc60.3.100 aac
[hls @ 0x808bde300] Opening 'output0.ts' for writing bitrate=N/A speed=0.929x    
[hls @ 0x808bde300] Opening 'output1.ts' for writing bitrate=N/A speed=0.994x    
[hls @ 0x808bde300] Opening 'output2.ts' for writing bitrate=N/A speed= 1.1x    
[hls @ 0x808bde300] Opening 'output3.ts' for writing bitrate=N/A speed=1.13x    
[hls @ 0x808bde300] Opening 'output4.ts' for writing bitrate=N/A speed=1.04x    

The transcode is not able to stay ahead of playback under FreeBSD

One of two things is going on: it either REQUIRES the newer extensions found in my deskop (e.g., FMA3 BMI2 AVX2) OR something is wrong with FFmpeg under FreeBSD.

@Matias314
Copy link
Author

I did some testing as well. I tried on Windows using the same build you used. To keep CPU extensions consistent I ran Windows in a bhyve VM on my TrueNAS server.

PS C:\Users\Matias\Desktop\ffmpeg-6.1-full_build\bin> .\ffmpeg.exe -version
ffmpeg version 6.1-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil      58. 29.100 / 58. 29.100
libavcodec     60. 31.102 / 60. 31.102
libavformat    60. 16.100 / 60. 16.100
libavdevice    60.  3.100 / 60.  3.100
libavfilter     9. 12.100 /  9. 12.100
libswscale      7.  5.100 /  7.  5.100
libswresample   4. 12.100 /  4. 12.100
libpostproc    57.  3.100 / 57.  3.100

Media info:

Input #0, matroska,webm, from '.\input.mkv':
  Metadata:
    encoder         : libebml v1.4.2 + libmatroska v1.6.4
  Duration: 01:34:53.54, start: 0.000000, bitrate: 9935 kb/s
  Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn (default)
    Metadata:
      BPS             : 9292883
      DURATION        : 01:34:53.521000000
      NUMBER_OF_FRAMES: 136508
      NUMBER_OF_BYTES : 6613653723
      _STATISTICS_WRITING_APP: mkvmerge v66.0.0 ('Josie') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2023-06-15 07:56:28
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(eng): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s (default)
    Metadata:
      title           : English
      BPS             : 640000
      DURATION        : 01:34:53.536000000
      NUMBER_OF_FRAMES: 177923
      NUMBER_OF_BYTES : 455482880
      _STATISTICS_WRITING_APP: mkvmerge v66.0.0 ('Josie') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2023-06-15 07:56:28
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:2 etc......

Parameters:

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (eac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000001dfe4520b00] using SAR=1/1
[libx264 @ 000001dfe4520b00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 000001dfe4520b00] profile Main, level 5.0, 4:2:0, 8-bit
[libx264 @ 000001dfe4520b00] 264 - core 164 r3161 a354f11 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http:/>
Output #0, hls, to '.\transcodes\output.m3u8':
  Metadata:
    encoder         : Lavf60.16.100
  Stream #0:0: Video: h264, yuv420p(tv, bt709, progressive), 1920x800 [SAR 1:1 DAR 12:5], q=2-31, 23.98 fps, 90k>
    Metadata:
      encoder         : Lavc60.31.102 libx264
    Side data:
      cpb: bitrate max/min/avg: 59616000/0/0 buffer size: 119232000 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 384 kb/s (default)
    Metadata:
      encoder         : Lavc60.31.102 aac

Results:

[out#0/hls @ 000001dfe3df9980] video:1457954kB audio:212675kB subtitle:0kB other streams:0kB global headers:0kB >
frame=136508 fps= 99 q=-1.0 Lsize=N/A time=01:34:52.56 bitrate=N/A speed=4.13x
[libx264 @ 000001dfe4520b00] frame I:1898  Avg QP:19.32  size:104438
[libx264 @ 000001dfe4520b00] frame P:36596 Avg QP:22.52  size: 23741
[libx264 @ 000001dfe4520b00] frame B:98014 Avg QP:24.54  size:  4345
[libx264 @ 000001dfe4520b00] consecutive B-frames:  3.2%  1.7%  4.3% 90.8%
[libx264 @ 000001dfe4520b00] mb I  I16..4: 49.9%  0.0% 50.1%
[libx264 @ 000001dfe4520b00] mb P  I16..4: 20.8%  0.0%  0.0%  P16..4: 35.6%  0.0%  0.0%  0.0%  0.0%    skip:43.6%
[libx264 @ 000001dfe4520b00] mb B  I16..4:  2.1%  0.0%  0.0%  B16..8: 11.5%  0.0%  0.0%  direct: 7.0%  skip:79.4>
[libx264 @ 000001dfe4520b00] coded y,uvDC,uvAC intra: 47.8% 43.5% 12.2% inter: 6.2% 7.9% 0.1%
[libx264 @ 000001dfe4520b00] i16 v,h,dc,p: 35% 23% 22% 20%
[libx264 @ 000001dfe4520b00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 20% 13%  9%  7%  7%  7%  6%  7%
[libx264 @ 000001dfe4520b00] i8c dc,h,v,p: 42% 24% 26%  9%
[libx264 @ 000001dfe4520b00] Weighted P-Frames: Y:1.9% UV:0.9%
[libx264 @ 000001dfe4520b00] kb/s:2097.75
[aac @ 000001dfe46abd80] Qavg: 60559.320
PS C:\Users\Matias\Desktop\ffmpeg-6.1-full_build\bin>

And on FreeBSD:

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (eac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x808aa9c00] using SAR=1/1
[libx264 @ 0x808aa9c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x808aa9c00] profile Main, level 5.0, 4:2:0, 8-bit
[libx264 @ 0x808aa9c00] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x>
Output #0, hls, to '/var/db/jellyfin/transcodes/output.m3u8':
  Metadata:
    encoder         : Lavf60.3.100
  Stream #0:0: Video: h264, yuv420p(tv, bt709, progressive), 1920x800 [SAR 1:1 DAR 12:5], q=2-31, 23.98 fps, 90k>
    Metadata:
      encoder         : Lavc60.3.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 59616000/0/0 buffer size: 119232000 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 384 kb/s (default)
    Metadata:
      encoder         : Lavc60.3.100 aac

Results:

frame=136508 fps= 51 q=-1.0 Lsize=N/A time=01:34:53.33 bitrate=N/A speed=2.15x
video:1324667kB audio:212669kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x808aa9c00] frame I:1898  Avg QP:19.30  size:104683
[libx264 @ 0x808aa9c00] frame P:35680 Avg QP:22.49  size: 21371
[libx264 @ 0x808aa9c00] frame B:98930 Avg QP:24.56  size:  3995
[libx264 @ 0x808aa9c00] consecutive B-frames:  2.5%  1.2%  4.2% 92.1%
[libx264 @ 0x808aa9c00] mb I  I16..4: 49.8%  0.0% 50.2%
[libx264 @ 0x808aa9c00] mb P  I16..4: 19.0%  0.0%  0.0%  P16..4: 37.0%  0.0%  0.0%  0.0%  0.0%    skip:44.0%
[libx264 @ 0x808aa9c00] mb B  I16..4:  1.9%  0.0%  0.0%  B16..8: 11.3%  0.0%  0.0%  direct: 6.8%  skip:79.9%  L0>
[libx264 @ 0x808aa9c00] coded y,uvDC,uvAC intra: 46.6% 42.7% 11.9% inter: 5.9% 7.8% 0.1%
[libx264 @ 0x808aa9c00] i16 v,h,dc,p: 36% 22% 22% 20%
[libx264 @ 0x808aa9c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 20% 13%  9%  7%  7%  7%  6%  7%
[libx264 @ 0x808aa9c00] i8c dc,h,v,p: 42% 23% 26%  9%
[libx264 @ 0x808aa9c00] Weighted P-Frames: Y:1.9% UV:0.9%
[libx264 @ 0x808aa9c00] kb/s:1905.97
[aac @ 0x808aaa400] Qavg: 60559.555
[root@jellyfin ~]#

It was nearly twice as fast in Windows even though virtualized. And it was multitheading much more effectively:
screenshot_2023-12-31_23-14-40_104732983

image

So I think something is wrong with FFmpeg on FreeBSD then?

ffmpeg version 6.0.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with FreeBSD clang version 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)
  configuration: --prefix=/usr/local --mandir=/usr/local/man --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt --enable-shared >
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100

This is the ports version I believe. Are there other builds I can try and do you think your static version would perform better?

I hope I didn't miss any important information. Thank you for your time and happy new years!

@Thefrank
Copy link
Owner

Thefrank commented Jan 1, 2024

This is the ports version I believe.

Yes. It is still on 6.0.1

Are there other builds I can try and do you think your static version would perform better?

A quick test with my static build showed it to be slightly slower (~5%) than the ports version. This is not unexpected despite it being version 6.1. It is a static binary. I make no changes to the patches that FFmpeg or its dependencies on FreeBSD use and just apply them directly.

There are two major differences: Mine has no hwaccel support. It supports chromaprint. The former because hwaccel requires dynamically loading in something from a driver and the later because people wanted chromaprint and ports version of FFmpeg lacks it.

I was going to try Plex's encoder but it has an extremely limited set of decoders/encoders, is unversioned (uses a git commit hash), and uses an old version of clang (11?!)

I hope I didn't miss any important information. Thank you for your time and happy new years!

Nothing appears to be missed. I am both amused and annoyed that virtualized windows binary works better than native FreeBSD binary.

Thank you for reporting and helping with troubleshooting!

As of right now it appears to be an FFmpeg issue and not a jellyfin+FreeBSD issue.
I will keep this issue open as any additional information would be welcome.

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

2 participants