Adding subtitle to mp4 movie with ffmpeg

I need to add a short copyright message at the beginning and ending of a short movie. So, I think it will be great to use ffmpeg for this simple task. Well, it turned out to be not as simple as I initially expected.

Running the initial simple command (show below) taken from somewhere in WWW result in error in reading the .srt file.

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

Initially, I have my .srt setup as follows:

1
00:00:00,000-->00:00:10,000
The movie should only be used in ...

Since the error message said it “cannot read” the file, I tried to change its name, adding fullpath, etc. Nothing worked. I also tried to change the contain. And finally, the following works. See the difference? I missed the spaces sounding “–>”!

1
00:00:00,000 --> 00:00:10,000
The movie should only be used in ...

Now the program run and produced a result mp4 file. However, when I viewed the movie, there was no subtitle! After reviewing the screen full of messages displayed during the conversion, I found there was a warning message about the missing fonts.conf file. Another round of information digging began.

This time, luckily, not before long, I came across a post (https://forum.videohelp.com/threads/371053-ffmpeg-burnt-in-subtitles-Fontconfig-invalid-attribute-mode) where it provided most information about setting up the fonts.conf file.

Here are steps I took:

1. Download the fonts.conf from the above post and put it in the root directory of ffmpeg which, in my case, is D:\WinApps\ffmpeg

2. Setup the envoironment variables as follows:

set FC_CONFIG_DIR=d:\WinApp\ffmpeg
set FONTCONFIG_FILE=fonts.conf
set FONTCONFIG_PATH=d:\WinApp\ffmpeg

3. Run the following command

ffmpeg -i input-dv.mp4 -vf subtitles=copyright.srt:force_style='Fontsize=18' output-dv.mp4

The first time I run the command, it took a bit longer to process.

The final problem is adding Chinese in the subtitle text. This turned out to be the most simple one to be solved. Just make sure the file encoding is in UTF-8. For this, I use the feature provided notepad directly.

Advertisements

“int RECV_PIN = TKD2;” error in Arduino IR library

Ok, it has been a long time since my last play-around with Arduino. This time, I tried to build a simple IR controller to open and close a window shader that I am planing to build. So I copy a sample program and test it out and get the error “TKD2 not defined” error in the following line of code in the file IRremoteTools.cpp which is part of the IRremote library.

int RECV_PIN = TKD2; // the pin the IR receiver is connected to

The simplest solution for this problem turned out to be just delete the two files IRremoteTools.cpp and IRremoteTools.h from the library directory. These two files just provide some additional function interface to the library which I am quite happy to live without them.

Error 1935 while try to upgrade blue tooth drive for lenovo X201

I recently tried to test my blue tooth stereo headset with my lenovo X201 and end up need to update the blue tooth driver in the computer. However, during the update process, the computer encountered an error 1935 and the update was not successful and rolled back. I tried a few times with the same result. I even tried to download and install the new driver manually, still without any luck. Reading the forums from web also gave me not much help. I finally do the following and magically it worked!

  1. In “Device Manager” (right-click Computer->property), right click the ThinkPad Bluetooth device and click “Uninstall”. The entire BT device will gone.
  2. In “Device Manager”, right click the top item (my notebook) and click “Scan for hardware changes”, wait a short while and it should find the BT device and start installing the most updated drivers!

Now, the device drivers are the most updated one!