Score:2

Can ffmpeg be used to concatenate files?

cn flag

A while back I asked how to convert mp4 files to mp3 and someone pointed me to ffmpeg. That is a great command and it does a great job.

Now I'd like to know about concatenating files together. Can ffmpeg be used for that? It didn't look like it when I tried to figure it out. Can it, or is there another command for that?

Score:2
ec flag

Your question as written doesn't appear to have anything to do with the Ubuntu OS. You'd likely be better served if you asked this question over on the Unix & Linux SE site.

That said, you may want to review the online FFmpeg documentation as it relates to concatenating files, as that appears to directly answer your question. From that site:

If you have media files with exactly the same codec and codec parameters you can concatenate them as described in "Concatenation of files with same codecs". If you have media with different codecs you can concatenate them as described in "Concatenation of files with different codecs" below.

P Simdars avatar
cn flag
I am using Ubuntu latest version.
Nmath avatar
ng flag
The question is definitely on topic, so the first half of this answer isn't useful. The second half of the answer could be improved with examples. It's currently not much more than a link only answer, and link only answers are considered low quality.
hu flag
@Nmath-onstrike ...on topic how? It has nothing to do with Ubuntu. :~) It is irrelevant which distro is used here. Kinda like, "My backside itched, how do I scratch it??? ...oh, and I aming using Ubuntu".
Nmath avatar
ng flag
Questions about how to perform tasks on Ubuntu are on topic even if they do not explicitly mention Ubuntu. ffmpeg is in official Ubuntu repositories. Questions about ffmpeg are on topic.
ec flag
My view on whether this question is on or off topic is whether the OP is having an issue with the configuration and operation of the OS or an application (in this case, `ffmpeg`), and whether the OS is a contributing factor. My read of the question was one of operation _independent from OS_ (they wanted to know how to concat files using the `ffmpeg` application). This question could just have easily been asked in any OS forum and it would still be relevant. This is my reasoning for recommending the OP ask the question on a different SE site. Happy to move this discussion elsewhere.
P Simdars avatar
cn flag
Because something can be used on another system is irrelevant. Do you propose that everyone who asks a question about something they are doing on Ubuntu should go out first and research whether this could relate to other OS before posting?
Esther avatar
es flag
@richbl it just so happens that "your view on whether questions are on or off topic" contradicts community consensus on Meta https://meta.askubuntu.com/questions/14523/are-not-only-ubuntu-specific-questions-on-topic https://meta.askubuntu.com/questions/20017/is-a-question-about-third-party-software-on-topic-if-there-is-no-reference-to-ub . These questions are definitely considered on-topic here.
Score:0
fk flag

There are ways to combine files in ffmpeg but they are a bit convoluted. So, I use a bash script to make it easier. This is an example of a script that you run with arguments (the names of the files to be combined) and it produces a combined .mp4 file, but you can change the .mp4 extension to something else if you prefer a different type of output file. A temporary file called mylist.txt is created (if a file of that name already exists it will be deleted first) and that is the file that ffmpeg reads to find the list of files to concatenate:

#!/bin/bash

rm -f mylist.txt
# Loop until all input filenames are used up
while [ "$1" != "" ]; do
    echo "file '~/$1'" >> mylist.txt
    # Shift all the input filenames down by one
    shift
done
file="$(date +%Y-%m-%d-%H-%M-%S)"

ffmpeg -f concat -safe 0 -i mylist.txt -c copy "~/combined_$file.mp4"
rm -f mylist.txt

Note that if the files you are combining are too dissimilar you may need to re-encode the video or audio rather than just doing a straight copy as shown here, but that will take much longer and you will probably lose some quality.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.