1

I am trying to merge two files (.mp3 & .mp4) to a single .mp4

The videos and audio are located in the same folder as my main.py, and aren't corrupted

Here is the code that seems to create the error:

    if (haveAudio):
        infile1 = ffmpeg.input(title+"_video.mp4")
        infile2 = ffmpeg.input(title+"_audio.mp3")

        merged  = ffmpeg.concat(infile1, infile2, v=1, a=1)
        output  = ffmpeg.output(merged[0], merged[1], title+".mp4")

I am getting an error on the last line:

Traceback (most recent call last):
  File "C:\Users\...\projectName\main.py", line 67, in <module>
    output  = ffmpeg.output(merged[0], merged[1], title+".mp4")
  File "C:\Users\...\Python\Python39\lib\site-packages\ffmpeg\nodes.py", line 70, in __getitem__
    raise TypeError("Expected string index (e.g. 'a'); got {!r}".format(index))
TypeError: Expected string index (e.g. 'a'); got 0

My guess would be that an argument is missing when calling ffmpeg.output() but based on the documentation it seems correct.

Dairop
  • 25
  • 8

1 Answers1

1

I learnt from this tutorial: https://github.com/JNYH/pytube/blob/master/pytube_sample_code.ipynb

I used below 2 ways and they both worked for me:

audio = ffmpeg.input('audio.mp3')
video = ffmpeg.input('video.mp4')

ffmpeg.output(audio, video, 'my_file.mp4').run()

or

ffmpeg.concat(video, audio, v=1, a=1).output('my_file.mp4').run(overwrite_output=True)
Adrian Ang
  • 520
  • 5
  • 12
  • This gives me a file not found error, even with the full paths of the files in the line ffmpeg.output(audio, video, 'my_file.mp4').run() – Dairop Jun 11 '22 at 14:03
  • The second error was due to an erroneous installation of ffmpeg, thanks for your help! – Dairop Jun 11 '22 at 14:23
  • yea, for my installation, I had to do both `!pip install ffmpeg-python` and `conda install ffmpeg` – Adrian Ang Jun 13 '22 at 10:00