Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts

Friday, December 02, 2016

Adding Subtitle and Scaling Film using ffmpeg

Linux Version :
# lsb_release -da
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty

You will need to install :
root@kecap:/tmp# apt-get install ffmpeg
ffmpeg used for adding and scaling film, for another information you can google it.

root@kecap:/tmp# apt-get install fontconfig
because i want use another font for my subtitle, in this case it's Arial

root@kecap:/tmp# apt-get install ttf-mscorefonts-installer
you need to install this package to get microsoft fonts, but if after installing this package and you got empty directory (like what happen to me), simple...just copy arial font from windows to /usr/share/fonts/truetype/msttcorefonts/ and run fs-cache.

Now, we go to main topic.

Adding subtitle using ffmpeg
Basic :
ffmpeg -i input.mp4 -vf subtitles=mysub.srt output.mp4
Advanced :
ffmpeg -i input.mp4 -vf subtitles="f=mysub.srt:force_style='FontName=Arial Bold,FontSize=22,PrimaryColour=&H0009FAFD,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=1,Outline=1,Shadow=1'" -y output.mp4
for .ASS tag description please read this

Scaling film using ffmpeg
Basic :
ffmpeg -i input.mp4 -vf scale=1028:720 output.mp4
Advanced :
ffmpeg -i input.mp4 -vf scale=-1:720 -c:v libx264 -profile:v high -level:v 3.1 -c:a copy output.mp4

Combining two ffmpeg command
ffmpeg -i input.mp4 -vf "scale=-1:720,subtitles="f=mysub.srt:force_style='FontName=Arial Bold,FontSize=22,PrimaryColour=&H0009FAFD,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=1,Outline=1,Shadow=1'"" -c:v libx264 -profile:v high -level:v 3.1 -y output.mp4

ffmpeg & bash
If you writing ffmpeg script inside bash, you will get "funny error"
Parse error, at least 3 arguments were expected, only 1 given in string....
the point is the bash script seems to produce input (Namely the 'c' key) which interferes with the ffmpeg process. just add >/dev/null at the end of the ffmpeg command to prevent ffmpeg from reading its standard input, see example below:
ffmpeg -i input.mp4 -vf scale=1028:720 output.mp4 >/dev/null
for more information you can read it here

Wednesday, June 29, 2016

Adding SQLite3 Binary on ROOTED Android (Advanced Mode)

Download SQLite3 binary from here, if you want another source to install SQLite3 with more simple step, then you may follow this instructions.

Info :
My android ip : 192.168.100.6
Downloaded sqlite3 binary location : /sdcard/Download/

1. In this step i'm using WIFI ADB (install it from Google Playstore).
2. install latest adb from here or here
3. start connect to your android device using adb command:
D:\tmp\adb connect 192.168.100.6:5555
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.100.6:5555

go to android shell
D:\tmp\adb shell

Become root
shell@android:/ $ su

mount system to allow read and write
root@android:/ # mount -o remount,rw /system

go to your place where you save sqlite3 binary, in this case i'm saving at sdcard/Download/
root@android:/ # cd sdcard/Download/
root@android:/ # ls sqlite3
sqlite3

copy sqlite3 binary into your /system/xbin/
root@android:/sdcard/Download # cp sqlite3 /system/xbin/
root@android:/sdcard/Download # ls -al /system/xbin/sqlite3
----rwxr-x root     root       868952 2016-06-29 11:26 sqlite3

make your sqlite3 binary become executable
root@android:/sdcard/Download # chmod 755 /system/xbin/sqlite3

Now lets mount back /system/ as read only (ro)
root@android:/ # mount -o remount,ro /system

