Golang : ffmpeg with os/exec.Command() returns non-zero status
Problem:
You want to use ffmpeg
with os/exec.Command() and Run() to create your video files.
However, it keeps bombing out with the error message:
exit status 1
You are able to execute the command with the supplied parameters and flags just fine on your terminal.
What's going on? How to fix this?
Solution:
Golang's os/exec.Command()
function does not have the shell=true
feature like Python did. ffmpeg is very sensitive to white spaces when running from another program. To fix the problem, simply remove whitespaces by using ,
instead of +
to assemble the flags and parameters to ffmpeg.
For example,
cmd := exec.Command("ffmpeg", "-r "+recordedFPSstring+" -i "+videoFileName+" -r 6 temp_"+videoFileName)
to
cmd := exec.Command("ffmpeg", "-r", recordedFPSstring, "-i", videoFileName, "-r", "6", "temp_"+videoFileName)
See also : Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
By
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.1k Golang : How to write backslash in string?
+8.3k Golang: Prevent over writing file with md5 hash
+21.1k Golang : Clean up null characters from input data
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+6.8k Mac/Linux/Windows : Get CPU information from command line
+9.1k Golang : Create and shuffle deck of cards example
+16.3k Golang : Find out mime type from bytes in buffer
+5.9k Golang : Use NLP to get sentences for each paragraph example
+17.6k Convert JSON to CSV in Golang
+6.1k Golang : Scan forex opportunities by Bollinger bands
+12.3k Golang : Extract part of string with regular expression
+17.5k Golang : delete and modify XML file content