Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gipi
Last active January 30, 2019 21:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gipi/a8f1065516217e3ae6ad to your computer and use it in GitHub Desktop.
Save gipi/a8f1065516217e3ae6ad to your computer and use it in GitHub Desktop.
#video #gif #ffmpeg #mplayer

Mplayer

$ mplayer dvdnav:// -mouse-movements -dvd-device /dev/sr0

Mount a disk image automatically

fdisk script from this repo.

I just discovered that it's possible to use kpartx

$ (master *+) sudo kpartx -av disk.img
add map loop1p1 (253:0): 0 114688 linear /dev/loop1 8192
add map loop1p2 (253:1): 0 6277120 linear /dev/loop1 122880
add map loop1p3 (0:0): 0 7812480 linear /dev/loop1 6400000

Update progress with dd

sudo pkill -USR1 -n -x dd

Creating GIF from Video

$ mkdir images
$ ffmpeg -t 14 -ss 00:00:04 -i VID_20150711_182009.mp4 \
  -s 640x480 -qscale 0 -f image2 images/out%04d.jpeg
$ convert -fuzz 5% \
  -delay 1x3 \
  $(seq -f images/out%04g.jpeg 1 10 830) \
  -coalesce -layers OptimizeTransparency \
  pov.gif

Stabilize&Deshake

$ transcode -J stabilize -i VID_20150711_182009.mp4
$ transcode -J transform -i VID_20150711_182009.mp4 -y xvid -o pov_stabilized.avi
'''
This script utilizes fabric to generate a list of name, uid and gid between two
remote systems; confronting them you will be able to restore a tar backup
without checking manually the permissions.
TODO:
0. add tar stream handling
1. generic check mode for possible unconsistency (uid,gid)
2. parse from cmdline the host passed and adapt for fabric
http://www.ibm.com/developerworks/aix/library/au-python/
'''
import sys
import json
import itertools
import tarfile
from fabric.api import task, settings
from fabric.operations import run, sudo, get, local, put, open_shell
from fabric.state import env
# this allows to use configuration as indicated in the .ssh/config file
env.use_ssh_config = True
def usage(progname):
print 'usage: %s <src server> <dst server>' % progname
@task
def info():
'''
Save into a temporary file the info dumped from a location.
Do not use directly dict-comprensions to be compatible with python2.6.
'''
return run('python -c "import pwd,json;print json.dumps(dict( (_.pw_name, { \'uid\': _.pw_uid, \'gid\': _.pw_gid }) for _ in pwd.getpwall()), indent=4)" ')
class PermissionManager(object):
def __init__(self, users_state):
self.users_state
def __call__(self, uid, gid):
pass
def handle_tar_entry(tarinfo, permission_manager):
tarinfo.uid, tarinfo.gid = permission_manager(tarinfo.uid, tarinfo.gid)
def handle_tar(tarfilepath, permission_manager):
archive = tarfile.open(mode="r", name=tarfilepath)
for _ in archive:
handle_tar_entry(_, permission_manager)
#archive.extractall(path='/tmp')
if __name__ == '__main__':
if len(sys.argv) < 3:
usage(sys.argv[0])
sys.exit(1)
src = sys.argv[1]
dest = sys.argv[2]
archive_path = sys.argv[3]
src_users = None
dst_users = None
with settings(host_string=src):
src_users = json.loads(info().stdout)
with settings(host_string=dest):
dst_users = json.loads(info().stdout)
# here will save the situation
result = {}
# we loop over all the users defined in both the systems
all_users = tuple(itertools.chain.from_iterable([src_users.keys(), dst_users.keys()]))
for user in all_users:
src = src_users.get(user, -1)
result[user] = {
'src': src,
'dts': dst_users.get(user, -1),
}
print json.dumps(result, indent=4)
pm = PermissionManager(result)
handle_tar(archive_path, pm)
#!/usr/bin/python
#*****************************************************************************
#
# Copyright (c) 2013 Andrea Bonomi <andrea.bonomi@gmail.com>
#
# Published under the terms of the MIT license.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
#*****************************************************************************
import cstruct
import sys
class Position(cstruct.CStruct):
__byte_order__ = cstruct.LITTLE_ENDIAN
__struct__ = """
unsigned char head;
unsigned char sector;
unsigned char cyl;
"""
class Partition(cstruct.CStruct):
__byte_order__ = cstruct.LITTLE_ENDIAN
__struct__ = """
unsigned char status; /* 0x80 - active */
struct Position start;
unsigned char partition_type;
struct Position end;
unsigned int start_sect; /* starting sector counting from 0 */
unsigned int sectors; /* nr of sectors in partition */
"""
def print_info(self):
print("bootable: %s" % ((self.status & 0x80) and "Y" or "N"))
print("partition_type: %02X" % self.partition_type)
print("start: head: %X sectory: %X cyl: %X" % (self.start.head, self.start.sector, self.start.cyl))
print("end: head: %X sectory: %X cyl: %X" % (self.end.head, self.end.sector, self.end.cyl))
print("starting sector: %08X" % self.start_sect)
print("size MB: %s" % (self.sectors / 2 / 1024))
class MBR(cstruct.CStruct):
__byte_order__ = cstruct.LITTLE_ENDIAN
__struct__ = """
char unused[440];
unsigned char disk_signature[4];
unsigned char usualy_nulls[2];
struct Partition partitions[4];
char signature[2];
"""
def print_info(self):
print("disk signature: %s" % "".join(["%02X" % x for x in self.disk_signature]))
print("usualy nulls: %s" % "".join(["%02X" % x for x in self.usualy_nulls]))
for i, partition in enumerate(self.partitions):
print("")
print("partition: %s" % i)
partition.print_info()
def main():
if len(sys.argv) != 2:
print("usage: %s disk" % sys.argv[0])
sys.exit(2)
f = open(sys.argv[1], "rb")
mbr = MBR()
data = f.read(len(mbr))
mbr.unpack(data)
mbr.print_info()
f.close()
if __name__ == "__main__":
main()
#!/bin/bash
ACTUAL_DIR=$(pwd)
INPUT="$1"
OUTPUT="${ACTUAL_DIR}/$2"
WORK_DIR=$(mktemp -d)
cd ${WORK_DIR}
mkdir images
ffmpeg -t 14 -ss 00:00:05 -i "${INPUT}" \
-s 320x200 -qscale 0 -f image2 images/out%04d.jpeg
COUNT="$(ls -1 images/*.jpeg | wc -l)"
convert -fuzz 5% \
-delay 1x3 \
$(seq -f images/out%04g.jpeg 1 10 "${COUNT}") \
-coalesce -layers OptimizeTransparency \
"${OUTPUT}"
import sys
import fdisk
import losetup
if __name__ == '__main__':
if len(sys.argv) != 2:
print("usage: %s disk" % sys.argv[0])
sys.exit(2)
imagepath = sys.argv[1]
with open(imagepath, "rb") as f:
mbr = fdisk.MBR()
data = f.read(len(mbr))
mbr.unpack(data)
#mbr.print_info()
for i, p in enumerate(mbr.partitions):
print i, p.start_sect
loops = losetup.get_loop_devices()
for _, device in loops.iteritems():
if device.is_used() and device.get_filename() == imagepath:
raise Exception("Already mounted image with %s" % device.device)
loop = losetup.find_unused_loop_device()
loop.mount(imagepath, offset=mbr.partitions[0].start_sect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment