2023-11-22

[Technology] How to "crop" a video in Pitivi

Tl;dr: first, go to Render > Advanced > Project Settings ... > Size, and change the width and height of the output video to be rendered. Then go to Clip > Transformation to shift (and scale) the input as needed to fit the cropped output region.

The problem

I found the process of trying to crop a video in Pitivi unintuitive, so I thought I would document it. I have a video that is in landscape orientation, and I'd like it in a portrait orientation to make it easier to watch on mobile devices.

Here is a 4s clip from the video:

I'd like to crop it from its original 1440x1080 size to 768×1024, centered.

From this:

To this:

(shaded region showing what will be excluded from the final video)

1st attempt: Clip Transformation

Once you have a Pitivi project started and you've imported your video file into it, there's a promising tab called "Clip" thas has some promising properties: X, Y, Width and Height. There is even a video preview with an adjustable bounding box that you can use to manually select a region! Nice! However, it will not crop the video. X and Y will translate (shift) the input video image, and Width and Height will scale it, but it won't change actually crop the output video. Look at the preview. Now you just get a huge black box around your attempt.

Here is the output video: not what we wanted.

2nd attempt: Crop effect

Pitivi has many cool effects you can apply to your video, and one is called 'crop'! A-ha! That must crop the video for us! No, no it does not.

Here is the output video: still not what we wanted.

Final attempt: Project Settings output resolution + Clip transformation

This probably makes sense to video editor people, but to actually crop a video such that the output is actually cropped, you have to dig through a few menus to find settings for the resolution of your output video, rather than acting upon the video that you're editing itself. To do this, go to Render > Advanced > Project Settings ... > Size and change the values to your desired output width and height.

Go to 'Render'

Expand 'Advanced' and go to 'Project Settings'

Once in 'Project Settings', go to 'Size' and update the output Width and Height as desired.

NOW we can go to Clip Transformation from earlier and adjust X and Y to shift our desired region over to where it should be. Since cropping via the Render Project Settings is anchored to the top-left corner, we'll use negative X and Y values to shift the image region left and up towards that anchor. Width and Height for Clip Transformation should continue to match the input video's dimensions, or we'll squish things up and ruin the crop.

And here is the final output, properly cropped.  (Blogger's thumbnail is misleading; but the video itself is correct.)

 
 

Issue

There's some discussion on making it easier in the future here:

[Technology] Nextcloud on a Raspberry Pi: the easy way

Note: nextcloudpi, while easy, is actually going away! But you can do a similar approach with Nextcloud All-in-One which I will try to play with soon.

In my previous post, I talked about setting up Nextcloud from source, including configuring a web server, a database, and PHP, based on Nextcloud's detailed guide.

In comparison, deploying it from a container is much simpler. E.g. using the (recently deprecated :|) ownyourbits' NextcloudPi project:

# # let's make sure our system is up-to-date first :)
# apt update
# apt upgrade   # don't forget to reboot periodically!
#
# # Use docker's handy install script to get it on your Raspberry Pi
# curl -fsSL https://get.docker.com -o get-docker.sh
# bash get-docker.sh          # adds 1.6GB
# 
# # pull nextcloudpi from ownyourbits and run it! (adjust ports to avoid collisions with any existing web servers as necessary)
# docker pull docker.io/ownyourbits/nextcloudpi:latest
# docker run --detach \
           --publish 4443:4443 \
           --publish 443:443 \
           --publish 80:80 \
           --volume ncdata:/data \
           --name nextcloudpi \
           ownyourbits/nextcloudpi YourPisHostName
           

Then visit https://YourPisHostName/ and follow steps for configuration. It will give provide you with administrative and user credentials, defaulting to the username 'ncp'. There will be some administrative configuration on port 4443 and regular user/admin experience on 443. Stored data will end up in /var/lib/docker/volumes/ncdata (based on the volume label given above in the docker run command). If you'd like to enter the container while it's running to adjust something, you can use

sudo docker exec -it nextcloudpi bash

I had to install vim once inside to have an editor. :) A useful tool for administering nextcloudpi from the command-line is ncp-config.

[Technology] Nextcloud on a Raspberry Pi: setting up a web server, a database, PHP and Nextcloud itself

Installing Nextcloud on a Raspberry Pi can be fun, or "fun".  Run your own suite of open source web services for greater control, customization, independence, and whatever.  I'll share my process for installing it from a tarball on a Raspberry Pi (4) running Raspberry Pi OS (bookworm).  Let's hope I don't skip any steps.

