2020年7月28日 星期二

MacOS Tips - Command Lines


OSX 終端機使用指含播放 mp3 檔案的方法

  • 使用 afplay 
    • afplay <mp3 filename>
語法說明
$ afplay -h

    Audio File Play
    Version: 2.0
    Copyright 2003-2013, Apple Inc. All Rights Reserved.
    Specify -h (-help) for command options

Usage:
afplay [option...] audio_file

Options: (may appear before or after arguments)
  {-v | --volume} VOLUME
    set the volume for playback of the file
  {-h | --help}
    print help
  { --leaks}
    run leaks analysis
  {-t | --time} TIME
    play for TIME seconds
  {-r | --rate} RATE
    play at playback rate
  {-q | --rQuality} QUALITY
    set the quality used for rate-scaled playback (default is 0 - low quality, 1 - high quality)
  {-d | --debug}
    debug print output


2020年5月13日 星期三

使用 ffmpeg 指令合併的多個MP4檔案


產生 ffmpeg concat 清單
使用指令如下


cd 0512_mp4_files
ls *.mp4 | xargs printf "file '%s'\n" "$1" > filelist.txt

合併用檔案清單 filelist.txt

file '140005.mp4'
file '140106.mp4'
file '140206.mp4'
file '140306.mp4'
file '140406.mp4'
file '140506.mp4'
file '140607.mp4'
file '140707.mp4'
file '140807.mp4'
file '140907.mp4'

執行下列指令合併的多個MP4檔案

使用指令

cd 0512_mp4_files
ffmpeg -f concat -i ./filelist.txt -c copy  your_target.mp4

範例

$ ffmpeg -f concat -i ./filelist.txt -c copy 0512_all.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.17)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags=-fno-stack-check --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd408016200] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from './filelist.txt':
  Duration: N/A, start: 0.000000, bitrate: 1328 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, 1300 kb/s, 20.02 fps, 20 tbr, 90k tbn, 180k tbc
    Metadata:
      creation_time   : 1983-04-09T07:52:37.000000Z
      handler_name    : xsj_vid
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, stereo, fltp, 27 kb/s
    Metadata:
      creation_time   : 1983-04-09T07:52:37.000000Z
      handler_name    : xsj_aud
Output #0, mp4, to '0512_all.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, q=2-31, 1300 kb/s, 20.02 fps, 20 tbr, 90k tbn, 90k tbc
    Metadata:
      creation_time   : 1983-04-09T07:52:37.000000Z
      handler_name    : xsj_vid
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, stereo, fltp, 27 kb/s
    Metadata:
      creation_time   : 1983-04-09T07:52:37.000000Z
      handler_name    : xsj_aud
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd408016200] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd409004800] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 1920672, current: 1920000; changing to 1920673. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 1920673, current: 1920160; changing to 1920674. This may result in incorrect timestamps in the output file.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd407800000] Auto-inserting h264_mp4toannexb bitstream filter
[concat @ 0x7fd408009800] DTS 16200000 < 16203870 out of order
...
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd409004800] Auto-inserting h264_mp4toannexb bitstream filter
[concat @ 0x7fd408009800] DTS 640980000 < 640988370 out of order
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:0; previous: 640988370, current: 640980000; changing to 640988371. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 113953720, current: 113952000; changing to 113953721. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:0; previous: 640988371, current: 640980900; changing to 640988372. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 113953721, current: 113952160; changing to 113953722. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:0; previous: 640988372, current: 640985400; changing to 640988373. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 113953722, current: 113953232; changing to 113953723. This may result in incorrect timestamps in the output file.
frame=144301 fps=11366 q=-1.0 Lsize= 1171225kB time=01:59:42.11 bitrate=1335.9kbits/s speed= 566x

video:1143434kB audio:24298kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.299121%

2020年5月4日 星期一

[TIPS] Git 常用指令範例匯整 (Useful use cases)


移除已合併的分支

問題

當多人協作時,其他成員 git merge 後,自動刪除來源時,
執行指令 git pull 有出現下列訊息:

