Wednesday, December 21, 2022

FFMPEG command Cheat Sheet

I've made many FFMPEG command lines over the years and keep losing track of them. 

I've decided to post them here in a list and edit them as I find / make more.


Create a time lapse video from an input file, one frame every 15 frames, maximum VBR quality, rotate 90 degrees counterclockwise and vertical flip, delete audio and encode with h.265 using cuda and nvenc on a nvidia graphics card.

ffmpeg.exe -hwaccel cuda -i input.MP4  -vf framestep=15,setpts=N/60/TB,fps=60,transpose=0 -c:v hevc_nvenc -rc vbr -cq 0 -qmin 0 -qmax 1 -profile:v main10 -pix_fmt p010le -b:v 0K -an -max_interleave_delta 0 output.mkv


Combine an input video and two separate mono audio tracks into a single video file, encoding with dxva using nvenc on a nvidia graphics card. Example input would be video exported from Davinci Resolve

ffmpeg -y -hwaccel_output_format d3d11 -hwaccel d3d11va -i "video.mxf" -i "A01.mxf" -i "A02.mxf"  -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" -map 0:v -c:v hevc_nvenc -rc vbr -cq 10 -qmin 6 -qmax 14 -profile:v main10 -pix_fmt p010le -b:v 0K out.mp4

Same as above but on an AMD/ATI card and with bitrate set to 100 megabit

ffmpeg -y -hwaccel_output_format d3d11 -hwaccel d3d11va -i '.\video.mxf' -i '.\A01.mxf' -i '.\A02.mxf'  -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" -c:a pcm_s16le -map 0:v -c:v hevc_amf -b:v 100M "out.mkv"


Trapezoid transform a video with perspective example, trim a bit off the left top and left bottom of a 4k vertical video

Top left corner 29:490

Top right corner 2160:0

Bottom left corner 76:3241

Bottom right corner 2160:3840


-lavfi "perspective=29:490:2160:0:76:3241:2160:3840:interpolation=linear"

Tuesday, September 27, 2022

How to fix broken MP4 Videos for free

 if you have any broken mp4s, such as mov atom missing from your phone/camera/card dying during recording..


This gnu v2 app works Awesome!

https://github.com/ponchio/untrunc


I used it a few days ago to repair a video from a drone that was corrupted


I have a paid app on my android that I was using but it couldn't figure out the drone video so I had to find an alternative, this one worked much better


I used an Ubuntu virtual machine and followed the instructions on that page and fixed my video.

Friday, August 19, 2022

 If you get

./mp4grep/bin/mp4grep: error while loading shared libraries: libvosk.so: cannot open shared object file: No such file or directory

You probably need to run ldconfig on the folder containing libvosk

in my case it was

sudo ldconfig /home/nate/.local/lib/

Monday, February 21, 2022

I wrote a python program to put a taskbar icon with the CPU IDLE Percentage over time.

Lots of this is copied from stackoverflow of course..

This is what it looks like: 


from infi.systray import SysTrayIcon
from PIL import Image, ImageDraw,ImageFont
import time
import psutil
import threading
import wx
import wx.adv
import datetime
from wx.lib.embeddedimage import PyEmbeddedImage

def background():
while True:
uptime = time.time() - psutil.boot_time()
global idle_ratio
idle_ratio = psutil.cpu_times().idle / psutil.cpu_count() / uptime * 100
d = uptime // (24 * 3600)
uptime = uptime % (24 * 3600)
h = uptime // 3600
uptime %= 3600
m = uptime // 60
uptime %= 60
s = uptime
print(idle_ratio)
time.sleep(10)
if stop_threads:
break
global stop_threads
stop_threads = False
# print(f"Uptime: {d:n}d {h:02n}:{m:02n}:{s:02n} - Idle Ratio: {idle_ratio:02.2f}%")


b = threading.Thread(name='background', target=background)
print("starting thread")
b.start()
print("\nIdle ratio:")
print(idle_ratio)
#
# A white box 28x28 pixels
#
toggletest = PyEmbeddedImage(
b'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAIAAAD9b0jDAAAACXBIWXMAAAsTAAALEwEAmpwY'
b'AAAAB3RJTUUH4wMfCgElTFaeRQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJ'
b'TVBkLmUHAAAAKElEQVRIx2P8//8/A7UBEwMNwKiho4aOGjpq6Kiho4aOGjpq6OAzFADRYgM1'
b'8cIRtgAAAABJRU5ErkJggg==')

class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
self.toggle = 0
wx.adv.TaskBarIcon.__init__(self)
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnToggle)
self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
self.font.SetPointSize(4)
self.OnSetIcon(self.NewIcon())

def CreatePopupMenu(self):
menu = wx.Menu()
togglem = wx.MenuItem(menu, wx.NewId(), 'Toggle Icon')
menu.Bind(wx.EVT_MENU, self.OnToggle, id=togglem.GetId())
menu.Append(togglem)
menu.AppendSeparator()
flashm = wx.MenuItem(menu, wx.NewId(), 'Flashing Icon')
menu.Bind(wx.EVT_MENU, self.OnTimer, id=flashm.GetId())
menu.Append(flashm)
menu.AppendSeparator()
quitm = wx.MenuItem(menu, wx.NewId(), 'Quit')
menu.Bind(wx.EVT_MENU, self.OnQuit, id=quitm.GetId())
menu.Append(quitm)
return menu

def NewIcon(self):
bitmap = wx.Bitmap(toggletest.Bitmap)
dc = wx.MemoryDC(bitmap)
# Use current time as text, for want of something useful
dc.SetFont(self.font)
ratio = str(idle_ratio)
dc.DrawText(ratio, 0, 7)
del dc
return bitmap

def OnSetIcon(self, bitmap):
icon = wx.Icon()
icon.CopyFromBitmap(bitmap)
self.SetIcon(icon)

def OnToggle(self, event):
bitmap = self.NewIcon()
self.OnSetIcon(bitmap)

def OnTimer(self,event):
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnUseTimer)
self.timer.Start(10000)

def OnUseTimer(self,event):
self.OnToggle(None)

def OnQuit(self, event):
self.RemoveIcon()
wx.CallAfter(self.Destroy)
self.frame.Close()
global stop_threads
stop_threads = True


if __name__ == '__main__':
app = wx.App()
frame=wx.Frame(None)
TaskBarIcon(frame)
app.MainLoop()

Wednesday, February 2, 2022

 Python script I found on stack exchange that was hard to understand so I modified it to make it better.

This script adds the glob feature from ffmpeg *.jpg or *.png etc image sequences to windows.


import subprocess
import glob
import os

filenames = glob.glob("path/to/folder*.jpg")
duration = 0.05

with open("ffmpeg_input.txt", "wb") as outfile:
for filename in filenames:
outfile.write(f"file '{filename}'\n".encode())
outfile.write(f"duration {duration}\n".encode())

command_line = f"ffmpeg -y -r 60 -f concat -safe 0 -i ffmpeg_input.txt out.mp4"
print(command_line)

pipe = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE).stdout
output = pipe.read().decode()
pipe.close()

Saturday, January 15, 2022

 For years I've been complaining about how terrible Windows search is. Today I posted on a chatroom "why is it that it's 2022 and C:\>dir /b /s |findstr *str* is still the fastest way to search for files"


Someone replied, 'everything is pretty nice'


This is going to change my life... D:


Everything is the best search program for windows i've ever used.. I love it!!!


You're welcome:


https://www.voidtools.com/