Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

MPlayer/MEncoder Tips and Tricks

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Message
Author
User avatar
garrincha
Posts: 2335
Joined: 2006-06-02 16:38

Re: MPlayer/MEncoder Tips and Tricks

#46 Post by garrincha »

L4m3b0yz wrote:I found a couple of interesting tips about mplayer here:
http://xt7-player.sourceforge.net/xt7fo ... p?f=5&t=81
http://xt7-player.sourceforge.net/xt7fo ... p?f=5&t=10

In particular about audio options tuning, channel mapping, and realtime audio normalization using ladspa, impressive!
Thanks. It's quite interesting especially for anyone who want to map 5.1 sound to 2.0 speaker system. As usual, mplayer by itself has options like pan and channels.

See, Chapter 4. Advanced audio usage in MPlayer's online documentation:

http://www.mplayerhq.hu/DOCS/HTML-singl ... l#advaudio

Btw, as an example to play 5.1 sound from first title of a DVD film in a 2.0 speaker system using the pan filter options given in the link above:

Code: Select all

mplayer dvd://1 -channels 6 -af pan=2:0.5:0:0:0.5:0.5:0:0:0.5:1:1:0.5:0.5
Maurice Green on Usain Bolt's 9.58: "The Earth stopped for a second, and he went to Mars."

L4m3b0yz
Posts: 3
Joined: 2009-06-26 10:20

Re: MPlayer/MEncoder Tips and Tricks

#47 Post by L4m3b0yz »

I'm reading the man page right now, and the pan filter syntax is driving me crazy, Not even that xt7-player has a gui for it, but i think i will succeed :evil: .

...Or maybe it's time to buy a 5.1 system...

oldboy
Posts: 724
Joined: 2007-08-09 12:45

Re: MPlayer/MEncoder Tips and Tricks

#48 Post by oldboy »

This is an old post, but I'll post here anyway in case some newbie search for answer.

I am a pretty new newbie. Had been trying for a few days to get mplayer working. I cannot follow the instruction here, e.g., I don't know where is "my path to video". Search LQ and mplayer.org and can't get it to work. :oops:

What I did to make it work was this:

