Drag'n'drop to compress/edit video using ffmpeg

Written by pmd - - no comments

1. Download ffmpeg

Link to download ffmpeg: https://github.com/BtbN/FFmpeg-Builds/releases

2. Create a *.bat file

compress_video_multiple_file.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input=%%A
    ECHO !input!
    SET "output=!input!.compressed.mp4"
    ECHO !output!
    ::"C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input!  -vcodec h264      -acodec mp3 !output!
    "C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input! -vcodec libx264 -preset veryfast -crf 23 -g 30    -acodec aac !output!
)
pause
pause
::  OTHER THING YOU COULD PUT IN THE COMMAND LINE:
::  ----------------------------------------------
::                                                   HORIZONTAL       VERTICAL
::  TO CHANGE OUTPUT RESOLUTION to 1080p (HD) =>  -s "1920x1080"   -s "1080x1920"
::                              to  720p (HD) =>  -s "1280x720"    -s "720x1280"
::                              to  480p (SD) =>  -s "854x480"     -s "480x854"
::                              to  360p (SD) =>  -s "640x360"     -s "360x640"
::                              to  240p (SD) =>  -s "426x240"     -s "240x426"
::  
::  TO KEEP ONLY SOME TIME (HH:mm:ss)         =>  -ss 00:00:20 -to 00:00:40
:: 

Discussion about ffmpeg command line to use: Compress mp4 using FFMPEG · GitHub

Setting a variable into a for loop (batch)

3. Create a shortcut on Desktop and drag'n'drop

It will create a new file in same path than the video you want to compress with following name: "original_file_name.extension.compressed.mp4".
You can drag'n'drop several files.

4. Other ffmpeg tricks

add_png_watermark_in_center.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input=%%A
    ECHO !input!
    SET "output=!input!.watermarked.mp4"
    ECHO !output!
    "C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input! -i "C:\path\to\some_text.png" -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.1[logo];[0][logo]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p" -c:a copy !output!
)
pause
:: https://stackoverflow.com/questions/10918907/how-to-add-transparent-watermark-in-center-of-a-video-with-ffmpeg
::
:: Centered: overlay=(W-w)/2:(H-h)/2
:: Top left: overlay=5:5
:: Top right: overlay=W-w-5:5
:: Bottom right: overlay=W-w-5:H-h-5
:: Bottom left: overlay=5:H-h-5
:: Transparency / opacity / alpha: adjust aa=0.1

 

add_text_watermark_in_center.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input=%%A
    ECHO !input!
    SET "output=!input!.watermarked.mp4"
    ECHO !output!
    SET /p stuff="What text do you want ? ":
    "C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input! -vf "drawtext=text='!stuff!':x=(w-text_w)/2:y=h-th-30:fontfile='C\:/\Windows/\Fonts/\calibrib.ttf':fontsize=48:fontcolor=white:alpha=0.9" -c:a copy !output!
)
pause
:: https://superuser.com/questions/939357/how-to-position-drawtext-text
::
:: Top left: x=0:y=0 (with 10 pixel padding x=10:y=10)
:: Top center: x=(w-text_w)/2:y=0 (with 10 px padding x=(w-text_w)/2:y=10)
:: Top right: x=w-tw:y=0 (with 10 px padding: x=w-tw-10:y=10)
:: Centered: x=(w-text_w)/2:y=(h-text_h)/2
:: Bottom left: x=0:y=h-th (with 10 px padding: x=10:y=h-th-10)
:: Bottom center: x=(w-text_w)/2:y=h-th (with 10 px padding: x=(w-text_w)/2:y=h-th-10)
:: Bottom right: x=w-tw:y=h-th (with 10 px padding: x=w-tw-10:y=h-th-10)

 

add_time_at_end.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input=%%A
    ECHO !input!
    SET "output=!input!.extended.mp4"
    ECHO !output!
    SET /p stuff="How long do you need to add at the end of video in seconds ? ":
    SET /a "stuffminus=!stuff!-1"
    "C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input! -filter_complex "  [0:v]tpad=stop_mode=clone:stop_duration=!stuff!,setpts=PTS-STARTPTS[v];  [0:a]apad=pad_dur=!stuff!,asetpts=PTS-STARTPTS[a]" -map "[v]" -map "[a]" -c:v libx264 -c:a aac -r 29.917  !output!
)
pause

 

add_time_in_beginning.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input=%%A
    ECHO !input!
    SET "output=!input!.preextended.mp4"
    ECHO !output!
    SET /p stuff="How long do you need to add at begining of video in seconds ? ":
    SET /a "stuffminus=!stuff!-1"
    "C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input! -filter_complex "  [0:v]trim=start=0:duration=1,select=eq(n\,0),scale=iw:ih,setsar=1,fps=1,loop=!stuffminus!:1:0,setpts=N/(1*TB)[vintro];  [0:v]setpts=PTS-STARTPTS[vmain];  [vintro][vmain]concat=n=2:v=1:a=0[v];  anullsrc=channel_layout=stereo:sample_rate=48000,atrim=duration=!stuff![asilence];  [0:a]atrim=start=0,asetpts=PTS-STARTPTS[aoriginal];  [asilence][aoriginal]concat=n=2:v=0:a=1[a]" -map "[v]" -map "[a]" -c:v libx264 -r 29.917 -c:a aac -shortest !output!
)
pause

 

