1

Me and a friend are currently working on a twitter bot which uploads images taken from randomly chosen video files.
We are using ffmpeg, with subprocess.call(), to get out.jpg from a video file,
which is working fine when the subtitles are hardcoded into the video.
We've also made it burn the subtitles into the out.jpg outside of python, but when trying it inside pyhton with subprocess.call() it won't work and it will say:

Output /file/path/to/file.mkv same as Input #0 - exiting
FFmpeg cannot edit existing files in-place.

This is the code for harcoded subtitles.

subprocess.call(
        ['ffmpeg', '-y', '-ss', str(randomTime), '-i', filepath, '-vframes', '1', '-vf', 'scale=1920:1080', '-q:v', '1',
         '-qmin', '1', tmpfilename])

And this the code for non hardcoded subtitles.

subprocess.call(
        ['ffmpeg', '-y', '-ss', str(randomTime), '-copyts', '-i', filepath, '-vf', 'subtitles', filepath, '-vframes', '1', '-vf', 'scale=1920:1080',
         '-vf', '-q:v', '1', '-qmin', '1', '-frames:v', '1', tmpfilename])

Also both me and my friend are not so sure if calling ffmpeg using subprocess.call() is the right way to do it in python.
Any kind of help is welcome and please ask me for more code or more details if needed.

Mevon
  • 11
  • 3
  • `-vf subtitles xxxxx` says to extract subtitles and store it in the file xxxxx. That is, `xxxxx` is an output. In your case, you're specifying the same name as the input file. What do you think that parameter is doing? – Tim Roberts Jun 13 '21 at 19:55
  • @TimRoberts when I was looking I found [this site](https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo), will definitly try out what you said. Thanks! – Mevon Jun 13 '21 at 20:20
  • You may consider passing the frames to `stdout` PIPE of FFmpeg sub-process. See my answer [here](https://stackoverflow.com/questions/67352282/pipe-video-frames-from-ffmpeg-to-numpy-array-without-loading-whole-movie-into-me) for example. You may use OpenCV for processing and encoding a single frame to JPEG or PNG format (in memory or to a file). ("Burning" the subtitles using FFmpeg may be a good idea regardless). – Rotem Jun 13 '21 at 22:51
  • About the error message: `filepath` and `tmpfilename` are the same video file. When the input and the output are the same file, FFmpeg displays an error message "Output file.mkv same as Input" and "FFmpeg cannot edit existing files in-place.". You may set `tmpfilename = /file/path/to/new_file.mkv` – Rotem Jun 14 '21 at 11:41

0 Answers0