Video Editing
These notes describe my attempts at editing video recordings made by
MythTV. Specifically, I wanted to extract ("cut") sections from
recordings. It is possible to do such editing, but it is not easy and
probably not worth the effort unless you are desperate.
Finding the recording to be edited
MythTV recordings are stored in two directories on sage: /video and /video1. Which directory a
recording is put in seems to depend on which one has most space at the
time. The recordings are in files with names like 1038_20100205155800.mpg, where '1' is always the same, '038' is the channel number, '20100205' is the date (in
YYYYMMDD format), and '155800'
is the time (in HHMMSS format). So to find the file you want to edit,
you need to know the channel that was recorded and the time that the
recording started. The time appears to be local time - i.e. BST during summer
and GMT during winter.
Preparing an editable copy
It's not a good idea to edit a file in the /video or /video1 directories, since
MythTV controls the content of these directories. The video files are
typically a few GB in size, so it's not sensible to copy them onto a
laptop - it would take too long. The best option is probably to
symbolically link to the file from elsewhere on sage. I've created the
partition /video2 on sage
to hold edited videos, so one can create a symbolic from there to the
file to be edited.
What editor to use
The best video for MPEG files seems to be avidemux. It is a bit of
a pain to build, and has a long list of prerequisites, but I have
managed to package it and install it on sage.
Where to run the editor
As noted above, the video file to be edited probably has to remain on
sage. The simplest (from a software point of view) way to edit is to
run avidemux on sage and
to sit in front of sage to use it. However, sage's keyboard/trackball
is awful to use and it would be nice if one could edit from a laptop.
There are a few possible ways of doing this:
- Run avidemux on
sage and use 'export DISPLAY'
to view/use avidemux from a laptop. Updating of the display is much too
slow for this to be usable.
- Use NFS to mount the /video2 partition on a laptop, and run avidemux on the laptop. Reading
the video data via NFS is much too slow for this method to be usable.
- Run avidemux on sage and use VNC to
view/use avidemux from a laptop. This produces very jerky video display
in avidemux, but is just
about usable.
Editing the recording
The avidemux wiki
contains user documentation. The pages on the main
window, cutting,
and cutting
MPEG files are probably the most useful.
- Open the video file in avidemux.
avidemux will ask you
whether to index the file - you have to answer yes to this, otherwise avidemux will refuse to open
the file. The index is written to a file in the same directory as the
file you are edting, and with a '.idx'
suffix. If you want to remove the (symbolic link to the) file you have
been editing, remember to remove its .idx file too.
- The drop-down lists on the left of avidemux's screen should be set
to 'Video:Copy', 'Audio:Copy' and 'Format:MPEG-PS (A+V)'.
- You may want to select 'Zoom
1:2' on the 'View'
menu to speed up displaying of the video.
- Find the beginning of the section you want to extract (using the
various play buttons and maybe the jog wheel), and mark it using the A
button. Find the end of the section you want, and mark it with the B
button. It's probably better to mark "key frames", since avidemux will
then not have to do any re-encoding.
- Use 'File->Save'
to save the marked section to a file.
- If you want to save several sections to the same file, you will
have to:
- Initially save each section to a separate file.
- Close the original video file.
- Open the first section file.
- Use 'File->Append'
to append each of the other section files.
- Save the combined sections file.
- Delete the individual section files.
Viewing the recording in MythTV
I have configured MythTV on sage to look for video recordings in the /video2 directory. You can use 'Media Library -> Watch Videos'
to select a video to watch. You may need to select 'Scan For Changes' from the menu
on this page to get the list of videos updated.
However, MythTV doesn't properly display an edited video file unless
you "index" it first. To do this, execute the command:
mythcommflag --rebuild --video foo.mpg
as root on sage, where foo.mpg
is the name of the edited video file.
The /video2 directory is
NFS exported from sage, so you can NFS mount it on a laptop and view
edited videos using mythfrontend
running on a laptop. You have to configure MythTV to look for videos in
this directory using 'Utilities/Setup
-> Setup -> Media Settings -> Videos Settings -> General
Settings -> Directories that hold videos'.
Deleting an edited video
If you want to delete a video that you have created by editing, you can
simply remove it from the /video2
directory. However, if you have run
mythcommflag to index the
video, this will have built an index in
MythTV's database. There doesn't appear to any simple way of removing
this index. The index appears to consist of entries in the 'filemarkup'
table in MythTV's database - you could probably manually remove these
entries using a SQL comand.
Sound synchronization
The recordings produced by MythTV are in format called MPEG-TS. This
format allows for errors in transmission, and players such as MythTV
and mplayer cope with these transmission errors without problems.
However, avidemux
apparently cannot handle these errors correctly. This
seems not to affect the video itself, but the sound can get out of sync
with the video.
The recommend
workaround for this problem is to process the video recording using
ProjectX before editing
with avidemux. I haven't
tried this procedure.