Skip to content

Instantly share code, notes, and snippets.

@senapk
Created March 5, 2021 19:09
Show Gist options
  • Save senapk/e3074f43f34e687b11c54f2ee5a0538e to your computer and use it in GitHub Desktop.
Save senapk/e3074f43f34e687b11c54f2ee5a0538e to your computer and use it in GitHub Desktop.
Scripts para um workflow para gravação de aulas menos sofridos
#!/bin/bash
# junta todos os arquivos da extensao passada na pasta atual,
# desde que usem os mesmos codecs
# ./ffmpeg_join.sh flv saida.flv
[ -e __list__.txt ] && rm __list__.txt
for f in *."${1}"
do
echo "file $f" >> __list__.txt
done
ffmpeg -f concat -i __list__.txt -c copy "${2}" && rm __list__.txt
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import os
from subprocess import PIPE
def time_to_sec(time):
return float(time[0]) * 60 * 60 + float(time[1]) * 60 + float(time[2])
def fix(value):
parts = str(value).split(".")
if len(parts[0]) == 1:
parts[0] = "0" + parts[0]
return ".".join(parts)
def sec_to_time(sec):
h, m = divmod(sec, 3600)
m, s = divmod(m, 60)
return [fix(int(h)), fix(int(m)), fix(int(s))]
files = os.listdir(".")
files = sorted(files)
files = [f for f in files if f.endswith(".mkv")]
acc = 0
for f in files:
cmd = ["ffmpeg", "-i", f]
p = subprocess.Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=PIPE, universal_newlines=True)
_stdout, stderr = p.communicate()
lines = stderr.split("\n")
lines = [l.strip() for l in lines if "DURATION" in l]
time_parts = lines[0].split(":")[-3:]
time_parts[-1] = time_parts[-1][:5]
print(":".join(sec_to_time(acc)), f)
acc += time_to_sec(time_parts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment