UP | HOME
Sachin Patil

Sachin

Free Software developer & Emacser

Handy commands

Published on Oct 09, 2016 by Sachin.

List of commands that I find useful.

(Last updated on March 05, 2019)

PDF tricks

  • Reduce PDF size

    gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -sOutputFile=new_file.pdf original_file.pdf
    
  • Unlock PDF file

    gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf
    
  • Extract pages from PDF file

    gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1 -dLastPage=3 -sOutputFile=out_file_page_1_to_3.pdf input_file.pdf
    

Media tricks

  • Rotate video

    1: # Using mplayer(watch rotated video)
    2: mplayer -vf-add rotate=1 sample.mp4
    3: 
    4: # Using ffmpeg
    5: ffmpeg -i infile.mp4 -strict -2 -vf "transpose=1" outfile.mp4
    
  • Convert 3GP to MP4

    ffmpeg -i VID_0050.3gp -strict -2 -q:a 0 -ab 64k -ar 44100 VID_0050.mp4
    
  • FLV to MP4

    ffmpeg -i input.flv -qscale 1 -ar 22050 output.mp4
    
  • MKV to MP4

    ffmpeg -i input.mkv -c:v mpeg4 -c:a libmp3lame -b:a 128K output.mp4
    # or you can keep the video stream
    ffmpeg -i input.mkv -c:v copy -c:a aac -b:a 128K output.mp4
    
    # Convert initial 10 seconds of the video for testing
    ffmpeg -t 10 -i input.mkv -c:v copy -c:a aac -b:a 128K output.mp4
    
  • PS4 compatible format (Special thanks to the Guys at #ffmpeg@freenode for helping me converting to the PS4 compatible format)

    1: # Ex1
    2: ffmpeg -i input.mkv -c:v libx264 -c:a libmp3lame -preset slow -profile:v high -level 4.2 -b:a 320K output.mkv
    3: # Ex2
    4: ffmpeg -i input.mkv -c:v libx264 -vf format=yuv420p -c:a libmp3lame -preset slow -profile:v high -level 4.2 -b:a 320K output.mkv
    5: # Ex3
    6: ffmpeg -i input.mkv -c:v libx264 -vf format=yuv420p -c:a libmp3lame -preset slow -profile:v high -level 4.2 -crf 21 -b:a 320K output.mkv
    7: # Ex4
    8: ffmpeg -i input.mkv -c:v libx264 -vf format=yuv420p -c:a aac -preset slow -profile:v high -level 4.2 -crf 21 -b:a 128K output.mkv
    

    Refer this post to compile ffmpeg with lame & libx264 support.

  • Extract audio(MP3) from MP4 video

    1: ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3
    2: 
    3: # or specify codec to use `libmp3lame` in this case.
    4: ffmpeg -i video.mp4 -f mp3 -codec:a libmp3lame -ab 320000 -vn music.mp3
    

    where

    -i: input file

    -f mp3: file format should be MP3

    -ab 192000: audio should be encoded at 192Kbps. 320000 for 320Kbps

    -vn: don’t want video

  • Cut video starting from 19 min 49 seconds up to 04 mins 18 seconds.

    ffmpeg -y -i Video.mp4 -qscale 1 -ss 00:19:49.0 -t 00:04:18.0 -acodec copy -vcodec copy output.mp4
    

    Note: -sameq was removed in the recent version of ffmpeg

  • Use mplayer to extract audio(MP3)

    mplayer -dumpaudio movie.flv -dumpfile movie_audio_track.mp3
    
  • Reduce resolution

    ffmpeg -i Birdman.mp4 -strict -2  -s 720x480 birdman.mp4
    
  • recordmydesktop

    recordmydesktop -x 100 -y 100 --width 1280 --height 720 --freq 48000 --fps 30 -o ~/Videos/recordings/test-video.ogv
    
  • Include subtitles(Use subtitleeditor to create subtitle)

    ffmpeg -i video.avi -vf subtitles=subtitle.srt out.avi
    

Image manupulation

  • Capture screenshot

    import -window root screenshot.png
    
  • Resize image 50% of its original size

    convert dragon.gif -resize 50% half_dragon.gif
    
  • Control compression level of an image

    convert input.png -quality 75 output.jpg
    

Git

  • Find commits by author between the timeline

    1: # Syntax
    2: git log --since "START" --until "END" --author=AUTHOR --pretty=oneline --diff-filter=A
    3: 
    4: # Example
    5: git log --since "Oct 1 2018" --until "DEC 28 2018" --author=psachin@redhat.com --pretty=oneline --diff-filter=A
    6: 
    7: # If you also want to see the file names
    8: git log --since "Oct 1 2018" --until "DEC 28 2018" --author=psachin@redhat.com --name-status --pretty=oneline --diff-filter=A
    

Misc

  • SOCKS proxy using SSH

    ssh -N -D 1080 user@server
    

    where

    -N: Do not execute remote commands.

    -D: [bind address:]port (Port in above example)

  • Clean up ~/.ccache/ directory

    1: # View statistics using
    2: ccache -s
    3: 
    4: # Clear cache using
    5: ccache -C
    
  • wget a website

    wget -rkp -l5 -np -nH -cut-dirs=1 https://example.com
    

    where

    -rkp: recursive, make link suitable for local viewing, download all files needed to properly view the page.

    -l5: recursively download 5 links away form the original page.

    -n: retrieve files below parent directory.

    -H: Span across hosts when doing recursive retrieving.