Håvard O. Nordstrand 4 år sedan
förälder
incheckning
2efc237c4a
4 ändrade filer med 194 tillägg och 82 borttagningar
  1. 0 82
      config/general/linux-examples.md
  2. 91 0
      config/media/ripping.md
  3. 98 0
      config/media/video-streaming.md
  4. 5 0
      index.md

+ 0 - 82
config/general/linux-examples.md

@@ -143,86 +143,4 @@ breadcrumbs:
 
 1. Install the graphical application `woeusb` from `ppa:nilarimogard/webupd8`.
 
-### Download Videos from YouTube and Sites
-
-Using [youtube-dl](http://ytdl-org.github.io/youtube-dl/) ([repo](https://github.com/ytdl-org/youtube-dl)).
-
-- Run in Docker:
-    - Using ([wernight's image](https://github.com/wernight/docker-youtube-dl)).
-    - Command prefix: `docker run --rm -v//$PWD:/downloads wernight/youtube-dl <...>`
-- Run binary:
-    - Find the download instructions in the repo.
-    - Install "ffmpeg" to allow downloading best quality audio and video: `apt install ffmpeg`
-- Download single video: `youtube-dl -c <URL>`
-    - `-c`/`--continue` to re-run the command if it previously failed during download.
-- Download full channel or playlist: `youtube-dl -qiwc --no-warnings [-o <format>] <URL>`
-    - `-q`/`--quiet` and `--no-warnings` to only errors. Alternatively, redirect STDERR to a log file and keep STDOUT non-quiet to be able to check the status. There may be videos that fail to download for different reasons, so do watch for errors.
-    - `-i`/`--ignore-errors` to avoid stopping on errors.
-    - `-wc`/`--no-overwrites --continue` to download only new/missing videos.
-    - `-o <format>` to specify the output filename format. See below.
-- Video quality:
-    - Specify `-f bestvideo+bestaudio` to download the best video format and best audio format and (by default) merge them. This is the default, but only as long as "ffmpeg" is installed. If it's not installed and this option is not specified, it may instead download a lower quality format.
-- Download audio from video: `youtube-dl -c --extract-audio --audio-quality 0`
-    - `--audio-format <format>`: Audio format, like "mp3", "wav", etc. Defaults to "best".
-    - `--audio-quality <0-9>`: Audio quality, where 0 is best. Defaults to "5".
-- Modify the output file path and name:
-    - Supports a Python-style format string.
-    - See [output template (youtube-dl)](https://github.com/ytdl-org/youtube-dl#output-template) for a list of variables.
-    - Example: `-o "%(uploader)s (%(upload_date)s) - %(title)s [%(id)s].%(ext)s"`
-- Full examples:
-    - YouTube video (video/channel/playlist): `youtube-dl -iwc -f bestvideo+bestaudio --cookie ~/cookies.txt -o "%(uploader)s (%(upload_date)s) - %(title)s [%(id)s].%(ext)s" <url>`
-- Common warnings and errors:
-    - "*WARNING: Requested formats are incompatible for merge and will be merged into mkv.*": The best quality video and audio are different formats and will therefore be merged into an MKV file. This is completely fine.
-    - "*ERROR: [...]: YouTube said: Unable to extract video data*": Try to open the video in an incognito browser to check what's up with it. If it requires you to log in, you may need to specify cookies and possibly your user agent. To specify cookies, log into a browser (Firefox or Chrome), export the cookies to file using the "cookie.txt" extension, and specify the cookie file for youtube-dl with the `--cookie <file>` option (see [How do I pass cookies to youtube-dl? (youtube-dl)](https://github.com/ytdl-org/youtube-dl/blob/master/README.md#how-do-i-pass-cookies-to-youtube-dl)).
-
-### Rip DVD to ISO
-
-CDs and DVDs use 2048 byte sectors and may have both unintentional and intentional data errors.
-Some will explode in size when you try to rip them.
-There are multiple methods to try.
-I recommend using ddrescue since it's the simplest and because of its error handling features.
-
-Install support for encrypted/protected DVDs:
-- Enable the `contrib` or `non-free` repo areas (I'm not sure which).
-- `apt install libdvd-pkg && dpkg-reconfigure libdvd-pkg`
-
-Gather information about the disc:
-- (Once) `apt install genisoimage`
-- `isoinfo -d -i /dev/sr0`
-
-#### Using dvdbackup
-
-1. (Once) `apt install dvdbackup`
-1. (Optional) Inspect the DVD: `dvdbackup -i /dev/sr0 -I`
-1. Rip the whole DVD to a subdirectory: `dvdbackup -i /dev/sr0 -o . -M`
-1. Make an ISO: `genisoimage -dvd-video -udf -o <name>{.iso,}`
-
-#### Using vobcopy
-
-1. (Once) `apt install vobcopy`
-1. Mount the disc: `mkdir -p /media/dvd && mount /dev/dvd /media/dvd`
-1. Rip it to the current dir: `vobcopy -i /media/dvd -l -m`
-1. Unmount the disc: `umount /media/dvd`
-
-#### Using dd
-
-If the disc is damaged, use ddrescue instead.
-
-1. Find sector size and count: `isosize -x /dev/sr0`
-1. `dd if=/dev/sr0 of=<name>.iso bs=2048 count=3659360 conv=noerror status=progress`
-    - `conv=noerror` prevents halting on error and writes zero to the output instead.
-
-#### Using GNU ddrescue
-
-ddrescue is a sophisticated recovery tool which gracefully handles read errors.
-When using a map file, it can be aborted and run multiple times and using different sources to try to fix corrupt sections.
-A typical way to use this method is to run it with fast options first and then optionally with slower options afterwards.
-When the output is a regular file, the corrupt sectors will contain zeros.
-This method can also be used to backup dying hard drives etc., but the options used below are for CD/DVD discs.
-
-1. (Once) `apt install gddrescue`
-1. Make sure the disk/disc is not mounted.
-1. Run without scraping: `ddrescue -n -b2048 /dev/sr0 <name>.{iso,map}`
-1. Run with direct access: `ddrescue -d -r1 -b2048 /dev/sr0 <name>.{iso,map}`
-
 {% include footer.md %}

+ 91 - 0
config/media/ripping.md

@@ -0,0 +1,91 @@
+---
+title: Media Ripping
+breadcrumbs:
+- title: Configuration
+- title: Media
+---
+{% include header.md %}
+
+## Download Videos from YouTube and Sites
+
+Using [youtube-dl](http://ytdl-org.github.io/youtube-dl/) ([repo](https://github.com/ytdl-org/youtube-dl)).
+
+- Run in Docker:
+    - Using ([wernight's image](https://github.com/wernight/docker-youtube-dl)).
+    - Command prefix: `docker run --rm -v//$PWD:/downloads wernight/youtube-dl <...>`
+- Run binary:
+    - Find the download instructions in the repo.
+    - Install "ffmpeg" to allow downloading best quality audio and video: `apt install ffmpeg`
+- Download single video: `youtube-dl -c <URL>`
+    - `-c`/`--continue` to re-run the command if it previously failed during download.
+- Download full channel or playlist: `youtube-dl -qiwc --no-warnings [-o <format>] <URL>`
+    - `-q`/`--quiet` and `--no-warnings` to only errors. Alternatively, redirect STDERR to a log file and keep STDOUT non-quiet to be able to check the status. There may be videos that fail to download for different reasons, so do watch for errors.
+    - `-i`/`--ignore-errors` to avoid stopping on errors.
+    - `-wc`/`--no-overwrites --continue` to download only new/missing videos.
+    - `-o <format>` to specify the output filename format. See below.
+- Video quality:
+    - Specify `-f bestvideo+bestaudio` to download the best video format and best audio format and (by default) merge them. This is the default, but only as long as "ffmpeg" is installed. If it's not installed and this option is not specified, it may instead download a lower quality format.
+- Download audio from video: `youtube-dl -c --extract-audio --audio-quality 0`
+    - `--audio-format <format>`: Audio format, like "mp3", "wav", etc. Defaults to "best".
+    - `--audio-quality <0-9>`: Audio quality, where 0 is best. Defaults to "5".
+- Modify the output file path and name:
+    - Supports a Python-style format string.
+    - See [output template (youtube-dl)](https://github.com/ytdl-org/youtube-dl#output-template) for a list of variables.
+    - Example: `-o "%(uploader)s (%(upload_date)s) - %(title)s [%(id)s].%(ext)s"`
+- Full examples:
+    - YouTube video (video/channel/playlist): `youtube-dl -iwc -f bestvideo+bestaudio --cookie ~/cookies.txt -o "%(uploader)s (%(upload_date)s) - %(title)s [%(id)s].%(ext)s" <url>`
+- Common warnings and errors:
+    - "*WARNING: Requested formats are incompatible for merge and will be merged into mkv.*": The best quality video and audio are different formats and will therefore be merged into an MKV file. This is completely fine.
+    - "*ERROR: [...]: YouTube said: Unable to extract video data*": Try to open the video in an incognito browser to check what's up with it. If it requires you to log in, you may need to specify cookies and possibly your user agent. To specify cookies, log into a browser (Firefox or Chrome), export the cookies to file using the "cookie.txt" extension, and specify the cookie file for youtube-dl with the `--cookie <file>` option (see [How do I pass cookies to youtube-dl? (youtube-dl)](https://github.com/ytdl-org/youtube-dl/blob/master/README.md#how-do-i-pass-cookies-to-youtube-dl)).
+
+## Rip DVDs (Linux)
+
+CDs and DVDs use 2048 byte sectors and may have both unintentional and intentional data errors.
+Some will explode in size when you try to rip them.
+There are multiple methods to try.
+I recommend using ddrescue since it's the simplest and because of its error handling features.
+
+Install support for encrypted/protected DVDs:
+- Enable the `contrib` or `non-free` repo areas (I'm not sure which).
+- `apt install libdvd-pkg && dpkg-reconfigure libdvd-pkg`
+
+Gather information about the disc:
+- (Once) `apt install genisoimage`
+- `isoinfo -d -i /dev/sr0`
+
+#### Using dvdbackup
+
+1. (Once) `apt install dvdbackup`
+1. (Optional) Inspect the DVD: `dvdbackup -i /dev/sr0 -I`
+1. Rip the whole DVD to a subdirectory: `dvdbackup -i /dev/sr0 -o . -M`
+1. Make an ISO: `genisoimage -dvd-video -udf -o <name>{.iso,}`
+
+#### Using vobcopy
+
+1. (Once) `apt install vobcopy`
+1. Mount the disc: `mkdir -p /media/dvd && mount /dev/dvd /media/dvd`
+1. Rip it to the current dir: `vobcopy -i /media/dvd -l -m`
+1. Unmount the disc: `umount /media/dvd`
+
+#### Using dd
+
+If the disc is damaged, use ddrescue instead.
+
+1. Find sector size and count: `isosize -x /dev/sr0`
+1. `dd if=/dev/sr0 of=<name>.iso bs=2048 count=3659360 conv=noerror status=progress`
+    - `conv=noerror` prevents halting on error and writes zero to the output instead.
+
+#### Using GNU ddrescue
+
+ddrescue is a sophisticated recovery tool which gracefully handles read errors.
+When using a map file, it can be aborted and run multiple times and using different sources to try to fix corrupt sections.
+A typical way to use this method is to run it with fast options first and then optionally with slower options afterwards.
+When the output is a regular file, the corrupt sectors will contain zeros.
+This method can also be used to backup dying hard drives etc., but the options used below are for CD/DVD discs.
+
+1. (Once) `apt install gddrescue`
+1. Make sure the disk/disc is not mounted.
+1. Run without scraping: `ddrescue -n -b2048 /dev/sr0 <name>.{iso,map}`
+1. Run with direct access: `ddrescue -d -r1 -b2048 /dev/sr0 <name>.{iso,map}`
+
+{% include footer.md %}

+ 98 - 0
config/media/video-streaming.md

@@ -0,0 +1,98 @@
+---
+title: Video Streaming
+breadcrumbs:
+- title: Configuration
+- title: Media
+---
+{% include header.md %}
+
+## General
+
+- Resources:
+    - [Webcam setup (ArchWiki)](https://wiki.archlinux.org/index.php/Webcam_setup)
+
+## Hardware
+
+- Some webcams come with H264 hardware encoders. Notably, Logitech's C920/C922 had a H264 hardware encoder in earlier versions but then removed it.
+- Webcams may require/reserve a lot of bandwidth, so try to avoid USB hubs.
+
+## Utility Stuff
+
+- Install Video 4 Linux 2 (v4l2): `apt install v4l-utils`
+- Show video devices:
+    - List devices: `v4l2-ctl --list-devices`
+    - Show brief device info: `v4l2-ctl [-d <dev>] --info`
+    - Show extended device info: `v4l2-ctl [-d <dev>] --all`
+    - Show device formats: `v4l2-ctl [-d <dev>] --info --list-formats`
+    - If no device is specified, it defaults to `/dev/video0`.
+    - Certain devices show up as multiple `/dev/video*` files. Typically there's one video capture device and one metadata capture device. Use the command above to find out.
+- Modify video device properties:
+    - Show properties with min, max and current values: `v4l2-ctl [-d <dev>] --all`
+    - Different webcams come with different properties and property names.
+    - Change a property (non-permanent): `v4l2-ctl [-d <dev>] -c <property>=<value>`
+    - Properties may be modified while the device is in use.
+    - As property changes are not permanent, you may want to set them in a script or something.
+    - Higher exposure may lead to reduced frame rate. To make it brighter you may increase the gain instead.
+    - Focus and white balance _can_ typically be left at auto. Brightness, contrast and saturation _should_ typically be left at default.
+    - Logitech C920 and similar:
+        - Disable auto focus: `focus_auto=0`
+        - Disable auto exposure: `exposure_auto=1`
+        - Set exposure manually (after auto is disabled): `exposure_absolute=250`
+        - Set gain: `gain=250`
+        - Disable auto white balance: `white_balance_temperature_auto=0`
+        - Set white balance manually (after auto is disabled): `white_balance_temperature=4000`
+        - Set brightness, contrast and saturation (generally not needed): `brightness=128`, `contrast=128`, `saturation=128`
+- Show video feed using `ffplay`:
+    - Requires package `ffmpeg` (Ubuntu).
+    - Command: `ffplay <dev>`
+    - For some reason this typically uses a limited framerate and resolution.
+
+## VLC
+
+- Resources:
+    - [Command line (VideoLAN)](https://wiki.videolan.org/Documentation:Command_line/)
+    - [Command line streaming (VideoLAN)](https://wiki.videolan.org/Documentation:Streaming_HowTo/Advanced_Streaming_Using_the_Command_Line/)
+    - [Command line streaming examples (VideoLAN)](https://wiki.videolan.org/Documentation:Streaming_HowTo/Command_Line_Examples/)
+    - [Streaming over IPv6 (VideoLAN)](https://wiki.videolan.org/Documentation:Streaming_HowTo/Streaming_over_IPv6/)
+- Basic command format: `vlc <input> --sout=#module1{options}:module2{options}:module3...`
+- Some modules:
+    - `standard`/`std`: Save the stream to file or send it over a network.
+    - `transcode`: Transcode the video.
+    - `duplicate`: Duplicate the feed, e.g. to send it to different destinations.
+    - `display`: Show the input stream locally. Can be used to verify that the input or previous parts chain is working as expected. Can be used with `duplicate` to monitor the stream.
+    - `rtp`: Stream as RTP/RTSP.
+- Transcode module options:
+    - Codec list: [Codec (VideoLAN)](https://wiki.videolan.org/Codec/)
+    - Specify video codec using `vcodec=` (e.g. `mp4v` or `h264`) and audio codec using `acodec=`. Use `none` to disable audio or video.
+    - Specify the video and audio buffer sizes in kB/s using `vb=` and `ab=`.
+- Standard module options:
+    - HTTP example: `--sout='#[...]:standard{access=http,mux=ts}' --http-host=localhost --http-port=5555`
+    - The `ts` mux is the most common one.
+- RTP module options:
+    - Supports RTSP.
+    - Basic example: `rtp{mux=ts,dst=<addr>,port=<port>}`
+    - `dst` must be some destination unicast or multicast address. `port` may be omitted to use the default.
+    - Uses UDP by default.
+- v4l2 input module:
+    - [v4l2 module (VideoLAN)](https://wiki.videolan.org/Documentation:Modules/v4l2/)
+    - Input format: `v4l2://<dev>[:<option>=<value>][more-options]`
+    - Specify format: `chroma=<format>` (e.g. `mjpg` or `h264` if supported) (`yuyv` may be the default and gives terrible frame rate)
+    - Specify width, height, frame rate: `width=1920:height=1080:fps=30` (1080p)
+- Stream webcam with RTP (no RTSP) (example):
+    - Command: `cvlc v4l2:///dev/video0:width=1920:height=1080:fps=30:chroma=mjpg --live-caching=10 --sout='#transcode{vcodec=mp4v,acodec=none}:rtp{mux=ts,dst=localhost}'`
+    - `dst` is the destination unicast or multicast address to continuously stream to.
+- Stream webcam with HTTP (example):
+    - Command: `cvlc v4l2:///dev/video0:width=1920:height=1080:fps=30:chroma=mjpg --live-caching=10 --sout='#transcode{vcodec=mp4v,acodec=none}:standard{access=http,mux=ts}' --http-host=localhost --http-port=5555`
+    - HTTP streams may be easily used as sources in e.g. OBS.
+- View network stream (example):
+    - View RTP stream: `vlc [--network-caching=100] <protocol>://<url>`
+    - Specify `--network-caching=<delay>` to set the buffering delay in milliseconds. Defaults to 1 second.
+    - Use `cvlc` to only show the video output and not the whole GUI.
+- Record network stream to file (example):
+    - Command: `cvlc <input> --sout='#transcode{vcodec=mp4v,acodec=none}:std{access=file,mux=ps,dst=test.mpg}'`
+
+## Record to File
+
+- Record HTTP (MPEG?) stream to file, automatically split every X seconds, restart if the stream is unavailable: `while true; do ffmpeg -hide_banner -loglevel error -i http://localhost:5555/ -c copy -map 0 -f segment -segment_time $((5*60)) -segment_format mp4 -strftime 1 "%Y-%m-%d_%H-%M-%S.mp4"; sleep 5; done`
+
+{% include footer.md %}

+ 5 - 0
index.md

@@ -68,6 +68,11 @@ Random collection of config notes and miscellaneous theory. Technically not a wi
 - [Minecraft (Bukkit)](config/game-servers/minecraft-bukkit/)
 - [Team Fortress 2 (TF2)](config/game-servers/tf2/)
 
+### Media
+
+- [Media Ripping](config/media/ripping/)
+- [Video Streaming](config/media/video-streaming/)
+
 ### Power
 
 - [APC PDUs](config/power/apc-pdus/)