Your configuration specifies to merge with the ref 'refs/heads/feature/your-branch-merged'
from the remote, but no such ref was fetched.


解決方法

git update command

使用指令如下擇一:

git remote update -p

# or


git remote update -prune


查看 Log 方法

date: 2020/05/13 v1
使用指令範例:

git log --oneline   # 列出全部的 commits

git log --oneline | head -n 5 # 列出最近5個 commits
Learnings$ git log --oneline | head -n 5
e4fea6a [new/make] syntax: value script and sorted filter out
509768f [new/make] example syntax to filter duplicated item by...
289b59d [fix/java] revise code to build on osx with android studio
a37b0fe [new/jni] example build script

336fce5 [new/py] create image file using pillow



2019年10月23日 星期三

[TIPS] 檢查CPU溫度 Raspberry PI


命令

 /opt/vc/bin/vcgencmd

CPU溫度


pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd version

Jul  9 2019 14:40:53

Copyright (c) 2012 Broadcom

version 6c3fe3f096a93de3b34252ad98cdccadeb534be2 (clean) (release) (start)

pi@raspberrypi:~ $ uname -a

Linux raspberrypi 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux

pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd measure_temp

temp=45.1'C

2019年9月23日 星期一

阿班 Bash 常用指令範例

Last Modified Date: 2025-03-28

mkdir

Date: 08-27 v1
建立新目錄

語法


mkdir  [-p]  <目錄名>


OPTION

無參數: 如果該目錄不存在,才建立它。若該目錄在則顯示目錄已存在錯誤訊息,並且回傳值為1 
-p: 如果該目錄不存在,才建立它。若該目錄在則略過,並且回傳值為 0

範例


$ mkdir new_directory
$ mkdir new_directory
mkdir: can't create directory 'new_directory': File exists
$ echo $?
1
$ mkdir -p new_directory
$ echo $?
0




mktemp


Date: 05-14 v1
產生暫存檔案或目錄

語法


mktemp [OPTION] ... [TEMPLATE]

OPTION

-u: --dry-run 不產生任何檔案或目錄,只顯示名稱 (不安全, 僅供測試, 因為有可能重複產生)

範例

$ mktemp -u /you_path/path2/your_prefix.XXXXXXXXXX

/you_path/path2/your_prefix.zjvveu0Ncs

# mktemp /tmp/your_prefix.XXXXXXXXXX
/tmp/your_prefix.5eEu7vU0zi
# ls -la /tmp/your_prefix.5eEu7vU0zi

-rw------- 1 test test 0 May 15 00:06 /tmp/your_prefix.5eEu7vU0zi


read

語法

read [argument1] [argument2] ...

範例

$ bash read_example_01.sh
./type_example_01.sh
./read_example_01.sh
$ find . -type f | while read filename ; do echo "$filename" ; done
./type_example_01.sh
./read_example_01.sh


sed

刪除空白行

語法

 sed -e "/^$/d" 

範例


bash-5.0# echo -e "te\n\nst" | sed "/^$/d"
te
st

type

語法

type command1 command2 ...

範例

a() { echo 'a'; }
b() {
  echo 'b'
}

c()
{
  echo 'c'
}

# type is a shell builtin
type a b c


執行結果

$ bash type_example_01.sh
a is a function
a ()
{
    echo 'a'
}
b is a function
b ()
{
    echo 'b'
}
c is a function
c ()
{
    echo 'c'
}


如果 type 配合 grep 指令把 is a function 去掉,則有自動排版函式的效果。

$ bash type_example_01.sh  | grep  -v "is a function"
a ()
{
    echo 'a'
}
b ()
{
    echo 'b'
}
c ()
{
    echo 'c'
}

xargs

語法

xargs [argument1] [argument2] ...

範例

bash-5.0# find . -type f | xargs wc -l | sed -e "s/^[ \t]*//g"
2 ./b.txt
1 ./c.txt
3 ./a.txt
6 total