Thursday, September 15, 2022

Compiling the Linux Kernel 5.19.8 under Ubuntu 22.04

Compiling the Linux Kernel version 5.19.8 in Ubuntu 22.04

First we need to install the following:

sudo apt install git libncurses-dev gawk openssl libssl-dev dkms libudev-dev libpci-dev libiberty-dev autoconf llvm

sudo apt install libncurses5-dev libncursesw5-dev

sudo apt install pkg-config

sudo apt install bison

sudo apt install flex

sudo apt install libelf-dev

sudo apt install openssl

sudo apt-get install libssl-dev

sudo apt-get install liblz4-tool 

After downloading and decompressing the Kernel file, under a Terminal go to that directory and run the configuration script:

MyPC:~/Downloads/LinuxKernel/linux-5.19.8$ make menuconfig


We can check our hardware characteristics using the following commands:

lshw

lscpu

lsmod

lspci

lsusb

With that information we can set the configuration file properly.

The compilation process can be started with the command:

make -j 8

The number 8 means that 8 threads will be used for the compilation process. You can check with the command lscpu how many cores and threads your computer support. If you have 4 cores and every core can support 2 threads that makes a total of 8. Using all your threads will speed up the compilation process, in average using 8 threads the compilation would be over in about 30 minutes. If you use just one core or thread it would take over 2 hours to finish the compilation.

If you get the following error:

make[1]: *** No rule to make target 'debian/canonical-certs.pem', needed by 'certs/x509_certificate_list'.  Stop.

make[1]: *** Waiting for unfinished jobs....

make: *** [Makefile:1847: certs] Error 2

make: *** Waiting for unfinished jobs....

You can fix it editing your ".config" file and changing the line:

CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"

to

CONFIG_SYSTEM_TRUSTED_KEYS=""

and run again the command for compilation.

Wednesday, March 09, 2022

Installing jGRASP in Linux

First download and unzip jGRASP for Linux (the bundled version).

Unzip it in a directory, in this case it was downloaded inside the directory "snap". Then create a link to it in /usr/bin/jgrasp as follows:

 sudo  ln  -s  /home/username/snap/jgrasp/bin/jgrasp  /usr/bin/jgrasp

You can call the program from command line or you can also create a desktop icon to call its execution.

Adding support for JavaFX:

First download the JavaFX and unzip it in a proper location, it could be also inside the "snap" directory. Then you need to go in jGRASP to "Settings ==> Compiler Settings ==> Workspace", a new window will be opened, and go to the "JavaFX" tab, there browse and input the JavaFX home path.


Note: the JavaFX has to be of the proper architecture, i.e. x64, or any other correctly corresponding to your machine, otherwise graphics won't work. 


After that, for testing purposes you can use the following code from Oracle.

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
 
public class HelloWorld extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
 
            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}

The outcome will be the following:


Every time the button is clicked you will get the string:

Hello World!

That string is in the terminal in pure text mode.





---

Thursday, February 24, 2022

Converting A4 PDF to Letter Size

 One solution that usually works is to use pdfjam from the texlive distribution

pdfinfo input.pdf 

pdfjam --outfile output.pdf --paper letter input.pdf 

pdfinfo output.pdf 

We can also do the opposite, from Letter size to A4 size.



----///

Wednesday, January 26, 2022

SOFT & HARD LINKS

Soft links

Commonly referred to as symbolic links, soft links link together non-regular and regular files. They can also span multiple filesystems. By definition, a soft link is not a standard file, but a special file that points to an existing file. Format: 

ln -s (file path [original] you want to point to) (the soft path pointing to the original)

Example:

ln -s  /home/simon/snap/jgrasp/bin/jgrasp   /usr/bin/jgrasp

Hard links

The concept of a hard link is the most basic. Every file on the Linux filesystem starts with a single hard link. The link is between the filename and the actual data stored on the filesystem. Creating an additional hard link to a file means a few different things. The syntax is:

ln (original file path) (new file path)

Example:

ln  TestFile  /tmp/link2TestF

First, you create a new filename pointing to the exact same data as the old filename. This means that the two filenames, though different, point to identical data. When changes are made to one filename, the other reflects those changes. The permissions, link count, ownership, timestamps, and file content are the exact same. If the original file is deleted, the data still exists under the secondary hard link. The data is only removed from your drive when all links to the data have been removed. If you find two files with identical properties but are unsure if they are hard-linked, use the "ls -i" command to view the inode number. Files that are hard-linked together share the same inode number. Example:

ls  -li  TestFile  /tmp/link2TestF

Conclusion

  • A hard link always points a filename to data on a storage device.
  • A soft link always points a filename to another filename, which then points to information on a storage device.



Reference: RedHat.

---


Sunday, December 26, 2021

CONCATENATION OF VIDEOS [CONCATENATE]

FFmpeg has three concatenation methods:


1. concat video filter

Use this method if your inputs do not have the same parameters (width, height, etc), or are not the same formats/codecs, or if you want to perform any filtering.

Note that this method performs a re-encode of all inputs. If you want to avoid the re-encode, you could re-encode just the inputs that don't match so they share the same codec and other parameters, then use the concat demuxer to avoid re-encoding everything.

ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv \

-filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] \

concat=n=3:v=1:a=1 [v] [a]" \

-map "[v]" -map "[a]" output.mkv


2. concat demuxer

Use this method when you want to avoid a re-encode and your format does not support file-level concatenation (most files used by general users do not support file-level concatenation).

$ cat mylist.txt

file '/path/to/file1'

file '/path/to/file2'

file '/path/to/file3'

$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4


3. concat protocol

Use this method with formats that support file-level concatenation (MPEG-1, MPEG-2 PS, DV). Do not use with MP4.

$ ffmpeg -i "concat:input1|input2" -codec copy output.mkv

This method does not work for many formats, including MP4, due to the nature of these formats and the simplistic concatenation performed by this method.

--

If in doubt about which method to use, try the concat demuxer.

---

Source: Stackoverflow.


Sunday, September 20, 2020

Commands useful along with Youtube-dl

The following is to download a only a particular part of a video from YouTube 

ffmpeg -i $(youtube-dl -f 22 --get-url https://www.youtube.com/watch?v=cmne_rokrs4) -ss 00:10:10 -to 00:12:52 -c:v copy -c:a copy happy.mp4

Or you can download all the video first and then cut some parts following the instructions here.

If you want to concatenate MP4 videos (you can prepare an script):

echo file input1.mp4 >  mylist.txt

echo file input2.mp4 >>  mylist.txt

ffmpeg -f concat -i mylist.txt -c copy output.mp4

To list all subs for a video:

youtube-dl --list-subs URL

To download all subs, but not the video:

youtube-dl --all-subs --skip-download URL

Or you can only download one subtitle

youtube-dl --write-sub --sub-lang en --skip-download URL

Or  for downloading the automatically generated subtitles

youtube-dl --write-auto-sub --skip-download URL

If you want to convert the subtitles do:

ffmpeg -i input.vtt output.srt

The following is to convert videos to a higher speed. For instance, if you want to multiply by 1.15, the command is:

ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.87*PTS[v];[0:a]atempo=1.15[a]" -map "[v]" -map "[a]" output.mkv

#The "setpts" corresponds to the inversed speed (in this case 100/1.25 = 0.8)

#while the "atempo" corresponds to the desired direct speed of the video.

#Those values are proportionally inversed.

#For a 25% higher speed output video the values

#would be "setpts=0.8*PTS" and "atempo=1.25"

100/1.25 = 0.8

References:

Friday, September 18, 2020

Setting a SSH server in a workstation



sudo apt install openssh-server

systemctl status sshd

sudo systemctl restart ssh

sudo ufw allow ssh

Enable the SSH server to start automatically during the boot.

sudo systemctl enable ssh

Connect from a remote client to your SSH server. First, obtain an IP address of your SSH server. 

ip a

If connecting over the internet you need your external IP address:

echo $(wget -qO - https://api.ipify.org)

Check if IP being used to login via SSH is correct. Re-check IP of device being SSH'd into with:

hostname -I

For Dynamic DNS the freedns.afraid.org works fine with ddclient in Linux.

If you don't want to use the default port 22 for SSH, you need to edit the sshd config file in:

/etc/ssh/sshd_config 

and change the value of "Port 22" in it for another number. You should run SSH on an unprivileged port number, i.e. from 1024 to 65535. You can check what local ports are in use currently to avoid a conflict with:

netstat -taulpn 

and also avoid IANA registered service numbers, check with:

cat /etc/services

Once you have made the appropriate change open a firewall port to correspond with the new SSH port where "xxxx" represent the new number that you chose:

sudo ufw allow xxxx/tcp

Then

sudo systemctl restart ssh

For a SSH connection through a specific port, where "xxxx" is the number chosen, do:

ssh -p xxxx username@{hostname or IP}



----

Sunday, September 06, 2020

Dual Boot Linux and Windows 10

 If Windows was installed to run in UEFI, the Linux OS must also be installed using the UEFI mode. This means that most likely you need to disable in the BIOS the legacy mode and allow secure boot.

Is the "Install Ubuntu alongside Windows 10" option missing?

Please note that in the following circumstances the Ubuntu 20.04 installation option "Install Ubuntu alongside Windows 10" may be missing, if your Windows 10 installation: is not correctly shutdown or is hibernating, has corrupted partition which needs repair, partition has not enough free disk space left for resizing, uses Dynamic Disk or the file system contains uncontrollable file fragmentation.

Another case is if you try to install Linux using legacy boot for your installation media; the installation would be possible but the dual boot won't work. 

-----

References: LinuxConfig.org 


Thursday, August 13, 2020

dd is a great tool to fully wipe out your disk data to forensic levels How to wipe a hard drive clean in Linux

dd is a great tool to fully wipe out your disk data to forensic levels

# dd if=/dev/zero of=/dev/DISK/TO/WIPE bs=4096

# dd if=/dev/zero of=/dev/sda bs=4096

# dd if=/dev/zero of=/dev/sdX bs=512 

If you messed up your master boot record (MBR) you can wipe it using this command:

dd if=/dev/zero of=/dev/hdX bs=446 count=1 #replace X with the target drive letter.

If you are wiping your hard drive for security, you should populate it with random data rather than zeros (This is going to take even longer than the first example.) :

# dd if=/dev/urandom of=/dev/DISK/TO/WIPE bs=4096

# dd if=/dev/urandom of=/dev/sda bs=4096

# dd if=/dev/urandom of=/dev/sdX bs=512 

# dd if=/dev/urandom of=/dev/sdX bs=4096 status=progress

---



Wednesday, April 29, 2020

Set a default audio output device in Ubuntu 18.04


First: List the audio output devices using:

pactl list short sources  

Example of the output:

0 alsa_output.usb-Dell_Dell_AC511_USB_SoundBar-00.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
1 alsa_input.usb-Dell_Dell_AC511_USB_SoundBar-00.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
2 alsa_output.pci-0000_00_1b.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz IDLE
3 alsa_input.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
4 alsa_input.usb-046d_HD_Pro_Webcam_C920_627B04DF-02.analog-stereo module-alsa-card.c s16le 2ch 32000Hz SUSPENDED

Now, to make this work at every restart, follow this :

sudo -H gedit /etc/pulse/default.pa

Example of the edit:

### Make some devices default ###  sink(for output) / source(for input)
#set-default-sink output 
#set-default-source input
set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
#set-default-source input

----
Sources:
AskUbuntu
Rastating.

Tuesday, October 08, 2019

Compiling the Linux Kernel 5.3.5

In Ubuntu 18.04 we need to install some tools first:

sudo apt install build-essential libncurses5-dev gcc libssl-dev bc flex bison

Then we download and decompress the kernel source code:

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.3.5.tar.xz

tar xvf linux-5.3.5.tar.xz

After that from inside the decompressed directory we run and do the preferred configuration:

make menuconfig

Other options for the configuration would be "oldconfig" and "xconfig"; for this last one we need QT 4.8 or 5.x.

sudo apt install qt5-default

After saving the configuration we run "make" with the option "-j" with the number of processors to speed up the compilation process:

make -j 8
 or
make -j8

My machine has 2 sockets with 4 cores each (Xeon), cache L1d and L1i of 32K each, L2 of 256K and L3 of 10240K; and a total of 16 GB of RAM
Just running plain "make" it took above 2 hours and 10 mins to finish the compilation. When using the -j8 option it took about 32 minutes.

The uncompressed executable that I got is saved directly in the linux-5.3.5 directory with a size of over a 665 MB with the name of "vmlinux".
The compressed executable kernel image is in arch/x86/boot/ with the name of "bzImage" and a size close to 9 MB.

If wanting to get a compiled kernel in the form of a Debian package we need to copy the configuration file from our running boot directory and into the linux-5.3.5 directory.

cp  /boot/config-4.15.0-65-generic  .config

We need to install the "pkg-config" and the "kernel-package" packages:

sudo  apt  install  pkg-config  kernel-package

And then compile it with the deb-pkg command:

make -j8 deb-pkg

Or doing the following steps:

make-kpkg clean

fakeroot make-kpkg -j8 --initrd --append-to-version=-custom kernel_image kernel_headers

After --append-to-version= you can write any string that helps you identify the kernel, but it must begin with a minus (-) and must not contain whitespace.

And to install the kernel in this case would be:

sudo dpkg -i linux-*.deb



Checking the linux kernel source code for special functions, we use the "grep" command to search for specific text inside the kernel source files:

 grep -iRl "sem_init" .

From the list that we get we can check for that text term:

vim ipc/sem.c

Other examples:

grep -iRl "pthread_create" .
vim tools/usb/testusb.c

grep -iRl "pthread_mutex" .
vim tools/lib/lockdep/include/liblockdep/mutex.h

grep -iRl "= fork(" .
vim tools/lib/subcmd/run-command.c

grep -iRl " signal(" .
vim tools/lib/subcmd/sigchain.c




-------------///

Thursday, August 15, 2019

Reducing the size of a video

Calculate the bitrate you need by dividing 1 GB by the video length in seconds. So, for a video of length 16:40 (1000 seconds), use a bitrate of 1000000 bytes/sec:

ffmpeg -i input.mp4 -b 1000000 output.mp4

Additional options that might be worth considering is setting the Constant Rate Factor, which lowers the average bit rate, but retains better quality. Vary the CRF between around 18 and 24 — the lower, the higher the bitrate.

ffmpeg -i input.mp4 -vcodec libx265 -crf 20 output.mp4

Vary the codec as needed - libx264 may be available if libx265 is not, at the cost of a slightly larger resultant file size.

------------||
Other option is to use the program "Handbrake" for Linux.

Friday, July 19, 2019

How to Install Linux Kernel 4.4 in Ubuntu 18.04

The default kernel line for Ubuntu 18.04 LTS is 4.18
I have a Chromebook ASUS C300 and the sound card is  working fine with kernel 4.4 line but not with 4.18, the 4.4 line corresponds to the Ubuntu 16.04 LTS

So I downloaded from the Ubuntu kernels server
https://kernel.ubuntu.com/~kernel-ppa/mainline/
The latest update in the 4.4 line which at this moment is 4.4.185:

linux-headers-4.4.185-0404185_4.4.185-0404185.201907100448_all.deb
linux-headers-4.4.185-0404185-generic_4.4.185-0404185.201907100448_amd64.deb
linux-image-unsigned-4.4.185-0404185-generic_4.4.185-0404185.201907100448_amd64.deb
linux-modules-4.4.185-0404185-generic_4.4.185-0404185.201907100448_amd64.deb

Then it can be installed with the command:
sudo  dpkg  -i  *.deb

You can see a list of your installed kernels with the following command:
dpkg --list | grep linux-image

I'm keeping only the latest versions of the two official lines, we can remove any older version of the 4.4 or the 4.18 with the command:
sudo apt remove linux-image-4.x.x-xxxxxxx-lowlatency

then
sudo apt autoremove

Then we do:  sudo update-grub

We have to edit our grub file to set the default booting kernel
https://forums.gentoo.org/viewtopic-t-1060880-start-0.html

sudo vim /etc/default/grub

In Grub2 we have two different screens before the selection of the kernel, you can check them hitting the "esc" key before the booting. The numbers begin with 0 for the first selection, 1 for the second, and so on. In my case the grub configuration file has the following values for the default, where the number 1 corresponds to the selection in the first screen and the number 2 correspond to the selection for the second screen before the actual boot:

GRUB_DEFAULT="1>2"

Other necessary changes
GRUB_TIMEOUT=10
and comment out either: 
#GRUB_HIDDEN_TIMEOUT=0
or
#GRUB_TIMEOUT_STYLE=hidden

Save & exit.

Then we have to commit with: sudo update-grub

If for some reason we need a higher kernel version, another solution could be downloading the corresponding driver for our sound card and recompiling it for the new kernel.

UPDATE: Up to the kernel 4.4.220 the sound and mic work fine, I have tested kernels beyond that version and the sound is not working. 
I also tried all this in Ubuntu 20.04 but there were broken dependencies for the kernel 4.4.220

----///

Creating Bootable USB Stick On Linux Using Command Line

dd if=~/home/username/path/to/myfile.iso of=/dev/sdb

dd bs=4M if=/path/to/myfile.iso of=/dev/sdx status=progress oflag=sync


----///

Thursday, October 25, 2018

Auto Forwarding Mail From ALPINE To Any Other Email Address

We need just to create a file named ".forward" at your home directory (where your ".pinerc" file is). Here is a sample file:

# Exim filter - do not edit this line!
# only works for exim... others will treat it as a plain .forward file...

# if this filter generates an error, then deliver to original address
if error_message then finish endif

# If you want to forward your email to an offsite address, uncomment and modify
# the following line to use your own email address:
#deliver mymailaddress@gmail.com
deliver myEmailUname@myUni.edu

finish

# Extra Note from Slide
# You can keep the incoming mails as well as
# forward them to unsuspecting recipients. Typing
# "\yourid, other@address.com"
#


We can also create a signature file ".signature" that will be automatically included in all the outgoing mail.

These configurations should also work for MUTT.

----
References:
snmlab.cs.nchu.edu.tw
PPT-PDF presentation

Wednesday, November 01, 2017

Cutting Video with ffmpeg

The highlighted represent the starting point for the cut. In this case no ending point set, so by default the output will include all the remaining of the video.

ffmpeg -i input.mp4 -ss 00:20:01 -async 1 -c copy output.mp4 

If we want to cut the video before the end we cand do it in two ways:

ffmpeg -i input.mp4 -ss 00:20:03 -t 00:01:08 -async 1 -c copy output.mp4

The "-t" option specifies a duration, not an end time. The above command will encode 1 minute and 8 seconds of video starting from the time 00:20:01

ffmpeg -i input.mp4 -ss 00:20:03 -to 00:21:11 -async 1 -c copy output.mp4

If you are using a current version of ffmpeg you can also replace "-t" with "-to" in the above command to end at the specified time.

Note:
Use "-c copy" for making it instantly. In that case ffmpeg will not re-encode the video, just will cut to according size.


-----///

Saturday, November 26, 2016

Rotate a PDF under Linux with pdftk

sudo apt-get install pdftk

To rotate page 1 by 90 degrees clockwise:
pdftk in.pdf cat 1east output out.pdf 

To rotate all pages clockwise:
pdftk in.pdf cat 1-endeast output out.pdf 

From the "man" page
The page rotation setting can cause pdftk to rotate pages and documents. Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page's rotation.

Adding a Swap Partition After System Installation

Updating partitions.
We need to edit /etc/fstab and add the new swap partition.

sudo nano /etc/fstab

We need to add a line that looks like

UUID=735b3be3-779c-4d21-a944-b033225f3ab4 none   swap    sw      0       0

The UUID can be got using the command

sudo blkid /dev/sdaX

---------///
We can format this partition with:

sudo mkswap /dev/sdX
replacing the X with your partition number. Mount this partition as swap with

sudo swapon -U UUID

If you want to use your swap for hibernating then you need to update the UUID in
/etc/initramfs-tools/conf.d/resume
with this content RESUME=UUID=xxx.
Don't forget to
sudo update-initramfs -u

-----///

Sunday, October 16, 2016

Embedding a PDF in Blogger

The following HTML code is to embed a PDF in Blogger (Blogspot). We only need to change the "srcid" value (the 0B6bwihHnzzPHbHdsQUpFYVQ3Mm8 part for the new corresponding PDF value)


The code can be downloaded from here.
Or copied from here:

<iframe height="480px" src="https://docs.google.com/viewer?srcid=0B6bwihHnzzPHbHdsQUpFYVQ3Mm8&amp;pid=explorer&amp;efh=false&amp;a=v&amp;chrome=false&amp;embedded=true" width="720px"></iframe>

Saturday, October 01, 2016

Mounting the Android Phone in Ubuntu 16.04

I was getting the following pop up message 'Unable to mount Android Device' every time that I plugged my Android smartphone in my Linux Ubuntu 16.04 machine.

I found the solution taking as a reference the following thread.

First I used the following command:

lsusb

That gives me:
Bus 001 Device 004: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy (MTP)

Then I included this info:
# Samsung LTD Galaxy
ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

in the following file:
sudo vim /lib/udev/rules.d/69-libmtp.rules

And the following line:
ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666"

In the following file:

sudo vim /lib/udev/rules.d/61-persistent-storage-android.rules

And that's all. After a reboot my Linux PC can mount without problems my Android phone.

-----///

Wednesday, June 29, 2016

Updating the Youtube-DL (Now YT-DLP)

One way to solve error: "externally-managed-environment" is to create a virtual environment folder in your root path. By creating and using a virtual environment, you bypass the system Python entirely, allowing you to install and manage packages freely without impacting the system-wide Python installation.

sudo apt install python3-pip
sudo apt install python3.13-venv

python3 -m venv ~/py_envs
source ~/py_envs/bin/activate

python3 -m pip install yt-dlp
python3 -m pip install --upgrade yt-dlp

Before executing the 2nd command above, you can try executing first the 3rd command to see if the prompt returns a newer version suggestion than python3.13-venv  

yt-dlp is a better option with more functionalities. It's a fork from the youtube-dl 

Note: After you leave the virtual environment, if you need to use yt-dlp again, you have to first execute the 3rd and 4th commands above to set the virtual environment. 

Since this is installed in a virtual environment, you won't get notices of new versions available, so you have to run the 6th command above to check if there's an update ready to be installed. 
Sometimes the yt-dlp command may return an error when trying to download a video, in most cases that's fixed installing the new version. 

Thre's a lot of information and help in the manual:

man yt-dlp 

If you want to check first all the available formats of a YouTube video you need the URL of it along with the flag "-F" after the yt-dlp command:

yt-dlp -F https://www.youtube.com/watch?v=wh-07BzfgYY

And you will have an output like the following:
There will be a list of all the formats with IDs, formats, resolutions, video and audio codecs used, file sizes, extensions, FPS, if video or audio only, etc.

The command to download the format of your preference, by example if ID 18 do the following now using the lower case flag "-f" : 

yt-dlp -f 18 https://www.youtube.com/watch?v=wh-07BzfgYY

That format with ID 18 includes video and audio. But you can choose to merge video only plus audio only formats, in this case you need to have installed FFMPEG for the merge, if not installed yet proceed with:

sudo apt install ffmpeg

Then you can download and merge, by example ID 396 (video only) plus ID 139 (audio only) with the following command:

yt-dlp -f 396+139 https://www.youtube.com/watch?v=wh-07BzfgYY

Note: It's possible to download videos not only from YouTube.

-----------------------
The following produce an error and now it has been deprecated. It's better to use a virtual environment as shown here above:

sudo apt install python3-pip

sudo pip3 install --upgrade youtube-dl

-----------
The following is also deprecated:

sudo apt install python-pip

sudo pip install youtube-dl

If you want to upgrade youtube-dl

sudo pip install --upgrade youtube-dl

or, if necessary

sudo pip install --upgrade pip


The following method of installation is even older and deprecated, it's here just as a reference:

sudo apt-get install python-setuptools

sudo easy_install pip

Friday, February 12, 2016

Segmentation fault (core dumped)

If after a segmentation fault you are not getting the core dumped file, you might need to edit the limits.conf (this is in Ubuntu 14.04)

sudo vim /etc/security/limits.conf

and add a line like:
username      soft    core            50000

The previous line is for a core dumped file up to 50000 KB for that user. The user would have to relogin for the changes to take effect. A "small" core dump file is around 10 MB.

-----/// 

Thursday, October 08, 2015

"ffmpeg" instead of "avconv" in youtube-dl

youtube-dl  https://www.youtube.com/watch?v=9SgpcpZU-tw

WARNING: Your copy of avconv is outdated and unable to properly mux separate video and audio files, youtube-dl will download single file media. Update avconv to version 10-0 or newer to fix this.

Use instead:

youtube-dl  --prefer-ffmpeg  https://www.youtube.com/watch?v=9SgpcpZU-tw

.

Sunday, September 27, 2015

Embedding Subtitles in a Video File

The easiest way is with the MP4Box tool.

First install the GPAC

sudo apt-get install gpac

Then you can use the following command

MP4Box  -add  inputfile.srt  target.mp4

More about this command in this link.

Another Option to do so:

apt-get install mkvtoolnix

mkvmerge -o output.mkv video.mp4 subtitles.srt

or

mkvmerge -o output.mp4 video.mp4 subtitles.srt

In the case you need subtitle conversion:

ffmpeg -i file.srt file.vtt

or

ffmpeg -i file.vtt file.srt

More info in the ffmpeg manual ("man ffmpeg").

How to download only subtitles of videos using youtube-dl

Options:
--write-sub                      Write subtitle file
--write-auto-sub                 Write automatic subtitle file (YouTube only)
--all-subs                       Download all the available subtitles of the video
--list-subs                      List all available subtitles for the video
--sub-format FORMAT              Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"
--sub-lang LANGS                 Languages of the subtitles to download (optional) separated by commas, use IETF language tags like 'en,pt'

So for example, to list all subs for a video:

youtube-dl --list-subs https://www.youtube.com/watch?v=Ye8mB6VsUHw

To download all subs, but not the video:

youtube-dl --all-subs --skip-download https://www.youtube.com/watch?v=Ye8mB6VsUHw

The other way, this really works but makes the file bigger:

mencoder movie.avi -sub movie.srt -o movie.hardsubs.avi -oac copy -ovc lavc -lavcopts vbitrate=1200

Source: Ubuntu Forums.


-----------///

Thursday, October 24, 2013

Converting Still Images to Video from the Command Line

ImageMagick and ffmpeg combined can be used to turn still images into video. Both ImageMagick and ffmpeg have been around for years, and are readily available as packages with most Linux distributions. The tips below allow you to convert images on the command line, which for a may appear to be time consuming, but once you know how to do it you'll find it much faster than using a GUI!

The Packages
You'll need:
ImageMagick
ffmpeg


Resizing Images from the Command Line
ImageMagick includes "mogrify" which is a fine tool for easily changing image size and resolution. Great for converting images for uploading to the web, or preparing large images for video. For example, the following code re-sizes all *.JPG images to a maximum width of 800 pixels and a maximum height of 600 pixels. This will over-write the originals, so take copies of your snaps first!

mogrify -resize 800x600 *.JPG

Morphing Images Together
This step is only needed if you want to create a smooth transition between the images.

Another fine part of ImageMagick is the ability to morph images together. In the following example we take all *.JPG files and create 10 images for each "gap" between the images. The resulting set of images are saved as XXXXX.morph.jpg, where X is the next number in the series.

convert *.JPG -delay 10 -morph 10 %05d.morph.jpg

Creating a Video from Images
ffmpeg can be used to stitch several images together into a video. There are many options, but the following example should be enough to get started. It takes all images that have filenames of XXXXX.morph.jpg, where X is numerical, and creates a video called "output.mp4". The qscale option specifies the picture quality (1 is the highest, and 32 is the lowest), and the "-r" option is used to specify the number of frames per second.

ffmpeg -r 25 -qscale 2 -i %05d.morph.jpg output.mp4

Putting It All Together
Here's a simple example of how to create a video from the command line, using the resizing and morphing techniques we have gone through above. The example first creates a "temp" directory to work in, so we don't risk destroying the original images. Note: the morphing stage may take a while, so be patient!

mkdir temp
cp *.JPG temp/.
mogrify -resize 800x800  temp/*.JPG
convert temp/*.JPG -delay 10 -morph 10 temp/%05d.jpg
ffmpeg -r 25 -qscale 2  -i temp/%05d.jpg output.mp4
# rm -R temp

The Code Used

# Create a directory and copy the original images there for manipulation:
mkdir temp
cp *.JPG temp/.

# Resize the images:
mogrify -resize 200x200  temp/*.JPG
# Create the morph images
convert temp/*.JPG -delay 10 -morph 5 temp/%05d.jpg
# Stitch them together into a video
ffmpeg -r 50 -qscale 2  -i temp/%05d.jpg output.mp4

---------------------------///
In order to make a video out of still images, like in a Power Point or Libre Office Impress, I created one image from every slide starting from a blanc one, naming them form 000.rdp.jpg to 025.rdp.jpg, then I used the command:

avconv -r .1 -qscale 2 -i %03d.rdp.jpg output.mp4

The "-r .1" gave 10 seconds lapse for every slide.


----------
Source: It For Everyone.