merge_two_video_verticaly.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET n=0
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input[!n!]=%%A
    ECHO !input[%n%]!
    SET "output=!input[%n%]!.no_in_use.mp4"
    ECHO !output!
    SET /A n+=1
)
"C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input[0]! -i !input[1]! -filter_complex "[0:v][1:v]hstack=inputs=2[v];[0:a]volume=1.0[a0];[1:a]volume=0.1[a1];[a0][a1]amix=inputs=2[a]" -map "[v]" -map "[a]" -c:v libx264 -c:a aac -strict experimental -shortest -r 29.917 output_merged.mp4
pause
:: https://stackoverflow.com/questions/11552565/vertically-or-horizontally-stack-mosaic-several-videos-using-ffmpeg

 

accelerate_video_multiple_file.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input=%%A
    ECHO !input!
    SET "output=!input!.speed2x.mp4"
    ECHO !output!
    "C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -i !input! -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2[a]" -map "[v]" -map "[a]" !output!
)
pause

 

concatenate_two_video.bat

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET n=0
FOR %%A IN (%*) DO (
    ECHO %%A
    SET input[!n!]=%%A
    ECHO !input[%n%]!
    SET "output=!input[%n%]!.no_in_use.mp4"
    ECHO !output!
    SET /A n+=1
)
"C:\path\to\ffmpeg-master-latest-win64-gpl\bin\ffmpeg" -y -i !input[0]! -i !input[1]! -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output_concatenated.mkv
pause
:: https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg

FFmpeg Filters Documentation #drawtext

AutoHotkey scripts for keyboard shortcuts

Written by pmd - - no comments

How do I put my hotkeys and hotstrings into effect automatically every time I start my PC?

There are several ways to make a script (or any program) launch automatically every time you start your PC. The easiest is to place a shortcut to the script in the Startup folder:

  1. Find the script file, select it, and press Ctrl + C.
  2. Press Win + R to open the Run dialog, then enter shell:startup and click OK or Enter. This will open the Startup folder for the current user. To instead open the folder for all users, enter shell:common startup (however, in that case you must be an administrator to proceed).
  3. Right click inside the window, and click "Paste Shortcut". The shortcut to the script should now be in the Startup folder.

Source

Activate a AutoHotkey script

Double-click to run *.ahk script. It will show up in the notification area.

Script #1: Insert Date in Any Program Using Keyboard Hotkey

^!d::                                               ; CTRL + ALT + D
    KeyWait, d                                      ; wait for d to be released
    KeyWait, d, D T0.2                              ; and pressed again within 0.2 seconds
    If ErrorLevel {                                 ; if timed-out (only a single press)
        FormatTime, CurrentDateTime,, yyyy_MM_dd_
        SendInput, %CurrentDateTime%
    }
    Else {                                          ; if not timed-out (double press)
        FormatTime, CurrentDateTime,, dd/MM/yyyy
        SendInput, %CurrentDateTime%
    }
return

Press Ctrl + Alt + D and it will print a date in this format: « 2022_01_14_ »
Press Ctrl + Alt + D + D and it will print a date in this format: « 14/01/2022 »

Source + FormatTime - Syntax & Usage | AutoHotkey

Script #2: Cursor Highlighter

Source

 

Classified in : Office - Tags : none

CSV editor

Written by pmd - - no comments

This script is working under Windows 7 and Windows 10 using Busybox.
To start it I made a shortcut to "busybox.exe sh -l".

To edit CSV for better and easier human reading.

#!/bin/bash
# File to be modified
FILE_IN="$1"
# Output file to be generated
FILE_OUT=$(echo -n "$FILE_IN" | sed 's@.csv@_mod.csv@g')
cp $FILE_IN $FILE_OUT

# delete all empty lines after header (header is 11 lines long)
sed -i '12,${\@^$@d;}' $FILE_OUT

# put back all samples together (delete in-file headers except first one)
sed -i '12,${\@Arming date:@{N;N;d}}' $FILE_OUT

# replace long path by short path of variables
# before: CPU1/CPU_fast//CPU_fast/appli/test/sf_12/do_low_power_tests/n_lpt
# after: CPU1/n_lpt
LINE_TO_MODIFY=$(cat $FILE_OUT | grep "/")
LINE_MODIFIED=$(echo -n "$LINE_TO_MODIFY" | sed -e 's@/[^;]*/@/@g')
echo "Old line to modify:"
echo "$LINE_TO_MODIFY"
echo
echo "New line modified:"
echo "$LINE_MODIFIED"

# remove and replace variable names with short path
sed -i "s@$LINE_TO_MODIFY@$LINE_MODIFIED@g" $FILE_OUT

Excel tricks

Written by pmd - - no comments

1- Generate a calendar in Excel

Here is how to generate a calendar in Excel. Using Excel 2010 in my case.

In cell B1 (by example), put a date :

01/06/2018

In cell B2 :

=IF(
MONTH(DATE(YEAR(B$1);MONTH(B$1);CELL("row";B2)-CELL("row";B$1)))=MONTH(B$1);
DATE(YEAR(B$1);MONTH(B$1);CELL("row";B2)-CELL("row";B$1));"")

Then you just have to drag-n-drop down and right (or left).

To highlight saturdays and sundays :

=IF(ISBLANK(B2)=FALSE;OR(IF(WEEKDAY(B2)=7;TRUE;FALSE);IF(WEEKDAY(B2)=1;TRUE;FALSE));FALSE)

Here is the result :<image>

2- Number of days in one month

Put a date in cell B1. Then in another cell, formula is :

=DAY(DATE(YEAR(B1);MONTH(B1)+1;0))

It will return the number of days of the month in cell B1.

Rss feed of the category