Showing posts with label h264. Show all posts
Showing posts with label h264. Show all posts

Thursday, 7 August 2014

Ripping DVD with FFMPEG

This more a post to myself than to others, but even so, others might find it useful as well. Because sometimes having a DVD is inconvenient compared to your usual Matroska file saved on a HDD, I was looking for a simple way to encode the DVD. I have it decrypted and copied in a folder, but there are a bunch of 1 GiB VOB files, which is a) big, b) inconvenient. So the idea is, join the VOBs and transcode it into h264 (substitute theora, vp8 or dirac if you are more radical FLOSS supporter than me) and FLAC for audio. Actually simple search on the net presented me with an easy solution using FFMPEG (I kinda had problems with using the GUI ripping software), but it took some more research (reading the ffmpeg man pages) to find out how to rip more than one audio stream into the final file (I used a JAP/ENG DVD about Aikido).

So, without further ado, here's the command:

ffmpeg -i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB -map 0:v -map 0:a -c:v libx264 -crf 18 -vf yadif -c:a flac aikido.mkv

And some info:

  • The ffmpeg command is in ffmpeg package, from rpmfusion free. It's not in Fedora proper because of patent issues, I believe.
  • -i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB marks that input file is a direct join of the three VOB files listed, the backslash is to escape the "|" so that it's seen by ffmpeg instead of bash.
  • -map 0:v tells that ALL video streams are to be copied/transcoded.
  • -map 0:a tells that ALL audio streams are to be copied/transcoded.
  • -c:v libx264 tells that for video streams we'll use libx264 codec (i. e. we'll transcode to h264).
  • -crf 18 tells that we want to use Constant Rate Factor, value 18 (which might be a bit of overkill, but I don't want to sacrifice quality for space and I don't have the time tune it).
  • -vf yadif use YADIF deinterlacing, because I don't wanna keep interlacing in the video – I'll be playing it on a computer, after all.
  • -c:a flac tells we'll be using FLAC for audio streams. It's free and lossless. Again, it might be overkill, but I like to keep the original sound without using nonfree codec like AAC or AC3.

When I originally omitted the -map parameters, only single video and single audio stream were transcoded, so it's necessary if you want to transcode more audio streams or different stream than the first one.

Saturday, 3 January 2009

Fedora 10 and Multimedia - Is It Worse or Better?

Well, a hard question. At first I got thrilled by some new features, especially the automatic codec install, and pretty stable pace of improvements on gstreamer front, but lately I'm starting to notice issues as well.

First let me say that while both video and audio handling in gstreamer got generally improved I recently came across a clip (video in h264 and dual audio FLAC and mp3 in matroska + karaoke using styled ASS subs) that fails misserably pretty everywhere. Totem plays the audio fine, but the video gets pretty quickly out of sync, in gst-launch the video even eventually stops altogether. Gxine does not support styled subs, but other than that it plays it pretty well, though it picks wrong audio track. Mplayer plays it well, but the subtitles are totally out of sync. And that's probably the biggest woe of recent mplayer builds (where recent spans even to some time before Fedora 10 GA) - slightly more complex styled (ASS) subs are frequently out of sync or not displayed at all (usually when there are more subtitles at once).