In gnome desktop, add media to sources.list as stated in post 1.
Using Synaptic package manager, check (search) if mplayer has been installed, if not mark and install it.
Again check if w64codec or w32codec (depending on your system) has been installed, if not install it.
Again check if smplayer has been installed, if not, install it. This is the front end to mplayer (a gui interface).
Next, execute smplayer (applications->sound & video->smplayer
Next option->preferences-general tab-video In this menu here choose what you wish to use. I use vx since it has hardware acceleration. For audio, I use OSS (I use alsamixer to configure my sound)
Next, under the video tab I checked all options, but for some dvd's postprocessing does more bad than good, if so, uncheck it.
Next under options-drives select cd devices, I use /dev/cdrom for both cd and dvd.

That is all, should work like a charm. :lol:
This oldboy has a lot of time in his hands
Linux slows down my Alzheimer and dementia :lol:

L4m3b0yz
Posts: 3
Joined: 2009-06-26 10:20

Re: MPlayer/MEncoder Tips and Tricks

#49 Post by L4m3b0yz »

"my path to video" is actually "your path to video".
:mrgreen:

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: MPlayer/MEncoder Tips and Tricks

#50 Post by stevepusser »

I see that debian-multimedia has added mplayer-mt (multicore playback for h.264 and mpeg2 codecs) to the testing and unstable repository. I tried a backport of the deb on 64 bit to a "safe" Lenny version (no restricted encoding ability, such as h.264 or mpeg4; plays back those files just fine, which is OK with the patent holders, more business for their content)

I did add some safe opensource libraries to build against:

libvdpau1 from debian-multimedia stable for accelerated hardware video for newer nvidia cards.
libopencore-amrnb and -amrwb from Squeeze, these can be directly installed into Lenny without any other updating needed.
libasound2 from lenny-backports, the Lenny version is just too old to work with the latest source code.

If anyone is interested, I could build a 32 bit version, too, and put the debs, plus the other deb files, into a zip archive. That way, you could just extract the archive and install them all with

dpkg -i *.deb
apt-get -f install

Edit: I could throw the latest SMplayer front-end deb builds from svn in there while I'm at it...
MX Linux packager and developer

User avatar
julian67
Posts: 4633
Joined: 2007-04-06 14:39
Location: Just hanging around
Been thanked: 7 times

Mencoder rip vobsubs (and convert vobsub to srt)

#51 Post by julian67 »

Here's how to use mencoder rip the vobsub subtitles from a DVD or disc image or video_ts folder, and then convert the vobsubs to text .srt if required.

You need the midentify script. You can get it from mplayer's source package TOOLS directory. I've attached it to this post gzipped if that's easier for you. It should be in /usr/bin not /usr/local/bin and must be executable.

First thing to note is that this method is for English subs. These are simplest because, at least on region 1 or 2 English language movies, the English subs are always the first and have subtitle id 0. For other languages you'll have to check each movie/disk individually for your preferred language's sid (subtitle ID), or modify the script to use midentify and grep the language and hence the sid you want.

So to dump the vobsubs I use a script:

Code: Select all

#!/bin/bash
# dumpenglishvobsub.sh
# input must be <devicename> <dvd://#>
# device can be physical device, disk image, video_ts folder
DISKNAME="$(lsdvd "$@" |grep Disc\ Title |awk -F ': ' '{print $2}')"_VOBSUBS
mkdir $DISKNAME
mencoder -dvd-device "$@" -ovc copy -o /dev/null \
-nosound -sid 0 -vobsuboutindex 0 -vobsubout $DISKNAME/0_en
So for example to dump the sub for title 2 of my disc image MYDISC.iso I'd run

Code: Select all

$ dumpenglishvobsub.sh MYDISC.iso dvd://02
and the vobsubs will be dumped to a new folder, named according to the disc title used by the manufacturer. Usually that's the name of the movie but some studios are lazy and it may be a serial number or the unimaginative DVD_VIDEO.

If you want the vobsubs for every language:

Code: Select all

#!/bin/bash
# ripvobsubs.sh
# input must be <devicename> <dvd://#>
# device can be physical device, disk image, video_ts folder etc

# get info about dvd
midentify -dvd-device "$@" >dvdinfo

# set variable:number of subtitle tracks.
# write subtitle lang identifiers to file
NUMSUB=$[$(grep ID\_SID dvdinfo |tee >(cat>subs.txt) |wc -l) -1]

# set variable of dvd diskname_VOBSUBS ##
DISKNAME="$(lsdvd "$@" |grep Disc\ Title |awk -F ': ' '{print $2}')"_VOBSUBS

mkdir $DISKNAME
echo $NUMSUB

for SUBNUM in $(seq 0 $NUMSUB) ; do

# use mencoder to dump vobsubs. one mencoder pass per subtitle.
# runs at about 2000 fps  
mencoder -dvd-device "$@" -ovc copy -o /dev/null \
-nosound -sid $SUBNUM -vobsuboutindex 0 -vobsubout \
$DISKNAME/$(grep \_$SUBNUM\_ subs.txt |awk -F '=' '{print $2}')_$SUBNUM
done
Again this will create a folder according to the title name and dump all the vobsubs into it, naming each set according to their language and sid. This is surprisingly fast. I've seen some people recommend to use '-ovc raw' but that's not right. A copy is always faster than any kind of manipulation or extraction. When I compared it for myself I found that using '-ovc raw' means vobsub extraction will run about 5 or 6 times slower than with '-ovc copy'.

If you want to convert your vobsubs to srt it's easy and quite fast, though you'd perhaps not find this to be the case if you follow the subtitleripper/transcode docs or online tutorials which have some errors of omission due to not being updated in line with the applications. You need the package subtitleripper (get it from debian-multimedia) and a spellchecker such as ispell. If you're using a graphical environment then Gaupol makes for a nice spellchecker for subtitles.

Copy the ifo file for the title from your DVD/video_ts/disc image. The ifo file for title 1 would be VTS_01_0.IFO, for title 2 would be VTS_02_0.IFO and so on.

So if your English vobsubs are en_0 (you have a file en_0.idx and a file en_0.sub) you can run

Code: Select all

vobsub2pgm -c 255,255,0,255 -i VTS_01_0.IFO -g 2  en_0 english
The '-g 2' is essential because it ensures the output is gzipped which the next tool pgm2txt now requires (earlier versions didn't expect the input to be gzipped and this new requirement is documented in exactly zero places as far as I can tell). This detail is absent from the docs and from every example I've ever seen. I cursed a lot of people.

Now run

Code: Select all

pgm2txt english
and you'll see gocr (optical character recognition) offer you unrecognised characters to identify. The characters composed of ### signs are the unrecognised ones. If you can't recognise any characters either then go back a step: delete all the output of vobsub2pgm and try it again with a slightly different -c option, so if -c 255,255,0,255 didn't produce useful results then this time try -c 255,0,255,255. Check the man page for more detail, but one or other of these two settings will probably work in most cases. Don't worry this is all easy and quick to do.

So run pgm2txt again and it should just take a couple of minutes and not too many prompts for input. Now you have a file called english.srtx and you can make an srt file

Code: Select all

srttool -s -w < english.srtx > moviename.srt
You should now spellcheck the moviename.srt because it will have some errors. On a console system ispell is decent enough but if you have a graphical desktop then a subtitle tool with built in spellchecker such as Gaupol makes a lot of sense. Probably the spellchecking will be the longest part of this process. When it's done you have an srt subtitle file ready to be merged into mkv or mp4 container or be used alongside a movie in avi container. The timings and spelling and grammar should be correct.

Most tutorials you'll see for this will use transcode's tccat and tcextract for the inital task of dumping the subs. I prefer mencoder because I'm more familiar with it and when I've compared them the initial extraction speed is identical. Overall mencoder is definitely faster because it doesn't require a further step (transcode method requires you to next run subtitle2vobsub).
Attachments
midentify.gz
(379 Bytes) Downloaded 257 times
Wisdom from my inbox: "do not mock at your pottenocy"

User avatar
Issyer
Posts: 3032
Joined: 2007-05-23 02:59
Location: Khakassia

Re: MPlayer/MEncoder Tips and Tricks

#52 Post by Issyer »

Here is the python script to rip DVDs. You need to change the path to your mencoder.

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-

mencoder='/opt/Mplayer-2010-06-03/bin/mencoder'

import os

os.system('lsdvd /dev/dvd > lsdvd.txt')

f=open('lsdvd.txt', 'r')
L=f.readlines()
f.close()

disk=''
i=1
for item in L:
  if item !='' and item != '\n':
    item.replace('\n','')
    if item.find('Title') == 0:
      print str(i)+' '+item[:item.find('Chapters')]
      i=i+1
    
  if item.find('Disc Title: ') == 0:
    disk = item[len('Disc Title: '):]
    disk=disk.replace('\n','')

if os.path.exists(disk)==False:
  os.mkdir(disk)

T=raw_input('\nTitles to rip separated by commas (eg. 1,2,3)\nDefault 1: ')
if T == '':
  T = '1'
  
print '\nSize: 480:320, 540:360, 600:400, 720:480'
S=raw_input('Default 540:360: ')
if S == '':
  S = '540:360'


vbitrate="vbitrate=2160000:mbd=2:keyint=132:v4mv:vqmin=3:vlelim=-4:vcelim=7:lumi_mask=0.07:dark_mask=0.10:naq:vqcomp=0.7:vqblur=0.2:mpeg_quant"

Titles=[]
if T.find(','):
  Titles=T.split(',')
else:
  Titles.append(T)
   
for item in Titles:
  
  if item !='':  
    # remove conflicting files
    os.system('rm -f divx2pass.log frameno.avi')

    # rip audio track (bitrate: 128, gain: 0)
    os.system('nice -n 3 '+mencoder+' -oac mp3lame -lameopts mode=2:cbr:br=128:vol=0 -vf scale='+S+' -ovc frameno -o frameno.avi  dvd://'+item)

    # video track (pass: 1, bitrate: 0)
    os.system('nice -n 3 '+mencoder+' -sws 2 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:'+vbitrate+':vhq:vpass=1 -ffourcc XVID dvd://'+item+' -o /dev/null')

    # video track (pass: 2, bitrate: 0)
    os.system('nice -n 3 '+mencoder+' -sws 2 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:'+vbitrate+':vhq:vpass=2 -ffourcc XVID   dvd://'+item+' -o "'+disk+os.sep+item+'.avi"')

os.system('rm -f lsdvd.txt')
os.system('frameno.avi')

User avatar
julian67
Posts: 4633
Joined: 2007-04-06 14:39
Location: Just hanging around
Been thanked: 7 times

Re: MPlayer/MEncoder Tips and Tricks

#53 Post by julian67 »

How to extract CC (Closed Caption) Subtitles using mplayer and ccextractor.

Closed Caption subtitles are found on DVDs sold in Region 1 (United States, Canada, Bermuda, U.S. territories).
They are usually used to provide subtitles for people who are deaf or hard of hearing. They are text subtitles
carried in the video stream (unlike vobsubs which are an image format). Because they are text subs it's easy to
dump them to a regular srt file with appropriate time codes, or to a text file without timing info, only transcription.

Tools like lsdvd and mplayer -identify don't seem able to detect CC subs though mplayer can play them fine with
-subcc. Check the DVD packaging for the CC logo. It should list any extra languages if there is more than just
English. English will probably always be the first title on English language DVDs. You might get Spanish as well.

You need mplayer and ccextractor. ccextractor isn't in Debian repos or in debian-multimedia. You can get it from
http://sourceforge.net/projects/ccextractor/ It only takes a few seconds to build it. Unpack it, cd into the
directory named linux and run

Code: Select all

$ ./build
and very shortly you'll have an executable binary. Place the binary in your path.

If your DVD is copy protected you'll need to have libdvdcss2 installed from debian-multimedia. lsdvd is also useful
for identifying the titles on the disc.

Assuming your DVD of your favourite movie, Bambi, is on /dev/sr0 and you want to dump the subtitle for title 3:

Code: Select all

$ mplayer -dvd-device /dev/sr0 dvd://3 -dumpstream -dumpfile bambi

Code: Select all

$ ccextractor bambi -o Bambi.srt
It won't take too long, and when it's done you have Bambi.srt which should load automatically when you play Bambi.avi.
Aaaaah, so cute & smiley, now where's my crossbow? Or you can mux it into matroska or mp4 container with the video
and audio.

If you want to know how to deal with the second CC track i.e. Spanish, or to output the subtitle in a different format, then run ccextractor with no options for info. VLC is quite useful for playing a title and checking what streams it contains as it presents the info to you, whereas with mplayer you'll have to just suck it and see. ffmpeg -i doesn't manage to identify any CC streams.
Wisdom from my inbox: "do not mock at your pottenocy"

Post Reply