Android Custom Ringtone

Samsung/HTC/LG all have a configuration entry for setting a custom ringtone,
heck! you can even select a MP3 file out of your External-SDCard!

For ROMs such as AOSP or LineageOS, you will have to walk through some extra steps in-order to add some custom sounds.

Continue reading

FFMPEG – Pre-Fill File Duration Into FFMPEG’s MP3-Concatenation File-List, Using FFPROBE

This is will generate a text file filed with all the mp3 files in the folder,
it will also PRE QUERY each file using FFPROBE and will add the result to the file,
helping to avoid sync-or-duration problems.

ffprobe supports built-in formatting, which might help you avoid using external commands such as cut, sed, grep, etc… .

Continue reading

FFMPEG – Real Proper Hard-Burn Subtitle Onto A Video

Full Hebrew Support. No gibberish.

    Use Subtitle-Workshop📎︎ and save your subtitle as .ass(Advanced SubStation Alpha).
  2. Resolve Gibberish.
    Open the .ass file using either:
    – Notepad2 📎︎ and click File→Encoding→UTF-8
    – Notepad++ 📎︎ and click Encoding→Encode in UTF-8 without BOM.
  3. Better Presentation.
    Open the .ass file using Notepad2 or Notepad++, and replace:

    Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
    Style: Default,Tahoma,24,&H00FFFFFF,&H00FFFFFF,&H00FFFFFF,&H00C0C0C0,-1,0,0,0,100,100,0,0.00,1,2,3,2,20,20,20,1


    Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
    Style: Default,Tahoma,20,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,1,0,2,10,10,20,1

    You may change the font-family, font-size, border color, etc.. to your liking..

  4. Run:
    ffmpeg -i video.mp4 -vf "ass=subtitle.ass" out_video.mp4
    or : ffmpeg -hide_banner -y -i "video.mp4" -filter_complex "[0:v]ass=subtitle.ass[VIDEO];" -map "[VIDEO]" -preset veryslow -crf 21 -pix_fmt yuv420p -movflags "+faststart" out_video.mp4 (advance filtering example).

FFMPEG Use In Product Review For Time-Lapse

I’ve bought 3 clocks from eBay seller (good4deal999) that offered a “Travel Quartz” quality clocks,

When two of the 3 started showing wrong hour I’ve decided to record them all together for as long as my phone’s camera will allow (two hours with the lowest pixel settings)

They are all the SAME initial state (the one on the left is just at an angle to the camera)

