Skip to content

Instantly share code, notes, and snippets.

# cheaply convert container only, given compatible internal codecs
ffmpeg -i ../panama_loop/WtoxxHADnGk_0820.ts -map 0 -c copy WtoxxHADnGk_0820.mp4
# extract every 150th frame (5s) (random ordering of files). jpeg preserve quality
ls ../panama_loop_mp4/ | shuf | xargs -L 1 -I {} -P 20 bash -c "mkdir -p {} && ffmpeg -i ../panama_loop_mp4/{} -vf 'select=not(mod(n\,150))' -q:v 2 {}/frame_%06d.jpg"
## need to add -vsync vpf above to avoid the same frame showing up multiple times
ls ../panama_loop_mp4/ | shuf | xargs -L 1 -I{} -P 120 bash -c "mkdir -p {} && ffmpeg -filter_threads 1 -i ../panama_loop_mp4/{} -threads 1 -vf 'select=not(mod(n\,300)), scale=1008:-1' -vsync vfr -f image2 -q:v 2 -threads 1 -an {}/frame_%06d.jpg"
plot_figure = figure(
title='embedding plot',
plot_width=700,
plot_height=400,
tools=('pan, wheel_zoom, reset, tap, box_select'),
output_backend="webgl"
)
color_col = 'curr_label'
cids = class_names#db_df[color_col].unique() # really should be class
@orm011
orm011 / copy_locals.py
Created June 14, 2021 15:10
copying all locals to jupyter top level
import inspect
def copy_locals():
'''
copies all local variables from this context into the jupyter top level, eg, for easier
debugging of data and for prototyping new code that is eventually meant to run within this context.
'''
stack = inspect.stack()
caller = stack[1]
@orm011
orm011 / gist:04f8190ee9b242c4467ad11038c7bbe4
Created September 18, 2020 17:42
scikit video with custom gpu ffmpeg
import os
ffmpeg_install_dir = '/nvme_drive/orm/ffmpeg_install2/'
os.environ['LD_LIBRARY_PATH'] = f'{ffmpeg_install_dir}/lib/'
import skvideo
skvideo.setFFmpegPath(f'{ffmpeg_install_dir}/bin/')
import skvideo.io
## minimal options
device=0
file = /big_fast_drive/orm/birds/birds_panama.mp4',
@orm011
orm011 / gist:94c3771352e96bf8cc9ed0a6254aed22
Last active December 6, 2021 17:08
ffmpeg gpu support
origin https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
# tag n10.0.26.0
# may be useful to point ffmpeg to different path, eg. conda
# --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu
base=/home/gridsan/omoll/
mkdir ${base}/ffmpeg_install
prefix=${base}/ffmpeg_install
nv_codec_install=${base}/nv-codec-headers-install/
@orm011
orm011 / gist:a45465beafb1e74058ddf1ea8b2f9311
Created September 9, 2020 20:51
download some ytb live stream into 1hr chunks for a long time
export ytbkey=<ytbkey here>;
for i in `seq -f '%04g' 672`;
do /home/gridsan/omoll/.local/bin/streamlink --hls-duration 01:00:00 --hls-live-restart -o ${ytbkey}_$i.ts https://www.youtube.com/watch?v=${ytbkey} best;
done;
# convert ts container without re-encoding with this
# ffmpeg -i ${ytbkey}_$i.ts -s 0:0 -vcodec copy -an ${ytbkey}_$i.mp4; done
@orm011
orm011 / plt2arr.py
Last active November 16, 2022 15:14
pyplot figure to numpy array
def plt2arr(fig, draw=True):
"""
need to draw if figure is not drawn yet
"""
if draw:
fig.canvas.draw()
rgba_buf = fig.canvas.buffer_rgba()
(w,h) = fig.canvas.get_width_height()
rgba_arr = np.frombuffer(rgba_buf, dtype=np.uint8).reshape((h,w,4))
return rgba_arr
@orm011
orm011 / geojson
Created September 21, 2018 21:44
geojsonplot
This file has been truncated, but you can view the full file.
{"type": "FeatureCollection", "features": [{"geometry": {"type": "LineString", "coordinates": [[-71.118052, 42.3661482], [-71.1180446, 42.3659904]]}, "type": "Feature", "id": "0", "properties": {"index": 0, "dst": 2671760283, "src": 61403923, "osm_id": 8646197}}, {"geometry": {"type": "LineString", "coordinates": [[-71.118052, 42.3661482], [-71.1181256, 42.3654855]]}, "type": "Feature", "id": "1", "properties": {"index": 1, "dst": 2671760279, "src": 2671760283, "osm_id": 8646197}}, {"geometry": {"type": "LineString", "coordinates": [[-71.1180446, 42.3659904], [-71.1180425, 42.3658109]]}, "type": "Feature", "id": "2", "properties": {"index": 2, "dst": 61372243, "src": 2671760279, "osm_id": 8646197}}, {"geometry": {"type": "LineString", "coordinates": [[-71.1180425, 42.3658109], [-71.1180266, 42.3637903]]}, "type": "Feature", "id": "3", "properties": {"index": 3, "dst": 2671858992, "src": 61372243, "osm_id": 8646197}}, {"geometry": {"type": "LineString", "coordinates": [[-71.1180266, 42.3637903], [-71.1180211,
@orm011
orm011 / geojson
Created September 21, 2018 21:17
geojsonplot
{"type": "FeatureCollection", "features": [{"geometry": {"type": "LineString", "coordinates": [[-71.0975293, 42.3617372], [-71.096938, 42.3613854]]}, "type": "Feature", "id": "0", "bbox": [-71.0975293, 42.3613854, -71.096938, 42.3617372], "properties": {}}, {"geometry": {"type": "LineString", "coordinates": [[-71.0961381, 42.3609094], [-71.0960005, 42.3608275]]}, "type": "Feature", "id": "1", "bbox": [-71.0961381, 42.3608275, -71.0960005, 42.3609094], "properties": {}}, {"geometry": {"type": "LineString", "coordinates": [[-71.0953508, 42.3604364], [-71.0948847, 42.3601506]]}, "type": "Feature", "id": "2", "bbox": [-71.0953508, 42.3601506, -71.0948847, 42.3604364], "properties": {}}, {"geometry": {"type": "LineString", "coordinates": [[-71.0936993, 42.3607137], [-71.0929964, 42.3610495]]}, "type": "Feature", "id": "3", "bbox": [-71.0936993, 42.3607137, -71.0929964, 42.3610495], "properties": {}}, {"geometry": {"type": "LineString", "coordinates": [[-71.0914907, 42.3617964], [-71.0907826, 42.3621783]]}, "type":
osm=# select postgis_full_version();
postgis_full_version
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POSTGIS="2.2.1 r14555" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.3, released 2015/09/16" LIBXML="2.9.3" LIBJSON="0.11.99" RASTER
(1 row)
-- the 10 is for decimal points, the 2 is for adding the SRID to the result.
osm=# select ST_AsGeoJSON(geometry, 10, 2) from import.osm_roads where osm_id = 8616015;
-- the 4326 stands for 'SRID:4326'