Project

General

Profile

Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break

Added by Neil Renaud about 11 years ago

Hi,

So I record a TV show and what I want to end up with eventually is an MKV file with Chapter marks to show the start and end of adverts. Ideally I'd also like to copy the metadata from the TV recording into the MKV properties.

So firstly I have to record in ts as mkv recording had sound issues for me in TVHeadEnd.

1) So I have a TS file.
2) I can remove any errors using projectx demux.
3) I can recombine the video and audio from projectx using mkvmerge to get an mkv file
4) I can run the mkv file through comskip to get a list of advert breaks
5) I can convert the list of adverts to a file that mkvmerge can handle manually
6) I can then run mkvmerge over the mkv file again with the chapter list as a parameter.

Does anyone else know of an easier way to do this on Linux? I can convert the chapters manually but does anyone know of an automated way or do I need to script it?

Any other thoughts/suggestions?


Replies (9)

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Prof Yaffle about 11 years ago

You can use Handbrake to simplify the creation of mkv from ts - yes, you're re-encoding, but it can fix errors and also sort out any interlacing issues you may have depending on resolution/format. I run even HD broadcasts through "just because". Use CBR, though, as comskip chokes on VBR.

So, I guess you could have a post-processing script that uses handbrake-cli, then comskips it - I find comskip is never that accurate, though, so I'd stop at automating completely as I like to check. Indeed, once I have the EDL file I just use XBMC and it'll happily skip over the adverts, but obviously VLC et al's ehaviour would be different.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Neil Renaud about 11 years ago

I didn't think Handbrake could do the error correction - all I've ever seen on Google is use projectx for the error correction - I'm sure I had a problem once but that might have been when I was recording mkvs instead of ts files. Maybe it was the CBR vs VBR that caused me issues.

The plan to only put chapter marks in is my way of avoiding the accuracy issue.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Prof Yaffle about 11 years ago

I don't think it's meant to correct errors, not like projectx - but it works for me. The raw ts files choke mkvmerge otherwise. Try it and see, there may be some combination of settings that mean you don't have to wait 12 hours to re-encode a 1080 H.264 HD broadcast... maybe...

I just wish that the sound worked properly in mkv, it'd save a lot of time. I know that the team has struggled valiantly with this one and problems remain, so I think it's something inherent in the mkv specification - it just doesn't like the sound channel changing mid-flight.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Neil Renaud over 10 years ago

It's been a while but as I've now got a backlog of Peppa Pig episodes and a 2 year old that doesn't seem to understand that Peppa Pig isn't the most important thing in the world I'm revisiting this.

HandBrakeCLI 
-i /videos/recordedtv/Peppa-Pig/Peppa-Pig.2014-01-06.08-2.ts 
-o /videos/recordedtv/Peppa-Pig/Peppa-Pig.2014-01-06.08-2.mkv
--encoder x264 --quality 20 --format mkv --audio 1,1 --aencoder faac,copy:ac3
--ab 160,160 --mixdown dpl2,none -arate Auto,Auto --drc 0.0,0.0 
--audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 --loose-anamorphic 
--modulus 2 --x264-preset medium --h264-profile high --h264-level 4.1 --two-pass 
--decomb --cfr

I'm trying to use the same parameters on both HD and SD content.

On HD content I seem to get lots of errors like:
[h264 0x2f77120] Cannot (re-)initialize context during parallel decoding.
[h264
0x2f77120] decode_slice_header error

and then Handbrake eventually dies having not produced a file.

Just running a test now to see why it's not working on SD content as well.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Neil Renaud over 10 years ago

Also seems the SD content fails as well when run as a script from TVHeadend yet when running as a script separately it seems to work. Very strange.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Prof Yaffle over 10 years ago

Not sure about the error - it looks like something's choking with multi-threading, but whether it's possible or practical to try single-threading, I don't know. I'd probalby start by checking ffmpeg/handbrake versions and see if upgrading helps at all.

Regarding what you're doing, I pretty much surrendered on comskip and the like, and now just run the files through avidemux. If I'm lucky, the file has no pts/dts errors and cuts nicely before remuxing to mkv; if I'm unlucky, it won't save, but avidemux still allows you to find the adverts accurately enough to create an EDL file that's suitable for XBMC.

There's also a thread over on the XBMC forum about how one could create a custom NFO from mkv metadata. I suppose a similar logic would hold true to either create the NFO from .ts filenames and/or dvrlog metadata, or even trying to use mkvmerge to insert those metadata into a remuxed file.

The things we do for our kids' TV pleasure. Peppa Pig was a short phase, but Chuggington haunted me, and now I'm cursed to Mythbusters and Power Rangers...

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Neil Renaud over 10 years ago

Chugginton I actually like - I'm hoping it will be the first step to getting my little girl a massive Scaletrix track ;)

So at the moment I'm stuck at the first hurdle really - converting the ts to mkv - no idea why HandBrake doesn't work - if you have the command you use for encoding that will be handy.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Prof Yaffle over 10 years ago

I tend to use the GUI, I'm afraid - and the Linux version of Handbrake doesn't seem inclined to tell you what command line it would otherwise use, unlike the Windows version.

It doesn't always work, though - that's why I ended up moving to avidemux - if there are too many errors then nothing will recode or cut it, and ProjectX is the only option... except ProjectX can't do HD streams (I think - or maybe it was H.264 - there's some reason it can't be used, anyway). Hence the EDLs, as they leave the original .ts file intact.

RE: Converting TV recordings to MKV with Chapters to mark the start of the program after an advert break - Added by Neil Renaud over 10 years ago

I found the problem...

To run HandbrakeCLI I have to pipe /dev/null into it otherwise it dies after a few seconds. I found that out from another thread so...

HandBrakeCLI --aencoder copy --encoder x264 -q 20 --decomb --two-pass -i $filename_with_path -o $mkv_filename < /dev/null >> $log_file 2>&1

NOT

HandBrakeCLI --aencoder copy --encoder x264 -q 20 --decomb --two-pass -i $filename_with_path -o $mkv_filename >> $log_file 2>&1

    (1-9/9)