I am trying to get the duration of a media file I have by running these lines from a python script:
test_file = 'path_to_file.mp4'
ffmpeg_get_mediafile_length = ["ffmpeg", "-i", test_file, '2>&1 | grep "Duration"']
output = subprocess.Popen(ffmpeg_get_mediafile_length,
stdout = subprocess.PIPE
).stdout.read()
print output # this gives None
matches = re_length.search(output)
print matches
Here is the ffmpeg
logs I get alongside with the error I get:
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.0.37)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'path_to_media_file':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:22:25.89, start: 0.000000, bitrate: 6059 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 6057 kb/s, 15 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
handler_name : VideoHandler
[NULL @ 0x7fedac802200] Unable to find a suitable output format for '2>&1 | grep "Duration"'
2>&1 | grep "Duration": Invalid argument