[SOLVED] Media newbie: How do I stitch together multiple .ts files into a single video?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Fedora 36; Homebrew desktop with Ryzen 5600G and 32Gb. Using Red Hat since 1998
Posts: 304
Rep:
Media newbie: How do I stitch together multiple .ts files into a single video?
I have a digital TV recorder. It saves recordings in a directory named for the show I am recording e.g. 'ABC1-01012014-2210-ABC News Late Edition.pvr', as a sequence of .ts files e.g. 'data0001.ts' , 'data0002.ts', 'data0003.ts' and a text file called 'MM_PLAY_TIME.ini'.
A web search indicated that .ts files are MPEG2 Transport Stream files and can be converted to MPEG2 Program Stream (.ps) files, for better interoperability with a wide range of players.
I can play all the .ts files, sequentially, on my Fedora 19 box, using VLC Media Player, but is there a way to stitch them together into a single file, so I can see the whole program without interruption?
If I can get that far, I believe a tool like avidemux will allow me to convert the file to .ps - does that sound right?
Distribution: Fedora 36; Homebrew desktop with Ryzen 5600G and 32Gb. Using Red Hat since 1998
Posts: 304
Original Poster
Rep:
Thanks, metaschima. Unfortunately, each of the first three files is 2.1Gb, so cat tries to create a humungous file, which does not work on my 32 bit platform. I only know, because I tried and it went 'bang' <grin>.
Distribution: Fedora 36; Homebrew desktop with Ryzen 5600G and 32Gb. Using Red Hat since 1998
Posts: 304
Original Poster
Rep:
Hmmmm .... I was wrong about the file size issue. I used avidemux, which opened the first file in the sequence and noticed the rest were sequentially numbered, so offered to open them all. I did this, set the output format to 'Mpeg-PS Muxer(ff)' and chose to 'Save', which asked for a target filename, then happily created a 6.5Gb file out of it. I have yet to play the file, so cannot assert everything went well, but the indications so far are good.
If the new file plays nicely, I will try using Openshot, to trim the opening and closing extra few minutes I recorded, to make sure I captured the whole movie. So far, so good.
Distribution: Fedora 36; Homebrew desktop with Ryzen 5600G and 32Gb. Using Red Hat since 1998
Posts: 304
Original Poster
Rep:
Well, OpenShot just died when I tried to play the file, so I used avidemux to trim the unwanted parts and ended up with a three-hour movie, which is what I wanted.
Distribution: Fedora 36; Homebrew desktop with Ryzen 5600G and 32Gb. Using Red Hat since 1998
Posts: 304
Original Poster
Rep:
Sequel:
The movie I eneded up with was a 5.8Gb file. To shrink it to fit a DVD, I used ffmpeg and specified a lower bit rate per second. As this was going to be a shrunk file, I told ffmpeg to output to 'shrunk.mpg'. When I was sure it was small enough (4.7Gb), I checked that Brasero would accept it for writing to a DVD. Brasero was happy with 'shrunk.mpg', but when I renamed the file to '<real movie name>.mpg', Braseo reported the error "<real movie name.mpg> is not suitable for audio or video media". I renamed it back to 'shrunk.mpg' and Brasero was happy again, so it seems Brasero checks the content of the file, to ensure some internal identifier matches the filename. Weird, to a newbie, but glad it is solved.
For the sake of anyone following this thread, the ffmpeg command line I used, to shrink a 5.8Gb file at 4150 kbits per second, to a 4.7Gb file, was:
ffmpeg -i <big filename>.mpg -c:v mpeg2video -b:v 3200k shrunk.mpg
Incidentally, I first tried limiting the file size by using the file size limit option to ffmpeg as '-fs 4700MiB', but this option was ignored, which is why I had to play around with the bit rate, until I ended up with an output file small enough to burn to DVD. Of course, I may have used incorrect syntax for this option, but I checked that it follows what the man page said. Also, first attempts had ffmpeg convert the output to mpeg1video, which is why I had to specify mpeg2video for the video stream. Curious.
Thanks CaptSaltyJack. I was unsure if video files contained any wrappers or similar to specify their start and end points, in which case a simple cat might have resulted in unreadable output. I'm glad to have it clarified. "8-)
Thanks CaptSaltyJack. I was unsure if video files contained any wrappers or similar to specify their start and end points, in which case a simple cat might have resulted in unreadable output. I'm glad to have it clarified. "8-)
Actually, this is often a concern. It will likely work, but you won't be able to seek, files will play far past their limit (cat 2 30sec files together and you get a clip that says it's 30 sec long but plays for 60 sec)
This is with files that aren't intended to be split or combined (eg mp4, ogg, mp3)
If your files were split after being encoded, the below doesn't apply.
I would consider cat the quick & dirty fix - since it works, but I would suggest using ffmpeg to put them together is you want it to look nice
Strange, I used the cat method to concatenate 500 separate TS files together, then load into Adobe Premiere to export as MP4. Worked totally fine. Maybe I got lucky.
Strange, I used the cat method to concatenate 500 separate TS files together, then load into Adobe Premiere to export as MP4. Worked totally fine. Maybe I got lucky.
It's important to consider when / why it's being split or combined.
I'm not familiar with .ts files, but if they are simply a sequential organized parts of a file with the first containing all info needed, concatenating them is fine (& the right thing to do)
On the other hand, concatenating a ogg file with another will likely make it work until the first song ends - then do something (good or bad)
Then using ffmpeg to re-write the correct info is the right thing to do in that scenario.
From the OP, it looks like they were mpeg2 files, so I would go with ffmpeg.
However, if a simple cat did it & there's no issues with seek or anything - go with it (it's easier).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.