pythonffmpegvideo-conversion

TypeError: expected str, bytes or os.PathLike object, not FilterableStream


I'm trying to make a conversion from an mp4 video to a jpeg frames with ffmpeg:

 from __future__ import unicode_literals
import argparse
import ffmpeg
import cv2
import numpy as np
import os
from glob import glob
#from __future__ import unicode_literals, print_function
import sys



def main():
    
    try:
        probe = ffmpeg.probe('./frames.mp4')
    except ffmpeg.Error as e:
        print(e.stderr, file=sys.stderr)
        sys.exit(1)

    video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
    if video_stream is None:
        print('No video stream found', file=sys.stderr)
        sys.exit(1)

    width = int(video_stream['width'])
    height = int(video_stream['height'])
    num_frames = int(video_stream['nb_frames'])
    print('width: {}'.format(width))
    print('height: {}'.format(height))
    print('num_frames: {}'.format(num_frames))
    
    
    inputt = ffmpeg.input('./frames.mp4')
    (
        ffmpeg
        .input(inputt)
        .filter('select', 'gte(n,{})'.format(num_frames))
        .output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
        .run()#capture_stdout=True)
    )
        
    
if __name__ == '__main__':
    main()  

Result:

Traceback (most recent call last):
  File "/Users/paula/Desktop/GameOn/video-segmentation-tests/video_to_image.py", line 51, in <module>
    main()   
  File "/Users/paula/Desktop/video_to_image.py", line 42, in main
    ffmpeg
  File "/opt/anaconda3/lib/python3.9/site-packages/ffmpeg/_run.py", line 313, in run
    process = run_async(
  File "/opt/anaconda3/lib/python3.9/site-packages/ffmpeg/_run.py", line 284, in run_async
    return subprocess.Popen(
  File "/opt/anaconda3/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/anaconda3/lib/python3.9/subprocess.py", line 1754, in _execute_child
    self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not FilterableStream

I've tried to change the path, try to set argparse instead of set directly the path, search for similar issues... but nothing works. I've also searched in ffmpeg documentation.


Solution

  • Try:

    ffmpeg.input('./frames.mp4') \
          .filter('select', 'gte(n,{})'.format(num_frames)) \
          .output('pipe:', vframes=1, format='image2', vcodec='mjpeg') \
          .run()#capture_stdout=True