Blu-ray Movie Authoring in Linux

IMPORTANT: Blu-ray Authoring in Linux needs your help! It has come to my attention that UDF 2.5 support, which is required for authoring Blu-ray content is currently not supported at a writeable filesystem in Linux. The current UDF tools (discussed below) haven’t been maintained in years, and appear to be a dead project. In order to make Linux Blu-ray authoring a reality, we need to revive this project (udftools), and continue the development of UDF 2.5 and UDF 2.6 support. But!!! All is not lost. There are workable solutions, that range from commercial (yet still accessible) software, to hoping that your Blu-ray player doesn’t care about UDF 2.5 support any more than you do… like mine did.

In the wake of producing ‘Reco‘ this summer, I’ve taken on the responsibility of DVD and Blu-ray authoring for the film. DVD authoring on Linux has mostly evolved to the point of being within the reach of the average user, with a number of solutions for DVD authoring. Blu-ray on the other hand is a whole different story. Blu-ray authoring can be a very complicated process, especially when you get into menus and such. Lucky for me, we are only producing Blu-ray discs for exhibition as festivals, which means we don’t care about fancy menus. Just put the disc in, and go…

This post will chronicle my attempts at BD authoring towards that goal, keeping the entire workflow limited to OFS, and Linux as the authoring platform.

So far, I found these useful tools…

ffmpeg (to encode the streams, of course!)
tsMuxeR (to mux the streams and generate the BD folder structure)
mkudfiso (to generate an ISO of the BD folder structure)
udftools (to generate the UDF image, this is in the Ubuntu repos)
dvd+rw-tools (to actually burn the ISO to a BD-R disc).

First things first… export your movie at the highest quality possible. Spare no expense here, just keep it in a format that FFMPEG will like. In my case, I export from Piranha using the Quicktime plugin, which supports HUFFYUV (lossless), and 24bit, 48k audio.

Then using ffmpeg, we have to convert this to H.264. ffmpeg uses libx264, which has some nice presets to make things easy. For me, quality if everything, so time isn’t an issue. I’ll 2-pass, please. I made a little shell script to actually do the encoding for me.

ffmpeg -i $1 -f rawvideo -an -pass 1 -vcodec libx264 -vpre slowfirstpass -b $3 -bt $3 -threads 0 -passlogfile $2.log -y /dev/null
ffmpeg -i $1 -an -pass 2 -vcodec libx264 -vpre hq -b $3 -bt $3 -threads 0 -passlogfile $2.log $2.h264
ffmpeg -i $1 -acodec pcm_s24le $2.wav

I invoke it like this:

$ blu-ray_encode.sh bluray-movie.mov bluray-movie 36M

The first parameter is the input Quicktime that I created from Piranha. The second parameter is the output filename, minus extension, for the resulting H.264 stream and WAV file. The third parameter is the encoding bitrate, in this case 36Mb/s. Blu-ray supports allows upto 54Mb/s total, so this should give me a very high-quality encoding, but still afford me the bandwidth for the audio, and still not push everything to the max.

With this done, we should have two files, a raw H.264 stream, the corresponding 24bit WAV file.

Addendum, courtesy of Dkottmair (and edited courtesy of me):

In your x264-settings, the x264 guys recommend very specific settings for Bluray (or AVCHD) in order to be fully compatible on any player. For example there is one chipset used in players that cannot do weighted p-frames (–weightp option in x264), even though it should according to the standard (yes, I also have no idea how they got this chip approved then, but thanks to this shitty chip all Bluray- or AVCHD-H.264 now cannot use weighted pframes!). I’ve seen two players during my try-outs that seemed to have this chip, one was a Sony, can’t remember the other one. It causes a lot of block artefacts.

These are the settings they recommend for x264: –preset slow –tune film –weightp 0 –nal-hrd vbr –vbv-maxrate 15000 –vbv-bufsize 15000 –aud –keyint 24 –bframes 3 –slices 4 –level 4.1 –b-pyramid strict

You can add bitrate control via -b or -crf, and also add reference-frames: -r 6 for 720p and -r 4 for 1080p. Also, –vbv-maxrate should be 40000 and –vbv-bufsize 30000 for Bluray, 15000 is for AVCHD – but works on Bluray, too.

“This is all true to spec”, Dkottmair says, having done “a lot of research on the subject, even before x264 got BD-certified! ;-)” Also, it seems, a new site was put up specifically dealing with X264 and Bluray encoding. Check it out: http://www.x264bluray.com

Here’s the full three commands Dkottmair uses (third one needs to be launched in a separate terminal, sending it to the background using & will NOT work!):

mkfifo stream.y4m
mplayer -vo yuv4mpeg:file=stream.y4m -nosound (source-moviefile)

(separate terminal, same directory):

x264 –crf 22 –preset slow –tune film –weightp 0 –nal-hrd vbr –vbv-maxrate 15000 –vbv-bufsize 15000 –aud –keyint 24 –bframes 3 –slices 4 –level 4.1 –b-pyramid strict -o (output.264) stream.y4m

Dkottmair says: “Remember to add/change those parameters mentioned above as needed! And delete that y4m file afterwards, though it won’t eat much of your harddrive, since it always remains at 0 bytes! ;-)”

As a final tidbit, keep in mind that the y4m/x264 encoding won’t handle your audio. For real film/movie geeks, you won’t blink at this, but if you’re trying to burn home movies, you’ll still need to render out a seperate WAV file, which can still be done with the last ffmpeg command above.