In-fact the one on the right even got the first battery, so it should, be ahead in few seconds but it is delayed for -5 minutes every ~hour.
The one in the middle is just F*CKED up entirely. the one on the left, as the ONLY one actually working :..(

– – – – – –
Took it with my Samsung phone on tripod.
Original file: 20160912_003810.mp4
Recorded video was two hours and 18 minutes (2:18:23) and about 3 Gigabytes (3.22GB)
Resolution is VGA 640x480, which is quite low but in close-up.
In order to rotate it (filmed on the side), fix it (double frames due to Samsung’s camera bug), remove background sound of me (kind’a) snoring (it was just before bed), make it ready for web-streaming better and speed it up x5 times more fast (which saves me uploading 3Giga, plus it helps identify the problem better
I’ve used the following FFMPEG command line:

ffmpeg -y -hide_banner -i 20160912_003810.mp4 -an -vf "transpose=2,mpdecimate,setpts=N/FRAME_
RATE/TB,setpts=0.2*PTS" -preset veryslow -tune zerolatency -pix_fmt yuv420p -movflags "+faststart" -crf 23 "output.mp4"

Full FFMPEG Output:
Continue reading

FFMPEG – Extract All Keyframes, But Don’t Fill Your Hard-Drive…


The following line will
– extract (well.. generate) an keyframe representing image, of EVERY keyframe image in your video file,
– a “ratio-correct” 100 pixel width image,
– a loosely JPEG output with quality of 15, which is about 53% (from 0-100) in terms of quality where 100 is highest quality and 0 is lowest quality,
– all total it will be a lot (!) of files, but 100 files will weight (size) in ~67.2 KB,
which if you’ll be using this command to generate a way of (let’s say..) trimming a video by visually showing the keyframes, and providing a range collector (..for example), will still generate nice output,

you can even stretch it a bit (in client side!) so it will “look bigger” if you’ll keep the 100x? ratio (which is easy to remember, right?)

ffmpeg -threads 4 -i my_movie.mp4 -vf "select=eq(pict_type\,I)" -vsync vfr -filter:v scale=100:-1,crop=iw:ih*0.8 -q:v 15 -qscale:v 15 out%05d.jpg

Here are the first ~~52 frames of this YouTube video:

Continue reading

FFMPEG – High-Interest Video Thumbnails

  • ffmpeg is capable of measuring the difference between every scene,
    and you may specify you want the difference to be above/below some rate to include that thumbnail.
  • black/white/uni-color screens are common as a transition, and are not a “problem”, we should generate quite a lot of thumbnails, and storing them as JPG (loosely format), which has very high compression rate for uni-color images, web can sort the images by size (later) and just remove that below 1kb images.
  • the same issue can also be addressed by performing quite large jumps into the movie, which in-turn also generate a more story-line variety.
  • Just Good Business:
    – Keeping thumbnails small enough, undistorted (in ratio) can be easily achieved by limiting the width to 200 pixels, together with height-ratio matching and smart-cropping, this way, in-image is mostly undisrupted, cropped without missing important-ingredient and provide unified size.
    – zero-padded output file name can help with sorting on older systems that might sort 10.jpg right after 1.jpg in normal cases (Windows XP/NT and below).
ffmpeg -ss 100 -i my_movie.mp4 -vf "select=gt(scene\,0.1)" -frames:v 50 -filter:v scale=200:-1,crop=iw:ih*0.8,fps=1/10 out%04d.jpg

for example this ~4minutes YouTube Video:

Continue reading

FFMPEG extract subtitle file from mkv video file

MKV (Matroska video/audio multimedia file) is a container like MOV and AVI, providing support for a huge number of different video, audio and subtitles compression formats. It is not really intended for media content distribution on a large scale, but is achieving it anyway.

MKV support several subtitles streams to be embedded along side the video/audio streams (several subtitle formats supported including SRT, SSA and USF text subtitles, or VobSub streams coming directly from the DVD).


** usage should be purely academic or for free/open license content only **


step #1 is getting some information on the streams in the video files (specifically, their identification in the list of embedded streams)

ffmpeg -i myVideo.mkv

on this example we will get a similar list:

Stream #0:0(eng): Video: h264 (High), yuv420p, 1912x796 [SAR 1:1 DAR 478:199], 23.98 fps, 23.98 tbr, 1k tbn, 2k tbc (default)
Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
Stream #0:2(eng): Subtitle: subrip
Stream #0:3(eng): Subtitle: subrip
Stream #0:4(spa): Subtitle: subrip
Stream #0:5(fre): Subtitle: subrip
Stream #0:6(por): Subtitle: subrip
Stream #0:7(gre): Subtitle: subrip
Stream #0:8(pol): Subtitle: subrip


step #2

extracting the English subtitle (first one on the list)
*note: due to some limitations we would need to demux it out (kind’a re-encoded it) which takes about 2 minutes.

ffmpeg -threads 4 -i myVideo.mkv -vn -an -codec:s:0.2 srt

extracting the Spanish stream is similar

ffmpeg -threads 4 -i myVideo.mkv -vn -an -codec:s:0.4 srt



-threads 4

will not be usable here due to mkv extraction of this stream could only be single threaded, but its good practice to use this annotation anyway on FFMPEG commands. just because some streams do support multi-threading processing.
you can always run the commands above in few separated command-line window, to make this process parallel (through multi-process) and save some time.


FFMPEG Video Crop

Use FFMPEG’s stream copy combined with the basic crop-by-time command

ffmpeg -threads 4 -ss 00:06:12 -t 00:01:20 -i inVideo.mp4 -vcodec copy -acodec copy outVideo.mp4

starting the 6th minute, and 12 seconds into the video (this is the start point for the cut), measure length of 1 minute and 20 seconds, and, using 4 threads, without re-encoding audio nor video stream, put data into new out file.

-threads 4

is optional, but recommended.

FFMPEG Fixes Your Video Files


FFMPEG’s stream copy is a mode that is really helpful to solve video glitches, slowness due to bad video-index, etc..

In that mode, ffmpeg omits the decoding and encoding step for the specified stream, so it does only demuxing and muxing (its very fast). It is useful for changing the container format or modifying container-level metadata. The diagram above will, in this case, simplify to this:

 _______              ______________            ________
|       |            |              |          |        |
| input |  demuxer   | encoded data |  muxer   | output |
| file  | ---------> | packets      | -------> | file   |
|_______|            |______________|          |________|


Since there is no decoding or encoding, it is very fast (few seconds for demuxing and muxing for full size 2 hours video), and there is no quality loss. However, it might not work in some cases because of many factors. Applying filters is obviously also impossible (since filters work on uncompressed data).

ffmpeg -threads 4 -i vid.avi -vcodec copy -acodec copy vidout.avi

the -threads 4 is optional, but recommended.

Continue reading