ffmpeg Converting i.e 10GB movie into 2GB

ffmpeg -i input.mkv -c:v libx265 -crf 23 output.mkv

 

If selecting video and audio is important for us, then we call first the code below to find out on what positions there is video and specific audio.

ffmpeg -i input.mkv

After we find out positions, we declares them (stream in 0:0 is video, stream in 0:1 is audio)

for %%f in (*.mkv) do (
 ffmpeg -i "%%f" -c:v libx265 -crf 23 -map 0:0 -map 0:1 "compressed-%%f.mp4"
)

 

ffmpeg add hardcoded subtitles to video

This command converts video to video

  • with hardcoded subtitles
  • with forced font size 30
  • with color yellow

ffmpeg -i video.mp4 -vf "subtitles=subtitle.srt:force_style='Fontsize=30,PrimaryColour=&H00ffff&'" "output.mp4"

And this command converts only sample from 120s to 300s

ffmpeg -ss 120 -t 300 -i video.mp4 -vf "subtitles=subtitle.srt:force_style='Fontsize=32,PrimaryColour=&H00ffff&'" output.mp4

And this is the default command just to add subtitles

ffmpeg -i video.mp4 -vf "subtitles=subtitle.srt" "output.mp4"

 

Helper to compare i.e two months in different years

This method will help in comparing two dates by trimming date format to our specific format. So we avoid unnecessary data.

Sample:

We compare two months in different years. First date is:

2017-10-10 10:00

First we convert it to milliseconds using `SimpleDateFormat`.

We want know only time for

2017-10

So after we get millisecond, we can convert it to another one `yyyy-MM-dd` using code below:

public long getTimeInMillis(long milliSeconds, String dateFormat) {
    SimpleDateFormat formatter = new SimpleDateFormat(dateFormat, Locale.forLanguageTag("pl"));
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    String format = formatter.format(calendar.getTime());

    long milli = milliSeconds;

    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.forLanguageTag("pl"));
    try {
        Date parse = sdf.parse(format);
        Calendar c = Calendar.getInstance();
        c.setTime(parse);
        milli = c.getTimeInMillis();
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return milli;
}

Converting transparency color to hex

Here is very interesting post I have found on stackoverflow. I though it is worth to repost here.

Android uses Hex ARGB values, which are formatted as #AARRGGBB. That first pair of letters, the AA, represent the Alpha Channel. You must convert your decimal opacity values to a Hexdecimal value. Here are the steps:

Alpha Hex Value Process

  1. Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5
  2. The fraction won’t convert to hex, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55.
  3. Enter your decimal value in a decimal to hexadecimal converter, like this http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values
  4. If you only get back a single value, prefix it with a zero. For example, if you’re trying to get 5% opacity and your going through this process you’ll end up with the hex value of D. Add a zero in front of it so it appears as 0D.

That’s how you find the alpha channel value. I’ve taken the liberty to put together a list of values for you. Enjoy!

Hex Opacity Values

  • 100% — FF
  • 95% — F2
  • 90% — E6
  • 85% — D9
  • 80% — CC
  • 75% — BF
  • 70% — B3
  • 65% — A6
  • 60% — 99
  • 55% — 8C
  • 50% — 80
  • 45% — 73
  • 40% — 66
  • 35% — 59
  • 30% — 4D
  • 25% — 40
  • 20% — 33
  • 15% — 26
  • 10% — 1A
  • 5% — 0D
  • 0% — 00