0

Is there an easy way to add chapters (i.e.: sections with titles) to .mp4 files using a python script?

For example, the script could process a 3-minutes video and label the first minute as "Beginning", the second minute as "Middle", and the last minute as "End".

The only solution (link) I stumbled upon so far involves using a ffmpeg command on the command line to extract the original ffmetadata from the video file before appending the chapters to it and updating the video with it.

However, I would like the process to be automated using a python script (instead of having to use the command line each time I have to process a video).

Random
  • 13
  • 3
  • Running the program via the command line to achieve your objective is already a form of automation, so what is your question? If it's a recommendation to find a library in Python to do this, I am afraid that is off-topic for StackOverflow. – metatoaster Mar 07 '23 at 03:09
  • Not really, I would like to run that command within a larger python program that processes video files. I just want to find a way to do so without having to go through the command line separately. – Random Mar 07 '23 at 03:27
  • 1
    You might be looking for a way to [run ffmpeg through Python subprocess](https://stackoverflow.com/questions/25955322/subprocess-call-ffmpeg-command-line). – metatoaster Mar 07 '23 at 03:30
  • I tried doing so but it tells me that it doesn't recognize ffmpeg as a command for some reason, although I did import it to my pycharm virtual environment. @metatoaster – Random Mar 07 '23 at 03:42
  • 1
    You may need to provide the full path to the `ffmpeg` executable. – metatoaster Mar 07 '23 at 05:06
  • I was able to solve the issue using subprocess.call(command, shell=True) function after updating my path variable. The 'shell=True' argument allowed me to process the command as a regular shell command, and updating the path variable made ffmpeg recognizable. I initially thought I had to use the ffmpeg-python module but it's easier to do it this way. Thank you @metatoaster for your help! – Random Mar 07 '23 at 16:55
  • Using `shell=True` may be dangerous. – metatoaster Mar 07 '23 at 22:09

1 Answers1

0

As mentioned in the comments above, I was able to achieve what I wanted using the subprocess.call(command, shell=True) function after updating my path variable.

The 'shell=True' argument allowed me to process the command as a regular shell command (link), and updating the path variable made ffmpeg recognizable.

I didn't have to use ffmpeg-python module after all since it was easier to use the ffmpeg (downloaded from here) command on shell that worked fine initially.

Random
  • 13
  • 3