Fire-up tsMuxerGUI, and import the files. Check the Blu-Ray radio in the output section, and specify a folder to generate the BD folder structure in. Double check the options under the “Blu-Ray” tab, for chapter creation, etc. When you’re ready, hit the “Start Muxing” button at the bottom of the window.

Before we dig into UDF creation in the next step, you should read this little comment, courtesy of Dkottmair:

“However, there’s one major issue with your usage of udftools: UDF 2.5. The problem is: UDFtools simply cannot create UDF 2.5 (or 2.6), which is a requirement for BD (or AVCHD) according to the standard. The maximum it does is UDF 2.01.

“This is also the reason why Brian gets that error on the PS3, it’s exactly what you see when the disc is not UDF 2.5, I know it, I’ve tried several times to burn working Blurays/AVCHDs with mkudffs-based OSS-tools such as Brasero or K3b! So when your discs play in your player, it is quite likely merely because your player doesn’t care what UDF-version the disc is in – Most players are built to be as compatible as possible, not to adhere 100% to the standard. Just like many DVD-players play DVDs that you burn in ISO instead of UDF…

“The only program I know (i also use it in my article) that can burn UDF 2.5 under Linux is Nero 4, which btw. works like a charm!) I’ve been bitching about these major shortcomings of mkudffs for ages now in several places (mailed lots of people, even filed a bug report for K3B: https://bugs.kde.org/show_bug.cgi?id=257602 ), but it appears nobody seems to care… Nonetheless, these tools claim in their changelog and release notes that they can “burn Bluray” – No. You can burn stuff onto BD-Rs using Bluray-Burners, but you CAN’T burn actual Blurays!”

With that out of the way, let’s look at this not-quite-solution that works for some players, but clearly not all… And remember, we need your help to drive continued support for UDF 2.5/2.6 in linux! Do your part! File a Bug!

Next, we need to make a UDF image file from the output of tsMuxeR. We have to create a UDF filesystem by hand, as a file on the regular system, mount it, copy the data into it, unmount, and then burn the resulting image.

Install udftools from the repos.
create a the file where the filesystem image will be stored:

mkudffs --vid="Blu-ray Movie" --media-type=hd --utf8 ./blu-ray.udf 11826176

Next, create, and mount that image as a file system. (PS, if you’re curious about the number ‘11826176’, its the number of 2k-blocks free on the BD-RE disc after formatting).

$ sudo mkdir /mnt/blu-ray
$ sudo mount ./blu-ray.udf /mnt/blu-ray -o loop

Copy the Blu-ray file structure created by tsMuxeR

$ sudo cp -R /path/to/bluray-content /mnt/blu-ray

Unmount:

$ sudo umount /mnt/blu-ray

This should create the contents of the Blu-Ray disc in the blu-ray.udf file. Now we can burn this to the BD-R/BD-RE disc.

Again, this shouldn’t take too long. Just be aware, throughout the muxing and mkudfiso steps, you are making copies of content which is probably very large. Expect hundreds of gigabytes to be consumed by this process, between the uncompressed MOV, the then compressed H.264 and WAV, the mux of those (which doesn’t recompress, only muxes them), and then a final copy of everything combined into the ISO. Essentially, you will have 3 copies of your film, NOT including the uncompressed version.

Once you’ve made the ISO, you should be able to burn it with growisofs. First use wodim to identify your BD burner:

$ wodim --devices
wodim: Overview of accessible drives (1 found) :
-------------------------------------------------------------------------
 0  dev='/dev/scd0'	rwrw-- : 'HL-DT-ST' 'BD-RE  GBW-H20L'
-------------------------------------------------------------------------

In my case, my BD-RE is /dev/scd0.

Before we do the burn, we need to format. Supposedly, ‘growisofs’ will format for us on-the-fly, but its not perfect and we’ll likely see an error and the disk won’t finalize. So, we use dvd+rw-format to to the format first:

$ dvd+rw-format -ssa=default /dev/scd0

Then I’ll do the actual burn using ‘growisofs’ with the following command:

$ growisofs -dvd-compat -Z /dev/scd0=blu-ray.udf

Word on the street is, you can also use Nero to create/burn the UDF, though its not OFS, but it is relatively cheap (assuming it does the job).

There is room for improvement in this whole process…
The UDF image is created to a fixed size, based on the size of the BD-RE media. In fact, your movie (or other BD content) may be less than that. Ideally, we’d only like to burn the size of our data, which in this case, we won’t know until after we encode and mux. We could figure the number of blocks required (UDF’s default is 2048b-per-block), by dividing the resulting space required by the BD content after muxing/generating the folder structure by 2048, rounding up, and allocating the UDF filesystem to that number of blocks.

With the use of mkudffs and udftools, you should be able to create and mount the udf image file before running tsMuxeR, and then have tsMuxeR render directly into the UDF mount. Then unmount, and burn the image. The downside is going this route, you don’t know what size to make the image before doing the mux. You could make an educated guess: (size of WAV + size of H264 * 1.10), but regardless, you’ll end up with wasted space.

There is still a real need for a tool like mkudfiso, that can take existing data and stuff it into a UDF file. I would encourage anyone capable and knowledgeable, to consider submitting a patch to the linux-udf/udftools for a tool that provides the same functionality as mkudfiso, but that which actually works, and is part of the standard implementation.

udftools, and mkudffs appears to allow creating the UDF directly to the media, though the documentation is poor. In theory, you should be able to mkudffs to /dev/scd0, mount, copy and unmout, but its unclear in the documentation how to actually start and finalize the burn. I didn’t have the patience to continue investigating.

UPDATE: In the spirit of awesomeness, I spent the better part of today putting all of this into a nice, slick, and hopefully reliable script. Copy/paste the text below into a file “mkbdmovie”, put the file into /usr/local/bin (or /usr/bin), and chmod +x the file, it should mostly do the rest for you. It won’t install ffmpeg or udftools, or download tsMuxeR, but it will tell you when you don’t have them, and tell you how to get them. It even has some very basic usage if you run it without parameters. A couple of notes that aren’t mentioned in the usage:

If you don’t specify a movie with -m, you can specify -a and -v to pass the already encoded elements to the muxer, in which case it won’t re-encode the H264/PCM, only remux . If you like, you can specify -a and -v in addition to -m, and -a and -v will specify where to render the H.264 and PCM assets, so they can be saved and reused again if you have to remux everything again later.

In order for the script to mount and copy the BDMV folder structure into the UDF image, mount and cp have to be ran via sudo. It will prompt you for your password at that point. If anyone has a solution to that, I’d love to include it in the script.

The script figures the size of the blu-ray folder structure after muxing, and creates the UDF image just large enough to hold that data (per my “room for improvements” above).

The script creates a meta file used by tsMuxeR to determine how to mux everything, including specifying chapter locations. I used some stupid values. I meant to add another parameter to allow specifying them on the command line, but then I got bored. If you want different chapter locations (times) (which you most likely will) you’ll need to modify the script to reflect the new times. It should be pretty self-evident what needs to be changed. If you really want to mix things up, you can run the tsMuxerGUI to find/set all of the parameters you like, and then copy the metadata information into the script.

Finally, the script only creates an UDF file (specified as the last parameter on the command line) from an existing movie. You still need to render to movie out of your NLE/finishing tool, and also run the growisofs command above to do the actual burn.

#!/bin/bash

FFMPEG=`which ffmpeg`
TSMUXER=`which tsMuxeR`
MKUDFFS=`which mkudffs`

function usage {
	echo "The arguments to use are"
	echo "-m: The movie file to encode (ffmpeg compatible)"
	echo "-v: The h.264 video asset to mux for BD content"
	echo "-a: The WAV audio asset to mux for BD content"
	echo "-b: The bitrate for h.264 video encoding (-m), default is 25M"
	exit
}

function test_ffmpeg_x264 {
	# Test whether ffmpeg has libx264 support compiled in
	if [ `ffmpeg -formats 2>/dev/null| grep x264 | cut -c 3-4` != "EV" ]; then
		echo "FFMPEG not compiled with libx264 support." | exit
	fi
}

function test_ffmpeg {
	if [ ! -x $FFMPEG ]; then
		echo 'Could not find FFMPEG in the path.  Try "sudo apt-get install ffmpeg".' | exit
	fi
}

function test_tsmuxer {
	if [ ! -x $TSMUXER ]; then
		echo 'Could not find tsMuxeR in the path.  Download from http://www.smlabs.net/tsmuxer_en.html' | exit
	fi
}

function test_mkudffs {
	if [ ! -x $MKUDFFS ]; then
		echo 'Could not find mkudffs in the path.  Try "sudo apt-get install udftools".' | exit
	fi
}

function test_dependancies {
	echo 'Verifying dependancies...'
	test_ffmpeg
	test_ffmpeg_x264
	test_tsmuxer
	test_mkudffs
}

function make_bluray_streams {
	#convert the movie to HQ H.264 and WAV
	echo "Encoding ${MOVIE} video to H.264, 1920x1080, ${BITRATE}bps - Pass 1"
	$FFMPEG -i $MOVIE -s hd1080 -f rawvideo -an -pass 1 -vcodec libx264 -vpre slowfirstpass -b $BITRATE -bt $BITRATE -threads 0 -y /dev/null >>mkbdmovie.log 2>&1
	echo "Encoding ${MOVIE} video to H.264, 1920x1080, ${BITRATE}bps - Pass 2"
	$FFMPEG -i $MOVIE -s hd1080 -an -pass 2 -vcodec libx264 -vpre hq -b $BITRATE -bt $BITRATE -threads 0 $H264_FILE >>mkbdmovie.log 2>&1
	echo "Encoding ${MOVIE} audio to PCM, 24bps, 48000 - Pass 1"
	$FFMPEG -i $MOVIE -acodec pcm_s24le -ar 48000 $WAV_FILE >>mkbdmovie.log 2>&1
}

function mux_bluray_assets {
	echo 'Muxing streams and generating BDMV file structure'
	# create the metafile needed by tsMuxeR

	echo "MUXOPT --no-pcr-on-video-pid --new-audio-pes --blu-ray --vbr  --custom-chapters=00:00:00.000;00:05:00.000;00:10:00.000;00:15:00.000;00:20:00.000;00:25:00.000 --split-size=2GB --vbv-len=500" > $TSMUXER_META
	echo "V_MPEG4/ISO/AVC, \"$H264_FILE\", fps=23.976, insertSEI, contSPS, ar=As source" >> $TSMUXER_META
	echo "A_LPCM, \"$WAV_FILE\", lang=eng" >> $TSMUXER_META

	# mux the two files and generate the BR-structure
	$TSMUXER $TSMUXER_META $BDMV_PATH >>mkbdmovie.log 2>&1
}

function create_udf_image {
	echo "Creating UDF Image: ${UDF_IMAGE}"
	# calculate the UDF size necessary (as 2k blocks) to fit the data
	UDFSIZE=`du -s -B 2K $BDMV_PATH | cut -f 1`
	UDFWORKSPACE=`mktemp -d /tmp/UDF_XXXXXXXXX`

	# make the udf filesystem, and mount it
	if [ -e $UDF_IMAGE ]
	then
		rm $UDF_IMAGE
	fi

	#MKUDFCMD="/usr/bin/mkudffs --vid=\"$3\" --media-type=hd --utf8 \"$2\" $UDFSIZE"
	$MKUDFFS --media-type=hd --utf8 $UDF_IMAGE $UDFSIZE >>mkbdmovie.log 2>&1
	sudo mount $UDF_IMAGE $UDFWORKSPACE -o loop >>mkbdmovie.log 2>&1

	# Copy the source into the UDF Workspace
	sudo cp -Rv $BDMV_PATH/* $UDFWORKSPACE >>mkbdmovie.log 2>&1

	#unmount, cleanup
	sudo umount $UDFWORKSPACE >>mkbdmovie.log 2>&1
}

function cleanup {
	sudo rm -rf $UDFWORKSPACE $TSMUXER_META >>mkbdmovie.log 2>&1
	if [ $TEMP_H264 = 1 ]; then
		sudo rm -rf $H264_FILE >>mkbdmovie.log 2>&1
	fi
	if [ $TEMP_WAV = 1 ]; then
		sudo rm -rf $WAV_FILE >>mkbdmovie.log 2>&1
	fi
}

MUX_ONLY=1
TEMP_H264=1
TEMP_WAV=1
BITRATE=25M

TMP_FILE=`mktemp -u /tmp/BDMV_XXXXXXXXXX`
TSMUXER_META=$TMP_FILE.meta
BDMV_PATH=`mktemp -d /tmp/BDMV_XXXXXXXXXX`

if [ $# -le 1 ]; then
	echo "Invalid or insufficient parameters."
	usage
fi

while [ $# -gt 1 ]
do
	case $1
	in
		-m)
			MOVIE=$2
			MUX_ONLY=0
			H264_FILE=$TMP_FILE.h264
			WAV_FILE=$TMP_FILE.wav
			shift 2
		;;

		-b)
			BITRATE=$2
			shift 2
		;;

		-v)
			H264_FILE=$2
			TEMP_H264=0
			shift 2
			echo "Using h.264 file: ${H264_FILE}"
		;;

		-a)
			WAV_FILE=$2
			TEMP_WAV=0
			shift 2
			echo "Using WAV file: ${WAV_FILE}"
		;;

		*)
			usage;
		;;
	esac
done
UDF_IMAGE=$1

test_dependancies

if [ $MUX_ONLY = 0 ]; then
	make_bluray_streams
fi

mux_bluray_assets
create_udf_image
cleanup
Advertisements

~ by kylemallory on October 17, 2010.

48 Responses to “Blu-ray Movie Authoring in Linux”

  1. wow, thanks for all the info! i’ll be trying this out shortly. i don’t see any mention of encryption in your post – does this create un-encrypted bluray discs? will the resulting discs play on a ps3? thanks!

    • Hey Brian,

      I haven’t tried on the PS3, but they play fine on my Vizio Blu-ray player. I believe the PS3 is pretty relaxed about the format, so I would expect it to work. I haven’t looked into encrypted content. I think the tsMuxer utility would handle that, and I don’t recall any settings to allow it, but I could be wrong.

      –Kyle

  2. Hi! I’ve had a whole lot of trouble to get my blu-ray drive working in linux and I was just wondering what model you use? You are of course using a blu-ray reader/writer, but if you know about any model which is just a reader and works without any problem in linux, please mail me 🙂

    • Niklas,

      Obviously, my writer works as a reader for me without issue. I guess the question I would ask, is what do you mean by “working”.. Can it read BD media? Can it play Blu-ray content? I have not had any luck (though I’ve not tried very hard) playing Blu-ray content, in part because its a pain with all the DRM. I know there are countless articles about ripping Blu-ray on the net. I don’t really have a need for that. As for my own BD-drive, it just worked.. both as a reader and writer. I didn’t need any special drivers or anything. It just worked.

  3. Finally got back to this. When I try to play a movie I burn with this method on my ps3, the system displays “error 80029941”, which the internet seems to think means some sort of codec problem. I used your directions exactly, except that I substituted in something low – 2M or 3M – for the bitrate. This failed on both a BD-RE (had to tweak my mkudffs encantation to account for the slightly lower capacity) and a BD-R, but growisofs reported an error closing the session, so that might have been a bad disk or something… Trying a 36M encode now to see if that’s the problem…

    I’ll report back. Thanks again for your info!

  4. Hmm, the problem seems to be related to a failed formatting of the BD-R medium??

    ski@deskaheh:/scratch/tmp/burn$ sudo dvd+rw-format -ssa=default /dev/scd1
    * BD/DVD±RW/-RAM format utility by , version 7.1.
    * 25.0GB BD media detected.
    – illegal command-line option for this media.
    – BD-R can be pre-formatted only once

    … then later during growisofs …
    24204673024/24220008448 (99.9%) @0.9x, remaining 0:03 RBU 45.7% UBU 50.0%
    24218894336/24220008448 (100.0%) @0.9x, remaining 0:00 RBU 3.3% UBU 50.0%
    builtin_dd: 11826176*2KB out @ average 0.9x4390KBps
    /dev/scd1: flushing cache
    /dev/scd1: closing track
    /dev/scd1: closing session
    :-[ CLOSE SESSION failed with SK=5h/INVALID FIELD IN CDB]: Input/output error

    • Brian,

      Interesting. Do you think the disc may have been pre-formatted, or had a previous failed burn? I had some problems very early on in my research on this post, with BD-R media. After wasting 3 disks, on what I presumed were user faults in using the tools, I decided to go buy a BD-RW, at which point I started to make progress. It’s entirely possible that there maybe an issue with the tools on BD-R media. Go buy a single BD-RW from OfficeMax or some place and see if things improve for you.

  5. Well, after going back to only trying BD-RE media, I’m still experiencing error 80029941 on the PS3. The only difference I can think of is that my source media is arbitrary avi or mkv files – not raw video – some of the sources in fact are lower than even 720p. But I’m still not sure what exactly is wrong with the file I’m outputting. Do you mind showing me the output of a ffmpeg -i on your input files & x264 files? Might help me rule out some other problems. Thanks again for the info!

    Cheers,
    Brian

  6. Very interesting article. I had been looking for something like that for ages myself, but then I just wrote my own – apparently at just the same time you wrote yours! 😉 It just got translated to English and will be in the next issue of Linux Magazine, titled “Homebrew HiDef”..

    However, there’s one major issue with your usage of udftools: UDF 2.5. The problem is: UDFtools simply cannot create UDF 2.5 (or 2.6), which is a requirement for BD (or AVCHD) according to the standard. The maximum it does is UDF 2.01.
    This is also the reason why Brian gets that error on the PS3, it’s exactly what you see when the disc is not UDF 2.5, I know it, I’ve tried several times to burn working Blurays/AVCHDs with mkudffs-based OSS-tools such as Brasero or K3b! So when your discs play in your player, it is quite likely merely because your player doesn’t care what UDF-version the disc is in – Most players are built to be as compatible as possible, not to adhere 100% to the standard. Just like many DVD-players play DVDs that you burn in ISO instead of UDF…

    The only program I know (i also use it in my article) that can burn UDF 2.5 under Linux is Nero 4, which btw. works like a charm!) I’ve been bitching about these major shortcomings of mkudffs for ages now in several places (mailed lots of people, even filed a bug report for K3B: https://bugs.kde.org/show_bug.cgi?id=257602 ), but it appears nobody seems to care… Nonetheless, these tools claim in their changelog and release notes that they can “burn Bluray” – No. You can burn stuff onto BD-Rs using Bluray-Burners, but you CAN’T burn actual Blurays!

    The second issue is your x264-settings. The x264 guys recommend very specific settings for Bluray (or AVCHD) in order to be fully compatible on any player. For example there is one chipset used in players that cannot do weighted p-frames (–weightp option in x264), even though it should according to the standard (yes, i also have no idea how they got this chip approved then, but thanks to this shitty chip all Bluray- or AVCHD-H.264 now cannot use weighted pframes!). I’ve seen two players during my try-outs that seemed to have this chip, one was a Sony, can’t remember the other one. It causes a lot of block artefacts.

    These are the settings they recommend for x264: –preset –tune –weightp 0 –nal-hrd vbr –vbv-maxrate 15000 –vbv-bufsize 15000 –aud –keyint 24 –bframes 3 –slices 4 –level 4.1 –b-pyramid strict

    (add bitrate control via -b or -crf, and also add reference-frames: -r 6 for 720p and -r 4 for 1080p. also, –vbv-maxrate should be 40000 and –vbv-bufsize 30000 for Bluray, 15000 is for AVCHD – but works on Bluray, too.) This is all true to spec, I’ve done a lot of research on the subject, even before x264 got BD-certified! 😉 btw: this site went online apparently just when I finished the article, you might wanna check that out, too: http://www.x264bluray.com

    I dunno what the ffmpeg -vpre hq preset actually contains as x264 parameters, but IIRC I checked it out when i wrote my article and found i cannot control it as precisely as I can x264 itself (IIRC some parameters were missing, such as the –vbv stuff!). So my solution is playing the video with mplayer which feeds uncompressed y4m video into a FIFO-file – from which x264 then reads, using the recommended settings. This way I avoid needing hundreds of gigabytes for the uncompressed y4m…

    The third thing you don’t mention (and which must be mentioned in an article like that!) is that the video needs to be exactly 1920×1080 or 1280×720 according to the spec. Lots of stuff that’s around is cropped, so you need to “uncrop” it before encoding (I do this by adding -vf dsize=1280:720:0,scale=0:0,expand=1280:720 or -vf dsize=1920:1080:0,scale=0:0,expand=1920:1080 to my mplayer options.

    Here’s my article in German, english version is not yet online (but will be once the issue is out): http://www.linux-community.de/Internal/Artikel/Print-Artikel/LinuxUser/2010/12/HD-Videodisks-selbst-erstellt

    I’d be too glad if some more people joined in asking for UDF 2.5 functionality in mkudffs! 😉 You could start by voting up my bug report for K3B, hehehe…

    • Dkottmair,

      Sorry for the late reply. Lots of good info there. I’m curious about the UDF aspect, since it hasn’t been an impact for me yet. I’m also curious what might be involved in adding support for 2.5/2.6 in UDFtools. Do you know where I can find the technical specs on the differences between 2.x and 2.5/2.6?

      Kyle

      • well, try your disks on various players (just go to any local electronics store and ask nicely if you can test your selfmade disks on their players!), I’m quite sure you’ll come across one soon that won’t play it (if in doubt, try the PS3, even though that still doesn’t adhere 100% to the spec (it plays DTS-Audio in AVCHD, which isn’t in the AVCHD spec!))
        From what Wikipedia these were the changes:
        # Revision 2.50 (April 30, 2003). Added the Metadata Partition facilitating metadata clustering, easier crash recovery and optional duplication of file system information: All metadata like nodes and directory contents are written on a separate partition which can optionally be mirrored.
        # Revision 2.60 (March 1, 2005). Added Pseudo OverWrite method for drives supporting pseudo overwrite capability on sequentially recordable media.

        The best place to get specification documents would probably be this: http://www.osta.org/specs/

        I’d be so glad if someone finally “adopted” the orphan ancient mkudffs and lifted it into the year 2003 at least, which is when UDF 2.5 was specified! 😉

  7. addendum: There was supposed to be something after -preset and -tune, but it got filtered because I put it in pointy brackets and the blogsoftware thought it was a html tag. Put whatever floats your boat (check x264 manpage!), i always use -preset slow and -tune film

    Here’s the full three commands I use (third one needs to be launched in a separate terminal, sending it to the background using & will NOT work!)

    mkfifo stream.y4m
    mplayer -vo yuv4mpeg:file=stream.y4m -nosound (source-moviefile)

    (separate terminal, same directory):
    x264 –crf 22 –preset slow –tune film –weightp 0 –nal-hrd vbr –vbv-maxrate 15000 –vbv-bufsize 15000 –aud –keyint 24 –bframes 3 –slices 4 –level 4.1 –b-pyramid strict -o (output.264) stream.y4m

    Remember to add/change those parameters mentioned above as needed! And delete that y4m file afterwards, though it won’t eat much of your harddrive, since it always remains at 0 bytes! 😉

  8. btw: I have tested discs (both BD and AVCHD) created with my method successfully on a variety of BD-players: Sony BDP-S370/570 & Playstation 3, Panasonic DMP-BD45/65, Pioneer BDP-120, Samsung BDC-6900, LG BX 580, Philips BDP-3000 and Sharp BD-HP90S.

    …and it seems the issue of Linux Magazine with the english version of the article is on the shelves right now, March 2011 issue, Page 44!

    I’m looking for someone that could turn all this rather complicated stuff into a nice standalone GUI app to go into the repositories, greatly simplifying the process for the common user. I can’t code GUIs, but I’d be very willing to work on designing and testing it (i already have good ideas in my head!). Post here if you’re interested…

  9. Dkottmair, thanks so much for your info. Are you sure there is no other tool that can create udf 2.(5|6) on linux (or for that matter, an open source tool on windows or mac?) Seems to me we’ve got some porting to do…

  10. Hmm, if I understand you correctly, I think we can work around this until there is a program like mkudffs that can deal with udf >= v2.5. The kernel has a separate udf implementation from udftools. so if I were to get my hands on a 20GB (say) blank udf 2.5 image, I could make a copy of it, loopback mount it, and then copy my files on it as in the tutorial (I’m assuming that linux can deal ok with udf 2.[56]). Just get rid of the mkudffs step, and instead add a cp step. Does that make sense? I’ll post back here if I have any luck with this approach…

  11. It *looks* like ubuntu (at least) had udf 2.5 support 2 years ago in 8.04… Hopefully that is still the case: https://help.ubuntu.com/community/RestrictedFormats/BluRayAndHDDVD

  12. A follow up: the hack I suggested above doesn’t work, as the kernel support of udf > 2.01 is read-only. What *might* work would be to install netbsd (perhaps in a VM), which has udf 2.[56]0 support, and create the udf images there – but netbsd’s support of same is still classified experimental.

    I tried to use nerolinux as a stopgap until there is a free & open solution, but it is freezing up when I insert a BD-R or BD-RE. Hopefully their email support is responsive… We’ll see.

    Dkottmair, looking for a local store that has the March edition of linux magazine 🙂

  13. I’d be interested in helping to develop code that would make this a much more simplified process, but my time to develop is seriously limited, and I’d need some help. What I’d really like to see is something that combines the UDF and the tsMuxer stuff into a single app. A gui complicates things a bit more, but if a solid CLI tool is available, Python folks smarter than me can whip up a GUI in a matter of hours.

    –Kyle

  14. Kyle: Since for now there’s no way under Linux to create and burn UDF 2.5 using OSS-tools and we need to rely on Nero to do the job, the UDF things in the tutorial are moot anyway. The GUI I envision would accept any input as video (mplayer!), offer a few checkboxes and radiobuttons and when you press the big “go” button it would then spit out a BDMV-folder, much like many DVD tools ouput VIDEO_TS, that you would need to burn yourself using Nero 4 Linux…

  15. Dkottmair: thanks a bunch, after creating some udf 2.50 images on my mac and copying them over, I can now burn blu-ray video 🙂 whee!

    Kyle & Dkottmair, I too would be interested in helping add udf 2.50/2.60 support to udftools and other FOSS tools, but the spec for 2.50 adds a whole lot of complexity that wasn’t there in 2.01, so I fear we will have a long way to go. The right thing to do is probably to get the userland tools first. I was hoping udfclient would do the trick, and indeed it builds fine on linux, but either I’m using it wrong or it doesn’t work.

  16. Brian: You can burn UDF2.5 just fine on MacOS using Toast 9 (or higher) with the HD-plugin. Actually, MacOS was where I figured out my method! 😉 At first I had to use TSmuxer on Windows when there was only that version (and I did try the old Linux CLI version and found it was broken for muxing BDMX folder structures!), but luckily since TSmuxer got released for all three OSses (not MacOS PowerPC though – grr!) we can now do the whole shebang in all three completely, not being dependant on any other OS! TSmuxer, x264 and mplayer exist for all three, and for burning in UDF2.5 you simply use IMGburn on Windows, Toast+HDplugin on MacOS and Nero 4 on Linux!

    About UDF2.5 for OSS: Yeah, i figured the changes were rather major, otherwise someone would’ve implemented them by now! 😉 But there’s really no way around it: Linux ist all about being compatible with anything on any level – Network, Filesystems, POSIX, WINE, OpenGL, whatever… So simply ignoring UDF2.5 burning capabilities, while at the same time CLAIMING that OSS-tools can “burn Bluray” simply cannot stand in the long run! We need to get the word out and need to make people aware of the problem and show that there’s demand for this! I mean – you can burn Bluray without all the horrible DRM crap, isn’t that something all Linux Users would be happy about?
    Looking at what the BSD guys did is probably a good starting point though…

    • I dropped an email to Ben at source-forge (who hosts/admins the UDF-tools project) to see if he can provide any details about previous attempts to implement 2.5+, but being as its been 6+ years since any progress on the project, I wouldn’t be surprised if his email is invalid or it goes months without a response. I’d like to be wrong, but…

  17. Kyle: Can you update the article for those people that come here and dont read the comments? I could mail you a PDF of the article if you want btw… Feel free to quote from it if you want to…

  18. For the record, Nero tech support was responsive, but couldn’t help – they are guessing it’s a firmware issue with my LG WH10LS30. I’m guessing most people can just use nero linux though – although I’m creating my udf 2.50 images on an osx machine and slurping them over.

    I still had one problem left though – I noticed that the ffmpeg encodes from this article were causing my playback device (a ps3) to periodically skip up at semi-predictable places in the input.

    I’m not sure if this was due to improper x264 settings or some other problem, but to fix it I did two things: 1) I adapted Dkottmair’s method of encoding the video with mplayer and x264, and 2) I started to use ac3 audio – 6 channel 24-bit PCM gets really quite big! I suspect many people will also find the mkvtoolnix suite of tools useful. Its mkvinfo and mkvextract programs do much better than ffmpeg if your source is an MKV.

    Still waiting for my local bookstore to get a copy of March’s Linux Magazine, Dkottmair – but will definitely get it when it comes out to see if you have any other x264 magic up your sleeve. Incidentally did you look at two-pass encoding with x264?

    Thanks again to all!

  19. Brian: The skipping is most likely due to bitrate or vbv issues. AVCHDs can only have a much lower max bitrate than BDs, try to go for 15MBps in total (Video+Audio) for AVCHD. And according to the x264 guys you should definately have the proper VBV settings in your encode to make sure everything’s okay! So since you mustn’t go overboard with the bitrate on AVCHDs, PCM audio is a VERY bad idea, especially with multichannel sound! My article also describes how you can encode AC3 easily using the VLC stream export…
    I do use CRF for my encodes as the quality is about the same as 2pass, but ofcourse you can use 2pass encoding, too, with the standard methods for x264 (-pass 1 for the first pass, -pass 2 for the second, setting bitrate with -b!)

  20. So Kyle, when will you finally update this article to reflect on the compatibility issues with mkudffs and the x264 settings? 😉 This tutorial is still the #1 hit for “bluray authoring linux” on Google, so it would seem like a good idea!…

    • Of course it is! 😉 The weight of the linux-bluray world rests in my hands!! Mwhahaha. Sorry.. I haven’t medicated yet this morning. But, since I am back to burning Blu-Rays again, I’ll do my best to update it right now…

      • Perfect, thank you very much! 😉 I’m actually thinking of getting a friend that can do Python-GUIs to wrap this all up into some neat little GUI-based program that everybody can use. It would only require mplayer, mencoder (for the audio, instead of VLC) and TSmuxer – and ofcourse Nero, but you’ll need to launch that separately.

        There is actually another way of transcoding the audio into Dolby Digital using mencoder, but unlike VLC, this one does require a videostream, too. It just plays any audio (DTS, AAC, WAV, whatever), also multichannel, and transcodes it into Dolby Digtal:

        mencoder -channels (number of channels) -aid (audiotrack-ID) -ovc copy -oac lavc -of rawaudio -lavcopts acodec=ac3:abitrate=(bitrate-in-kbps) -o (outputfile.ac3) (input-movie)

        [b]number of channels[/b] would be 2 for stereo, 6 for 5.1 multichannel.
        [b]audiotrack-ID[/b] would be the respective audiotrack, starts with 0 for AVI and 1 for mkv.
        Valid AC3 [b]bitrates[/b] are: 80,96,112,128,160,192,224 (up to here it’s usually stereo!), 256, 320, 384, 448, 512, 576 and 640 (this is usually multichannel)

        At some point the mencoder-guys did change the standard channel layout, so make sure with your mencoder that the C/LFE channel is not swapped with Surround L/R!

      • Oh, ofcourse it would also require x264! 😉 And AC3 also supports 32, 40, 48, 56 and 64 kbps, but even for mono i would not use this!….
        P.S: Too bad the b-tag doesn’t seem to work!

  21. Kyle, i just noticed you left out the part about the mplayer scaling options that you need to add to expand video to exactly 1920×1080 or 1280×720, it’s in the posting from 2nd Feb… Would be great if you could add that as well! 😉

  22. Why wouldn’t mkisofs not work for iso creation? With the –iso-level=3, it can create UDF format ISOs that are larger than 4GB.

    • Hey Pete,

      My understanding, not having looked into this recently, is that mkisofs doesn’t support writing of UDF version 2.5 or higher. I don’t believe the –iso-level param is a direct correlation to the UDF version. Some Blu-ray players don’t care about 2.5, but many others do.

      I’ll have to look into the specific UDF versions that mkisofs supports (unless you have already) to see if that’s still valid. I’d love to put this remaining issue to bed and finally have a complete, legal solution.

      Speaking of legal, you planning on running again against our favorite love-to-hate Senator? I still got your yard sign from the last go-a-round!

      –Kyle

  23. For ac3 encoding, check out Aften as well. Once you got the Channel order figured out and exported a 6 Channel WAV, it works like a charm.

    i simply used “aften -b 448 6track.wav out.ac3”

    [audio src="http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/Samples/Microsoft/6_Channel_ID.wav" /]

    is nice to use as a confirmation that you did everything right!

    cheers

  24. I managed to create a UDF 2.6 ISO with ImgBurn (which is a free download) running in Wine.

  25. There is a possibility to use a KdeNlive for video preparations (add some features to your video, subtitles and so on). This application have some loseless output templates. At the same time method for x264 is a perfect (with help of 2 terminals semultaneously) for “final polishing”. Tested all mentioned steps – it works for Samsung BDP-1400.
    K3B can burn UDF filesystem onto the BD-RE (only one time – not more), but this BD-RE must be formatted with help of growisofs and UDF image filled with info or blank – not sure about the BD-R. It is nesessary to use growisofs for BD-R burn for sure.

  26. […] this can help: https://irishjesus.wordpress.com/2010…ring-in-linux/ The problem seems to be that Linux still has no tools to create UDF 2.5/2.6 file-systems for […]

  27. Hi, I’ve started a personal project to add UDF 2.5 and bluray structure support to the genisoimage tool of the cdrkit open-source project. Some parts are already in place in my bluray branch in my cloned cdrkit repository. But, the most important one, the metadata partition support is still in TODO state. I hope I’ll have some time soon to terminate this project.

    Regards,
    David

    • David, how goes your battle for UDF 2.5? Unfortunately, I’ve been so completely disconnected from my blog, and most of my projects for some time due to personal stuff. Fortunately, that should be changing soon.

      –Kyle

      • Hi Kyle, I just have two days in august to made deep analysis of small UDF2.50 image made by ImgBurn. So my understanding of the way metadata partitions need to be written is better, but not yet coded in my cloned cdrkit repo. I’ll write on my website when I’ve done one more step in coding.

        Regards,
        David

  28. PCM surround-sound audio is wayyyy to big, but using ffmpeg, worked for me to extract the raw AC3:

    ffmpeg -i movie.mpg -acodec copy audio.ac3

  29. You guys might think it’s “dirty”, but the previous comment about “imgburn” under wine works even better than it sounds:

    In a *single* command-line, you can replace the mkudffs and copy steps like this:

    bash$ wine ~/.wine/drive_c/Program\ Files/ImgBurn/ImgBurn.exe /MODE BUILD /OUTPUTMODE IMAGEFILE /SRC “C:\users\username\Desktop\path\to\tsMuxer\output\folder” /DEST “C:\users\username\Desktop\path\to\final.iso” /FILESYSTEM “UDF” /UDFREVISION “2.50” /VOLUMELABEL “some disk label” /NOIMAGEDETAILS /START /CLOSE

    Works perfectly, and its free =)

    imgburn even can replace the dvd+rw-tools step too (in a single script).

  30. […] I am referencing the post located here:Blu-ray Movie Authoring in Linux […]

  31. This has been a great help to me but I have a question… The beginning of the article uses ffmpeg (as does the provided script) while it later shows using mplayer to extract the video, but the x264bluray.com site shows using x264 directly.

    The latter seems the easiest way. Is there any downside to calling x264 versus having to user mplayer and two terminal windows?

    Also, I may or may not have the time but I have made some incremental improvements to the script. I added quotes around $MOVIE so it can handle files with spaces in the name and a few other tweaks. If I had time I was going to try and figure out if I can inspect the audio of a file and if it’s already AC3, just extract it rather than decoding to PCM.

    • To be honest – there is a possibility to use “Restricted VBR” at tsMuxer. You can select 40000 kbps as max and 0 kbps as min rating for video flow. But don’t forget to set up “VBV buffer size, ms” – as You can see from this long post – buffer size for BD video flow must be 30000 kbps, but tsMuxer offering to set up it in milliseconds – max rating = 40000 kbps (it’s 1000 milliseconds), so You can select 750 ms. I’ve tested it on mpeg2 video flow with 1.06 tsMuxer version and it was good. Now there is a new version of tsMuxer available so You can test all other new features that it offering. I’ll try to test ISO (I think that it’s UDF image) image creating for BD when I’ll be able to pay more time for it.

      • Yes – it works. TsMuxer is able to create an UFD image with disc structure and data (new feature that has a name “Blue-ray ISO” in tsMuxer interface). It works for BDP-1400 Samsung player.

  32. Hi gentlemen.
    Please check out the new version of tsMuxer for Linux. It available on http://www.videohelp.com/tools/tsMuxeR . As I can understand – it can create an ISO image (but I think that it’s a UDF image) for BD. So there is only one command line to burn it on a blank disc – $ growisofs -dvd-compat -Z /dev/scd0=image.iso or $ growisofs -dvd-compat -Z /dev/scd0=image.udf .

    • Please don’t forget about the next fact – last updates for tsMuxer are 32-bit applications – it You are user of 64-bit system – You are able to install some additional libs (same way as a way to force Skype to work on 64-bit system).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: