trimming/splitting recordings *with* subtitle stream

Added by Rob vh almost 9 years ago

I save my recordings in pass through format (.ts files). Using VLC and ffmpeg you can see the streams in the files, including the subtitles stream. I would like to split several of the recordings, removing the "start before" and "end after" trash, whilst keeping the subtitle stream. Note, I do not want to read/add/extract closed-caption subtitles, just want to keep the stream in, as is.

I have already tried several tools, but they seem to remove the subtitle stream (or are too clunky). I would really like a previewer where you can click the progress bar for start and end of the segment, and then press Save. Windows, Linux, either platform is fine.

Replies (8)

RE: trimming/splitting recordings *with* subtitle stream - Added by Prof Yaffle over 8 years ago

ProjectX doesn't handle H.264, though, does it? It might not be a problem, but it's becoming increasingly obsolete (sadly - it was a good tool).

After that, there seems to be a number of Windows tools to extract subtitles from .ts files, but they're not free or open source in general. If you want to stay in the FOSS domain, you're looking at tsmuxer and/or subrip - you need to extract the stream and OCR them into a text file from what I can gather.

I suppose the alternative - given the nature of ts - would be to simply cut the file if you can determine the end of the 'start before' or the start of the 'end after' trash. You might find dd or similar would do it, though I've no idea if it would work or with what accuracy you could cut it.

RE: trimming/splitting recordings *with* subtitle stream - Added by Ron L over 8 years ago

I dump a lot of tv shows, movies etc out of an IP data stream on satellite. The files all have extra non mpeg data written to them at the end that messes up seek in most players. I wrote some scripts that use head -c to cut off the extra data at the end and mplayer to find the point in MB where you want to cut the file. You could swap out head with tail to cut stuff from the beggining of the file as well I expect. Doesn't alter the TS in any way just trims raw bytes off the file.

For an example you can look here....

tailsize is what I use to find the point in MB where I want to split the file. It's just kind of trial and error until you find the point. Once I find that point I feed the MB number into clipfile. If you don't recognize pv that is the pipe viewer app. It's in the repos.

Because there is no error correction in the IP data stream dumps a lot of the files I get will have minor errors in the stream at places. Trying to cut the stream using any video editing software generally results in the audio becoming out of sync. projectx didn't have that issue, but it can't do h.264 which is most things these days. Just trimming with head and tail is much faster any way.

RE: trimming/splitting recordings *with* subtitle stream - Added by Latty Jordan over 8 years ago

ProjectX can't extract H264 video, but it can extract the subtitles from a .ts file where the video is H264. Simply load the file up, set the appropriate ProjectX settings then click on start. OK you may have to edit out a few lines at the start and end, and sometimes the subtitle timing is out, but I use SubtitleEdit to correct that. It's also got a nifty feature whereby you can get foreign language subs automatically translated on-line.

For cutting H264, Avidemux is the best I've found although it's nowhere as easy to use as ProjectX. You can't for example cut out multiple commercial breaks in one go, but have to convert each segment to a file then merge those. And it doesn't have the nice batch handling abilities of ProjectX, so you have to do it one job at a time.

RE: trimming/splitting recordings *with* subtitle stream - Added by Prof Yaffle over 8 years ago

Re: ProjectX - that's good to know, maybe I'll grab a copy just in case. I wonder if you could extract, convert to .SRT or similar, re-mux them with the original streams in something like mkv and then cut? Would that give better timings?

Re: avidemux - my (grudging) tool of choice for cutting as well. However, it's easier than you suggest, as you don't have to save the sections and merge them. Instead, simply select (A to B) the bits you don't want and delete them, then save what's left as a single file. I normally save out to mkv with audio and video set to 'copy', so it's effectively seamless so long as you've cut on I-frames - if the stream only has B- and P- then cutting will have slight corruption, but it's very momentary. If that's a problem, or if you need to re-encode audio streams/trim black bars/correct errors, I've found that dropping it through Handbrake first is easier than fighting with avidemux's filters. As part of that, you create new I-frames and can specify how frequent they are (keyint/min-keyint) to give an easier, cleaner cut - you just need to think about your frame rate (e.g. 50 fps with a GOP of 250 means you may only have an I-frame every 5 seconds, which is useless for fine tuning cut points).