My Pi, luxuriating on the soft bedding it deserves
 
Nextcloud's website offers a lot of options, and you can run Nextcloud in containers, install it from snaps, from Fedora's RPM repositories, etc. One benefit of installing it from a simple tarball, from its source, is that you can better understand a lot of its dependencies and the configuration needs.  I used their extensive directions found here:

Honestly, they're comprehensive enough that you can follow that instead of the below, but hopefully in the end I'll have a streamlined guide, at least for myself.

Regarding storage, going through this on my Raspberry Pi (already in use for other things) used 3.5GB of disk space. Going through it on the docker.io/library/debian:latest container image, I used 4.8GB of disk space (starting from a minimal 172MB!). And this is before user data gets accumulated. So if you want to store a lot, you will likely want to get a larger microSD card for your Pi or use some external USB storage.

Regarding performance, I've had some mixed results. During a demo to a group of friends on a local network using the nextcloudpi docker container, many features were quite slow. However, testing at home recently, using either the container or the source installation described below, those same features were now fast with very low latency!

Environment

My environment:

  • Hardware:
    • Raspberry Pi 4 Model B Rev 1.4
    • Storage: 29GB
  • OS:
    • Raspberry Pi OS (Debian GNU/Linux 12 (bookworm))
    • image: 2023-10-10-raspios-bookworm-arm64-lite.img
  • Nextcloud
    • version: 27.1.3
    • build: 2023-10-26T17:25:16+00:00 565dc36226d08d071c30d8ad4fd54126dfa4be79

Nextcloud can work with a variety of databases and web servers, and the choices can be overwhelming.  For this process, I'm going with their recommendations in their install guide and making some boring, conventional choices. 

Software choices:

  • web server: Apache
    • apache2-2.4.57-2
  • database: MariaDB (mysql)
    • mariadb-server-1:10.11.4-1~deb12u1

If you would like to follow along but don't have a Raspberry Pi to play with, you can get a very similar set-up experience using a standard Debian GNU/Linux 12 (bookworm) installation.  If you like containers, docker.io/library/debian:latest is currently bookworm.  I used that with podman to do testing along the way.

Another note is that I generally use systemd but feel free to use your favourite service manager/init system.

1. Set-up Environment

# # update the base system
# apt update
# apt upgrade
# # install some useful tools
# apt install vim
# apt install less
# apt install wget 
# # install some tools that Nextcloud requires
# apt install bzip2
  

2. Database

As noted above, I'm using MariaDB, a MySQL-compatible derivative. You'll create an empty database, as well as a username and a password, for Nextcloud. Nextcloud will handle table creation on its own. Don't forget to replace username and password with your own unique values below.

# apt install mariadb-server       # 18.3MB download, 197MB installed
# systemctl enable --now mariadb
# mysql -u root
> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
> CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
> GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'localhost';
> FLUSH PRIVILEGES;
  

Next, we need to add some configuration to MariaDB/MySQL in /etc/mysql/my.cnf (which maps to /etc/mysql/mariadb.cnf for me). The installation guide suggests the following settings. I'll note that my default config already has a similar [client-server] section, so I excluded I only added the other ones that weren't present. The transaction_isolation and binlog_format settings are particularly important.

[server]
skip_name_resolve = 1
innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1

[client-server]
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

[client]
default-character-set = utf8mb4

[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1    
  

Later on, when configuring Nextcloud itself, you'll provide it with the database name, username, password and host (in this case, localhost). You can manually configure it or use the web installation wizard (which I'll do for in post.)

3. PHP

Nextcloud requires a bunch of PHP modules, some of which were already installed on my system, and some not. Below I only show install commands for those that I were not already there. You can view Nextcloud's documentation to see all the modules they require and recommend, including some optional ones that I am skipping.

# apt install php
#
# # install required modules
# apt install php-curl
# apt install php-gd
# apt install php-json
# apt install php-mbstring
# apt install php-xml                  # SimpleXML, XMLReader, XMLWriter
# apt install php-zip
# apt install php-mysql                # for DB since I use MariaDB
#
# # install recommended modules
# apt install php-bz2                  # for installing packages
# apt install php-intl                 # faster language translation performance (I run it in German)
# apt install php-redis                # cache for faster performance; alt: php-acpu, php-memcached
# apt install redis-server             # see notes
# systemctl enable --now redis-server  # or redis-server
#
# # file preview generation
# apt install php-imagick              # image preview generation (22.4MB down, 84.0MB installed)
# apt install ffmpeg                   # video preview generation; alt: avconv;  (127MB down, 415MB installed)
# apt install libreoffice              # (318MB down, 1,235MB installed)
  