Now run your sqlite3 from command shell, and try to query database inside your android
root@android:/storage/sdcard0 # sqlite3 /data/data/jp.naver.line.android/databases/naver_line
SQLite version 3.8.11.1 2015-07-29 20:00:57
Enter ".help" for usage hints.
sqlite> .tables
android_metadata       group_home             sns_friends
chat                   groups                 sticker
chat_history           membership             sticker_package
chat_member            more_menu_item_status  sticon_packages
chat_notification      my_theme               sticons
contacts               permanent_tasks        version
email_recommend        product
esk_history            setting
sqlite> SELECT * FROM setting;
AU_SMART_PASS_AGREEMENT|1
AU_SMART_PASS_FUNC_ACTIVATE|1
CHANNEL_ENCRYPTED|1
USER_STATUS_ACCESS_MOBILE_NETWORK_TIMESTAMP|1467159063483
APP_CURRENT_VERSION|15060403_6.4.1
APP_INIT|true
USER_STATUS_LAST_FOREGROUND_TIMESTAMP|1467164323745
MAT_INITIALIZED|1
APP_TIMELINE_TAB_BADGECOUNT|0
...
sqlite>

Done

Adding SQLite3 Binary on ROOTED Android (Simple Mode)

Some devices come with luxury binary, but some lacking that luxury item, but as we are love to hack android it doesn't matter anymore, in this little post, i will show you how to insert SQLite3 binary into our system.

Okay, now follow the instructions below, if you like using adb command then you can read advanced mode.

1. Download SQLite3 binary from here or here or here
2. Install any File manager with ROOT Capability like Root Explorer or Root Browser
3. Copy SQLite3 binary into /system/xbin/sqlite3
4. Chmod 0755 /system/xbin/sqlite3, you can do this inside Root Explorer or Root Browser


5. Done

Example shell output from sqlite3
root@android:/storage/sdcard0 # sqlite3 --help
Usage: sqlite3 [OPTIONS] FILENAME [SQL]
FILENAME is the name of an SQLite database. A new database is created
if the file does not previously exist.
OPTIONS include:
   -ascii               set output mode to 'ascii'
   -bail                stop after hitting an error
   -batch               force batch I/O
   -column              set output mode to 'column'
   -cmd COMMAND         run "COMMAND" before reading stdin
   -csv                 set output mode to 'csv'
   -echo                print commands before execution
   -init FILENAME       read/process named file
   -[no]header          turn headers on or off
   -help                show this message
   -html                set output mode to HTML
   -interactive         force interactive I/O
   -line                set output mode to 'line'
   -list                set output mode to 'list'
   -lookaside SIZE N    use N entries of SZ bytes for lookaside memory
   -mmap N              default mmap size set to N
   -newline SEP         set output row separator. Default: '\n'
   -nullvalue TEXT      set text string for NULL values. Default ''
   -pagecache SIZE N    use N slots of SZ bytes each for page cache memory
   -scratch SIZE N      use N slots of SZ bytes each for scratch memory
   -separator SEP       set output column separator. Default: '|'
   -stats               print memory stats before each finalize
   -version             show SQLite version
   -vfs NAME            use NAME as the default VFS
1|root@android:/storage/sdcard0 # sqlite3 -version
3.8.11.1 2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f

Another source for SQLite3 you may interesting:
sqlite3-android
sqlite3
forum.xda-developers

Monday, June 08, 2015

Linux Advanced Copy ( Modified Original cp Command )

