Files
hpr-knowledge-base/hpr_transcripts/hpr4077.txt

86 lines
7.7 KiB
Plaintext
Raw Normal View History

Episode: 4077
Title: HPR4077: FFMPEG Series: Joining and Splitting files
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr4077/hpr4077.mp3
Transcribed: 2025-10-25 19:18:39
---
This is Hacker Public Radio, episode 4,077 for Tuesday, the 19th of March 2024.
Today's show is entitled, FFMPG series, Joining and Splitting Files.
It is hosted by the EZ and is about nine minutes long.
It carries a clean flag.
The summary is, in this episode, I explain how to use FFMPG to join and split media files.
Hello Hacker Public Radio fans.
This is Mr. Young coming back again with another episode, Sorry for the delay in releases, but I've been very busy.
But I'm back and I'm here with another in the series for FFMPG.
This time we're going to be talking about joining and splitting files.
Now, it seems like it would be a straightforward thing, and actually it's not as straightforward as you might think.
And hopefully this will be an insight.
It might seem a little bit premature to talk about this, but I'm trying to be as useful as possible
before getting into a lot of the mechanics about how FFMPG works.
And so a little bit more of a how to rather than a deep dive into the mechanics of exactly how FFMPG works.
So let's start out with some concatenation of files.
So the structure of the command FFMPG dash i dash i is always input.
And then in quotes, you put the work concat c o n c a t colon, and then you put the name of the first file, and then a bar, like a vertical bar, and then the next one of the bar and a vertical bar again for everyone in between.
For every file that you want, and then a close quote at the end.
And then you do a dash c copy, and then you do the output file name.
Now this only works with lossless files, and it only works when they are of the same codec.
So if I'm looking at that wave files or dot TS files, I haven't tried it without flack, but I've tried it without TS and that wave.
And then if you want to from there, you can always convert.
And so that's the structure of the file and the command.
If you want to do something like an MP4 file to concat those together, you might have to convert them into a dot TS file first, so that they're of a format where they can be put together.
And to do that, you use the command ffmpeg-i and put one dot MP4 dash c copy, and then intermediate file one dot TS, and then you do that for every file.
And then you can use the command that I just said before ffmpeg-i concat the first file, the second file, however many files you have dash c copy and then output file dot TS.
And then you can use ffmpeg-i output dot TS.
Then you can even say dash c copy and then say output dot MP4 and now you're back at MP4 format.
So hopefully that helps you learn a little bit about how to put files together.
The dash c is what codec to use, and in more advanced episodes, we'll talk about different types of codecs, but dash c is all codec.
So if it's just a music file or a sound file, you're just copying the sound.
If you're doing dash c on an audio visual file, it's going to copy both the audio codec and the visual codec.
So I hope that was helpful. Now we're going to go on to splitting files.
And splitting files is actually a little bit easier than putting them together.
One of the reasons why I took me so long to do this episode is because I've always had actually a hard time putting files together.
And so it took me a while to find the right tutorials to really make this work.
And so I've in my show notes, I have where I've got where I took my commands from and it's from track.ffmpeg.org.
It's a wiki for ffmpeg.
Here we're going to also talk about splitting files. This is, like I said, a little bit easier.
It's from the same website.
And you can go ffmpeg-i-input.mp4-t.
I think they do, like, some type of timestamp in the format of 00.colon05.000.
That's five minutes. And then output.mp4.
So what that would do is I would give you the first five minutes of a file.
You can go, you can do it a little bit differently.
And you can use, if you just don't want to start at the beginning, you can do ffmpeg-i-input.file.
Then dash t00.colon05.colon00.
And then a dash SS0500.colon05.colon00.
I'll put that in before.
What that does, what the SS1 will do is that will say what your starting position is.
So I'm going to start five minutes in and then get five minutes.
And if I don't do anything, it's going to copy the formats to make that implicit.
You can do a dash c copy to make sure that it's going to make the outputs exactly the same.
And so all this, all these actions actually happen really quickly.
If you are staying within the same format and you're not trying to change either the audio or video codec.
So right now, like I said, I'm using.mp4, but most of these commands will work with other types of files as well.
And I'll go into other episodes where I talk a little bit more about the benefits and the distractors, detractors from each of the different file formats.
But for now, this is just something that is really useful.
If you wanted to split by size, I have a command for that too, but before I get there, you can actually, if you wanted to split by chapters or markers.
I don't, I haven't figured out a way to do that automatically.
But if you have a, if you can find the markers either inside the mkv format or inside of other formats where you can actually view all the timestamps, you can either create another script or just manually write down those timings and then turn it into a script where you create using the commands I made above.
You can use the same commands to split the files into multiple parts for each chapter.
When it comes to splitting by size, you can use a dash map command, so MAP.
So in this case, I'm going to say ffmpeg-i input dot mp4 dash map 0 dash C copy dash segment underscore size 50 m dash segment times one and then output underscore percent sign 0 3d dot mp4.
Now, let's break down that command a little bit.
The dash map 0 means select the first stream, the first audio and video stream that is in the that that follows the dash i command.
And then dash C copy once again is stream copy of the codex without re encoding dash segment underscore size as you can think of is the size of the segment that you want and then dash segment times that's how many segments that you want.
So if I say that dash segment times one, I'm going to get the first 50 megabyte file segment, but if I put dash two, it will get the first two 50 megabyte segments.
And then the end part of the output underscore percent 0 3d dot mp4, if you're familiar with print f of it or other program language that used the similar format, we're using a a basically a pattern for the alpha files.
So percent 0 3d means I'm going to have a three a padded a three zero padded output name.
So for this one is going to be underscore 0 0 0 problem for the first one and then for the second will be 0 0 1 0 0 2 all the up if you were going to make a lot.
So that's how that works. It's a it's a print of style output file. So that way you don't have to name each one of the files that each get an automatic name based on that that pattern.
Like I said, all these commands going to be in the show notes. I just wanted to give you a quick rundown of how to combine and split files. Hopefully this was useful to you.
Once again, this is Mr. Young. I'm signing off for Hacker Public Radio.
You have been listening to Hacker Public Radio at Hacker Public Radio does work.
Today's show was contributed by a HPR listener like yourself. If you ever thought of recording a podcast, you click on our contribute link to find out how easy it leads.
The hosting for HPR has been kindly provided by an honest host.com, the internet archive and our syncs.net.
On the Sadois status, today's show is released under Creative Commons Attribution 4.0 International License.