====== Video Capture ======
I am using Kodi to make all my DVDs and Bluray Discs available on demand on all screens I have in my house. I legally purchased and I am owning all titles on original disc (no pirated copies!) or through a subscription. I wrote this guide for myself, as the steps to create a working file to be used by Kodi can be quite elaborate. If you want to follow this guide please be reminded that copyright infringement (piracy) is punishable by law, and that you need to make sure you do not violate copyright laws in your country. Copying titles from streaming services might be illegal, or you might be required to delete such copies after termination of the subscription.
===== Hardware =====
I'm using the following hardware for capturing movies and will refer to the names in **//bold italic//** within my walk-throughs:
* A **//PC//** running Windows 10, Linux, or MacOS. This guide is verified on Windows 10 ([[hw:machines#hercules|Hercules]]) and Linux Debian 9 ([[hw:machines#hercules|Olympus]]).
* [[hw:udp203|OPPO UDP-203]] 4K Ultra HD Bluray Disc Player (**//UDP//**) for capturing DVD and BD discs. This player has analog surround 7.1 audio outputs.
* An older "Denon" Receiver - Alternatively, if your AV Receiver has pre-outs, you can use those to capture the different audio channels. As pre-outs usually are adjustable with the volume on the AVR you need to fix the volume (for example, always play the movie with -20dB volume), and you need to figure out how much amplification you need to apply in Audacity to get to an acceptable base volume when playing the movie.
* [[android:miboxs|Xiaomi Mi Box S 4K (AndroidTV 9) with Kodi and Netflix]] media player (**//MiBox//**).
* [[https://www.ugreen.co.th/product/22/ugreen-40281-hdmi-audio-extractor-hdmi-to-hdmi-with-optical-toslink-spdif-audio|UGREEN 40281 HDMI Audio Extractor]] necessary to disable HDCP (**//UGREEN//**), and it also features a Spdif out connector, with which the 5.1 audio can be sent to a receiver with 5.1 pre-out connectors (record 5.1 sound in 3 passes, see below).
* [[https://usa.yamaha.com/products/audio_visual/av_receivers_amps/rx-a860_u/index.html|Yamaha RX-A860]] Receiver and [[https://www.denon.com/en-us/product/av-receivers/avr-4308ci|Denon AVR-4308]] Receiver (**//AVR//**), both have surround 7.1 pre-out connectors.
* [[https://www.blackmagicdesign.com/products/intensitypro4k|Blackmagic Design Intensity Pro 4K]] capture card (**//BMDI//**).
I use the excellent Blackmagic Design Intensity Pro 4K as capture card. Linux, Windows, and Mac are supported by Blackmagic Design. However, like every other current capture card on the market it does not allow to capture compressed surround sound. The Intensity Pro 4K has excellent image quality, and allows to capture audio in digital or analog stereo. The cards primary usage scenario is not capturing game play, but capturing HDMI video for video mastering purposes. The Hauppauge Colossus 2 capture card reportedly is capable of capturing compressed surround audio, but the video section is much weaker compared to the Intensity Pro 4K (1080p limited to 30fps, for example) and I did not bother to try it. I haven't found any current technology card at a reasonable price which can do this.
===== Software =====
All software required and listed below are available on Windows 10, Mac, and Linux.
* [[https://mkvtoolnix.download/downloads.html|MKVToolNix]]. Used to mux (combine) the video and audio streams.
* [[https://sourceforge.net/projects/gmkvextractgui/|gMKVExtract]] which is GUI overlay for //mkvextract//, included in the MKVToolNix download. Used to extract video and audio streams from a mkv file.
* //mkvmerge//, included in the MKVToolNix download, but does not have a GUI, you need to use it on the command line (explained below). Used to trim the mkv file at the beginning and at the end.
* [[https://www.audacityteam.org/|Audacity]]. Used for audio file manipulation, combining tracks into a AC3 5.1 file, or to stretch audio.
* [[https://www.blackmagicdesign.com/support/family/capture-and-playback|Media Express]] from Blackmagic Design, included in //Desktop Video 12.0// or later. Used to capture video and audio from HDMI.
* [[https://obsproject.com/|OBS Studio]]. Used to capture video and audio from HDMI or Desktop screen.
* [[https://handbrake.fr/|HandBrake]] and [[https://handbrake.fr/downloads2.php|HandBrakeCLI]].
* [[https://www.smplayer.info/|SMPlayer]] to play captured videos and determine desired start and end positions in the raw video file. VLC and avidemux do not decode large avi files correctly. (Windows and Linux only). Work around for Mac: encode the avi generated by OSB Studio then play it with VLC to determine start and end positions.
* [[https://forum.videohelp.com/threads/313620-How-to-extract-subtitles-from-a-Blu-ray-and-convert-to-srt-or-sub-idx#:~:text=Extract%20Blu%2Dray%20subtitle%20streams&text=Click%20on%20the%20title%20you,files%20for%20each%20subtitle%20track.|eac3to and HdBrStreamExtractor]] (Windows only)
* [[https://sourceforge.net/projects/avidemux/|avidemux]]. Used to trim the video. (Windows only)
Media Express delivers better quality capture compared to OBS Studio when capturing from HDMI. However, the streams are not compressed, and the generated files are huge, 2 hours capture results in a 1 TB large file if encoded in 10 bit quality. You will need very fast disc access achievable with a SSD, use //Blackmagic Disc Speed Test// to verify your system is fast enough for the capture. OBS Studio is more tolerant if you compress the file before writing to disc, but stresses the CPU more than Media Express.
===== Capture from Bluray Disc =====
==== Good to know ====
I normally use [[media:makemkv|MakeMKV (Rip DVD and BD to mkv video file)]] on //Hercules// to create mkv files from DVD and BD discs. There seem to exist a few BD discs which are protected with some sort of hardware protection MakeMKV refuses to read or copy. Those titles need to be captured from the BD disc player, here are the necessary steps for a best possible capture quality. This work flow is based on using //UDP//, //AVR//, //BDMI//, and //UGREEN//.
==== Work flow ====
- Decide first, how you want to capture the audio. For stereo, set //UDP//'s speaker configuration to stereo, for 5.1 set it to 5.1 downmix. This will make sure that the correct audio channels are served through UDP's analog audio outputs. I normally capture my main audio track with 5.1, and other audio tracks with stereo. For me, the main audio track is English, but I also capture German and Thai if available.
- Connect HDMI from //AVR// HDMI out --> //UGREEN// --> //BMDI// HDMI in. As my //AVR// has 2 HDMI out ports this allows to watch the video during capture, but it is also possible to connect from HDMI out of the BD disc player (//UDP//). Remark: do not switch off the TV after capturing has started, as this will result in lost frames in the recording.
- Connect analog audio from //UDP// FL/FR --> //BMDI// Analog Stereo in. You have several options for this (be reminded that the frame rate is taken from the input source):
* Media Express: Capture video and audio as AVI or Quicktime 10-bit YUV. You need a lot of super-fast disc space, 2 hours 1920x1080 @ 24 fps requires 1TB, 2 hours 1920x1080 @ 60 fps requires 2.5TB disc space! It's the best quality option at very high cost of disc space.
* OBS Studio: Capture video and audio as AVI lossless 8-bit YUV (Lossless Quality setting). You need a lot of fast disc space, 2 hours 1920x1080 @ 24 fps requires 370GB, 2 hours 1920x1080 @ 60 fps requires 1TB disc space! It's a good quality option at high cost of disc space.
* OBS Studio: Capture video and audio with indistinguishable or high quality setting. The video stream will be compressed, but you need much less disc space, and it's also your only choice if you do not have a large SSD available.
- Connect analog audio from //UDP// SL/SR --> //BMDI// Analog Stereo in. Capture video and audio. The format does not matter as we will discard the video stream of this recording.
- Connect analog audio from //UDP// C/LFE --> //BMDI// Analog Stereo in. Capture video and audio. If you prefer to create stereo audio you can skip the last 2 captures.
- Encode the first capture with your preferred video encoder settings in //Handbrake//. I'm using HEVC (H265) 10 bit 1920x1080, quality setting 22. The BD disc most likely was encoded with 24 or 25fps, you can keep this.
- Audio streams in Media Express are raw 24-bit @ 48kHz, in OBS Studio they are raw 16-bit @ 48kHz.
- If you require 2 channel stereo audio you can encode it along with the video in Handbrake.
- If you require 5.1 channel surround audio you need to create the 5.1 AC3 file first:
* import the 3 audio streams of the 3 captured video files in the correct sequence, FL/FR, then C/LFE, then SL/SR. Split all stereo tracks into mono tracks and rename them for easier identification.
* audio streams from Media Express might be too large to handle for Audacity, in which case you encode them with Handbrake using a simple video encoder (which makes it faster, as we only need the audio stream) setting the audio to FLAC 24 bit for lossless audio encoding
* amplify the streams to get the correct volume. If you used your AVR's pre-outs to obtain the surround audio tracks you need to amplify the signal (all tracks with the same value). Once you have determined how much the amplification should be write down the amplification value and the volume of the AVR you used when recording, so you can set the same values again for any later recordings.
* time-shift the streams to sync all channels. For this you need to find some suitable positions in the audio. Find a "surround" location in the audio and sync FL/FR and SL/SR, then find a location with speech and sound to sync C. When finished, listen to several locations in the audio file to check the sound.
* //Export Audio...//, save as type AC3, and set the Bit Rate to 640 kbps.
- Identify where the video should begin and end, then trim the video stream with one of the following 2 programs. [[https://sourceforge.net/projects/avidemux/|avidemux]] allows to use a GUI, //mkvmerge// is part of [[https://mkvtoolnix.download/downloads.html|MKVToolNix]] and requires usage of the command line.
* //SMPlayer//. Open the video file and find beginning and end of the stream to keep.
* //avidemux//. Open the video file and find beginning and end of the stream to keep, then cut & paste into the same file, which brings the required part to the front of the file. Now find again the end, and delete everything after that marker.
* //mkvmerge//. Open the command line, change directory on the drive to where //mkvmerge// is located, for example C:. Change to the drive and directory where the video stream is located, for example E:\Handbrake, then issue the following command:c:mkvmerge --split parts:00:00:10-01:57:20 -o "output.mkv" "input.hevc"
- This would create a video stream file with the length of 1 hour 57 min 10 sec and which starts 10 sec after the original capture file. Note that //mkvmerge// cannot handle audio streams encoded with FLAC lossless. You might need to trial and error the stream end by a few seconds, as it appears that the length of the video file is not always accurately cut.
- Mux the video stream and the newly created AC3 audio stream into a mkv file with [[https://mkvtoolnix.download/downloads.html|MKVToolNix]]. Set //delay// to offset the start of the video and the audio.
- You might want to create a chapter file to be loaded into the mkv file, too. Either create one with fixed chapter length, for example every 10 minutes, or search for chapter positions in the video file, which you can also do using the BD disc player and the original Bluray disc. Export a chapter file from an existing mkv file to get the format of the chapter file correct.
- Check your final result. DONE.
==== Stereo capture only ====
- To capture audio in stereo only set the //UDP// to stereo and capture audio through HDMI embedded with BMDI.
- For stereo capture from //Mi Box//, connect the Mi Box's audio out with BMDI RCA analog audio in.
==== In case not all streams are protected or broken ====
- It is possible that some streams within the file are readable, even if MakeMKV aborts with read errors.
- Check it and extract streams with HdBrStreamExtractor.
- In one of my BDs I could extract all audio and subtitle streams, but not the video stream. I then captured the video stream only with BMDI, extracted audio and subtitles from the disc, and muxed everything into one file with mkvtoolnix.
- Consider to transcode DTS-HD or other high definition formats with Handbrake to AC3 surround to save space.
===== Screen Capture =====
==== Good to know ====
* Most streaming apps on Windows 10 do not allow screen capture and show a black window in OBS Studio, however, audio can still be captured. This is not a restriction from OBS Studio but from the OS (operating system, such as Windows 10 and MacOS), and applies to other screen capture software too.
* Use a web browser to play and capture video instead, however, surround audio cannot be captured from the web browser stream.
* It is possible to combine 2 captures for video and audio as explained in [[media:capture#capture_from_bluray_disc|Capture from Bluray Disc]].
* Some streaming services restrict video resolution to SD when streaming on a computer running an OS other than Windows 10 and MacOS.
* The best results are achieved in full screen mode on a monitor with 1920x1080 or 3840x2160 display resolution, with a second monitor to control OSB Studio.
==== Simple work flow ====
One pass capture without re-encoding of the video and a single audio track.
- For stereo, set your speaker configuration to stereo, for 5.1 set it to 5.1, irrespective of what kind of speakers you have connected to your system. In Windows 10 20H2 open Settings, then System --> Sound, and select //Sound Control Panel// to the right. Highlight //Speakers// and select //Configure// to set the audio channels. Remember to set this back to stereo after the capture if you have stereo speakers or headphones connected.
- Open the app, media player, or browser from which you want to capture. Browser capture will allow stereo audio only.
- Open OSB Studio, then setup Display Capture and select the monitor dedicated to display the video.
- Setup Audio Output Capture and select the Speakers you configured in the first step.
- In //Settings --> Audio//, set Channels to Stereo or 5.1.
- In //Settings --> Output//, set "Recording Quality" to "Same as stream" or "High Quality" and start capturing, wait until the mkv file is created.
- Identify where the video should begin and end, then trim the video stream with [[https://sourceforge.net/projects/avidemux/|avidemux]]. Note that avidemux can correctly trim the video only at a key frame, which occurs approximately every 10 seconds. Refer to the advanced work flow if you need more accurate trimming.
==== Advanced work flow ====
Multi-pass capture with re-encoding of the video and multiple surround or stereo audio tracks. Requires a lot more time and extensive usage of the command line, but delivers best possible quality.
- For stereo, set your speaker configuration to stereo, for 5.1 set it to 5.1, irrespective of what kind of speakers you have connected to your system. In Windows 10 20H2 open Settings, then System --> Sound, and select //Sound Control Panel// to the right. Highlight //Speakers// and select //Configure// to set the audio channels. Remember to set this back to stereo after the capture if you have stereo speakers or headphones connected.
- Open the app, media player, or browser from which you want to capture.
- Open OSB Studio, then setup Display Capture and select the monitor dedicated to display the video.
- Setup Audio Output Capture and select the Speakers you configured in the first step.
- In //Settings --> Audio//, set Channels to Stereo or 5.1.
- In //Settings --> Output//, set "Recording Quality" to "Lossless Quality" and start capturing, wait until the avi file is created.
- If capturing multiple languages, set the next language in the app (or media player or browser) and disable "Display Capture" which will save a lot of disc space.
- Find beginning and end of the stream to keep
* //SMPlayer// allows to play full video and step by frame with "." or step back with ",".
* //avidemux//, but for some very large avi files //avidemux// cannot detect the end of file, so you might need to encode a second time with the correct duration of the video. Do not use avidemux to trim the file, just to identify where HandBrakeCLI should start and stop encoding.
- Encode with HandBrakeCLI which allows setting start and end markers of the encode, which will set new key frames. The easiest way is to define presets in HandBrake (GUI) which work for you, and then use that preset for the encode. You might need to override the frame rate, if your preset is used for discs and streams. To simplify the command I recommend to place a short batch file into the same directory where HandBrakeCLI.exe is located:@ECHO OFF
IF "%4" == "" GOTO:usage
HandBrakeCLI -i "H:\Blackmagic\%~1.avi" -o "E:\Handbrake\%~1.mkv" --preset-import-gui --preset "1080p H265" --rate %2 --cfr --start-at seconds:%3 --stop-at seconds:%4
GOTO:eof
:usage
echo Usage: %0 "file name" ^ ^ ^
Handbrake might not be able to read the audio tracks, in which case you will need to convert the format in Audacity first. If you convert a stereo track you can offset the track in Audacity with the same number of seconds.milliseconds as you offset the video.
- Create a new project in //Audacity// and import all audio files of all languages. Stereo audio tracks will be imported as 1 Stereo track, Surround 5.1 audio tracks will be imported as 6 Mono tracks, sequence FL, FR, C, LFE, SL, SR.
- Stereo:
- align (time-shift) the tracks by listening to speech which no or minimal sound, do this in several locations, preferrably at the beginning and at the end of the tracks.
- Surround:
- Move all C-tracks up so you get them next to each other, e.g. move language 2 C-track up until it is below language 1 C-track, then move language 3 C-track up until it is below language 2 C-track.
- align (time-shift) the tracks by listening to speech which no or minimal sound, do this in several locations, preferrably at the beginning and at the end of the tracks.
- move all C-tracks down to the original position
- time-shift all tracks of the same language to be aligned with the C-track
- find a common start and end location in the tracks and take a note of it, for example 00h00m10.000s - 01h43m22.380s
- Set the selection range at the bottom of Audacity to 00h00m00.000 - 00h00m10.000s in each track and cut the selection
- Set the selection range at the bottom of Audacity to 01h43m12.380 - 02h43m12.380s in each track and cut the selection (the location in the track is 10s earlier as we cut 10s in the previous step)
- Noise reduction:
- You might get some noise into your audio when capturing through analog output from the AVR or UDP. To reduce it, do one or all of the following.
- connect BMDI to AVR with a HDMI cable, which creates a ground connection between the 2 devices to eliminate a possible ground loop
- use a stereo cinch cable with a magnetic ring or add a magnetic ring to your cable to reduce signal noise
- use Audacity's //Noise Reduction// effect to reduce the noise. Follow the help screen's instructions, the default values have worked well for me
- Set //Use Advanced Mixing Options// in //Edit --> Preferences --> Import / Export// when exporting 6 mono channels into one 5.1 AC3 file
- Select the audio tracks of the same language and //Export Selected Audio//. For surround choose AC3 and 640 kbps, for stereo choose AC3 and 160 kbps. You might first need to install ffmpeg in Audacity to get access to the AC3 codec.
- Mux the video track and all audio tracks into a mkv file with [[https://mkvtoolnix.download/downloads.html|MKVToolNix]]. You will need to sync the video with the audio, find some positions in the file with clear speech to do so.
- You might want to create a chapter file to be loaded into the mkv file, too. Either create one with fixed chapter length, for example every 10 minutes, or search for chapter positions in the video file. For the latter, export a chapter file from an existing mkv file to get the format of the chapter file correct.
===== Capture from a streaming service which streams to Windows 10 in Surround =====
- Connect HDMI from //Mi Box// or //AVR// HDMI out --> //UGREEN// --> //BMDI// HDMI in and capture. See also [[media:capture#capture_from_bluray_disc|Capture from Bluray Disc]]).
- Do a [[media:capture#screen_capture|Screen Capture]] of the same movie played in the Windows 10 app and record audio only.
- Extract the audio from the second capture and mux it with the video file of the first capture. Add a chapter file and downloaded subtitles.
===== Capture from a streaming service which does not stream to Windows 10 in Surround =====
- Connect HDMI from //Mi Box// or //AVR// HDMI out --> //UGREEN// --> //BMDI// HDMI in and follow the same steps as described in [[media:capture#capture_from_bluray_disc|Capture from Bluray Disc]].
- If you use your AVR's pre-outs you will need to connect the spdif out from //Mi Box// or //UGREEN// to the AVR.
===== Capture from a streaming service which streams to Windows 10 but not to a TV app =====
- Connect HDMI from //PC// HDMI out --> //UGREEN// --> //BMDI// HDMI in and follow the same steps as described in [[media:capture#Capture from a streaming service which streams to Windows 10 in Surround|Capture from a streaming service which streams to Windows 10 in Surround]].
- Helpful if the movie you want to record is not available in your region but can be streamed through login to a different regional marketplace.
===== Adjusting track length =====
Some special considerations are necessary if you combine tracks from different sources. For example, you want to capture an additional audio track for a movie you already own on disc. Such movies can have different length in minutes, even if the scene cut is identical. For example, the movie //Six Days Seven Nights// on DVD with English and Thai audio and subtitles (NTSC version) is 1h 41m 57s, where as the same movie with identical cut on a German DVD (PAL version) is 1h 37m 51s, so the NTSC version is 1.0427 times longer, and the PAL version is 0.959 times shorter. This is exactly the ratio between 25 fps (PAL, fps = frames per second) and 23.976216 fps (NTSC).
* //MakeMKV//: use the percentages as mentioned above to stretch the subtitle time positions (1.0427 or 0.959)
* //Audacity//: check the length of the movie and the audio stream to be added, convert the lengths into seconds, then use //Change Tempo// and enter the lengths in seconds for from/to
===== Links =====
* [[https://www.diyphotography.net/learn-choose-best-frame-rate-videos-just-10-minutes/|LEARN HOW TO CHOOSE THE BEST FRAME RATE FOR YOUR VIDEOS IN JUST 10 MINUTES]]
* [[https://handbrake.fr/docs/en/latest/cli/cli-options.html|HandBrake CLI options]]
* [[https://handbrake.fr/docs/en/latest/cli/command-line-reference.html|HandBrake CLI command line reference]]
===== Capture Surround Sound from HDMI or spdif =====
FIXME I haven't figured out how to do that yet. Below are some links to information.
* [[https://support.focusrite.com/hc/en-gb/articles/360005040720-How-to-set-up-your-audio-interface-in-OBS-Open-Broadcaster-Software-on-Windows#:~:text=From%20the%20Sources%20menu%20click,Aux%20channel%2C%20and%20click%20OK.|How to set up your audio interface in OBS on Windows]]
* [[https://www.cmedia.com.tw/technology/AUDIO_PROCESSING|Cmedia Audio Processing]]
* [[https://obsproject.com/docs/plugins.html#sources|OBS Plugins]]
* [[https://obsproject.com/wiki/Surround-Sound-Streaming-And-Recording#:~:text=OBS%2DStudio%20is%20the%20first,up%20to%208%20audio%20channels.|OBS - Surround Sound Streaming And Recording]]
* [[https://www.cmedia.com.tw/products/USB20_HIGH_SPEED/CM6212|Cmedia CM6212]]
* [[https://forum.videohelp.com/threads/367983-Capture-5-1-DD-with-spdif-input|Capture 5.1 DD with spdif input]]
* [[https://www.videohelp.com/software/AC3-Filter|AC3Filter]]
* [[https://www.free-codecs.com/ac3_filter_download.htm|AC3Filter Downloads]]
* [[http://ac3filter.sourceforge.net/draft/ac3filter_eng.html|AC3Filter Docs]]
* [[https://www.videohelp.com/software/ffmpeg|ffmpeg]]
* [[https://forum.doom9.org/showthread.php?t=128135|How to Record SPDIF Dolby Digital Input]]