Skip to content

Instantly share code, notes, and snippets.

View wanghaisheng's full-sized avatar
🏠
got a covid like heavy fever for the last days

HeisenBerg? wanghaisheng

🏠
got a covid like heavy fever for the last days
View GitHub Profile
@wanghaisheng
wanghaisheng / 01-mac-profiling.md
Created December 18, 2023 11:18 — forked from loderunner/01-mac-profiling.md
Profiling an application in Mac OS X

Profiling an application in Mac OS X

Finding which process to profile

If your system is running slowly, perhaps a process is using too much CPU time and won't let other processes run smoothly. To find out which processes are taking up a lot of CPU time, you can use Apple's Activity Monitor.

The CPU pane shows how processes are affecting CPU (processor) activity:

@wanghaisheng
wanghaisheng / custom-log-filtering-and-formatting.py
Created October 28, 2023 15:14 — forked from acdha/custom-log-filtering-and-formatting.py
Example of how to filter or apply custom formatting using Python's logging library
#!/usr/bin/env python
# encoding: utf-8
from pprint import pformat, pprint
import logging
class PasswordMaskingFilter(logging.Filter):
"""Demonstrate how to filter sensitive data:"""
@wanghaisheng
wanghaisheng / autotranslate_hardsubs.py
Created July 15, 2023 05:06 — forked from kumorikuma/autotranslate_hardsubs.py
Takes as input a video with hardsubs, and will generate translated softsubs in the target language
# Requirements:
# - ImageMagick binary
# - Windows.Media.Ocr.Cli binary
# - VideoSubFinder binary
#
# Official GCloud Translate Setup:
# First 500k characters / mo is free: https://cloud.google.com/translate/pricing
# Install Python Module: pip install google-cloud-translate
# Setup Google Cloud account and billing information: https://cloud.google.com/
# Make a new project and enable "Cloud Translation API": https://console.cloud.google.com/apis/dashboard
@wanghaisheng
wanghaisheng / ffmpeg.md
Created May 18, 2022 08:00 — forked from protrolium/ffmpeg.md
ffmpeg guide

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

You can get the list of installed codecs with:

@wanghaisheng
wanghaisheng / build_flask_.sh
Created May 8, 2022 12:39 — forked from mrf345/build_flask_.sh
Building one-file executable for Python Flask using Pyinstaller
#!/bin/bash
pyinstaller -F -w \
--hidden-import='email.mime.multipart' \
--hidden-import='email.mime.message' \
--hidden-import='email.mime.text' \
--hidden-import='email.mime.image' \
--hidden-import='email.mime.audio' \
--hidden-import='sqlalchemy.sql.default_comparator' \
--hidden-import='jinja2' \
main.py
@wanghaisheng
wanghaisheng / compress_video.py
Created April 18, 2022 05:23 — forked from ESWZY/compress_video.py
An example Python code for compressing video file to target size.
import os
import ffmpeg
def compress_video(video_full_path, size_upper_bound, two_pass=True, filename_suffix='1'):
"""
Compress video file to max-supported size.
:param video_full_path: the video you want to compress.
:param size_upper_bound: Max video size in KB.
:param two_pass: Set to True to enable two-pass calculation.
:param filename_suffix: Add a suffix for new video.
@wanghaisheng
wanghaisheng / gist:49682cc434e99f0e4c28ed1bee355d0f
Created March 8, 2022 02:54 — forked from eviltester/gist:7beef92896fdd8b638656f996fac38c0
Convert videos into subtitled sections using ffmpeg
# Create a new caption file
~~~~~~~~
ffmpeg -i captions.srt captions.ass
~~~~~~~~
# Add subtitles to main video without changing it
~~~~~~~~
ffmpeg -i video.mp4 -vf "subtitles=captions.ass:force_style='OutlineColour=&H80000000,BorderStyle=4,Outline=1,Shadow=0,MarginV=20'" subtitled-video.mp4
@wanghaisheng
wanghaisheng / ffmpeg-watermark.md
Created December 7, 2021 11:41 — forked from bennylope/ffmpeg-watermark.md
FFmpeg add a watermark to video

How to Add a Watermark to Video

FFMPEG filters provide a powerful way to programmatically enhance or alter videos, and it’s fairly simple to add a watermark to a video using the overlay filter. The easiest way to install ffmpeg is to download a pre-built binary for your specific platform. Then you don’t have to worry about including and installing all the right dependencies and codecs you will be using.

Once you have ffmpeg installed, adding a watermark is as easy as passing your existing source through an overlay filter like so:

ffmpeg -i test.mp4 -i watermark.png -filter_complex "overlay=10:10" test1.mp4

Basically, we’re passing in the original video, and an overlay image as inputs, then passing it through the filter, and saving the output as test1.mp4.

Rank Type Prefix/Suffix
1. Prefix my+
2. Suffix +online
3. Prefix the+
4. Suffix +web
5. Suffix +media
6. Prefix web+
7. Suffix +world
8. Suffix +net
9. Prefix go+
@wanghaisheng
wanghaisheng / python_time.py
Created October 18, 2021 18:55 — forked from junzis/python_time.py
Time conversions in python
from datetime import datetime
import time
#-------------------------------------------------
# conversions to strings
#-------------------------------------------------
# datetime object to string
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
date_str = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
print date_str