Showing posts with label media. Show all posts
Showing posts with label media. Show all posts

Friday, July 26, 2013

Creating a DVD in Linux

There are a number of documents created that describe the inception of a DVD from DV (Digital Video) files, or even "ripping" (capturing the contents of a DVD into a movie file), but none that I saw delt with convering a captured movie from a TV tuner card into a DVD.  This document describes the basic steps performed in taking a video capture file and converting it into a DVD.

The first step is to carve the captured file into the exact pieces desired.  I performed this step using the mplayer in playing to the point where I wanted the video capture file to start, and then noting the "seconds" field.  Then, I noted where the ending point was that I needed from the video.  At that point, I ran :
    
    mencoder -ovc copy -oac copy -ss 604 -endpos 4845 -o chopped_file.mpg original-file.mpg
    
    
The above command took the file original-file.mpg and made a copy - but only copied 4845 seconds (see the -endpos 4845 parameter) starting from the 604 second mark (see the -ss 604 parameter).  The copy was named chopped_file.mpg.

At this point, it is a good time to note that the -endpos parameter is not an "end position", but a time from the -ss (or start position), so that can often be confusing.

Once I had the file I needed, I converted that to a DVD-compatible, MPeg-encoded file using the ffmpeg utility :
    
    ffmpeg -i chopped_file.mpg -target dvd -aspect 4:3 -sameq dvd-ready.mpg
    
    
