From f33bef4e4ca9e3f2b83b953cbb9ff7c11bde884a Mon Sep 17 00:00:00 2001 From: Emil Oppeln-Bronikowski Date: Fri, 20 Mar 2020 23:08:20 +0100 Subject: [PATCH] Comments, ignore, etc --- .gitignore | 1 + extract_frames.sh | 8 ++++++-- grab.py | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index cbf3631..06960d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ audio.mp3 +out.mp4 diff --git a/extract_frames.sh b/extract_frames.sh index 1bdb416..aa7875e 100755 --- a/extract_frames.sh +++ b/extract_frames.sh @@ -3,6 +3,10 @@ for file in output/*.mpg ; do new_file=`echo $file | cut -d. -f1`.png echo $new_file - ffmpeg -i $file -vf "select=eq(n\,0)" -vframes 1 $new_file + if [ -f $new_file ] ; then + echo "Skip" + else + ffmpeg -i $file -vf "select=eq(n\,0)" -vframes 1 $new_file + fi done -ffmpeg -pattern_type glob -i 'output/*.png' -an -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 out.mp4 +ffmpeg -pattern_type glob -i 'output/*.png' -i audio.mp3 -map 0:v -map 1:a -acodec aac -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 out.mp4 diff --git a/grab.py b/grab.py index 2ba0ad2..df76b11 100644 --- a/grab.py +++ b/grab.py @@ -1,23 +1,35 @@ -import requests -from datetime import datetime -from time import sleep +import requests # klient HTTP +from time import sleep # chcemy pauzować +# wpisany na twardo adres z którego będę pobierał informacje URL = 'https://cdn-3-go.toya.net.pl:8081/kamery/lodz_piotrkowskaschillera_0{}.ts' + +# formad do zapisywania, index poprzedzony dopełnieniem 12 zer OUTPUT = 'output/{:012}_frame.mpg' + +""" Żeby się było łatwiej kręcić, wartości [42…91] w liście """ frames = range(42, 92) idx = 0 while True: + # Cała lista otwarzania ma (92-42)*2 sekund rotation_time = len(frames) * 2 + + #Kiedy zaczynamy proces start_time = datetime.now() + for frame in frames: print("Grabing {}".format(frame)) + # Klasyczny HTTP GET / i zapisanie pliku docelowego response = requests.get(URL.format(frame)) if response.status_code == 200: with open(OUTPUT.format(idx), 'wb') as f: f.write(response.content) idx = idx + 1 + # Jak przelecieliśmy wszystkie ramki to czekamy resztę sekund, aż  + # się wszystkie podmienią after_downloading = datetime.now() remaining_seconds = rotation_time - int((after_downloading - start_time).total_seconds()) print("Clips fetched, sleeping for {}".format(remaining_seconds)) + # …i do łóżka sleep(remaining_seconds) -- 2.45.2