You may want to review suggested configuration changes to see which ones you need.

4. Web server

As noted above, I'm using Apache 2. We will enable some modules; several that Nextcloud want were enabled by default but I'm listing them anyway.

It's 2023, so of course we will encrypt our connections and traffic. In this case, we are going to use a default self-signed certificate, but if you are actually going to deploy it, at least use Let's Encrypt to get a certificate for your actual domain.

# apt install apache2
# systemctl enable --now apache2
#
# # required modules, for at least pretty urls :)
# a2enmod rewrite
# # recommended modules
# a2enmod headers
# a2enmod env            # already enabled for me
# a2enmod dir            # already enabled for me
# a2enmod mime           # already enabled for me
#
# # SSL
# a2enmod ssl
# a2ensite default-ssl
#
# # use php-fpm, Nextcloud recommends it over mod_php
# apt install php-fpm
# a2enmod proxy_fcgi
# a2enmod setenvif       # already enabled for me
# a2enconf php8.2-fpm
# systemctl enable --now php8.2-fpm
#
# systemctl restart apache2
# systemctl reload apache2
  

Next, we'll configure our Nextcloud site in Apache. You can set it up as either a sub-directory or a subdomain on your host. I picked sub-directory. More details here. Note that it disables mod_dav, as Nextcloud uses SabreDAV.

Nextcloud Apache Configuration

Create this file /etc/apache2/sites-available/nextcloud.conf with the following content:

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off
  </IfModule>
</Directory>
  

Afterwards, run this:

    a2ensite nextcloud.conf
    systemctl reload apache2
  

We will actually create and populate the /var/www/nextcloud directory when we finally get to installing Nextcloud itself from its tarball.

5. Nextcloud

Now that we have our web server, database, and PHP configured, we can finally install Nextcloud itself. As noted above, I am installing it from their latest source tarball. You can find it by going to their Install page > Community Projects > Archive, or just follow this direct link: https://download.nextcloud.com/server/releases/latest.tar.bz2.

# cd /var/www
# wget https://download.nextcloud.com/server/releases/latest.tar.bz2  # 172MB download, 607MB unpacked
# tar -xf latest.tar.bz2                                              # this unpacks 'nextcloud/' here at '/var/www/nextcloud'
# chown -R www-data:www-data /var/www/nextcloud/
#
# # verify that necessary services are running
# systemctl status mariadb
# systemctl status php8.2-fpm
# systemctl status apache2
  

Now, if everything went smoothly, you should be able to pop open https://yourpihostname:443/ and be greeted with the initial configuration page!

  • create an admin account
  • configure database settings (back from step #2 up above)
  • install recommended apps

Now you can have some fun playing around. Some features require extra configuration, like using Nextcloud Office with Collabora Online (Development Edition, CODE), and I may update this in the future with some more nuance.

Admin user and DB set-up screen


User dashboard with some test data added

Next steps

In a future post, I may discuss setting up a Google Docs-like experience with Nextcloud Office using Collabora Online office, as well as explore more of the options and configuration settings. I will also discuss the much-simpler ways of installing and running Nextcloud (e.g. from VM or container images!)

Update: just wrote up the very quick-to-start-but-deprecated nextcloudpi container image.

2023-11-04

[Technology] IDEs, Emacs and LSP: Python and TypeScript

Back in my day, we had a text editor, a compiler and a Makefile, and we liked it like that.  Maybe we didn't really like it like that.  But it let you write and compile code.

I got attached to Emacs early on (sorry vi) and over the years have accumulated a number of additional packages and lisp code to make development easier and more efficient.  More "recently," Language Server Protocol (LSP) [wiki] [git] was born, initially targeting Microsoft's VSCode, which has allowed the creation of Language Servers that are independent of any specific editor, and made editors more agnostic to which languages they support, by facilitating a standardized interface between the two facilitating the helpful features wanted in Integrated Development Environments (IDEs).

Some common features include:

  • code completion
  • syntax highlighting
  • in-line error/warning indicators
  • refactoring support
  • code navigation to definitions and references
  • in-line API documentation for function signatures and variable typing

With Emacs, many of these features have been available through a variety of internal and external packages independently for a while.   Modes for languages (c-mode, python-mode, web-mode, etc.) have enabled syntax highlighting and code formatting assistance.  company has supported code completion.  flymake has supported syntax checking and error/warning indicators.  Etc.

I decided to update my environment, though, to benefit from the existence of LSP language servers and hopefully simplify my configuration and approach.  With Emacs often comes a lot of choice and some custom configuration.  That can be great to achieve an ideal environment for yourself, but it can also require a lot of time and attention to figure out what that ideal environment should look like, and just how to glue interacting packages together.  So, I'll share my process.

LSP client modes in Emacs

There are now two prominent options in Emacs

Eglot has recently been merged into core GNU Emacs v29.  According to "the Internet", lsp-mode is more featureful.  I want to try both, but Fedora 38 only ships GNU Emacs v28.3, so I have tried lsp-mode first!   I'll try Eglot once I upgrade to Fedora 39 next week. 

Language Servers for Python

I'm decided to try two different languages, first Python and then TypeScript.  However, both have multiple language servers available.  The pain of making choices!

lsp-mode's language server page lists several options for Python already

  • Pylsp / python-lsp-server [git]
  • Jedi Language Server [git]
  • Palantir Python Language Server [git] (deprecated)
  • Microsoft's Pyright [git]
  • Microsoft Python Language Server [git] (superseded by Pyright)
  • Ruff [git]

So many nice options.  Which to pick?  Well, an interviewer once recommended Pyright so there I go to start.

 Language Servers for TypeScript/JavaScript

Again, options!

  • Deno [site]
  • Sourcegraph's javascript-typescript-langserver [git] (unmaintained)
  • TypeScript Language Server [git] (formerly theia-ide by TypeFox)

This time I went with TypeScript Language Server because lsp-mode's page for it explicitly marks it as recommended.

Additional packages

One issue with IDEs is that all of their features can make an interface busy/noisy and slow.  Sometimes similar information will be redundantly surfaced at multiple points on screen.  lsp-mode is delightful in that it's very modular and (like many IDEs) you can toggle features on and off as you need them.  They even offer a handy visual guide to disabling features.  

lsp-mode also leverages a lot of other packages, some internal and some external, to offer a lot of its functionality.  They list these as some of them: lsp-ui, company, flycheck, flymake, projectile, imenu, xref, lsp-treemacs, dap-mode, lsp-helm, lsp-ivy, consult-lsp, which-key, dired, iedit, emacs-tree-sitter.

Some of these will also leverage other packages and external tools, too.  E.g. flycheckwhich runs syntax checkers can also call pylint, mypy, etc. from outside emacs, to surface errors and warnings on screen. :)  The bolded ones will be included in my set-up steps below.

My configuration: lsp-mode, pyright, pylint

After configuring my system, I reproduced it in a minimal container image (registry.fedoraproject.org/fedora) via podman 

Install emacs and (for pyright) npm.

  $ sudo dnf install emacs
  $ sudo dnf install npm    # for pyright, which is written in typescript