So I was looking for a workaround using different video player, but... VLC a xine-lib don't support styled subtitles and for gstreamer there is a bug filled, with experimental plugin attached (using libass). So I've created packages for libass (it's built-in in mplayer, but I needed a standalone library) and for the gstreamer plugin (called assrender) and installed it. Yep, totem does not know about the new plugin for subtitles rendering, but after some googling and trying I sort-of learned how to make gst-launcher use it.

And well, though gst-launcher is good for debugging it's not good for playback, so I wanted to make a simple one-purpose media player using gstreamer and ruby (just for the fun of it :) But it seems, ruby bindings for gstreamer are not exactly in a state that makes it possible at the moment...

The assrender plugin, though highly experimental and not official, works pretty well and even support using fonts that are attached in matroska files (that's a really useful and pretty widely used), but because it supports only RGB colorspace output there are two colorspace conversions needed (YUV to RGB and back) which consumes cpu cycles and on my not so hi-end laptop it makes HD (1280p) videos, that are just about what my CPU is capable of, to fail miserably. So dear lazy web, if you want not-so-hard to do coding for gstreamer, you can help out with bringing libass support there. It would remove the last obstacle which prevents me from using gstreamer for everything ;-)

But at the same time, I am a bit concerned about mplayer as well - because on the same hardware, since Fedora Core 6 it's playback capabilities are getting steadilly worse. Not that it cannot play videos, but mplayer tends to fail resuming of paused video, then there's the issue with subtitles and lastly I've experienced a very weird bug (and workarounded it for my own purposes) - there's one assertion in ffmpeg code that prevents playing of certain matroska videos in mplayer.

Basically someone obviously expected that if you have chapters in a movie, than they will be strictly chronological, meaning next chapter (in list) won't start before current one. In matroska this is not always true and the failed assertion makes mplayer crash... For those who are interested, it's in libavformat/utils.c in compute_chapters_end () somewhere around line 1950 or 1960... It's this simple line:

assert(s->chapters[i]->start <= s->chapters[i+1]->start);

I'm still in doubts whether I should fill a bug or not about it... In my opinion there should be just if conditional, assert seems to me like an overkill, especially given that not aborting the code here (if the assertion fails) does not make mplayer doing things it is not expected to do.

Friday, 1 August 2008

Making Good Screen-casts - How To?

I am gradually making some screen-casts for echo tutorials and I wonder what is the best way to make them. There is a lot of options and one needs to choose... What I've done so far is available on my Fedora People page.

First thing to choose is the application that will do the actual screencast. From rough investigation I discovered these three that are available in fedora/livna:
  • instanbul - easy to use, however almost non-existant configuration, output compressed terribly much, which makes the video small but ugly
  • xvidcap - configuration options are pretty good, you can customize the output as much as you want, however tend to freeze during captioning, also does not support encoding to theora
  • gtk-recordMyDesktop - seems to support output only to ogv/theora/vorbis, not very well handled area selection, adds skeleton track to the output, usage not very intuitive
So after some thinking I dismissed instanbul, as the output does not have the desired quality (and I cannot do anything about that) and xvidcap due to frequent freezes (before that I managed to record one 3 min long screencast though). That leaves gtk-recordMyDesktop.

Next, we need to decide about the content - will we add commentary? If yes, will it be spoken or via subtitles? Subtitles are very good for translating, you just use the original one and use e.g. subtitleeditor (in fedora repos) to make a translation without changing the subtitles timing/styling. Also it's good for deaf people. On the other hand, you need to show the subtitles somewhere, which might render the part of screen on which they are shown unreadable. You can minimize the costs by using styled subs (e.g. ASS/SSA) to position the subtitles, but you'll then need special programs that can handle the styling (e.g. mplayer with -ass option).

Audio has the drawback that it can be hard to understand, for the person doing the screencast harder to create (not all of us are good English speakers), also it's harder to make a translation. So I guess subtitles are overally a better choice.

Now what format choose for video? If I had a choice, I'd go with MPEG-4/AVC (H264) which is excelent format with probably the best quality to compression ratio (and is pretty much used for most of HDTV content). It has however a drawback of being patent encumbered which renders it not an option for videos targeted on all Fedora users (even though you can play it in Fedora if you install additional codec packages from livna, but that's not an official Fedora repository). Software patents also put out of the game most of the other codecs, which leaves Theora. It has pretty good quality to compression ratio and is already the output of the gtk-recordMyDesktop, so if you are content with the compression, you don't need to recompress/re-encode the video.

Lastly we need to choose a container format. In opensource world the best choices are probably OGG/OGM/MKV (listed in no order). I don't know if OGG can handle subtitle tracks and OGM seems to be rather hack of OGG to better support videos. It's not much widely used either. On the contrary Matroska Video (mkv) is designed to be portable, fast, open, ... It can contain almost anything which renders it almost ideal container for shipping videos (it can contain multiple video, audio, subtitle tracks, fonts, various other files..., and yet it's generally very fast). It also comes with handy tools that makes adding new subtitle or audio track to existing video a piece of cake [mkvmerge(-gui)].

So what's my choice? It's obvious from the previous text:
  • gtk-recordMyDesktop
  • Theora
  • ASS/SSA subtitles
  • Matroska Video (mkv)
  • (optionally Vorbis audio)
What do you think? Do I have even better choices?