Add a new audio track to an existing file

There is yet another common use of FFMPEG, i.e. adding a new audio track to an existing file which can be a video-only file or a video file already with an audio track. A use case will be adding a second audio track to a file already with video and sound. The following is an example of the command to add audio.dts audio track to an existing mkv file:

ffmpeg -i input.mkv -i audio.dts -map 0 -map 1 -c copy output.mkv

Correcting for audio/video sync issues

Due to various reasons, the audio and video tracks sometimes may become out-of-sync in a video clip, i.e. there are some delay between the tracks affecting the overall viewing experience. Use the following as examples to fix the issue.

CASE 1: Audio happens before video (aka “need to delay audio stream 1”):

ffmpeg -i clip.mp4 -itsoffset 0.150 -i clip.mp4 -vcodec copy -acodec copy -map 0:0 -map 1:1 output.mp4

The “itsoffset” in the above example is placed before file 1 (remember that linux counts from 0, so 0 is the first and 1 is the second), so when the mapping happens, it says “Take the video of file 0 and the audio of file 1, leave the video of file 0 alone and apply the offset to the audio of file 1 and merge them into a new output file”. The delay is only .15 seconds.

CASE 2: Video happens before audio (aka “need to delay video stream 0”):

ffmpeg -i clip.mp4 -itsoffset 0.150 -i clip.mp4 -vcodec copy -acodec copy -map 0:1 -map 1:0 output.mp4

The “itsoffset” in the above example is placed before file 1. When the mapping happens, it says “Take the audio of file 0 and the video of file 1, leave the audio of file 0 alone and apply the offset to the video of file 1 and merge them into a new output file”. The delay is only .15 seconds.

Flashing Firmware on Scishion V88 TV Box

To flash the firmware of Scishion V88 TV Box and V88 mini TV Box, both use Rockchip RK3229, there are basically two main methods. The first one is to prepare a microSD card with the desired firmware using a utility such that when the TV Box starts from a recovery mode, it will boot from the microSD card. Another method is to connect the TV Box to a computer and flash the firmware from the connected computer. Details follow.

First of all, locate the desired version of firmware that you want to apply to the TV Box. Many versions can be found in the web without much difficulty. Then install the USB driver designed for Android devices with Rocketchip. Open Android Tool and point to the firmware just downloaded. Without connecting to the AC power, use a pin to poke and hold the reset button; connect a male-to-male USB cable from the computer to the TV box while the reset button is being pushed and held. Android Tool should then recognize the TV Box and start the upgrading process.

Note that there is only one USB port on the TV Box that will work. For V88 TV Box, this is the one at the back of the unit. For V88 mini TV Box, this is the third USB port closest to the back. A sound should be played if the computer recognizes a device is being connected to it. (Click here to download the necessary tools mentioned in this post and a version of firmware based on Android 5.1)

Swap the audio tracks without re-encoding

Many video file formats allow you to have multiple sound tracks (e.g. karaoke videos) where the first audio track is treated as the default by many audio-visual editing applications. Many of those can only handle one audio track which is the first one. If you want to switch the audio tracks, you can use FFMPEG without re-encoding the media. The following example is the command to switch the two audio tracks in a video file:

ffmpeg -i input -map 0:v:0 -map 0:a:1 -map 0:a:0 -c copy output

TeamViewer Won’t Start

If you experience problems starting TeamViewer in Windows, one the possible causes may be that the communication stack WINSOCK has been corrupted. Uninstalling and reinstalling TeamViewer, tweaking the Firewall settings and rolling back to previous software version will not resolve the problem. A simple command may do the trick. Open and run the Command Prompt (CMD) under administrator privilege, and enter the following command:

“netsh winsock reset”

Restart the computer and TeamViewer may very well be working again.

VMware Bridged Network

If you use Bridged Network in VMware Workstation Player and experience network problems after software upgrade (either VMware or Windows), resetting the network configuration to its default settings usually resolves the problems. Since there is no network configuration tool in Workstation Player, an alternate way to achieve the same results is to shutdown the host machine and re-configures its network adapters.

Screen Resolution of an Android on Virtual Machines

It’s been quite some since one can install Android on Windows-based systems, whether through an emulator or through virtual machines (such as Virtual Box or VMware Workstation).

When running Android on virtual machines, there is one common adjustment which is not readily available through obvious user interface, namely the screen resolution. This web page discusses how this can be done and the settings be saved.

Converting PDFs Using ImageMagick

There may be situations that you would like to convert a coloured PDF document to black-and-while (monochrome or greyscale) for whatever reasons. One of the methods that can accomplish this is to use ImageMagick, free command-line software that can perform all sorts of functions related to images. The following examples are commands to convert a PDF in colour to black-and-white. Values in the parameters should be adjusted to suit the particular document in question to obtain optimal results. (Note: Ghostscript needs to be installed for working with PDFs)

“magick -density 600 in.pdf -threshold 60% -type bilevel -compress fax out.pdf”

“magick -density 600 in.pdf -level 10%,90% -type grayscale -depth 8 out.pdf”

Increasing volume in a video without re-encoding

I needed for a reliable, fast and non-destructive way to increase gain on a video’s audio track. I found it in using the ffmpeg tool, which is a swiss army knife for dealing with video and audio files. It’s conveniently cross-platform and works wonders.
To increase the volume of the first audio track for 10dB use:
ffmpeg -i inputfile -vcodec copy -af “volume=10dB” outputfile
To decrease the volume of the first audio track for 3dB use:
ffmpeg -i inputfile -vcodec copy -af “volume=-3dB” outputfile