Advanced-Copy is a powerful command line program which is modified version of original cp command. This modified version of cp command adds a progress bar and etc. shortly, it's much better than original cp command. How to get advanced copy on Debian "Wheezy" 7.8 .And this step work and tested. Download all required file all in one from HERE
root@prc-04:/tmp# wget https://www.dropbox.com/s/o9rs7o0l0569iv3/coreutils-8.4-receipt.tar.gz?dl=0
root@prc-04:/tmp# mv -v coreutils-8.4-receipt.tar.gz?dl=0 coreutils-8.4-receipt.tar.gz
Extract it
#root@prc-04:/tmp# tar -zxvf coreutils-8.4-receipt.tar.gz
coreutils-8.4.tar.gz
coreutils-8.4.patch
Extract coreutils-8.4.tar.gz
root@prc-04:/tmp# tar -zxvf coreutils-8.4.tar.gz
Copy file pacth
root@prc-04:/tmp# cp -v coreutils-8.4.patch coreutils-8.4/
`coreutils-8.4.patch' ---> `coreutils-8.4/coreutils-8.4.patch'
Go to coreutils-8.4/
root@prc-04:/tmp# cd coreutils-8.4/
root@prc-04:/tmp/coreutils-8.4#
Patch it
root@prc-04:/tmp/coreutils-8.4# patch -p1 -i coreutils-8.4.patch
(Stripping trailing CRs from patch.)patching file src/copy.c
(Stripping trailing CRs from patch.)patching file src/copy.h
(Stripping trailing CRs from patch.)patching file src/cp.c
(Stripping trailing CRs from patch.)patching file src/mv.c
patch unexpectedly ends in middle of line
Hunk #5 succeeded at 500 with fuzz 1.
Configure
root@prc-04:/tmp/coreutils-8.4#./configure
Make it
root@prc-04:/tmp/coreutils-8.4#make
Once, compilation completes, two new commands are created under src/cp and src/mv. You need to replace your original cp and mv commands with these two new commands to get the progress bar while copying files. Replace original cp and mv file
root@prc-04:/tmp/coreutils-8.4#cp src/cp /usr/local/bin/cp
root@prc-04:/tmp/coreutils-8.4# cp src/mv /usr/local/bin/mv
BUT If you don’t want to copy these commands under standard system paths, you can still run them from source directory like “./cp” and “./mv“.
root@prc-04:/tmp/coreutils-8.4/src# ./cp --version
cp (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjörn Granlund, David MacKenzie, and Jim Meyering.


root@prc-04:/tmp/coreutils-8.4/src# ./mv --version
mv (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker, David MacKenzie, and Jim Meyering.
Option to show progress bar while copying, add -g
root@prc-04:/tmp/coreutils-8.4/src# ./cp --help | grep progress

-g, --progress-bar add progress-bar

root@prc-04:/tmp/coreutils-8.4/src# ./mv --help | grep progress

-g, --progress-bar add progress-bar
Copying example.
root@prc-04:/tmp/coreutils-8.4/src# ./cp -g /tmp/test.img /tmp/tes

root@prc-04:/tmp/coreutils-8.4/src# 861.7 MiB / 1.0 GiB[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||--------------------------] 84.1 % Copying at 52.6 MiB/s (about 0h 0m 0s remaining) /tmp/test.img 861.7 MiB / 1.0 GiB[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||--------------------------] 84.1 % Done

Friday, April 26, 2013

scp or rsync with plain password using sshpass

Sometimes i don't care with security, i just want to put my password inside my script (hard code), why? Because i need to run that script automatically. If you face same problem with me, then you lucky came to my blog. The solution is simple, use sshpass, download and compile it, then run it.

Using with scp (not like rsync, scp does not support plain password)
sshpass -p yourpassword scp username@server.com:/path/to/file/singlefile .

Using with ssh
sshpass -p yourpassword ssh username@server.com

Friday, December 07, 2012

Checking Connection Via Ping using Bash

Create bash file on the /tmp (you can put anywhere), this is just an example.
$ touch /tmp/ping.sh
added this code inside it
#!/bin/bash
ip=192.168.110.33
ping -c 3 $ip > result
grep 100% result > /dev/null
if [ $? = 0 ]
        # result dari $? kalau 0 artinya tidak output grep di screen
        # artinya, grep tidak mendapatkan apa yang di cari
        # dalam hal ini grep mencari 100% packet loss (host yg off)
        #
        then
        echo "Host off"
        else
        echo "Host on"
fi
Make sure the script has permission to execute
$ chmod +x ping.sh
Test it !
$ sh ping.sh
Result is "Host on" it mean the computer you try to check is a live.
Host on
else computer you try to check is off
Host off
Done