Crop video files with FFmpeg

I have previously written about how to trim video files with FFmpeg. It is also easy to crop a video file. Here is a short how-to guide for myself and others.

Cropping is not the same as trimming

This may be basic, but I often see the concepts of cropping and trimming used interchangeably. So, to clarify, trimming a video file means making it shorter by removing frames in the beginning and/or end. That is not the same as cropping a video file, which only selects a particular part of the video for export.

The one-liner

If you want to get it done, here is the one-liner:

ffmpeg -i input.avi ffmpeg -i output2.mp4 -vf crop=1920:1080:0:200 output.avi

There is more information about this command in many places (for example, here). the most critical parts of the above command are:

  • -vf is the command for “video filter”. It can also be spelt out as -filter:v.
  • crop=1920:1080:0:200 means to make a 1920×1080 video starting from the leftmost side of the source image (=0 pixels horizontally) and 200 pixels down from the top.

Of course, this command can be combined with other FFmpeg combinations.

MusicLab Copenhagen

After nearly three years of planning, we can finally welcome people to MusicLab Copenhagen. This is a unique “science concert” involving the Danish String Quartet, one of the world’s leading classical ensembles. Tonight, they will perform pieces by Bach, Beethoven, Schnittke and folk music in a normal concert setting at Musikhuset in Copenhagen. However, the concert is nothing but normal.

Live music research

During the concert, about twenty researchers from RITMO and partner institutions will conduct investigations and experiments informed by phenomenology, music psychology, complex systems analysis, and music technology. The aim is to answer some big research questions, like:

  • What is musical complexity?
  • What is the relation between musical absorption and empathy?
  • Is there such a thing as a shared zone of absorption, and is it measurable?
  • How can musical texture be rendered visually?

The concert will be live-streamed (on YouTube and Facebook) and it will also be aired on Danish radio. There will also be a short film documenting the whole process.

Researchers and staff from RITMO (and friends) in front of the concert venue.

Real-world Open Research

This concert will be the biggest and most complex MusicLab event to date. Still, all the normal “ingredients” of a MusicLab will be in place. The core is a spectacular performance. We will capture a lot of data using state-of-the-art technologies, but in a way that is as little obtrusive as possible for performers and the audience. After the concert, both performers and researchers will talk about the experience.

Of course, being a flagship Open Research project, all the collected data will be shared openly. The researchers will show glimpses of data processing procedures as part of the “data jockeying” at the end of the event. However, it is first when all data is properly uploaded and pre-processed that data processing can start. All the involved researchers will dig into their respective data. But since everything is openly available, anyone can go in and work on the data as they wish.

Proper preparation

Due to the corona situation, the event has been postponed several times. That has been unfortunate and stressful for everyone involved. On the positive side, it has also meant that we have been able to rehearse and prepare very well. Already a year ago we ran a full rehearsal of the technical setup of the concert. We even live-streamed the whole preparation event, in the spirit of “slow TV”:

I am quite confident that things will run smooth during the concert. Of course, there are always obstacles. For example, one of our eye-trackers broke in one of the last tests. And it is always exciting to wait for Apple and Google to approve updates of our MusicLab app in their respective app stores.

Want to see how it went. Have a look here.

From Open Research to Science 2.0

Earlier today, I presented at the national open research conference Hvordan endres forskningshverdagen når åpen forskning blir den nye normalen? The conference is organized by the Norwegian Forum for Open Research and is coordinated by Universities Norway. It has been great to follow the various discussions at the conference. One observation is that very few questions the transition to Open Research. We have, finally, come to a point where openness is the new normal. Instead, the discussions have focused on how we can move forwards. Having many active researchers in the panels also led to focus on solutions instead of policy.

Openness leads to better research

In my presentation, I began by explaining why I believe opening the research process leads to better research:

  • Opening the process makes the researcher more carefully document everything. For example, nobody wants to make messy data or code available. Adding metadata and descriptions also help improve the quality of what is made available. It also helps in removing irrelevant content.
  • Making the different parts openly available is important for ensuring transparency in the research process. This allows reviewers (and others) to check claims in published papers. It also allows for others to replicate results or use data and methods in other research.
  • This openness and accessibility will ultimately lead to better quality control. Some people complain that we make available lots of irrelevant information. True, not everything that is made available will be checked or used. The same is the case for most other things on the web. That does not mean that nobody will never be interested. We also need to remember that research is a slow activity. It may take years for research results to be used.

Of course, we face many challenges when trying to work openly. As I have described previously, we particularly struggle with privacy and copyright issues. We also don’t have the technical solutions we need. That led me to my main point in the talk.

Connecting the blocks

