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
+5.4k How to check with curl if my website or the asset is gzipped ?
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+7.2k Golang : How to iterate a slice without using for loop?
+12k Golang : convert(cast) string to integer value
+5.3k Golang : What is StructTag and how to get StructTag's value?
+8.3k Golang: Prevent over writing file with md5 hash
+13.7k Generate salted password with OpenSSL example
+10.6k Golang : Underscore string example
+40.9k Golang : How to check if a string contains another sub-string?
+9.5k Golang : Read file with ioutil
+7.5k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+26.3k Golang : Convert(cast) string to uint8 type and back to string