Recording TV is easy. Take a USB TV Stick and start recording your favorite show, movie or cartoon. The next step is to process it, so that you keep only the most interesting part. There are plenty of programs to process your recordings. Until recently everything was smooth. But I had a problem lately where the audio and video was not in synch after processing.
After some research it happens that I need to first pass the recorded file through projectx. It is an application which repair DVB recordings and adds timestamps where needed. After that I can use my usual program for the final transformation. In fact projectx takes a DVB recording and generates two files: one constaining the video and another for the sound.
Recomposing a single MPEG file is possible with the FFMPEG program. In the end follow these two steps and you are done:
Now that the process is clear, you can write a nice script to automate it. Writing one in Scheme is easy. Here is one solution.
#! /usr/bin/env scmscript
(define (resynch-file file-name)
(let ((m2v (replace-extension file-name ".m2v"))
(mp2 (replace-extension file-name ".mp2"))
(final (string-append (file-name-sans-extension file-name)
"-synched.mpg")))
(run (projectx ,file-name))
(run (ffmpeg -i ,m2v -i ,mp2 -acodec copy -vcodec copy ,final))))
(define (main args)
(for-each (lambda (fn)
(display "converting ") (display fn) (newline)
(resynch-file fn))
args))