Transcode Video

From MythTV Official Wiki
Jump to: navigation, search

How to transcode video for iPod, iPhone, PSP, PDA, or other portable devices. There are a lot of different ways to transcode video for use on portable devices, both automated and manually. Some of these methods may be out of date and no longer work.


nuvexport is a utility that can be run from the commandline. You select the output format, the videos you'd like to transcode, and it does it for you. It does not automatically transcode for you, however

See Nuvexport.


mythTV can automatically transcode videos after recording them using mythtranscode. It can only transcode to RTJPEG and MPEG4, however, which may not be what your device requires.

See Mythtranscode.


Mythbrake is a user job script that transcodes recordings to MP4 files using Handbrake. It can create multilanguage files with mutliple audio tracks. It automatically preserves any surround sound (e.g. AC3 5.1) using pass-through if available.

See Mythbrake.


See Mythnuv2mkv.


See Nuv2avi.

3gp Video

Transcoding video to 3gp format for mobile phones

See Transcoding into a 3gp Video.


a perl script that can be installed as a User-Job to automatically transcode video for the iPod. May work for other portable devices as well.

Other iPod exporting Scripts

Here are some alternatives to video2ipod

OTA HDTV to DVD with AC3 stream copy transcode Script


# Step 1, generate DVD resolution file from HDTV content, preserving AC3 audio streams
# produce less log output with the -quiet switch
/usr/bin/nice -19 /usr/bin/mencoder -quiet -oac copy -of mpeg \
-mpegopts format=dvd:tsaf -vf scale=720:-3,harddup -ovc lavc -lavcopts \ 
vcodec=mpeg2video:vbitrate=4000:keyint=15 /myth/tv/$1 -o /myth/tv/$1.tmp

if [ "$?" -ne "0" ]; then
   echo "mencoder died"
   /usr/bin/nice -19 rm /myth/tv/$1.tmp

# Step 2, replace orig HDTV file with transcoded DVD file
/usr/bin/nice -19 mv /myth/tv/$1.tmp /myth/tv/$1

# Step 3, clean up MPEG2 sync issues and using mythtranscode.  Output is a .tmp file.
/usr/bin/nice -19 /usr/bin/mythtranscode --mpeg2 -i /myth/tv/$1 --showprogress

# Step 4, replace DVD file with cleaned DVD file
/usr/bin/nice -19 mv /myth/tv/$1.tmp /myth/tv/$1

# Step 5, update index in database
/usr/bin/nice -19 /usr/bin/mythcommflag --rebuild -f /myth/tv/$1

# OPTIONAL Step 6, Flag commercials on final file
/usr/bin/nice -19 /usr/bin/mythcommflag -f /myth/tv/$1

#Only thing to sort out is updating the MySQL DB for the new filesize after transcoding
# to reflect the new file size. Any ideas on how to do this easily??

# You can do something like this:
SIZE=`ls -l $MYTHDIR/$1 | awk '{print $5}'`

mysql --user=(your username) --password=(your password) mythconverg << EOF
update recorded set filesize = '$SIZE' where basename = '$1';


The Handbrake_userjob is a perl script which is intended to run as user job. It creates .mkv (matroska) files with multilanguage audio tracks. Audio tracks are selected by language, amount of channels (5.1 > 2.0) and codec (ac3, mp2, ..). Uses new (0.25) feature of season / episode info to form video filename with the scheme: TITLE - SxxExx - SUBTITLE.mkv

See Handbrake_userjob.


This is a very simple procedure to transcode a video for display on a phone. It does not skip advertisements.

Make sure the program avconv is available

 which avconv

Otherwise, install it. In ubuntu:

 sudo apt-get install libav-tools

In mythfrontend, navigate Media Library -> Watch Recordings and browse to the recording you want to transfer. Type "i" to bring up Program Details. Note the Recorded File Name, e.g. 1833_201406281100000000.mpg. Hit <esc> to close Program Details.

Remove the uSDHC card from your phone. Connect it to the computer's USB port with a suitable adaptor, and identify the device:

 sudo fdisk -l|grep FAT
 /dev/sdc1            8192    61405183    30698496    c  W95 FAT32 (LBA)

Mount the disk:

 sudo mount /dev/sdc1 /mnt

cd to /var/lib/mythtv/recordings and confirm the file is present:

 cd /var/lib/mythtv/recordings
 /var/lib/mythtv/recordings# ls 1833_20140628110000.mpg

Transcode and copy to the card in one step:

 sudo avconv -i 1833_201406281100000000.mpg -strict experimental "/mnt/music/The Movie Title.mp4"

On my phone (Samsung Galaxy S4) the Video Player or MX Video apps can display an MP4 file. Your phone may take something different. The video I got was very low resolution.

Use mediainfo (from the Ubuntu "mediainfo" package) to display the details about a video file. Here's part of the listing for the original Myth recording:

 $ mediainfo 1833_20140628110000.mpg
 ID                                       : 0 (0x0)
 Complete name                            : 1833_20140628110000.mpg
 Format                                   : MPEG-TS
 File size                                : 12.4 GiB
 Duration                                 : 1h 59mn
 Overall bit rate mode                    : Variable
 Overall bit rate                         : 14.8 Mbps
 ID                                       : 1984 (0x7C0)
 Menu ID                                  : 1 (0x1)
 Format                                   : MPEG Video
 Format version                           : Version 2
 Duration                                 : 1h 59mn
 Bit rate mode                            : Variable
 Bit rate                                 : 13.2 Mbps
 Maximum bit rate                         : 20.0 Mbps
 Width                                    : 1 920 pixels
 Height                                   : 1 080 pixels
 Display aspect ratio                     : 16:9
 Stream size                              : 11.0 GiB (89%)
 Audio #1
 ID                                       : 1985 (0x7C1)
 Menu ID                                  : 1 (0x1)
 Format                                   : AC-3
 Format/Info                              : Audio Coding 3
 Mode extension                           : CM (complete main)
 Codec ID                                 : 129
 Duration                                 : 1h 59mn
 Bit rate mode                            : Constant
 Bit rate                                 : 448 Kbps
 Channel(s)                               : 6 channels

The transcoding using the above command line had a video bit rate of only 2 Mbps. I improved the video greatly by increasing the video bit rate to 8 Mbps like this:

 sudo avconv -i 1833_201406281100000000.mpg -b:v 8M -strict experimental "/mnt/music/The Movie Title.mp4"

However, the output file was larger than the maximum permitted (about 4GB) by the FAT filesystem on the uSDHC card, so I split the movie into three segments of one hour each. The -ss option specifies the start point, and the -t specifies the duration, both in hours:minutes:seconds notation.

 sudo avconv              -i foo.mpg -t 01:01:00 -b:v 8M -strict experimental /mnt/foo_1.mp4
 sudo avconv -ss 01:00:00 -i foo.mpg -t 01:02:00 -b:v 8M -strict experimental /mnt/foo_2.mp4
 sudo avconv -ss 02:00:00 -i foo.mpg             -b:v 8M -strict experimental /mnt/foo_3.mp4

The one or two minute overlap allows for some inaccuracy in seeking to the starting point.

Transcoding takes a while. Over the air video normally runs at 30 frames per second, so if avconv displays "fps=60" then transcoding will take half the running time of the video. If you have a multicore system, you may want to open another terminal window and start a second transcoding job that can run in parallel.

When jobs are finished, unmount the disk:

 sudo umount /mnt