[mythtvnz] Cutting DVB-T recordings - a crude but fast solution

David Moore dmoo1790 at ihug.co.nz
Wed Aug 4 04:28:45 BST 2010


I have posted a script at http://gist.github.com/507582 which I'm using 
to cut my DVB-T recordings.

I have tested this on many of my recordings and it's not perfect but it 
is fast and doesn't require any external programs like ffmpeg or vlc. It 
also doesn't lose any info so things like alternate audio streams and 
subtitles are preserved. It uses the info in the recordedseek table to 
cut and paste sections from the recording using the Linux dd command.

It has an undo option which is handy for testing. Undo files are simply 
dumps from mysql using the outfile option. The undo code loads these 
files back into the database which is very fast and saves a lot of time 
by avoiding rebuilding the seektable. However I haven't figured out 
mysql file write/delete permissions yet so if you use the default /tmp/ 
undo directory you will lose undo info after a reboot. I use a different 
undo directory on my system but it was a pain (apparmor, chgroup, etc.) 
to give mysql write permissions to this directory and I still haven't 
figured out how to give mysql delete permissions. Any mysql gurus out 
there who can help?

You can only undo the last edit so always undo before the next edit 
otherwise the original recording will be overwritten.

Cuts are always made at keyframes regardless of where you make cutpoints 
when editing the recording. The cutpoints are adjusted to the nearest 
keyframe before or after the cutpoint depending on whether it is a cut 
end or cut start. Cuts at keyframes are not adjusted.

Playback through cutpoints is reasonable provided that you allow some 
time before and after the cutpoints for the player to resync, i.e., make 
your cuts later and earlier than the visual end/start of program 
segments. One thing I have noticed is that the video in the first second 
or so after a cutpoint may play back slower than normal but the audio 
sounds OK. I guess this is something to do with decoder resyncing audio 
and video.

It seems that most channels fade out the program audio as they fade in 
their channel logo or something else. So I have found that cutting at 
the first keyframe after the logo avoids losing any audio.

The best way to experiment is to cut small sections around commercial 
breaks, e.g., one minute before and after the break. This allows you to 
quickly test playback through a cut. Once you figure out how much 
"padding" to allow at the start and end of a cut you can edit a whole 
show pretty quickly.

I don't now much about MPEG transport streams but I have a feeling it 
may be possible to improve the cut transitions with some additional 
code, e.g., maybe with a 1 frame/packet adjustment of cuts or insertion 
of some null or other packets to help the decoder resync. Any ideas 
welcomed.

It's also possible I have one or more errors in my logic. This script 
has gone through several iterations and I did have one error where the 
data was shifted by one byte but was quite hard to see on playback. So 
there may be a small bug lurking which is subtly affecting playback.



More information about the mythtvnz mailing list