Skip to main content

Modifying Video Data using FFMPEG

FFMPEG has become very popular for so long time as a tool that can help us manipulate, convert, or configure video and audio data. We can resize our video, convert a file into a different container, change the bitrate, embed subtitles, or even stream real-time video. These are a few examples of its utilization.

Converting file into a different container

For example, we want to convert an MKV file into MP4 without changing its codec.

ffmpeg -i input.mkv -codec copy output.mp4

Or, we want to convert an MP4 file into Webm with some customizations.

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 28 -b:v 0 -b:a 128k -c:a libopus output.webm

Change video size

We can resize a video width and height too.

ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4

We can set the width or height to "-1" to keep the origin ratio. Note that some codecs require a size that can be divided by 2 to be successful.

ffmpeg -i input.mp4 -vf scale=1280:-1 output.mp4

Insert subtitles

We can attach a subtitle file to a video container.

ffmpeg -i input.mp4 -i input.srt -c copy -c:s mov_text output.mp4

Extracting subtitles from multi-track video

If a video file is attached with subtitles, we can generate the ".srt" file from it too.

ffmpeg -i input.mkv -map 0:s:0 subs.srt

Embed subtitles

We can also append the subtitle texts into video frames directly.

ffmpeg -i input.mp4 -vf subtitles=input.srt output.mp4

Download Live Stream Video

We can download live steam video from its manifest file and convert it to MP4.

ffmpeg -i http://source.m3u8 -c copy -bsf:a aac_adtstoasc output.mp4

Delay Video/Audio Track

If video or audio tracks are out of sync, we can add some offset to the specific track. For example, we want to cut a video and adjust the audio track.

ffmpeg -i input.mp4 -itsoffset -3.2 -i input.mp4 -map 0:v -map 1:a -c:v copy -c:a copy -ss 12:00 -to 22:30 output.mp4

Comments

Popular posts from this blog

Increase of Malicious Activities and Implementation of reCaptcha

In recent time, I've seen the increase of malicious activities such as login attempts or phishing emails to some accounts I manage. Let me list some of them and the actions taken. SSH Access Attempts This happened on a server that host a Gitlab server. Because of this case, I started to limit the incoming traffic to the server using internal and cloud firewall provided by the cloud provider. I limit the exposed ports, connected network interfaces, and allowed protocols. Phishing Attempts This typically happened through email and messaging platform such as Whatsapp and Facebook Page messaging. The malicious actors tried to share a suspicious link lured as invoice, support ticket, or something else. Malicious links shared Spammy Bot The actors leverage one of public endpoint on my website to send emails. Actually, the emails won't be forwarded anywhere except to my own email so this just full my inbox. This bot is quite active, but I'm still not sure what...

Configuring Swap Memory on Ubuntu Using Ansible

If we maintain a Linux machine with a low memory capacity while we are required to run an application with high memory consumption, enabling swap memory is an option. Ansible can be utilized as a helper tool to automate the creation of swap memory. A swap file can be allocated in the available storage of the machine. The swap file then can be assigned as a swap memory. Firstly, we should prepare the inventory file. The following snippet is an example, you must provide your own configuration. [server] 192.168.1.2 [server:vars] ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_rsa Secondly, we need to prepare the task file that contains not only the tasks but also some variables and connection information. For instance, we set /swapfile  as the name of our swap file. We also set the swap memory size to 2GB and the swappiness level to 60. - hosts: server become: true vars: swap_vars: size: 2G swappiness: 60 For simplicity, we only check the...

Deliver SaaS According Twelve-Factor App

If you haven't heard of  the twelve-factor app , it gives us a recommendation or a methodology for developing SaaS or web apps structured into twelve items. The recommendation has some connections with microservice architecture and cloud-native environments which become more popular today. We can learn the details on its website . In this post, we will do a quick review of the twelve points. One Codebase Multiple Deployment We should maintain only one codebase for our application even though the application may be deployed into multiple environments like development, staging, and production. Having multiple codebases will lead to any kinds of complicated issues. Explicitly State Dependencies All the dependencies for running our application should be stated in the project itself. Many programming languages have a kind of file that maintains a list of the dependencies like package.json in Node.js. We should also be aware of the dependencies related to the pla...

Kenshin VS The Assassin

It is an assassin versus assassin.

Free Cloud Services from UpCloud

Although I typically deploy my development environment or experimental services on UpCloud , I do not always stay updated on its announcements. Recently, I discovered that UpCloud has introduced a new plan called the Essentials plan, which enables certain cloud services to be deployed at no cost. The complimentary services are generally associated with network components or serve as the foundation for other cloud services. This feature is particularly useful when retaining foundational services, such as a load balancer, is necessary, while tearing down all services and reconfiguring the DNS and other application settings each time we temporarily clean up infrastructure to reduce costs is undesirable.  When reviewing the service specifications of the cloud services in the Essentials plan, they appear to be very similar to those in the Development plan. The difference in service levels is unclear, but it could be related to hardware or resource allocation. For instance, the loa...

What's Good About Strapi, a Headless CMS

Recently, I've been revisiting Strapi as a solution for building backend systems. I still think this headless CMS can be quite useful in certain cases, especially for faster prototyping or creating common websites like company profiles or e-commerce platforms. It might even have the potential to handle more complex systems. With the release of version 5, I'm curious to know what updates it brings. Strapi has launched a new documentation page, and it already feels like an improvement in navigation and content structure compared to the previous version. That said, there's still room for improvement, particularly when it comes to use cases and best practices for working with Strapi. In my opinion, Strapi stands out with some compelling features that could catch developers' attention. I believe three key aspects of Strapi offer notable advantages. First, the content-type builder feature lets us design the data structure of an entity or database model, including field ...