Changes to be committed:

- Starkes Komprimieren von png
	new file:   src/Makefiles/Makefile.pngCompress
- Dynamische Bitrate, damit eine max. Dateigröße von 10MB eingehalten wird
	modified:   src/Makefiles/Makefile.vidstabTest
	new file:   src/galleryHelper/getVideoDuration.py
	new file:   src/galleryHelper/getVideoDurationJson.py
This commit is contained in:
marko
2018-11-13 14:28:18 +01:00
parent 93f4371093
commit e808faf8eb
4 changed files with 154 additions and 21 deletions

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env python3
import sys
import subprocess
#ffprobe =
def getLength(filename):
result = subprocess.Popen(
["C:\\proggis\\media\\editoren\\ffmpeg-4.0.2-win64-static\\bin\\ffprobe.exe", filename],
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
# print( result.stdout.readlines() )
# for x in result.stdout.readlines():
# print(x)
return [x for x in result.stdout.readlines() if b"Duration" in x]
#print( str( getLength(sys.argv[1]) ) )
getLength(sys.argv[1])

View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
#
# Command line use of 'ffprobe':
#
# ffprobe -loglevel quiet -print_format json \
# -show_format -show_streams \
# video-file-name.mp4
#
# man ffprobe # for more information about ffprobe
#
import subprocess as sp
import json
import sys
def probe(vid_file_path):
''' Give a json from ffprobe command line
@vid_file_path : The absolute (full) path of the video file, string.
'''
if type(vid_file_path) != str:
raise Exception('Gvie ffprobe a full file path of the video')
return
command = ["ffprobe",
"-loglevel", "quiet",
"-print_format", "json",
"-show_format",
"-show_streams",
vid_file_path
]
pipe = sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT)
out, err = pipe.communicate()
return json.loads(out)
def duration(vid_file_path):
''' Video's duration in seconds, return a float number
'''
_json = probe(vid_file_path)
if 'format' in _json:
if 'duration' in _json['format']:
return float(_json['format']['duration'])
if 'streams' in _json:
# commonly stream 0 is the video
for s in _json['streams']:
if 'duration' in s:
return float(s['duration'])
# if everything didn't happen,
# we got here because no single 'return' in the above happen.
raise Exception('I found no duration')
#return None
if __name__ == "__main__":
# video_file_path = "/tmp/tt1.mp4"
video_file_path = sys.argv[1]
durationInSec = duration(video_file_path)
rateInKbPerSec = (10 * 1024 * 1024 * 8)/( durationInSec * 1000 )
#print( duration(video_file_path) ) # 10.008
print( int(min(500, rateInKbPerSec)) )