Make sure you have the MELPA package archive configured in your ~/.emacs

  ;; ---- Package Management (package.el, melpa) ----                                
  (require 'package)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  (package-initialize)

Next, you can start emacs and run these commands:

  M-x package-refresh-contents
M-x package-install use-package
;; install a few minimal packages we'll use for LSP/IDE features M-x package-install lsp-mode M-x package-install lsp-ui M-x package-install flycheck ;; show errors and warnings from pyright M-x package-install company ;; auto-complete

;; now to install language support (servers + mode) M-x package-install lsp-pyright
M-x package-install typescript-mode M-x lsp-install-server pyright-tramp
M-x lsp-install-server typescript-language-server

Additional .emacs configuration for newly added LSP/IDE packages:

;; From https://emacs-lsp.github.io/lsp-mode/page/installation/                         
(use-package lsp-mode
:init
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
(setq lsp-keymap-prefix "s-l")
:hook ((python-mode . lsp-deferred))
:hook ((typescript-mode . lsp-deferred))
:commands (lsp lsp-deferred))

(use-package lsp-ui :commands lsp-ui-mode) (setq lsp-ui-doc-show-with-cursor t) ;; From https://emacs-lsp.github.io/lsp-pyright/ (use-package lsp-pyright :ensure t :hook (python-mode . (lambda () (require 'lsp-pyright) (lsp-deferred))))
Show some additional API documentation on screen for symbols!
M-x lsp-ui-sideline-toggle-symbols-info

"flycheck isn't working?!"

One issue that stumped me for a while was lsp failing to show errors/warnings from flycheck when flycheck was configured to use "lsp" as its syntax checker. It turns out that because I often use symlinks from my home directory to my current active projects, I ran into lsp-ui's previously-resolved issue #119 (or potentially a new, similar one). So, if lsp-ui doesn't indicate warnings/errors from flycheck (or flymake), make sure your path isn't via a symlink.  Oops.

Handy Keybindings

Here are some of my most-used/commands keybindings:

  • s-l r r - refactor > rename a symbol
  • s-l g g - go to definition
  • s-l g r - list references
  • C-x ` - go to next error (flycheck)
  • M-x lsp-format-region
  • M-x lsp-format-buffer

Here is a list of others: https://emacs-lsp.github.io/lsp-mode/page/keybindings/

I don't see "s-" often as a prefix, but it's for the Super key (e.g. Windows key).  On my system (Fedora 38 with GNOME), s-l locks my screen, but holding shift along with super works for Emacs too, e.g. "<shift>+<super>+l r r" to rename a symbol.

Conclusion

Something I appreciate most about IDEs and their fancy features is the early detection of problems and API guidance as you code.  I still will add linting/syntax checking/test steps to my build process to guard against bad code entering my repositories.  I will say that I think there is some benefit to being able to code without the guidance of an IDE (e.g. code completion) as it can encourage you to better learn an API in the first place.  But there comes a point when you can focus more on being productive (with the help of tools!) than on exercising your API memorization for a hundredth time. :)

Dieses Blog durchsuchen

Labels

#Technology #GNOME gnome gxml fedora bugs linux vala google #General firefox security gsoc GUADEC android bug xml fedora 18 javascript libxml2 programming web blogger encryption fedora 17 gdom git emacs libgdata memory mozilla open source serialisation upgrade web development API Spain containers design evolution fedora 16 fedora 20 fedora 22 fedup file systems friends future glib gnome shell internet luks music performance phone photos php podman preupgrade tablet testing typescript yum #Microblog Network Manager adb apache art automation bash brno catastrophe css data loss debian debugging deja-dup disaster docker emusic errors ext4 facebook fedora 19 gee gir gitlab gitorious gmail gobject google talk google+ gtk html libxml mail microsoft mtp mysql namespaces nautilus nextcloud owncloud picasaweb pitivi ptp python raspberry pi resizing rpm school selinux signal sms speech dispatcher systemd technology texting time management uoguelph usability video web design youtube #Tech Air Canada C Electron Element Empathy Europe GError GNOME 3 GNOME Files Go Google Play Music Grimes IRC Mac OS X Mario Kart Memento Nintendo Nintendo Switch PEAP Selenium Splatoon UI VPN Xiki accessibility advertising ai albums anaconda anonymity apple ask asus eee top automake autonomous automobiles b43 backup battery berlin bit rot broadcom browsers browsing canada canadian english cars chrome clarity comments communication compiler complaints computer computers configuration console constructive criticism cron cropping customisation dataloss dconf debug symbols design patterns desktop summit development discoverability distribution diy dnf documentation drm duplicity e-mail efficiency email english environment estate experimenting ext3 fedora 11 festival file formats firejail flac flatpak forgottotagit freedom friendship fuse galaxy nexus galton gay rights gdb german germany gimp gio gjs gnome software gnome-control-center google assistant google calendar google chrome google hangouts google reader gqe graphviz growth gtest gtg gvfs gvfs metadata hard drive hard drives hardware help hp humour ide identity instagram installation instant messaging integration intel interactivity introspection jabber java java 13 jobs kernel keyboard language language servers languages law learning lenovo letsencrypt libreoffice librpm life livecd liveusb login lsp macbook maintainership mariadb mario matrix memory leaks messaging mounting mouse netflix new zealand node nodelist numix obama oci ogg oggenc oh the humanity open open standards openoffice optimisation org-mode organisation package management packagekit paint shedding parallelism pdo perl pipelight privacy productivity progress progressive web apps pumpkin pwa pyright quality recursion redhat refactoring repairs report rhythmbox rust sandboxes scheduling screenshots self-navigating car shell sleep smartphones software software engineering speed sql ssd synergy tabs test tests themes thesis tracker travel triumf turtles tv tweak twist typing university update usb user experience valadoc video editing volunteering vpnc waf warm wayland weather web apps website wifi wiki wireless wishes work xinput xmpp xorg xpath
Powered by Blogger.