RE: trimming/splitting recordings *with* subtitle stream - Added by Latty Jordan over 8 years ago

The timing problem with subtitles ripped from.ts files where the video is H264 is entirely due to the fact that without the video preview you can't see where to start and stop ripping, so you're stuck with your tvheadend recordings of plus or minus approximately 10 minutes. Now I suppose the smart thing to do would be to first cut the audio and video, note where the programme actually starts (the first A point with Avidemux), and use that to adjust the timings with SubtitleEdit if necessary. But in practice it's not always necessary because quite a few broadcasters seem to send some sort of zero-the-clock-for-subtitles signal at the start of every sub-titled programme, so the subs you get from ProjectX show the right timings anyway. Otherwise I find it easy enough to watch for a line, write down the timing (to the nearest second is plenty good enough for me), find that line in the .srt file, them work out what adjustment I need to make.

When ripping subtitles with ProjectX you can choose what format to save them in, and it will even extract and save the new .sup and .sup.ifo format from the (bitmap) dvb subtitles. SubtitleEdit also has an option to OCR these to try to get a .srt file, but fortunately I've not yet needed to do this because it all looks a bit of a faff.

RE: trimming/splitting recordings *with* subtitle stream - Added by summers pan over 7 years ago

I think it's might be so much easier when you choose some right tool to crop the video as your need.You might try set the parameters or something to keep the caption or subtitles,I think it's the hard subtitles here?
Anyway, I've been using some video editor which is quite helpful for me, here's the tutorial for cropping videos and other useful info for clip videos too:

RE: trimming/splitting recordings *with* subtitle stream - Added by Anonymous over 7 years ago

You can use ffmpeg (not avconv) to do the trimming/splitting recordings with subtitle stream.
When you have movies with hard subtitles (picture-based subtitles) you must transcode to a container with the "hard subtitle" as a overlay video over the actual videofile. For instance, dvdsub is a type of picture-based overlay subtitles. With hard subtitles you don't have to export the hard subtitle to a .srt or .ass file as with soft subtitles.

Exampel: Here I have a Matroska file with two dvb_subtitle. Ffmpeg will choose the first stream by default, which is Stream #0:3(nor). You can also choose the other subtitle in ffmpeg with the correct Streamid.

ffmpeg -i Matematikkmysteriet.mkv

 Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 1k tbn, 100 tbc (default)
    Stream #0:1(nor): Audio: mp2, 48000 Hz, stereo, s16p, 256 kb/s (default)
    Stream #0:2(nor): Audio: ac3, 48000 Hz, stereo, fltp, 448 kb/s (default)
    Stream #0:3(nor): Subtitle: dvb_subtitle (default)
    Stream #0:4(nor): Subtitle: dvb_subtitle (default)

The ffmpeg command will be:

ffmpeg -i Matematikkmysteriet.mkv -filter_complex "[0:v][0:s]overlay[v]" -map [v] -map 0:a Matematikk.ts

Everything is well documented in the Ffmpeg wiki here: [[]]

You can also do trimming/splitting recordings with ffmpeg if you know the starttime and the stoptime or the duration.
Look here for ffmpeg exampel: [[]]

Here is a exampel where I cut the beginning of the recordings with 2 minuts and the duration of the video is 55 minuts with hard subtitle stream:

ffmpeg -ss 00:02:00 -i Matematikkmysteriet.mkv -filter_complex "[0:v][0:s]overlay[v]" -map [v] -map 0:a -b:v -t 00:55:00 MatematikkCutted.mpg