Reputation: 381
Here's the code -
import os
file = open("list.txt", "rw+")
text = file.readline()
print "ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 \""+text+".mp4\""
os.system("ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 \""+text+".mp4\"")
But the output is like this :
ffmpeg -loop 1 -i image.jpg -i "some-file-path
" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 "some-file-path"
Whereas it should be in a single line
And ffmpeg throws an error that file doesn't exist !
Upvotes: 2
Views: 60
Reputation: 814
ALl lines in textfiles (when python reads them at least) end in "\n"
easy solution
text = file.readline()[:-1]
this will trim the last character "\n" from the line. careful when doing this, since if you want to write the line back, you need to append a "\n" to it (when useing file.write("something"))
Upvotes: -2
Reputation: 81684
Because your file has a new line character ('\n'
) in the end of the line,
so text
is "some-file-path\n"
.
You should change text = file.readline()
to text = file.readline().strip()
.
Upvotes: 5