Playing with Video Files on Linux

A man doing video editing on his computer
Photo by Mark Cruz on Unsplash

I have been recently playing with editing videos for some of my personal work. For e.g., obtaining the frames from a video, merging the frames back into a video after making some changes to the frame(s) or combining audio and video. The ffmpeg utility on Linux is a very handy tool to do all these stuff and I list only a few commands that I have used for my use here:

Obtaining frames from a video

ffmpeg -i <Your_Video> -qscale 0 scene%d.jpg

It goes without saying that <Your_Video>should be replaced with your own video without the <> sign.

Merging frames into a video

ffmpeg -framerate <frame_rate> -i scene%d.jpg -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p <newvideo>

The frame rate should be the same as the original frame rate of the video. so that the audio and video are in sync. Also, the video obtained will contain no sound. I will typically extract the audio from the original video and merge the extracted audio with the new modified video using some tool like KDenLive on Linux.

Finding the frame rate for a video

To properly create a video from frames, the frame rate should be the same as the original video so that when we merge the audio and video later on, both are synchronized. So the command below can be used to find the frame rate of the video:

ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate <Your_Video>

The output looks like this, indicating 25 fps:

25/1

Combining Audio and Video

I use the Lecture Notes. It is wonderfull which comes with a Lecture Presentation and a Lecture Videos extension. The Lecture Video extension allows me to annotate my lecture videos while I am recording my lecture. This allows for a more immersive experience for the audience as compared to just going through the slides.

The Lecture Videos extension saves the audio and video separately on the mobile device. One can merge them before exporting, but the merging takes a long time and the file size is very big. Instead, one can export the audio and video separately and use the following command of ffmpeg to merge them:

ffmpeg -r <frame_rate> -i video1.h264 -i video1.3gp -b 1.5M video1.mp4

Disclaimer

I am not an expert in video editing. Based on my needs I search the internet for answers and all the commands listed above were obtained from various sources on the internet including, but not limited to, stackoverflow. However, I do not remember the actual websites and I have modified the commands to suit my needs.

--

--

--

A reluctant researcher, making the transition to industry. Opinions expressed in my posts are mine and not of my employer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Stand Out Features of Network in a Box, Your Portable Network Device

Round and round we go!

Coding has got me down, so I’m chronicling what has happened and the journey to hopefully a happy…

Steps to create and deploy an Express API on Firebase

Woman stand with a laptop

Building the Serverless Superman

Web Frameworks:Foundational Technologies

How to Handle a Very Common Warning for Python Data Scientists

Node.js plain ICMP ping implementation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Syed Asad Alam

Syed Asad Alam

A reluctant researcher, making the transition to industry. Opinions expressed in my posts are mine and not of my employer.

More from Medium

Bypassing Hetzner mail port block (port 25/465)

Wazaterm Features

Creating JKS or PFX files from cert and private key.

How to debug a docker image.