How do I resolve ffmpeg concat command error "unknown keyword..."?
Asked Answered
F

9

16

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?

Flanker answered 20/6, 2017 at 1:10 Comment(0)
N
11

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
Nickell answered 21/6, 2017 at 23:7 Comment(3)
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?Culicid
the difference is the word file. Look at my answer belowReputed
This file-level copy method only work for some formats (MPEG-1, MPEG-2 PS, DV) , but not for mp4.Bolme
S
22

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.

Surfboarding answered 11/10, 2020 at 16:14 Comment(4)
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.Mannes
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.Cicala
And this is the issue when you create a file with echo in powershell.Balm
Exactly what I needed. In VSCODE, you can click the current encoding in the lower-right of the app tray (near Ln, Col, Spaces and line-endings), pick UTF-8, then "Save with new encoding".Aquiline
R
13

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

Reputed answered 3/4, 2021 at 7:38 Comment(0)
N
11

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
Nickell answered 21/6, 2017 at 23:7 Comment(3)
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?Culicid
the difference is the word file. Look at my answer belowReputed
This file-level copy method only work for some formats (MPEG-1, MPEG-2 PS, DV) , but not for mp4.Bolme
U
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.

Urethrectomy answered 14/11, 2020 at 13:17 Comment(0)
B
3

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
Baudelaire answered 8/1, 2023 at 14:0 Comment(0)
U
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.

Upperclassman answered 20/6, 2017 at 1:27 Comment(2)
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.Flanker
Sure. See the other examples in that link.Upperclassman
F
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
Flea answered 16/11, 2020 at 19:7 Comment(0)
M
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

Marcellusmarcelo answered 23/2, 2023 at 14:45 Comment(0)
P
0

for me it worked by disabling BOM on the UTF-8 format. So the file was UTF-8 and noBOM.

e.g. the contents of the text file:

file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'

and use:

ffmpeg -f concat -i input_videos.txt -c copy ffmpeg_out.mp4
Pouched answered 6/12, 2023 at 8:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.