Skip to content

Commit

Permalink
get frame rate and resolution utilites from ffprobe
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jan 31, 2018
1 parent 0cd02b3 commit f3759ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 25 additions & 4 deletions PyLivestream/__init__.py
Expand Up @@ -43,20 +43,41 @@ def getexe() -> str:
def get_framerate(fn:Path) -> float:
"""
get framerate of video file
https://askubuntu.com/a/468003
http://trac.ffmpeg.org/wiki/FFprobeTips#FrameRate
"""
fn = Path(fn).expanduser()

fps = sp.check_output(['ffprobe','-v','0','-of','csv=p=0','-select_streams','0',
'-show_entries','stream=r_frame_rate',
str(fn)], universal_newlines=True)
fps = sp.check_output(['ffprobe','-v','error',
'-select_streams','v:0','-show_entries','stream=avg_frame_rate',
'-of','default=noprint_wrappers=1:nokey=1', str(fn)], universal_newlines=True)

fps = fps.strip().split('/')
fps = int(fps[0]) / int(fps[1])

return fps


def get_resolution(fn:Path) -> tuple:
"""
get resolution (widthxheight) of video file
http://trac.ffmpeg.org/wiki/FFprobeTips#WidthxHeight
"""
fn = Path(fn).expanduser()

res = sp.check_output(['ffprobe','-v','error',
'-of','flat=s=_',
'-select_streams','v:0',
'-show_entries','stream=height,width', str(fn)], universal_newlines=True)

res = res.strip().split('\n')
res = (int(res[0].split('=')[-1]), int(res[1].split('=')[-1]))

print(res)

return res



# %% top level
class Stream:

Expand Down
8 changes: 7 additions & 1 deletion README.rst
Expand Up @@ -118,7 +118,7 @@ Screen Share Livestream
Audio is included::

python Screenshare.py stream.ini site(s)

Stream to multiple sites, in this example Periscope and YouTube Live simultaneously::

python Screenshare.py stream.ini youtube periscope
Expand Down Expand Up @@ -181,6 +181,12 @@ This script saves your screen capture to a file on your disk::



Utilities
=========

* ``PyLivestream.get_framerate(vidfn)`` gives the frames/sec of a video file.
* ``PyLivestream.get_resolution(vidfn)`` gives the resolution (widthxheight) of video file.


Notes
=====
Expand Down

0 comments on commit f3759ec

Please sign in to comment.