The main argument in my presentation was that we need to think about connecting the various blocks in the Open Research puzzle. There has, over the last few years, been a lot of focus on individual blocks. First, making publications openly available (Open Access). Nowadays, there is a lot of discussion about Open Data and how to make data FAIR (Findable, Accessible, Interoperable, Reusable). There is also some development in the other building blocks. What is lacking today is a focus on how the different blocks are connected.

There is now a need to connect the different blocks. Dark blue blocks are part of the research process, while the light blue blocks focus on applications and assessment.

By developing individual blocks without thinking sufficiently about their interconnectedness, I fear that we lose out on some of the main points of opening everything. Moving towards Open Research is not only about making things open; it is about rethinking the way we research. That is the idea of the concept of Science 2.0 (or Research 2.0, as I would prefer to call it).

There is much to do before we can properly connect the blocks. But some elements are essential:

  • Persistent identifiers (PID): Having unique and permanent digital references that makes it possible to find and reuse digital material is essential for finding this. This could be DOIs for data, ORCID for researchers, and so on.
  • Timestamping: Many researchers are concerned about who did something first. For example, many people wait with releasing their data because they want to publish an article first. That is because the data (currently) does not have any “value” in itself. In my thinking, if data had PIDs and timestamping they would also be citable. This should also be combined with proper recognition of such contributions.
  • Version control: It has been common to archive various research results when the research is done. This is based on pre-digital workflows. Today, it is much better to provide solutions for proper version control of everything we are doing.

Fortunately, things move in the right direction. It is great to see more researchers try to work openly. That also exposes the current “holes” in infrastructures and policies.

Converting a .WAV file to .AVI

Sometimes, there is a need to convert an audio file into a blank video file with an audio track. This can be useful if you are on a system that does not have a dedicated audio player but a video player (yes, rare, but I work with odd technologies…). Here is a quick recipe

FFmpeg to the rescue

When it comes to converting from one media format to another, I always turn to FFmpeg. It requires “coding” in the terminal, but usually, it is only necessary to write a oneliner. When it comes to converting an audio file (say in .WAV format) to a blank video file (for example, a .AVI file), this is how I would do it:

ffmpeg -i infile.wav -c copy outfile.avi

The “-c copy” part of this command is to preserve the original audio content. The new black video file will have a copy of the original .WAV file content. If you are okay with compressing the audio, you can instead run this command:

ffmpeg -i infile.wav outfile.avi

Then FFmpeg will (by default) compress the audio using the mp3 algorithm. This may or may not be what you are after, but it will at least create a substantially smaller output file.

Of course, you can easily vary the above conversion. For example, if you want to go from .AIFF to .MP4, you would just do:

ffmpeg -i infile.aiff outfile.mp4

Happy converting!

Travelling only with a mobile phone

I usually travel with my laptop. There is always some e-mails to write, some documents to read and comment on, or some photos to transfer. Still, I often think about whether it was really necessary to drag along the laptop on short trips. It doesn’t weigh too much, but I usually end up carrying a backpack when I bring the laptop. That may not always be a problem, but sometimes it limits mobility and flexibility. I have, therefore, always been eager to find alternatives.

The failure of tablets

I know some people that love their tablets and bring them on travels instead of a laptop. I have always tried to like tables and have owned several over the last decade. I bought the first Samsung Galaxy tablet and the first iPad. I have tried both small and large iPads, but they have all been passed on to my daughters. Over the last few years, I have used a Sony tablet on and off. Usually, more off than on. I like that it has a built-in SIM card, which means it is easy to use for online activities. However, it is a pain to get the keyboard to work. I always have to pair it a couple of times.

One main problem with tablets is that they are something between PC and phone. My Sony tablet actually works as a phone. I have tried (once) to travel with only the tablet. That felt weird. In theory, it worked. In practice, it was a pain. Calling from the tablet worked when I was at the hotel, but not out on the street. So I have found it impossible to travel without a phone.

I am currently on a trip to Germany (my first post-corona trip!) and decided to try travelling with only my phone. No laptop. No tablet. The journey is short, and there is not much time to work anyways. In addition, I wanted to travel as lightweight as possible. So I decided to rely on my mobile phone as the only communication device. The conclusion is that it has worked well. There are a couple of reasons for that, which I will explain in the following.

Great communication

Most of my meetings these days are on Zoom. On this trip, I would only have one Zoom meeting, and it was easy to do that on the mobile phone. Since I didn’t know where I would be located during the call, it was, in fact, easier to take it from the phone. I have found the Android Zoom app to very efficiently handle different bandwidths. The same can not be said about the Zoom client I use on Ubuntu, which requires relatively high bandwidth to function well (the Windows client seems to be more optimised).

The trick for doing Zoom’ing on the phone is to have a small camera stand available. I always carry a camera stand around anyways since I take many photos and videos. I always also carry some headset. Usually, I prefer a larger headset, but I decided to go for a small pair of earbuds (again, the main point was a small and lightweight setup). All in all, for Zoom’ing, using the mobile phone works well.

