I’m running a ffmpeg command to try to get the duration of a video file, the command is as follows…
system('ffmpeg -i C:\Users\example\Desktop\video9.mp4 -f ffmetadata')
When I run that line it outputs a lot of info to the rails console, including duration. But how would I capture that info so I can split it and grab the data I need? (I’m doing this inside a rails controller)
When I run something like this…
metadata = system('ffmpeg -i C:\Users\example\Desktop\video9.mp4 -f ffmetadata')
puts metadata
All it returns is false.
Use:
The problem is that
systemdoesn’t capture the output of the command being run. Instead, we use%x[...]or its equivalent using backticks, which captures the sub-shell’s STDOUT.If you need more control, look at
Open3.capture3.