Skip to content

FFmpeg mpegCoder for Python

Compare
Choose a tag to compare
@cainmagi cainmagi released this 20 Dec 01:41
· 44 commits to master since this release

mpegCoder

This is the first release version of FFmpeg mpegCoder for python, just download it and use it in your video processing script!


  __   _                         _ _ _                ,___            
 ( /  /        /        o       ( / ) )              /   /     /      
  (__/ , , _, /_  _  _ _'  (     / / /  ,_   _  _,  /    __ __/ _  _  
   _/_(_/_(__/ /_(/_/ / /_/_)_  / / (__/|_)_(/_(_)_(___/(_)(_/_(/_/ (_
  //                                   /|       /|                    
 (/                                   (/       (/                     

Yuchen's Mpeg Coder - Readme

This is a mpegcoder adapted from FFmpeg & Python-c-api.Using it you could get access to processing video easily. Just use it as a common module in python like this.

  import mpegCoder

Noted that this API need you to install numpy.

An example of decoding a video in an arbitrary format:

  d = mpegCoder.MpegDecoder()
  d.FFmpegSetup(b'inputVideo.mp4')
  p = d.ExtractGOP(10) # Get a gop of current video by setting the start position of 10th frame.
  p = d.ExtractGOP() # Get a gop of current video, using the current position after the last ExtractGOP.
  d.ExtractFrame(100, 100) # Extract 100 frames from the begining of 100th frame.

An example of transfer the coding of a video with an assigned codec:

  d = mpegCoder.MpegDecoder()
  d.FFmpegSetup(b'i.avi')
  e = mpegCoder.MpegEncoder()
  e.setParameter(decoder=d, codecName=b'libx264', videoPath=b'o.mp4') # inherit most of parameters from the decoder.
  opened = e.FFmpegSetup() # Load the encoder.
  if opened: # If encoder is not loaded successfully, do not continue.
      p = True
      while p is not None:
          p = d.ExtractGOP() # Extract current GOP.
          for i in p: # Select every frame.
              e.EncodeFrame(i) # Encode current frame.
      e.FFmpegClose() # End encoding, and flush all frames in cache.
  d.clear() # Close the input video.

For more instructions, you could tap help(mpegCoder).