A small camera stand with a mobile phone holder is an essential accessory. It makes it possible to easily participate in Zoom meetings from anywhere.

External keyboard

The biggest challenge with mobile phones is the limited input capacity. Typing with the finger is not an option in the long run. So for travelling, bringing an external keyboard is the only real solution. I have occasionally tested connecting one of my tablet keyboards to my phone. For some reason, it never occurred to me that I could bring one of them with me when travelling.

The conclusion is that I should have thought about this a long time ago. I am currently writing this blog post on my phone using a small, Bluetooth-based Logitech keyboard. It is a minimal and convenient setup. The setup and connection of the keyboard have also worked well so far. Some years ago, I always struggled with pairing up keyboards. The software has improved since now; the connection works every time.

I finally found use for my collection of wireless tablet keyboards.

Connecting to a big screen

Another issue with working on a mobile phone is the screen size. It is less important than the keyboard but still an issue for doing accurate typing. A mobile phone screen is ok for writing short texts and replying to e-mails. However, working on a manuscript is challenging.

When I bought my Samsung Galaxy Note 8 some years ago, the main motivation was the Dex mode. This was first based on a particular docking station connected to a screen and keyboard, and mouse. The Dex mode essentially turns the phone into a small “PC”. Well, not a complete PC experience, but at least a full-screen Android experience.

Some, but not all, Android apps work in fullscreen mode. The most important is that all the essential apps, e-mail, browser, notes, etc., function.

I have had a Dex hub in my office for several years but haven’t used it much. After all, in the office, I already have access to a nice PC setup. It was only recently that I discovered that Dex mode now works when connecting the phone through a regular HDMI cable. That is interesting because it is unnecessary to carry the Dex docking station to get the fullscreen experience.

Now I decided to try out Dex when travelling. I brought along an HDMI cable and USB-C adapter, which means I can connect to the TV in hotels. I never watch TV when travelling, but I have noticed that there are always TVs around, usually with easily accessible HDMI ports.

Typing this blog post using a wireless keyboard and connected to the TV screen at the hotel. Note the Dex mode on the screen.

The new “office”

I have for some days relyed on my phone-based setup. On train rides, I have connected the keyboard to type away. At the hotels, I have also connected to TVs to get a fullscreen experience. This has made it possible to keep up with e-mailing and manuscript editing while travelling. There are several benefits to this setup:

  • Lightweight: I haven’t weighed the keyboard and HDMI cable and adapter. However, I think they weigh less than the power adapter of my laptop.
  • Small size: I can carry the essentials in a small bag.
  • Security: Having fewer items to think about also makes it safer. I don’t need to worry about carrying the laptop with me because I don’t dare leave it in a hotel storage.
  • Access: Being able to roam without extra cost throughout Europe is one reason this type of setup works. Instead of having to connect the PC to a network or my phone, I am now always on the mobile network. I am used to having 4G everywhere in Norway, but travelling around in Germany for a couple of days, I have had some kind of network in most places.
My new travelling kit.

Not perfect

I am generally very positive about this lightweight setup. It is an excellent alternative to bringing the laptop on such short travels, and I think I will continue with this approach when possible. However, it is not perfect. Some of the things I have thought about:

  • Ergonomics: on this trip I brought a small (7″) bluetooth keyboard. That is tiny. I also have a 10″ keyboard at home and will probably switch to that one for the next travel.
  • Battery life: Using the phone for everything also means that the battery drains quicker. The challenge now is that my HDMI adapter has no charging input. Thus I end up draining the battery when using the screen. I will need to check if I can find another HDMI adapter with USB-C charging.
  • Android limitations: A challenge of using a limited OS like Android is that, well, it is a limited OS. I tend to use quite a bit of terminal commands for doing things. I also miss having a proper file manager. I still think that the mobile OSes (both Android and iOS) have made it utterly complicated to do regular file management. In practice, I therefore end dumping files in one place and wait to get to a computer to sort everything out.
  • Media handling: I am a creator. I write texts, record sound and video, and take photos. I do this on my phone, but also with separate cameras and recorders. All of these can be connected to my phone for media handling, but it is cumbersome. I also don’t have space on my phone to copy over too many files. So now I have to rely on filling up the memory cards and wait for getting back to a PC to copy over. That works for a short trip, but would be difficult for longer.

Summing up

I don’t understand why it took me so long to “discover” this setup. After all, I have had the keyboard and cables I brought along on this trip for many years. Still, it never occurred to me that this could be a viable travel setup. After trying it for a couple of days, I am very optimistic. Bringing a small keyboard + HDMI cable and adapter has allowed me to do what I wanted to do without needing a laptop. It won’t always work, but for such short travels, it is ideal.