13

I am trying to concatenate two video files using ffmpeg, and I am receiving an error.

To eliminate compatibility issues between the two videos, I have been concatenating the same video with itself, and the same error persists.

ffmpeg \
  -f concat \
  -safe 0 \
  -i intro_prepped.avi intro_prepped.avi \
  -c copy \
  concat.avi  

And the error output I receive is....

[concat @ 0x220d420] Line 1: unknown keyword 'RIFFf�?' intro_prepped.avi: Invalid data found when processing input

I have tried various combinations of concat flags and have not been able to get it to work. Has anyone seen this error before?

8 Answers 8

19

This is a bit late for the original post, but I was just searching for answers to the same problem so I think it's still relevant and I haven't found any more recent posts answering the same problem.

I found that my .txt file was encoded wrong. I opened the file in Notepad and did a 'Save As...' I changed the encoding to UTF-8 and the ffmpeg concat command worked.

2
  • This was the issue for me too. Thank you. For those using Notepad++, the same can be done there with the 'Encoding' tab on the main title bar. Mar 8, 2021 at 18:42
  • Click on current encoding name on right side of status bar or press Ctrl+Shift+P - and type "Change File Encoding" to achieve this in VSCode. Aug 30, 2021 at 9:25
11

I tried all of the aforementioned and it didn't work.

It looks like that the file names in the list have to be specially formatted to look like:

file '/path/to/file1.wav'

with a word file included. I spend a lot of time trying to guess why ffmpeg encountered an error trying to read the file names. It didn't matter if they were in the list or in the command line. So only after I utilized a command

for f in *.wav; do echo "file '$f'" >> mylist.txt; done

to make list from ffmpeg's manual I had success. The only difference was an additional word file.

Here you can read it yourself: https://trac.ffmpeg.org/wiki/Concatenate#demuxer

10

Docs for several ways of concatenating files: https://trac.ffmpeg.org/wiki/Concatenate

Here's a command I use to concatenate videos:

ffmpeg \
  -i "concat:input1.avi|input2.avi|input3.avi" \
  -c:a copy \
  -c:v copy \
  output.avi
3
  • 7
    I tried: ` ffmpeg -i "concat:media3.mp4|media4.mp4|media5.mp4" -c:a copy -c:v copy output.mp4` And it just produced a copy of media3.mp4, without any concatenation. However, this version from your link worked: ` ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4` worked, where mylist.txt was: ` # this is a comment file 'media3.mp4' file 'media4.mp4' file 'media5.mp4'` Any idea what the difference is here?
    – Astrokiwi
    Feb 25, 2020 at 13:05
  • the difference is the word file. Look at my answer below Apr 3, 2021 at 7:42
  • 1
    This file-level copy method only work for some formats (MPEG-1, MPEG-2 PS, DV) , but not for mp4.
    – Ben L
    Oct 3, 2022 at 17:48
6

Your text file is likely encoded in UTF-16.

Fix: (Windows 10)

  • Open text file
  • Select 'Save as'
  • Look by the save button, you get to pick encoding with a drop down box, select UTF-8.
  • Save and run ffmpeg again.

I used the Powershell code on ffmpegs webpage to make a text file with filenames, and Powershell seems to save text files as some variant of UTF-16, so I chose the safer UTF-8.

1

The input file should be a text file, not an avi. The text file lists the files to concatenate.

See the concat demuxer documentation and FFmpeg Wiki: Concat.

2
  • 1
    Is there a way to concatenate two files on the command line? I am doing it from a bash script and do not know the file names ahead of time.
    – Scorb
    Jun 20, 2017 at 2:02
  • Sure. See the other examples in that link. Jun 20, 2017 at 2:14
1

Nobody had a full, working, concat text file batch file anywhere. So I am posting it

md ts
for %%x in (input\*.m4a) do (ffmpeg -i "%%x" -c copy -bsf:v h264_mp4toannexb ts\%%~nx.ts)
for %%c in ("ts\*ts") do (echo file '%%c')>>list.txt
for %%f in (input\*.m4a) do (set fn=%%~nf)
ffmpeg -f concat -safe 0 -i "list.txt" -c copy "%cd%\%fn%".m4a
0

I struggled with all these instructions above on my Mac (M1, Ventura, ffmpeg version N-109530-g4a80db5fc2-tessus). None of them worked for me - but a combination of all did the trick!

This is how I got it running:

  • place all input files the same folder
  • create input.txt in this folder - content looks like this:
    file 'input1.mp4'
    file 'input2.mp4'
    file 'input3.mp4'
    file 'input4.mp4'
    
    • Note:
      • file encoding must be UTF-8
      • file keyword must be present
      • filename must not be fully qualified (I got exceptions using '/path/to/input1.mp4')
      • filename must be enclosed by '
  • navigate to this folder in the terminal
  • execute ffmpeg -f concat -i input.txt -c copy ffmpegOUT.mp4
0

Latest:

Using windows 10

  1. gather files using this with sort according to date modification:

    foreach ($i in Get-ChildItem -Path .\*.mp4 | Sort-Object -Property LastWriteTime) {echo "file '$i'" >> mylist.txt}
    
  2. save as the mylist as UTF-8

  3. combine them by running this at powershell:

    ffmpeg -f concat -safe 0 -i mylist.txt -vcodec copy output.mp4
    
  4. ffmpeg must be installed to use directly.

  5. if you want to just directly use ffmpeg exe without installation then use:

     ./ffmpeg -f concat -safe 0 -i mylist.txt -vcodec copy output.mp4
    

    given that ffmpeg.exe is in the same directory and powershell is at that directrory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.