Upgrade to Xiaomi Mi 6

I have been using Xiaomi 2S for a long time without upgrading. It is still usable but getting slow on task switching. I like Xiaomi because of its OS support. Up to now, my 2S still getting software upgrade every now and then.

As for my new Mi 6. The one I get is Chinese version which does not have Google Play. So, the first task I had was to try to install Google framework on the phone. After some search on the Internet, I found two ways to do so:

  1. Flash the official “global” ROM from the MIUI website (http://en.miui.com/download.html). This ROM contains the Google framework in it. However, Mi 6 is a locked phone which means I need to unlock the phone first before I can directly flash any ROM to it. There is instruction on MIUI website (http://en.miui.com/unlock/) and the Internet showing to apply and perform the unlocking. After unlocking, you can flash the global ROM to gain the Google framework.
  2. The second option is using the local restore option which provided on the Internet. The idea is to restore the set of apps which form the Google framework. The backup of this set of apps is available for download from the Internet. The advantage of this approach is you do not need to unlock or root your device at all. However, if you want to root your device, you do need to unlock it first.

I tried the global ROM approach first. I found it has very good support of Google framework include the use of “ok Google” to unlock or activate voice command. However, even I used the developer version of ROM, it does not support rooting the device. This means I have to use some third-party apps for both flashing and rooting the device. Even worse, after each MIUI upgrade, I have to do the flashing and rooting again.

This brings me to try to reverse the device back to the Chinese ROM and try the restore approach for installing the Google framework. It works out fine. I can use Google Play and all other Google apps. However, the “ok google” cannot be activated in the same way as in the Global ROM. But now, I have the MIUI rooting support back!

In my opinion, if you want to root the device, the Chinese ROM together with the restore approach is a better choice.

Advertisements

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.

“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.

Allowing a local WiFi router to connect to the Internet through a wire LAN

I recently need to set up a WiFi router in my room where I have a computer that connects to a wired network with 802.1x authentication. The network is connected to the internet. Since the WiFi router cannot directly connect to a network with 802.1x authentication, the router is connected to the computer (running Ubuntu 16.04.1 LTS) instead. The following is the code, allowing the traffic from the WiFi router through my computer connect to the network with Internet capability.

#
# Perform NAT so that the WiFi route can connect to the Internet
# eth0 connect to a network which can connect to the Internet
# eth1 connect to LAN through WiFi router
#
# code taken from http://www.revsys.com/writings/quicktips/nat.html
#
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

“symbol(s) not found for architecture x86_64 error” when compiling OpenCV example program in Mac OS X 10.12

I just completed the installation of OpenCV 3 in my Mac (running OS X 10.12) after a long search of various installation methods.  However, when I tried to compile a sample C++ program, the following error was resulted:

Undefined symbols for architecture x86_64:
  "cv::imread(cv::String const&, int)", referenced from:
      _main in DisplayImage-6f69a1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [DisplayImage] Error 1

So, once again, the search is on. After searching for the entire morning for solutions, I came across many “solution posts” that did not work!

Finally, I reached a post that mentioned “imread has been moved in the opencv_imgcodecs library.” and should “Try to add -lopencv_imgcodecs to your linker flags.” This solved my problem.

This case made me wonder how many people who posted “incorrect solution” had actually tried to replicate the error and actually solved the problem? Or did they just “think” what may be the problem and provide “guesses” about the possible solutions?

I am not saying that try ones best to provide information to the other is a bad thing. But providing too many “unproven” information in the web not only not able to help, it also makes the searching for true solution more difficult!

Using cmake-gui to Create MinGW lib for OpenCV 2.4.13

Recently, I have tried to learn how to use OpenCV. Of course, the first thing is to install OpenCV. The version I tried to install is 2.4.13. The development tools I used is MinGW g++. After download and install all the tools (including cmake), I soon found out that there is no library for MinGW g++ in the distribution. This means I need to build my own if I want to use g++. The search is on…

There is not much information I can find for my environment which is Windows 10 and using g++ as my main c++ compiler. After putting the pieces together, I eventually hit the right path, the following is my procedure for building the MinGW lib for OpenCV 2.4.13:

  1. run cmake-gui as follows:
    cmake-gui -G "MinGW Makefiles"

    Setup the location for source (in my case is D:/WinApps/opencv/sources) and the binaries (D:/WinApps/opencv/build/x86/mingw). Add the following two entries as well:

    CMAKE_CXX_COMPILER <em>path_to_g++</em>
    CMAKE_C_COMPILER <em>path_to_gcc</em>
  2. Click Configure then with the default selection of components click Generate
  3. In cmd, change directory to D:/WinApps/opencv/build/x86/mingw and execute the command
    make all

    I encountered two errors during the make process:

    • A compile error for the file window_w32.cpp where the symbols ‘BTNS_AUTOSIZE‘ and ‘BTNS_BUTTON‘ were not declared. I fixed it by change them to 16 and 0 (where I found in one of the header file of g++).
    • Another error from the files in ‘nonfree’ module, for which I just deselect the ‘BUILD_opencv_nonfree’ from cmake and reclick Generate again, then make all again. This time, it went all the way to finish without serious error.
  4. Done!

I test drive the system by creating a c++ program loadimg.cpp which I copied from here.

g++ -I"D:\WinApps\opencv\build\include" -L"D:\WinApps\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core2413 -lopencv_highgui2413 -o loadimg

The program compiled and run!

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!