I think I figured it out. It looks like you are having an issue with bash white space. On the command line, you enclosed the entire -vf
option in quotes. In the python script, you created x
as a string; Popen
would interpret the string like the other arguments you have in the list and end up leaving it unquoted in the actual command run. On the command line, this would look like:
ffmpeg -f video4linux2 -y -r 4 -i /dev/video0 -vf drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:expansion=strftime:text='%Y-%m-%d %H\\:%M\\:%S': fontcolor=white:box=1:boxcolor=black@0.8:x=w-text_w:y=h-line_h -vframes 20 -vcodec mpeg4 out.mp4
So in effect, you would want:
x = '"drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:expansion=strftime:text=\'%Y-%m-%d %H\\:%M\\:%S\': fontcolor=white:box=1:boxcolor=black@0.8:x=w-text_w:y=h-line_h"'
Otherwise, that argument would be split at the white space in the date format when actually run by bash and cause some unexpected behavior.
(Sorry for the wall of text, just want to make sure that I'm not confusing.)