The ffmpeg command executed read in the chopped_file.mpg, forced a dvd format (the -target dvd parameter) in a TV format (not wide screen - that would have used a -aspect 16:9 parameter.  The -sameq parameter just meant to preserve as much of the quality as possible.  The resulting file was dvd-ready.mpg.

It is also possible to do the previous two steps (mencoder and ffmpeg) in one fell swoop.  The following command will extract the segment of video that is needed, de-interlace it, and get it ready to be put onto a DVD image.
    
    ffmpeg -i original-file.mpg -ss 00:10:04 -t 01:20:46 -target dvd -aspect 16:9 -deinterlace -sameq dvd-ready.mpg
    
    
This is the perfect opportunity to convert that dvd-ready movie file into a DVD video image.  This is done using the wonderful tool called dvdauthor, in two stages.  The first creates a title video from the dvd-ready.mpg file we have created, and sets up some of the required pieces for a DVD video.  The second creates the table of contents and completes the structure for the subsystem :
    
    dvdauthor --title -f dvd-ready.mpg -o DVD/
    dvdauthor -T -o DVD
    
    
Note : you may want to create the DVD/ directory that the dvdauthor commands above will be placing the files into because this is not done by default.

At this point, it is time to create the ISO image.  Some experts prefer to use growisofs, but I'm just a little pickier than that - I want more control over the command.  I typically use mkisofs, but I'll shorten the command to the essential parameters :
    
    mkisofs -dvd-video -udf -o dvd.iso DVD/
    
    
The -dvd-video parameter tells mkisofs to turn on some minor DVD-compatability (setting the order of the appropriate files and padding betweem files if required).  The -udf parameter is adding UDF file system compatability (very similar to Joliet file systems on CD-Rom's).  The -o dvd.iso is telling the mkisofs to create the DVD video image as dvd.iso, and the DVD/ is where the base of the image will come from.

Once that is completed, it is possible to burn the ISO image directly to the DVD recorder using cdrecord, burncd, K3B (if you prefer GUI's), or even rebooting into windows and using Nero.  It should be a functional DVD video at that point in time.

Saturday, January 5, 2013

Creating a 3TB Filesystem in Linux

I moved my media drive out of the portable enclosure, and into the chassis, and ran into a problem.

The filesystem was showing as available, but was unable to mount.  Wondering what was going on, I ran :

fdisk -l /dev/sdb

and had a nice, wonderful message about the DOS partition table being unable to handle disks larger than some arbitrary amount.  Note, this is a new drive that I had mkfs.ext2'd on it a week and a half ago (it was a Christmas present - my wife ROCKS!), so it was (in theory) already having data on it.  I still had the original data ready to go, but couldn't get that mounted, and opted to look into doing this properly.

That lead me to actually re-create the filesystem on it, complete with a new partition table.  This time, instead of using fdisk and mkfs.ext2, I opted for ext4 (still want to turn off journalling) and parted (after removing the partition) :

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart primary ext2 0% 100%
(parted) quit
Information: You may need to update /etc/fstab.

This allowed me to start to create the filesystem after a quick check :


[root@hostname mnt]# fdisk -l /dev/sdb

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      267350  2147483647+  ee  GPT
Partition 1 does not start on physical sector boundary.
[root@hostname mnt]#

So, now it's time to create the filesystem :
 
[root@hostname mnt]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks, Stripe width=0 blocks
183148544 inodes, 732566272 blocks
36628313 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
22357 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@hostname mnt]#

So, the filesystem is created.  But, EXT4 filesystems have journalling enabled by default.  I don't like this, so I must disable it :

[root@hostname mnt]# tune2fs -o journal_data_writeback /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
[root@hostname mnt]# tune2fs -O ^has_journal /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
[root@hostname mnt]# dumpe2fs /dev/sdb1 |grep 'Filesystem features'
dumpe2fs 1.41.12 (17-May-2010)
Filesystem features:      ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
[root@hostname mnt]#


As long as you don't see has_journal in the output, journalling has been disabled.  The next step is to get the filesystem's unique ID :

[root@hostname mnt]# blkid /dev/sdb1
/dev/sdb1: UUID="1ec5551c-10eb-4bad-9232-5710613ba4d2" TYPE="ext4"
[root@hostname mnt]#

Next, ensure we have the mount entry in /etc/fstab :

[root@hostname mnt]# cat /etc/fstab |grep 1ec5551c-10eb-4bad-9232-5710613ba4d2
UUID=1ec5551c-10eb-4bad-9232-5710613ba4d2 /home/media   ext4    defaults     1 2
[root@hostname mnt]#

In some cases, it's wise to reboot the machine and make sure you can still mount it up.  I did that since this is the home media server, and everything looks good:

[root@hostname ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   17G   31G  35% /
tmpfs                 3.8G     0  3.8G   0% /dev/shm
/dev/sda1             485M   90M  370M  20% /boot
/dev/mapper/VolGroup-lv_home
                      400G  347G   33G  92% /home
/dev/sdb1             2.7T   73M  2.6T   1% /home/media
[root@hostname ~]#

That means it's time to rsync things back over.  Hooray!

Tuesday, July 24, 2012

ZoneMinder CentOS 6.2 64bit

A continuation of our project, homebrew security project, we need to tie in a security camera. I've started trying to install zoneminder in CentOS for the homesecurity project. So far, I haven't been able to locate an RPM for it, but I should be able to use the source. First, grab the source and prepare to compile it :

  1. wget http://www2.zoneminder.com/downloads/ZoneMinder-1.25.0.tar.gz
  2. tar xzvf ZoneMinder-1.25.0.tar.gz
  3. cd ZoneMinder-1.25.0
I kept having problems compiling, so I'll hold off on the configure line that I was using at the time (until after the errors are described). Those errors were :
zm_mpeg.h:63: error: use of enum ‘PixelFormat’ without previous declaration
zm_mpeg.h:64: error: ISO C++ forbids declaration of ‘AVOutputFormat’ with no type
zm_mpeg.h:64: error: expected ‘;’ before ‘*’ token
zm_mpeg.h:65: error: ISO C++ forbids declaration of ‘AVFormatContext’ with no type
zm_mpeg.h:65: error: expected ‘;’ before ‘*’ token
zm_mpeg.h:66: error: ISO C++ forbids declaration of ‘AVStream’ with no type
zm_mpeg.h:66: error: expected ‘;’ before ‘*’ token
zm_mpeg.h:67: error: ISO C++ forbids declaration of ‘AVFrame’ with no type
zm_mpeg.h:67: error: expected ‘;’ before ‘*’ token
zm_mpeg.h:68: error: ISO C++ forbids declaration of ‘AVFrame’ with no type
zm_mpeg.h:68: error: expected ‘;’ before ‘*’ token
zm_mpeg.h:69: error: ISO C++ forbids declaration of ‘uint8_t’ with no type
zm_mpeg.h:69: error: expected ‘;’ before ‘*’ token
zm_mpeg.h:85: error: ‘uint8_t’ has not been declared
In file included from zm_zone.h:27,
from zm_monitor.h:27,
from zmc.cpp:27:
Digging in, I found that my configure was also giving some errors :
checking libavutil/avutil.h usability... no
checking libavutil/avutil.h presence... no
checking for libavutil/avutil.h... no
checking libavcodec/avcodec.h usability... no
checking libavcodec/avcodec.h presence... no
checking for libavcodec/avcodec.h... no
checking libavformat/avformat.h usability... no
checking libavformat/avformat.h presence... no
checking for libavformat/avformat.h... no
checking libswscale/swscale.h usability... no
checking libswscale/swscale.h presence... no
checking for libswscale/swscale.h... no
Just as an FYI, I was using the ffmpeg-devel package from the rpmfusion.org repositories. For those, the include files are in your /usr/include/ffmpeg directory, not /usr/include. Digging into the configure script, I found a few things I could change to make it compile, so now I will provide the configure line :
CPPFLAGS=”-I/usr/include/ffmpeg -I/usr/include” CFLAGS=”-I/usr/include/ffmpeg -I/usr/include” CXXFLAGS=”-D__STDC_CONSTANT_MACROS -I/usr/include/ffmpeg -I/usr/include” ./configure –with-webdir=/var/www/html/zm –with-cgidir=/var/www/cgi-bin –with-libarch=lib64 –with-ffmpeg=/usr –with-webuser=apache –with-webgroup=apache ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER=zmuser ZM_DB_PASS=zmpass –with-extralibs=”-L/usr/lib64 -L/usr/lib64/mysql” ZM_SSL_LIB=openssl
Then I ran into a segmentation fault. The backtrace looked like :
[root@cottonwoodheights ZoneMinder-1.25.0]# gdb zmc
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /usr/local/bin/zmc...(no debugging symbols found)...done.
(gdb) run -m 1
Starting program: /usr/local/bin/zmc -m 1
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff71f6700 (LWP 21926)]

Program received signal SIGABRT, Aborted.
0x00000039b0832885 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install SDL-1.2.14-3.el6.x86_64 alsa-lib-1.0.22-3.el6.x86_64 bzip2-libs-1.0.5-7.el6_0.x86_64 dbus-libs-1.2.24-5.el6_1.x86_64 enca-1.13-1.el6.x86_64 expat-2.0.1-11.el6_2.x86_64 ffmpeg-libs-0.10.2-3.el6.x86_64 flac-1.2.1-6.1.el6.x86_64 fontconfig-2.8.0-3.el6.x86_64 freetype-2.3.11-6.el6_2.9.x86_64 fribidi-0.19.2-2.el6.x86_64 glibc-2.12-1.47.el6_2.12.x86_64 gnutls-2.8.5-4.el6_2.2.x86_64 gsm-1.0.13-4.el6.x86_64 keyutils-libs-1.4-3.el6.x86_64 krb5-libs-1.9-22.el6_2.1.x86_64 libICE-1.0.6-1.el6.x86_64 libSM-1.1.0-7.1.el6.x86_64 libX11-1.3-2.el6.x86_64 libXau-1.0.5-1.el6.x86_64 libXext-1.1-3.el6.x86_64 libXfixes-4.0.4-1.el6.x86_64 libXi-1.3-3.el6.x86_64 libXtst-1.0.99.2-3.el6.x86_64 libass-0.10.0-1.el6.x86_64 libasyncns-0.8-1.1.el6.x86_64 libcdio-0.81-3.1.el6.x86_64 libcom_err-1.41.12-11.el6.x86_64 libdc1394-2.1.2-3.4.el6.x86_64 libgcc-4.4.6-4.el6.x86_64 libgcrypt-1.4.5-9.el6_2.2.x86_64 libgpg-error-1.7-4.el6.x86_64 libjpeg-6b-46.el6.x86_64 libogg-1.1.4-2.1.el6.x86_64 libraw1394-2.0.4-1.el6.x86_64 librtmp-2.3-3.el6.x86_64 libselinux-2.0.94-5.2.el6.x86_64 libsndfile-1.0.20-5.el6.x86_64 libstdc++-4.4.6-4.el6.x86_64 libtasn1-2.3-3.el6_2.1.x86_64 libtheora-1.1.0-2.el6.x86_64 libusb1-1.0.3-1.el6.x86_64 libuuid-2.17.2-12.4.el6.x86_64 libv4l-0.6.3-2.el6.x86_64 libvorbis-1.2.3-4.el6_2.1.x86_64 libxcb-1.5-1.el6.x86_64 mysql-libs-5.1.61-4.el6.x86_64 nss-softokn-freebl-3.12.9-11.el6.x86_64 openal-soft-1.12.854-1.el6.x86_64 openjpeg-libs-1.3-7.el6.x86_64 openssl-1.0.0-20.el6_2.5.x86_64 pcre-7.8-4.el6.x86_64 pulseaudio-libs-0.9.21-14.el6_3.x86_64 speex-1.2-0.12.rc1.1.el6.x86_64 tcp_wrappers-libs-7.6-57.el6.x86_64 x264-libs-0.120-5.20120303.el6.x86_64 xvidcore-1.3.2-3.el6.x86_64 zlib-1.2.3-27.el6.x86_64
(gdb) bt
#0 0x00000039b0832885 in raise () from /lib64/libc.so.6
#1 0x00000039b0834065 in abort () from /lib64/libc.so.6
#2 0x00000000004142be in Logger::logPrint(bool, char const*, int, int, char const*, ...) ()
#3 0x000000000046d675 in Zone::Load(Monitor*, Zone**&) ()
#4 0x000000000043c78c in Monitor::Load(int, bool, Monitor::Purpose) ()
#5 0x00000000004068a8 in main ()
(gdb)
Splashing a few fprintf(stderr,...) messages throughout the code, I got the zmc command down to the following error:
Zone 1/All for monitor camera-name extends outside of image dimensions, 0, 0, 1279, 1039
Aborted (core dumped)
I added another fprintf(stderr...) line right above the panic line with that error, and pow, I knew what the problem was: the monitor was set up at 1280x1024, and the "Zone" (the motion rectangle) is for 1280x1040. Looking in the DB, yes indeed, the Zone was set badly. I corrected the DB entry, restarted zoneminder, and the camera was STILL showing up in red, meaning it wasn't able to view the camera. So, off to /var/log/messages to see if anything is showing up in there :
Jul 23 12:40:39 security setroubleshoot: SELinux is preventing zmdc.pl from write access on the sock_file zmdc.sock. For complete SELinux messages. run sealert -l 5dde3dda-0d7c-47db-8bfd-5ce7e48fb992 Jul 23 12:40:40 security setroubleshoot: SELinux is preventing uptime from read access on the file /var/run/utmp. For complete SELinux messages. run sealert -l 17270870-69b2-4101-9955-53415acf164f
Hmmm. SELinux again bites me. After a few runs of grabbing data from the audit log (again, the process is "append the AVC error into a separate log file, run audit2allow, enable the module, and try again. Repeat if necessary.") That got me suddenly into the mode where the source is in yellow, not red (meaning the camera is "operational"). But the camera image kept coming up blank. Back to /var/log/messages :
Jul 25 09:42:19 security zmc_m1[2544]: ERR [Error while decoding frame 0]
Jul 25 09:42:19 security zmc_m1[2544]: ERR [256: 00 00 01 b6 51 f4 18 08 85 f7 53 f8 bc 64 17 c1 68 13 c7 79 b1 9c 4d 8c 5c 31 e4 bd 78 38 80 35 18 27 87 60 3a da 9a 69 12 4e a6 db 6b 7b fc ea dd 6b 90 98 f0 8f 13 f3 6b 08 70 22 9a 0a d0 f8 61 dd 6b 84 20 b9 45 ba 06 2c 95 8d 82 41 2e 1c 07 61 42 c2 e7 05 3e 0d 8a eb 0b 86 e7 d2 a2 4c 8c fc 46 50 9b ab b2 26 07 0a 22 67 9c 11 ed a3 e8 d0 1d 45 99 44 36 ea 6b 05 a1 f0 0c 0c 82 be 20 03 8d f3 a0 e2 92 50 e8 59 43 86 87 22 f4 b8 0f 40 18 8e 5b e0 68 32 0a 79 08 23 26 d6 86 29 c9 01 35 c0 ba 43 dc 1e 8d 86 ec 1d 19 f8 44 f6 c1 70 d3 62 10 68 c9 38 38 84 28 f0 bd a0 72 41 9b 70 30 75 01 e1 4b b8 c0 38 ac 88 32 07 15 99 0a 7d d9 37 66 ec 4e 0b b0 70 b4 62 1e 14 8c 4a c2 63 a1 5b 07 42 d1 04 c4 3a 14 0d 7e 87 a0 91 07 06 81 c1 f8 c8 28 b4 20 e3 a1 f8 26 b8 32 08]
Next, I simply tried various configurations until I had one that worked. Next - the configuration for the camera.

Tuesday, July 17, 2012

Finally, the How-To for forked-daapd on CentOS 6.2 64 Bit

FYI, I have superseded this post - I got very frustrated with recompiling the whole kit and caboodle every time I did an update just to have this running.  So, I opted for the mt-daapd server, and it was easier to install, less external dependencies, and still did everything I needed it to.  Try this post before continuing on!

Okay, I'm finally getting to the point of writing up how I finally got forked-daapd installed on my CentOS 6.2 64 Bit media server. It was a pain, but it works.

My process was : try to configure, compile, and install. If it failed, deal with the problem and repeat.

Simple process, but there was a LOT that was problematic.

First, the dependencies (you will need the rpmfusion repository configured) :

yum install gcc glibc-devel avahi-devel ffmpeg-devel libplist-devel taglib-devel flac-devel libunistring-devel java libgcrypt-devel mxml-devel libevent-devel alsa-lib-devel gettext-devel libconfuse-devel gperf zlib-devel ant ant-antlr ant-apache-bcel ant-junit ant-trax antlr tcl-devel git

You will note that we need a stringtemplate RPM as well (hard to find, so I slapped a copy at http://svn.silverhawk.net/files/stringtemplate-3.2.1-3.jpp6.noarch.rpm). I needed to search a bit for one, as it's not in the regular distro, but grab that one.

This should get ALMOST everything. Note that sqlite has to be recompiled. In order to satisfy dependencies, I rebuilt that into an RPM to replace what was there (this one has the option required for forked-daapd). A few others were not found, so I slapped them together, building a number of these RPM's. Currently, the source RPM's are available here :

http://svn.silverhawk.net/files/antlr3-3.1.1-10.el6.src.rpm
http://svn.silverhawk.net/files/libantlr3c-3.1.3-0.2.src.rpm
http://svn.silverhawk.net/files/sqlite-3.6.20-2.el6.src.rpm

You will also want to install the -devel packages for each one once you've built good system packages. You can seamlessly replace any sqlite packages. Note that upgrades might not work with the custom sqlite, but it's easy to grab the source RPM for the upgraded sqlite, add the param, and then upgrade it manually, then the system should update again.

Once those dependencies are installed, you must toss in mxml (available from http://svn.silverhawk.net/files/mxml-2.7.tar (after compiling and installing, copy the mxml.pc file into the appropriate location, mine was /usr/share/pkgconfig/), and then libavl (available from http://alioth.debian.org/~jblache/forked-daapd/libavl_0.3.5.tar.gz) :

  1. Edit the make file, and Comment out "CFLAGS ?= -O2 -fomit-frame-pointer -pipe -mcpu=i686 -w"
  2. Add a new CFLAGS Line :
    CFLAGS = -fPIC -O2 -fomit-frame-pointer -pipe -Wall -g
  3. Replace all "$(LIBRARIES)" variables with "$(LIBRARY)" due to a bug.
  4. Save and Close
  5. Build and install :
    gmake -f GNUmakefile ; gmake -f GNUmakefile install
Now, open the forked-daapd source code, but grab a specific version (you might need to install git if you didn't get it installed earlier) specific for the iTunes 10.5.x functionality (otherwise it will time out) :
  1. mkdir tmp
  2. cd tmp/
  3. git clone https://github.com/CBGoodBuddy/forked-daapd.git
  4. cd forked-daapd
  5. git checkout itunes_v10_5
  6. autoreconf -i
  7. ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-flac --enable-musepack --enable-itunes
  8. make
  9. make install
To run the app, first modify your configuration (/etc/forked-daapd.conf), and then add a user :
useradd -s /sbin/nologin -M -r -d /var/cache/forked-daapd -c "iTunes service account" daapd

Friday, June 29, 2012

forked-daapd in CentOS 6.2 64 Bit

Hey, folks; I was setting up forked-daapd in CentOS 6.2 (64 Bit), and ran into a few problems. One of the most recent was that the libantlr3c was not being used (headers were found). I found that if I add a --enable-64bit to the configure line (I used an RPM spec file), it will create it for 64 bit, which is really what I needed. I realized this when it kept failing to configure the forked-daapd with an error about libantlr3 and a missing function, and when I looked in the config.log for the error, the linker was ignoring the 32 bit libraries. (If you haven't enabled 64 bit, it is 32 by default, and you would have to use a 32 bit compiler by default if you wanted to). So, there is another quick hack.