Why does ffmpeg concat require the word "file" before each file name in the text file?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
HyperBear
Level 2
Level 2
Posts: 97
Joined: Thu May 04, 2023 3:39 am

Why does ffmpeg concat require the word "file" before each file name in the text file?

Post by HyperBear »

To concatenate a video using ffmpeg -f concat, meaning to put many videos into one file, one has to create a text file looking like this:

Code: Select all

file 'path/1.mp4'
file 'path/2.mp4'
file 'path/3.mp4'
file 'path/4.mp4'
file 'path/5.mp4'
My question is: Why can't the files be written without the "file" keyword? E.g.:

Code: Select all

1.mp4
2.mp4
3.mp4
4.mp4
5.mp4
Why does ffmpeg require putting the "file" keyword before each file? What is the point of having to put the "file" keyword before each file? This makes it more tedious to create file lists. Without this requirement, file lists could be copied out of Nemo and directly pasted into an unprocessed text file.

Here is a function that does the processing automatically:

Code: Select all

fflist() {
	selected_file="$1"
	# return with error code 1 if no file selected
	if [ "$1" == "" ]; then echo "No file selected."; return 1;fi
	echo "Creating concatinated video from: $selected_file"
	
	# sort file names and filter out blank lines
	sort "$selected_file" |grep -v "^$" >> $selected_file.sorted
	mv "${selected_file}.sorted" "$selected_file"
	
	if [[ $(head -n 1 $selected_file) == "file '"* ]]; then return 1; fi # return if file already modified
	sed -i -r "s/([^#]+)/file '\1'/g" "$selected_file"; # make file list digestable for ffmpeg concat, exclude comments with "#"
}
Last edited by LockBot on Tue Jul 02, 2024 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
spamegg
Level 17
Level 17
Posts: 7503
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Why does ffmpeg concat require the word "file" before each file name in the text file?

Post by spamegg »

I don't know the reason, the syntax is described here:
https://ffmpeg.org/ffmpeg-formats.html#Syntax

I guess "file" is there to distinguish it from the rest of the syntax, which has a lot of other keywords.

There is a script here to generate the text file automatically, instead of manually writing "file":
https://trac.ffmpeg.org/wiki/Concatenat ... einputfile

Over the years I've learned not to ask the question why. Programmers are just weird people and they do weird things for inexplicable reasons sometimes. I've just accepted it and find ways to work around it.
Hoser Rob
Level 21
Level 21
Posts: 14116
Joined: Sat Dec 15, 2012 8:57 am

Re: Why does ffmpeg concat require the word "file" before each file name in the text file?

Post by Hoser Rob »

I suspect that if I sat down with an ffmpeg dev and asked him or her to explain this I wouldn't have a frakking clue what they were saying. And I'm not that much of a stranger to this sort of thing.

IMHO trying to do the console jockey thing with something like ffmpeg is silly anyway. There are many GUI encoders that use them as a backend or something just as good. The only advantage to using ffmpeg in CLI for encoding is that you then have access to very advanced features that the GUI programs usually lack. But the vast majority of users doing encoding have absolutely no clue what those features do, when you'd want to use them, and how they work. Unless you're an actual pro it's just pointless. And you can drag/drop media files into GUI programs too.

As suggested just work with programs in general.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
mikeflan
Level 19
Level 19
Posts: 9252
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: Why does ffmpeg concat require the word "file" before each file name in the text file?

Post by mikeflan »

I don't know the reason, the syntax is described here:
https://ffmpeg.org/ffmpeg-formats.html#Syntax
And here is the relevant section of examples that suggest the 'file' is needed:
.
Locked

Return to “Software & Applications”