Use ffmpeg copy codec to combine *.ts files into a single mp4
I've got a bunch of ts segments described by a single index.m3u8 file:
index.m3u8
segment1_0_av.ts
segment2_0_av.ts
segment3_0_av.ts
segment4_0_av.ts
segment5_0_av.ts
I know they are all encoded the same way. ffprobe gives me the following:
Input #0, mpegts, from 'segment1_0_av.ts':
Duration: 00:00:10.00, start: 0.100511, bitrate: 1251 kb/s
Program 1
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 12.50 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 105 kb/s
Stream #0:2[0x102]: Unknown: none ([21][0][0][0] / 0x0015)
I'd like to combine them into a single mp4 container. But when I try commands like:
ffmpeg -f concat -i filelist.txt -c copy output.mp4
where the generate the filelist.txt from the index.m3u8 file, it complains about not being able to read various files. But converting the ts files themselves seem to work fine. I think I'm not using ffmpeg properly.
How do I use ffmpeg to combine the ts files described by index.m3u8 into a single mp4 container using the copy codec?
command-line ffmpeg video-conversion codec mp4
add a comment |
I've got a bunch of ts segments described by a single index.m3u8 file:
index.m3u8
segment1_0_av.ts
segment2_0_av.ts
segment3_0_av.ts
segment4_0_av.ts
segment5_0_av.ts
I know they are all encoded the same way. ffprobe gives me the following:
Input #0, mpegts, from 'segment1_0_av.ts':
Duration: 00:00:10.00, start: 0.100511, bitrate: 1251 kb/s
Program 1
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 12.50 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 105 kb/s
Stream #0:2[0x102]: Unknown: none ([21][0][0][0] / 0x0015)
I'd like to combine them into a single mp4 container. But when I try commands like:
ffmpeg -f concat -i filelist.txt -c copy output.mp4
where the generate the filelist.txt from the index.m3u8 file, it complains about not being able to read various files. But converting the ts files themselves seem to work fine. I think I'm not using ffmpeg properly.
How do I use ffmpeg to combine the ts files described by index.m3u8 into a single mp4 container using the copy codec?
command-line ffmpeg video-conversion codec mp4
add a comment |
I've got a bunch of ts segments described by a single index.m3u8 file:
index.m3u8
segment1_0_av.ts
segment2_0_av.ts
segment3_0_av.ts
segment4_0_av.ts
segment5_0_av.ts
I know they are all encoded the same way. ffprobe gives me the following:
Input #0, mpegts, from 'segment1_0_av.ts':
Duration: 00:00:10.00, start: 0.100511, bitrate: 1251 kb/s
Program 1
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 12.50 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 105 kb/s
Stream #0:2[0x102]: Unknown: none ([21][0][0][0] / 0x0015)
I'd like to combine them into a single mp4 container. But when I try commands like:
ffmpeg -f concat -i filelist.txt -c copy output.mp4
where the generate the filelist.txt from the index.m3u8 file, it complains about not being able to read various files. But converting the ts files themselves seem to work fine. I think I'm not using ffmpeg properly.
How do I use ffmpeg to combine the ts files described by index.m3u8 into a single mp4 container using the copy codec?
command-line ffmpeg video-conversion codec mp4
I've got a bunch of ts segments described by a single index.m3u8 file:
index.m3u8
segment1_0_av.ts
segment2_0_av.ts
segment3_0_av.ts
segment4_0_av.ts
segment5_0_av.ts
I know they are all encoded the same way. ffprobe gives me the following:
Input #0, mpegts, from 'segment1_0_av.ts':
Duration: 00:00:10.00, start: 0.100511, bitrate: 1251 kb/s
Program 1
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 12.50 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 105 kb/s
Stream #0:2[0x102]: Unknown: none ([21][0][0][0] / 0x0015)
I'd like to combine them into a single mp4 container. But when I try commands like:
ffmpeg -f concat -i filelist.txt -c copy output.mp4
where the generate the filelist.txt from the index.m3u8 file, it complains about not being able to read various files. But converting the ts files themselves seem to work fine. I think I'm not using ffmpeg properly.
How do I use ffmpeg to combine the ts files described by index.m3u8 into a single mp4 container using the copy codec?
command-line ffmpeg video-conversion codec mp4
command-line ffmpeg video-conversion codec mp4
asked Dec 25 '13 at 17:53
Ana
4512915
4512915
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
I'm not sure why ffmpeg is giving you an error. However ts is one of the few formats that can simply be concatenated. Then, once you have a single ts, transmux to mp4.
Under windows:
copy /b segment1_0_av.ts+segment2_0_av.ts+segment3_0_av.ts all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
Under GNU/Linux, using bash:
cat segment1_0_av.ts segment2_0_av.ts segment3_0_av.ts > all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
12
You may also need-bsf:a aac_adtstoasc
.
– Camilo Martin
Jul 3 '16 at 20:38
1
interesting to note that the command is NOTffmpeg copy ...
, it iscopy ...
(under Windows)
– Ron Royston
Apr 4 '18 at 18:07
add a comment |
Using copy or cat to combine the files like szatmary's current top answer might leave you with a file that plays far past the limit and can't seek along with playback issues.
Instead, to combine these files properly use ffmpeg as instructed in https://trac.ffmpeg.org/wiki/Concatenate. (Install ffmpeg here if you don't already have it https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg.)
If you're too lazy to read my first link, you basically have to create a .txt file listing all the files you want to combine like so (which my first link gives instructions on how to do easily) in the folder where you're doing the concatenation:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Here's a copy paste from my first link on one way to create a text file if you have Windows on commandline for instance but obviously you can make the file manually or however you want:
(for %i in (*.ts) do @echo file '%i') > mylist.txt
Double check that your .txt file looks good and is formatted correctly!
After this, on commandline run:
ffmpeg -f concat -i mylist.txt -c copy all.ts
where 'mylist.txt' is the .txt file you just made.
Check if the resultant file plays video correctly. From here, you can transmux to mp4 as usual if you like:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
add a comment |
2017 answer
But when I try commands like
...
, it complains about not being able
to read various files.
When I execute ffmpeg -i some.ts -c copy some.mp4
on a certain video, I get this error message:
Malformed AAC bitstream detected: use the audio bitstream filter
'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)
av_interleaved_write_frame(): Operation not permitted
Not surprisingly, executing ffmpeg -i some.ts -c copy -bsf:a aac_adtstoasc some.mp4
fixes it.
3
Get a new enoughffmpeg
and it will now do this automatically.
– llogan
Nov 11 '17 at 18:40
add a comment |
Putting all together
Using the Juan Aquino's answer (and correcting the first command to be compatible with Bash and using the natural ordering of files), plus the 7vujy0f0hy's answer, a simple working script for a Linux Bash shell is:
#!/bin/bash
for i in `ls *.ts | sort -V`; do echo "file $i"; done >> mylist.txt
ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
add a comment |
You can do the concatenating simple like so (with bash):
for f in ./{0..<number>}.ts; do cat $f >> out.ts; done
Replace <number>
with the highest number (obviously). The variants with ffmpeg didn’t work properly. The output video file would stutter weirdly.
I use the for loop to ensure the correct order of the files. Maybe you don’t need it. Maybe it’s even possible to pipe the output to ffmpeg and convert it to mp4 on the fly.
add a comment |
The correct way to concat multiple video files from m3u8 playlist is
ffmpeg -i "index.m3u8" -codec copy output.mp4
- the m3u8 playlist can be on web or locally in directory
- it contains list of file paths relative to the playlist
-codec copy
to avoid encoding- container type matters:
*.mp4
is fine but it seems little slow to mux when playlist is fetched from web
*.mkv
or*.ts
worked best for me
add a comment |
All the popular answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.
delimiterBeforeFileNumber="-"
ls |egrep '[.]ts$'
|sort "-t$delimiterBeforeFileNumber" -k2,2n
|sed -r "s/(.*)/file '1'/" >ts.files.txt
ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4
The two preparatory lines of code just create a file containing a list of TS files in this line format:
file 'seg-37-a.ts'
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f692990%2fuse-ffmpeg-copy-codec-to-combine-ts-files-into-a-single-mp4%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure why ffmpeg is giving you an error. However ts is one of the few formats that can simply be concatenated. Then, once you have a single ts, transmux to mp4.
Under windows:
copy /b segment1_0_av.ts+segment2_0_av.ts+segment3_0_av.ts all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
Under GNU/Linux, using bash:
cat segment1_0_av.ts segment2_0_av.ts segment3_0_av.ts > all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
12
You may also need-bsf:a aac_adtstoasc
.
– Camilo Martin
Jul 3 '16 at 20:38
1
interesting to note that the command is NOTffmpeg copy ...
, it iscopy ...
(under Windows)
– Ron Royston
Apr 4 '18 at 18:07
add a comment |
I'm not sure why ffmpeg is giving you an error. However ts is one of the few formats that can simply be concatenated. Then, once you have a single ts, transmux to mp4.
Under windows:
copy /b segment1_0_av.ts+segment2_0_av.ts+segment3_0_av.ts all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
Under GNU/Linux, using bash:
cat segment1_0_av.ts segment2_0_av.ts segment3_0_av.ts > all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
12
You may also need-bsf:a aac_adtstoasc
.
– Camilo Martin
Jul 3 '16 at 20:38
1
interesting to note that the command is NOTffmpeg copy ...
, it iscopy ...
(under Windows)
– Ron Royston
Apr 4 '18 at 18:07
add a comment |
I'm not sure why ffmpeg is giving you an error. However ts is one of the few formats that can simply be concatenated. Then, once you have a single ts, transmux to mp4.
Under windows:
copy /b segment1_0_av.ts+segment2_0_av.ts+segment3_0_av.ts all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
Under GNU/Linux, using bash:
cat segment1_0_av.ts segment2_0_av.ts segment3_0_av.ts > all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
I'm not sure why ffmpeg is giving you an error. However ts is one of the few formats that can simply be concatenated. Then, once you have a single ts, transmux to mp4.
Under windows:
copy /b segment1_0_av.ts+segment2_0_av.ts+segment3_0_av.ts all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
Under GNU/Linux, using bash:
cat segment1_0_av.ts segment2_0_av.ts segment3_0_av.ts > all.ts
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
edited Dec 19 '15 at 17:08
Guillaume Pascal
1033
1033
answered Dec 25 '13 at 18:42
szatmary
1,679710
1,679710
12
You may also need-bsf:a aac_adtstoasc
.
– Camilo Martin
Jul 3 '16 at 20:38
1
interesting to note that the command is NOTffmpeg copy ...
, it iscopy ...
(under Windows)
– Ron Royston
Apr 4 '18 at 18:07
add a comment |
12
You may also need-bsf:a aac_adtstoasc
.
– Camilo Martin
Jul 3 '16 at 20:38
1
interesting to note that the command is NOTffmpeg copy ...
, it iscopy ...
(under Windows)
– Ron Royston
Apr 4 '18 at 18:07
12
12
You may also need
-bsf:a aac_adtstoasc
.– Camilo Martin
Jul 3 '16 at 20:38
You may also need
-bsf:a aac_adtstoasc
.– Camilo Martin
Jul 3 '16 at 20:38
1
1
interesting to note that the command is NOT
ffmpeg copy ...
, it is copy ...
(under Windows)– Ron Royston
Apr 4 '18 at 18:07
interesting to note that the command is NOT
ffmpeg copy ...
, it is copy ...
(under Windows)– Ron Royston
Apr 4 '18 at 18:07
add a comment |
Using copy or cat to combine the files like szatmary's current top answer might leave you with a file that plays far past the limit and can't seek along with playback issues.
Instead, to combine these files properly use ffmpeg as instructed in https://trac.ffmpeg.org/wiki/Concatenate. (Install ffmpeg here if you don't already have it https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg.)
If you're too lazy to read my first link, you basically have to create a .txt file listing all the files you want to combine like so (which my first link gives instructions on how to do easily) in the folder where you're doing the concatenation:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Here's a copy paste from my first link on one way to create a text file if you have Windows on commandline for instance but obviously you can make the file manually or however you want:
(for %i in (*.ts) do @echo file '%i') > mylist.txt
Double check that your .txt file looks good and is formatted correctly!
After this, on commandline run:
ffmpeg -f concat -i mylist.txt -c copy all.ts
where 'mylist.txt' is the .txt file you just made.
Check if the resultant file plays video correctly. From here, you can transmux to mp4 as usual if you like:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
add a comment |
Using copy or cat to combine the files like szatmary's current top answer might leave you with a file that plays far past the limit and can't seek along with playback issues.
Instead, to combine these files properly use ffmpeg as instructed in https://trac.ffmpeg.org/wiki/Concatenate. (Install ffmpeg here if you don't already have it https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg.)
If you're too lazy to read my first link, you basically have to create a .txt file listing all the files you want to combine like so (which my first link gives instructions on how to do easily) in the folder where you're doing the concatenation:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Here's a copy paste from my first link on one way to create a text file if you have Windows on commandline for instance but obviously you can make the file manually or however you want:
(for %i in (*.ts) do @echo file '%i') > mylist.txt
Double check that your .txt file looks good and is formatted correctly!
After this, on commandline run:
ffmpeg -f concat -i mylist.txt -c copy all.ts
where 'mylist.txt' is the .txt file you just made.
Check if the resultant file plays video correctly. From here, you can transmux to mp4 as usual if you like:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
add a comment |
Using copy or cat to combine the files like szatmary's current top answer might leave you with a file that plays far past the limit and can't seek along with playback issues.
Instead, to combine these files properly use ffmpeg as instructed in https://trac.ffmpeg.org/wiki/Concatenate. (Install ffmpeg here if you don't already have it https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg.)
If you're too lazy to read my first link, you basically have to create a .txt file listing all the files you want to combine like so (which my first link gives instructions on how to do easily) in the folder where you're doing the concatenation:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Here's a copy paste from my first link on one way to create a text file if you have Windows on commandline for instance but obviously you can make the file manually or however you want:
(for %i in (*.ts) do @echo file '%i') > mylist.txt
Double check that your .txt file looks good and is formatted correctly!
After this, on commandline run:
ffmpeg -f concat -i mylist.txt -c copy all.ts
where 'mylist.txt' is the .txt file you just made.
Check if the resultant file plays video correctly. From here, you can transmux to mp4 as usual if you like:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
Using copy or cat to combine the files like szatmary's current top answer might leave you with a file that plays far past the limit and can't seek along with playback issues.
Instead, to combine these files properly use ffmpeg as instructed in https://trac.ffmpeg.org/wiki/Concatenate. (Install ffmpeg here if you don't already have it https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg.)
If you're too lazy to read my first link, you basically have to create a .txt file listing all the files you want to combine like so (which my first link gives instructions on how to do easily) in the folder where you're doing the concatenation:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Here's a copy paste from my first link on one way to create a text file if you have Windows on commandline for instance but obviously you can make the file manually or however you want:
(for %i in (*.ts) do @echo file '%i') > mylist.txt
Double check that your .txt file looks good and is formatted correctly!
After this, on commandline run:
ffmpeg -f concat -i mylist.txt -c copy all.ts
where 'mylist.txt' is the .txt file you just made.
Check if the resultant file plays video correctly. From here, you can transmux to mp4 as usual if you like:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
edited May 4 '17 at 14:24
answered Jan 1 '17 at 19:32
Juan Aquino
19114
19114
add a comment |
add a comment |
2017 answer
But when I try commands like
...
, it complains about not being able
to read various files.
When I execute ffmpeg -i some.ts -c copy some.mp4
on a certain video, I get this error message:
Malformed AAC bitstream detected: use the audio bitstream filter
'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)
av_interleaved_write_frame(): Operation not permitted
Not surprisingly, executing ffmpeg -i some.ts -c copy -bsf:a aac_adtstoasc some.mp4
fixes it.
3
Get a new enoughffmpeg
and it will now do this automatically.
– llogan
Nov 11 '17 at 18:40
add a comment |
2017 answer
But when I try commands like
...
, it complains about not being able
to read various files.
When I execute ffmpeg -i some.ts -c copy some.mp4
on a certain video, I get this error message:
Malformed AAC bitstream detected: use the audio bitstream filter
'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)
av_interleaved_write_frame(): Operation not permitted
Not surprisingly, executing ffmpeg -i some.ts -c copy -bsf:a aac_adtstoasc some.mp4
fixes it.
3
Get a new enoughffmpeg
and it will now do this automatically.
– llogan
Nov 11 '17 at 18:40
add a comment |
2017 answer
But when I try commands like
...
, it complains about not being able
to read various files.
When I execute ffmpeg -i some.ts -c copy some.mp4
on a certain video, I get this error message:
Malformed AAC bitstream detected: use the audio bitstream filter
'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)
av_interleaved_write_frame(): Operation not permitted
Not surprisingly, executing ffmpeg -i some.ts -c copy -bsf:a aac_adtstoasc some.mp4
fixes it.
2017 answer
But when I try commands like
...
, it complains about not being able
to read various files.
When I execute ffmpeg -i some.ts -c copy some.mp4
on a certain video, I get this error message:
Malformed AAC bitstream detected: use the audio bitstream filter
'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)
av_interleaved_write_frame(): Operation not permitted
Not surprisingly, executing ffmpeg -i some.ts -c copy -bsf:a aac_adtstoasc some.mp4
fixes it.
edited Mar 25 '17 at 22:44
answered Mar 25 '17 at 22:38
7vujy0f0hy
1
1
3
Get a new enoughffmpeg
and it will now do this automatically.
– llogan
Nov 11 '17 at 18:40
add a comment |
3
Get a new enoughffmpeg
and it will now do this automatically.
– llogan
Nov 11 '17 at 18:40
3
3
Get a new enough
ffmpeg
and it will now do this automatically.– llogan
Nov 11 '17 at 18:40
Get a new enough
ffmpeg
and it will now do this automatically.– llogan
Nov 11 '17 at 18:40
add a comment |
Putting all together
Using the Juan Aquino's answer (and correcting the first command to be compatible with Bash and using the natural ordering of files), plus the 7vujy0f0hy's answer, a simple working script for a Linux Bash shell is:
#!/bin/bash
for i in `ls *.ts | sort -V`; do echo "file $i"; done >> mylist.txt
ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
add a comment |
Putting all together
Using the Juan Aquino's answer (and correcting the first command to be compatible with Bash and using the natural ordering of files), plus the 7vujy0f0hy's answer, a simple working script for a Linux Bash shell is:
#!/bin/bash
for i in `ls *.ts | sort -V`; do echo "file $i"; done >> mylist.txt
ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
add a comment |
Putting all together
Using the Juan Aquino's answer (and correcting the first command to be compatible with Bash and using the natural ordering of files), plus the 7vujy0f0hy's answer, a simple working script for a Linux Bash shell is:
#!/bin/bash
for i in `ls *.ts | sort -V`; do echo "file $i"; done >> mylist.txt
ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
Putting all together
Using the Juan Aquino's answer (and correcting the first command to be compatible with Bash and using the natural ordering of files), plus the 7vujy0f0hy's answer, a simple working script for a Linux Bash shell is:
#!/bin/bash
for i in `ls *.ts | sort -V`; do echo "file $i"; done >> mylist.txt
ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
answered Nov 11 '17 at 10:10
Francesco Galgani
1366
1366
add a comment |
add a comment |
You can do the concatenating simple like so (with bash):
for f in ./{0..<number>}.ts; do cat $f >> out.ts; done
Replace <number>
with the highest number (obviously). The variants with ffmpeg didn’t work properly. The output video file would stutter weirdly.
I use the for loop to ensure the correct order of the files. Maybe you don’t need it. Maybe it’s even possible to pipe the output to ffmpeg and convert it to mp4 on the fly.
add a comment |
You can do the concatenating simple like so (with bash):
for f in ./{0..<number>}.ts; do cat $f >> out.ts; done
Replace <number>
with the highest number (obviously). The variants with ffmpeg didn’t work properly. The output video file would stutter weirdly.
I use the for loop to ensure the correct order of the files. Maybe you don’t need it. Maybe it’s even possible to pipe the output to ffmpeg and convert it to mp4 on the fly.
add a comment |
You can do the concatenating simple like so (with bash):
for f in ./{0..<number>}.ts; do cat $f >> out.ts; done
Replace <number>
with the highest number (obviously). The variants with ffmpeg didn’t work properly. The output video file would stutter weirdly.
I use the for loop to ensure the correct order of the files. Maybe you don’t need it. Maybe it’s even possible to pipe the output to ffmpeg and convert it to mp4 on the fly.
You can do the concatenating simple like so (with bash):
for f in ./{0..<number>}.ts; do cat $f >> out.ts; done
Replace <number>
with the highest number (obviously). The variants with ffmpeg didn’t work properly. The output video file would stutter weirdly.
I use the for loop to ensure the correct order of the files. Maybe you don’t need it. Maybe it’s even possible to pipe the output to ffmpeg and convert it to mp4 on the fly.
answered Jan 5 '18 at 19:00
ragnarsson
211
211
add a comment |
add a comment |
The correct way to concat multiple video files from m3u8 playlist is
ffmpeg -i "index.m3u8" -codec copy output.mp4
- the m3u8 playlist can be on web or locally in directory
- it contains list of file paths relative to the playlist
-codec copy
to avoid encoding- container type matters:
*.mp4
is fine but it seems little slow to mux when playlist is fetched from web
*.mkv
or*.ts
worked best for me
add a comment |
The correct way to concat multiple video files from m3u8 playlist is
ffmpeg -i "index.m3u8" -codec copy output.mp4
- the m3u8 playlist can be on web or locally in directory
- it contains list of file paths relative to the playlist
-codec copy
to avoid encoding- container type matters:
*.mp4
is fine but it seems little slow to mux when playlist is fetched from web
*.mkv
or*.ts
worked best for me
add a comment |
The correct way to concat multiple video files from m3u8 playlist is
ffmpeg -i "index.m3u8" -codec copy output.mp4
- the m3u8 playlist can be on web or locally in directory
- it contains list of file paths relative to the playlist
-codec copy
to avoid encoding- container type matters:
*.mp4
is fine but it seems little slow to mux when playlist is fetched from web
*.mkv
or*.ts
worked best for me
The correct way to concat multiple video files from m3u8 playlist is
ffmpeg -i "index.m3u8" -codec copy output.mp4
- the m3u8 playlist can be on web or locally in directory
- it contains list of file paths relative to the playlist
-codec copy
to avoid encoding- container type matters:
*.mp4
is fine but it seems little slow to mux when playlist is fetched from web
*.mkv
or*.ts
worked best for me
answered Nov 14 '18 at 20:18
Vlastimil Ovčáčík
1,50211025
1,50211025
add a comment |
add a comment |
All the popular answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.
delimiterBeforeFileNumber="-"
ls |egrep '[.]ts$'
|sort "-t$delimiterBeforeFileNumber" -k2,2n
|sed -r "s/(.*)/file '1'/" >ts.files.txt
ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4
The two preparatory lines of code just create a file containing a list of TS files in this line format:
file 'seg-37-a.ts'
add a comment |
All the popular answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.
delimiterBeforeFileNumber="-"
ls |egrep '[.]ts$'
|sort "-t$delimiterBeforeFileNumber" -k2,2n
|sed -r "s/(.*)/file '1'/" >ts.files.txt
ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4
The two preparatory lines of code just create a file containing a list of TS files in this line format:
file 'seg-37-a.ts'
add a comment |
All the popular answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.
delimiterBeforeFileNumber="-"
ls |egrep '[.]ts$'
|sort "-t$delimiterBeforeFileNumber" -k2,2n
|sed -r "s/(.*)/file '1'/" >ts.files.txt
ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4
The two preparatory lines of code just create a file containing a list of TS files in this line format:
file 'seg-37-a.ts'
All the popular answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.
delimiterBeforeFileNumber="-"
ls |egrep '[.]ts$'
|sort "-t$delimiterBeforeFileNumber" -k2,2n
|sed -r "s/(.*)/file '1'/" >ts.files.txt
ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4
The two preparatory lines of code just create a file containing a list of TS files in this line format:
file 'seg-37-a.ts'
answered Nov 23 '18 at 7:35
Douglas Daseeco
1011
1011
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f692990%2fuse-ffmpeg-copy-codec-to-combine-ts-files-into-a-single-mp4%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown