Canon XM2 (DV) to DVD, on Linux

I wanted to transfer some material from DV cassettes to DVD. My main workstation is running Ubuntu 12.04, and I decided to use the tools that are available with the distribution. I tried multiple ways of doing each of the tasks, and git many dead ends, mainly due to crashing programs, bugs, or incompatible tools. For instance, tovid looked very promising until it turned out that it is not compatible with the new version of the ffmpeg utility. My source material was DV, recorded by Canon XM2, the video format was 768×576, interlaced (576i), with audio at 48kHz, PCM, stereo. Interlacing was giving me some headache, because the first attempts lead to unsightly stripey output. The camera outputs double-scan interlace, which should be interpreted as 50 frames per second with reduced resolution. Interlacing might be tricky

The first step is to capture the video from the camera. Connect the camera to the laptop, switch the camera to the playback mode, rewind the tape and:

dvgrab birthday-

The “birthday-” bit is a prefix that will be added to the saved .dv files. dvgrab will save multiple 1GB files, each file about 4 minutes long. Once the material is captured, you can merge the multiple files into one, by simply concatenating them:

cat birthday-001.dv birthday-002.dv birthday-003.dv > birthday.dv

Once you have one file with the complete material, fire off a player and note down (I used paper and pencil) the times of segments you want to extract. You won’t be able to do a lot of cutting that way, but if it’s a couple of segments, it shouldn’t be too labor intensive. Once you know what are the segments you want to extract, you can extract them and encode as .vob files. Suppose one fragment starts at 02:13 and is 135 seconds long:

avconv -i birthday.dv -target pal-dvd -flags +ilme+ildct -b:v 6000k -ss 02:13 -t 135 birthday-01.vob

The “+ilme+ildct” bit is responsible for correct handling of interlacing, because DV uses different field order than DVD. Repeat the above command for each segment, and you’ll get a list of VOB files. These VOB files are DVD compliant, and they are implementing the interlace correctly. They must not be re-encoded when transferred to DVD, otherwise the interlacing settings will be most likely lost. You can try if your interlacing settings are correct by watching the VOB file using VLC with automatic deinterlace detection:

vlc --deinterlace -1 --deinterlace-mode bob --play-and-exit birthday-01.vob

You should see no stripes during movement in the video, and the displayed frame rate should be 50fps (although the video frame rate is set to 25fps).

The next step is to create a DVD menu. There is a number of DVD authoring software. I had most success with DVD Styler. I also tried tovid, and Bombono.

In DVD Styler, I managed to create a DVD directory structure, but not an ISO image, and I was not able to burn a DVD directly from DVD Styler. Instead, I only generated the DVD structure on disk, and used k3b, using its DVD template. I created a new project, found the generated VIDEO_TS directory from DVD Styler, and added it to the project in k3b. This was enough to arrive at a working DVD.

DVD Styler would recognize that the files are already DVD compatible and did not attempt to re-encode them.

The above method is rather basic and crude, but gets the job done. There isn’t a video editor used at any stage; instead we just note down the times and then extract time regions using the -ss and -t options of avconv. I tried to use pitivi for video editing, but there were issues with rendered video, and since I didn’t really need any editing, I dropped pitivi from the workflow. The main problem to solve in pitivi would be to encode a DVD compliant VOB video file. You can select a DVD VOB as the output format, but there’s still a lot of things you can mess up, for instance accidentally encode audio in 44.1kHz instead of 48kHz, which results in a DVD disc with no audio.

I suspect that tovid will be reasonably soon adapted for use with the new ffmpeg tools (using /usr/bin/avconv instead of /usr/bin/ffmpeg), which will make it easier to script out the process if I had more of such (e.g. archival) DVDs to make.

The trouble with Portuguese subtitles

I was looking for a way to improve my Portuguese.  Reading and writing is relatively easy to practice, but comprehension of spoken language is hard to practice.  Just listening to radio in Portuguese isn’t very helpful at this stage.  I tried listening to shoutcast Brazilian radios.  While listening, every now and then I go “oh, I know this word, it means to bring”, or “oh, he just said for your family”.  But what was for the family, I wouldn’t know.  It’s fun only for a couple minutes.

They speak too fast on the radio. I have trouble separating words from one another. Understanding the structure of a sentence can also be a challenge.  There’s no way I can process it in real-time.

Ideally, there would be something that:

  • Contains a recording of spoken language
  • Contains a transcription
  • Is possible to pause and rewind
  • If it’s interesting, it’s a plus

The first thing that comes to mind: a movie in Portuguese, with Portuguese subtitles.

The product pages on Amazon rarely specify the subtitle languages, I guess the assumption is that any foreign movie on Amazon has English subtitles.  Since the transcriptions all the dialogs must have been done, together with synchronization of the subtitles, to include the Portuguese subtitles is something that requires virtually no work.  I hoped that at least some of the Brazilian movies would have Portuguese subtitles as well as English ones.

Apparently, I was wrong.  I’ve bought Elite Squad, Central Station and City of Men.  None of the three Brazilian movies had Portuguese subtitles.

City of Men has the subtitles done the wrong way.  Normally, the subtitles are included in such a way that you can turn them on and off as you see fit.  In City of Men, the subtitles are burned into the video track.

