syrtsevser

Combine Twitch vod+chat using ffmpeg

Jul 19th, 2021 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. Instructions for combining twitch vod+chat into single 1440p video, using ffmpeg and hardware acceleration.
  2. Example of how what it looks like: https://youtu.be/05THM5wwXMU
  3.  
  4.  
  5. 1) Get a custom ffmpeg with cuda modules and a launcher:
  6. https://drive.google.com/u/0/uc?id=19IIgUz8iyCj1j4i-IwbGxz-XjCPdo5eE&export=download
  7.  
  8. OPTIONAL: In case you REALLY want to, the instructions for building ffmpeg yourself are at the end.
  9.  
  10. 2) Download vod, render chat.
  11. Get TwitchDownloader: https://github.com/lay295/TwitchDownloader/releases
  12. Run TwitchDownloader.exe, download a VOD (.mp4) and it's chat (.json). Make sure they're of same length/duration.
  13. Render chat using following settings: https://imgur.com/a/BW21Nln
  14.  
  15. 3) Combine vod+chat using custom ffmpeg. Have x4 disk space of original vod's size.
  16. Either use the launcher from step #1, or run ffmpeg manually (commands listed at the end as well).
  17.  
  18. 4) Upload the 1440p video.
  19. It should get encoded in VP9 regardless of view count.
  20. You're good to go here.
  21.  
  22.  
  23. --------------------------------------------------------------------------
  24. OPTIONAL: Building a beefy ffmpeg for yourself.
  25. Necessary functionality requires proprietary modules, which is why distributed pre-built ffmpeg builds don't include them. We'll make them.
  26.  
  27. Prerequisites:
  28. - CUDA Toolkit: https://developer.nvidia.com/Cuda-toolkit
  29. - Media-autobuild_suite: https://github.com/m-ab-s/media-autobuild_suite
  30.  
  31. - Have at least 12 Gb available, the final build will be around 700 Mb. Building itself will take several hours.
  32. - With CUDA installed, run media-autobuild_suite.bat
  33. - Follow instructions, generally self explanatory. Important choices: select "non-free", select "yes, custom ffmpeg options".
  34. - If you get errors during "/making" of ffmpeg, visit ...\build\ffmpeg_options.txt and comment out sketchy modules.
  35. My options, for example: https://pastebin.com/zGhA8CJG
  36.  
  37. Once building has finished (suite should autoclose itself), copy following files into your directory of choice:
  38. - All files from ...\media-autobuild_suite\local64\bin-video\
  39. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppc64_11.dll
  40. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppicc64_11.dll
  41. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppidei64_11.dll
  42. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppig64_11.dll
  43.  
  44. Now that ffmpeg is ready, you can uninstall CUDA and remove all MAS files. The copied over files SHOULD get the job done.
  45.  
  46.  
  47. --------------------------------------------------------------------------
  48. OPTIONAL: Run ffmpeg manually (without launcher).
  49. Open CMD in ffmpeg's folder and run following command:
  50.  
  51. ffmpeg.exe -hwaccel cuda -hwaccel_output_format cuda -vsync 1 -i Vod_864p.mp4
  52. -hwaccel cuda -hwaccel_output_format cuda -i Chat.mp4
  53. -c:a copy -map 0:a -c:v hevc_nvenc -preset p7 -tune hq -tier high
  54. -b:v 26M -minrate 24M -r 60 -refs:v 16 -rc-lookahead 32
  55. -temporal-aq 1 -i_qfactor 0.75 -b_qfactor 1.1
  56. -bf 3 -b_ref_mode middle -filter_complex "
  57. [0:v]scale_npp=2106:-1:interp_algo=cubic:format=yuv420p, setsar=1/1, hwdownload,
  58. pad=w=2560:h=1440:x=0:y=-1, hwupload_cuda, scale_npp=format=nv12[base];
  59. [1]scale_npp=format=nv12[overlay];
  60. [base][overlay]overlay_cuda=x=main_w-overlay_w:y=-1" Final_1440p.mp4
  61.  
  62.  
  63. --------------------------------------------------------------------------
  64. BONUS: Overlaying transparent chat over vod.
  65.  
  66. 1. Generating chat+mask: https://youtu.be/D-_TD1-w3fY
  67. 2. FFmpeg instructions and gallery: https://imgur.com/a/F8yDN6v
  68.  
Advertisement
Add Comment
Please, Sign In to add comment