Needless to say, I’m disappointed.  What am I to do now?

What I could potentially do, is to transfer the DVDs into my laptop, download fan-made subtitles in Portuguese (if I can find any), and overlay the subtitles myself.  Sadly, I’m not even sure if it’s legal to do so.  It would be reasonable to think that if I own the DVD, I should be allowed to make a copy for my own use.  But you never know, and each country has its own rules.

It would be more convenient to download the whole ripped DVD from the net, together with the subtitles.  I wouldn’t have to synchronize the subtitles with the video.

Potentially, an option would be to buy DVDs in Brazilian internet stores.  Presumably, at least some Brazilian DVDs would have subtitles for the hearing impaired.

I’ll keep on trying.

PS3 and Matroska with subtitles

Suppose you have a video file with subtitles, in the Matroska format.  How to play it on a PS3?  Probably set up mediatomb or ps3mediaserver and… I’ve made a number of attempts, and each had certain problems.  Here’s the list of ideas I had:

  • Try to just play .mkv with PS3
    …won’t work because PS3 doesn’t support Matroska.
  • Use ps3mediaserver to recode .mkv on the fly
    …won’t work because ps3mediaserver doesn’t hardsub (doesn’t embed the subtitles in the image).
  • Use mencoder to create an .avi file with embedded subtitles (using mpeg4 for video and mp3 for audio)
    …in theory should work, but my PS3 said it’s an “unsupported format”, no idea why.
  • Use mencoder to create an .mp4 file with embedded subtitles
    …doesn’t work, because mencoder’s mp4 support is broken, causing audio and video to go out of sync.
  • Use mencoder to create an .avi file with embedded subtitles (using mpeg4 for video and mp3 for audio), and use ffmpeg to convert it (without recoding) into MP4
    …doesn’t work, because PS3 won’t play an .mp4 with mp3 audio
  • Use mencoder to create an .avi file with AAC audio (using faac), and use ffmpeg to convert it to MP4
    …does work if you pass -faacopts mpeg=4:raw=1 options to mencoder, but there’s still a problem with a/v going out of sync
  • Add the -mc 0 option
    …fixes the a/v sync problem in most cases, but there’s still the problem with the video being crap quality
  • Use x264 to encode video
    …gives the best results:

I’ve also searched the web to look for encoder options and I came up with the following recipe.  It requires mencoder with x64 and faac support, and ffmpeg.  The following example uses Japanese audio track and English subtitles.  It leaves the intermediate .avi file. The first steps are to set the file names and recode the video and audio content, saving it in an .avi file.

mencoder -o "${outfile}.avi" \
   -oac faac \
   -faacopts raw=1:mpeg=4 \
   -ovc x264 \
   -x264encopts bitrate=3000:pass=1:threads=auto \
   -mc 0 \
   -vf pullup,softskip,harddup \
   -alang jpn \
   -slang eng \

Repeat that with pass=2. After the second pass has completed, it’s time to move the encoded content from the AVI container to the MP4 container.

ffmpeg \
   -acodec copy \
   -vcodec copy \
   -i "${outfile}.avi" \

The resulting MP4 file should be playable on PS3. This example doesn’t contain any further automation. I’m leaving it to you. Other possible improvement include skipping the audio recoding, if audio is in AAC already.  There’s also a lot of potential for tweaking the x264 options for better video quality. I’ve decided to leave these out for now to keep the example as simple as possible.

Please leave a comment whether it worked for you or not; suggestions for updates and improvements are also appreciated.


Watching an interlaced DVD with MPlayer

Resuming my tech-notes blogging…

I’ve recently bought three Studio Ghibli’s movies. I don’t have a TV-set (yes, lenina, I’m still not watching any TV), so I’m watching DVDs on my laptop. DVDs I got are interlaced, when watching them on a computer, you can see small horizontal stripes along the sides of moving objects.

On a TV-set, this is not a problem, actually, interlacing makes animation on TV-set smoother. But on a computer, all you get from interlacing is stripes.

MPlayer comes with few deinterlacing plugins, from which yadif and kerndeint seem to work best (but I’m open to other suggestions). However, my video output is GL:

maciej@clover ~ $ cat .mplayer/config
vo = gl
autosync = 20
monitorpixelaspect = 1
af = volnorm=2:0.6
ao = pulse

The problem with those deinterlace filters is that they don’t cooperate with the gl video output. Fortunately, there’s an easy fix for that: append scale filter.

mplayer -vobsubid 1 -vf kerndeint,scale dvd://5

Replace 5 with your title number. The vobsubid option tells MPlayer to display subtitles. I like to watch Japanese movies with the original soundtrack and English subtitles. Usually, English dubbing reveals too much about the characters and lacks the original expression.


Spin website screenshot
Have you seen the short (8 minutes) film “Spin” from Double Edge Films? You can watch it on-line, or find it as a part of a German television program about the Open-Source and Creative Commons licensed movies. It’s also available in Google Video, but at least on my computer video and audio go out of sync, what effectively destroys the expression of the sound and image. The television program has the best quality. Spin begins in about 24 minutes 30 seconds of the program.

Maybe I’m biased with this, but the Spin’s story is much like software development and bugfixing. I couldn’t think of it any other way that the DJ is a programmer, the city is a program and all the wrong events are software bugs.