republican-creole
Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » All Things Unix » mkv4ps3.pl - convert mkv files to mp4/avi for the PS3
Search Topic:
Uniqs:
8035
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
SSH over WAN »
« Nice CPU %-age  
page: 1 · 2 · 3
AuthorAll Replies


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME


edit:
March 1st, @03:10PM

 mkv4ps3.pl - convert mkv files to mp4/avi for the PS3

I decided to put together a script that would be able to convert an MKV file into a compatible mp4 or avi for the PS3. This uses all open-source tools and while I tested it on FreeBSD, it should also work on Linux/windows(cygwin), assuming the path to the commands is found, etc.

Anyway, in a nutshell it does the following:

* for 720p source
- split mkv into ac3/h264
- modify h264 header to change level_idc to 0x29 (4.1)
- transcode ac3 to aac (keeping channel mapping proper)
- remux to mp4 with mp4box
- split the resulting mp4 into 3.5G chunks since the PS3 doesn't like mp4 files that are too large
- for h264 streams that are incompatible, you can use the -target option to specify you want an xvid/ac3 avi (see 1080p source)

* for 1080p source
- transcode from mkv (h264/ac3) to avi (high bitrate xvid/ac3), leaving the audio track intact
- or, transcode the h264 stream to a High@4.1 compliant h.264 stream and mux that with a transcoded AAC as with the 720p files into an mp4

Right now, all the transcoding is only doing 1-pass. I'm going to look into adding 2-pass later, but for now this should give you a file that will happily play back on the PS3 either locally or streaming (I use ushare to stream, works great).

I wish the mp4 file size limitation would be fixed, since the PS3 will play back an AVI that's larger than 4GB just fine.

Anyway, here's the link:

mkv4ps3.pl

Enjoy! Feedback appreciated! I tested it fairly thoroughly, but was up late writing it so there may be a few bugs I'm unaware of.
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

I tried your script, but received an error:

Cannot open temporary h264 file

I tried running the script as sudo , in a directory with chmod 777 priviledges, plenty(?) of disk space and still get this error. I don't know perl well enough to debug. Thanks for your help.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
Hmm can you post the full command line you used?

Also, the output of:

mkvinfo blah.mkv

Thanks!
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

reply to deblin
Here's the info:

$ mkvinfo /sdb3/Ratatouille.mkv
+ EBML head
|+ Doc type: matroska
|+ Doc type version: 1
|+ Doc type read version: 1
+ Segment, size 4657813898
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4025)
|+ Segment information
| + Timecode scale: 1000000
| + Muxing application: libebml v0.7.7 + libmatroska v0.8.1
| + Writing application: mkvmerge v2.1.0 ('Another Place To Fall') built on Aug 19 2007 13:40:07
| + Duration: 6632.971s (01:50:32.971000000)
| + Date: Thu Jan 10 08:36:59 2008 UTC
| + Title: Ratatouille 720p
| + Segment UID: 0xb5 0xd3 0xea 0xb4 0x59 0x9b 0xe0 0xf0 0x8d 0x15 0x57 0x20 0x94 0x64 0x5a 0x68
|+ Segment tracks
| + A track
| + Track number: 1
| + Track UID: 1
| + Track type: video
| + Enabled: 1
| + Default flag: 1
| + Forced flag: 0
| + Lacing flag: 0
| + MinCache: 1
| + Timecode scale: 1.000000
| + Max BlockAddition ID: 0
| + Codec ID: V_MPEG4/ISO/AVC
| + Codec decode all: 1
| + CodecPrivate, length 68
| + Default duration: 41.708ms (23.976 fps for a video track)
| + Language: eng
| + Name: Ratatouille 720p (English)
| + Video track
| + Pixel width: 1280
| + Pixel height: 528
| + Interlaced: 0
| + Display width: 80
| + Display height: 33
| + A track
| + Track number: 2
| + Track UID: 3414678942
| + Track type: audio
| + Enabled: 1
| + Default flag: 1
| + Forced flag: 0
| + Lacing flag: 1
| + MinCache: 0
| + Timecode scale: 1.000000
| + Max BlockAddition ID: 0
| + Codec ID: A_AC3
| + Codec decode all: 1
| + Default duration: 32.000ms (31.250 fps for a video track)
| + Language: eng
| + Name: Dolby Digital Surround Ex 5.1 (English)
| + Audio track
| + Sampling frequency: 48000.000000
| + Channels: 6
| + A track
| + Track number: 3
| + Track UID: 3404336571
| + Track type: audio
| + Enabled: 1
| + Default flag: 0
| + Forced flag: 0
| + Lacing flag: 1
| + MinCache: 0
| + Timecode scale: 1.000000
| + Max BlockAddition ID: 0
| + Codec ID: A_AC3
| + Codec decode all: 1
| + Default duration: 32.000ms (31.250 fps for a video track)
| + Language: spa
| + Name: Dolby Digital Surround Ex 5.1 (Español Neutro)
| + Audio track
| + Sampling frequency: 48000.000000
| + Channels: 6
| + A track
| + Track number: 4
| + Track UID: 4028376243
| + Track type: subtitles
| + Enabled: 1
| + Default flag: 1
| + Forced flag: 0
| + Lacing flag: 0
| + MinCache: 0
| + Timecode scale: 1.000000
| + Max BlockAddition ID: 0
| + Codec ID: S_VOBSUB
| + Codec decode all: 1
| + CodecPrivate, length 348
| + Language: eng
| + Name: English
| + Content encodings
| + Content encoding
| + Order: 0
| + Scope: 1 (1: all frames)
| + Type: 0 (compression)
| + Content compression
| + Algorithm: 0 (ZLIB)
| + A track
| + Track number: 5
| + Track UID: 3478347420
| + Track type: subtitles
| + Enabled: 1
| + Default flag: 0
| + Forced flag: 0
| + Lacing flag: 0
| + MinCache: 0
| + Timecode scale: 1.000000
| + Max BlockAddition ID: 0
| + Codec ID: S_VOBSUB
| + Codec decode all: 1
| + CodecPrivate, length 348
| + Language: spa
| + Name: Español
| + Content encodings
| + Content encoding
| + Order: 0
| + Scope: 1 (1: all frames)
| + Type: 0 (compression)
| + Content compression
| + Algorithm: 0 (ZLIB)
|+ EbmlVoid (size: 1024)
|+ Cluster

Here are all the variations of the command

$ cat .bash_history|grep .pl
/home/johnz/mkv4ps3.pl
/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out /sdb3
/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out /sdb3
/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi
/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3
/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp
/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp
sudo /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp
sudo /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi
sudo /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -target mp4
sudo /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -target mp4 -tmp /sdb3/tmp
sudo /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp
sudo /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp

Thanks again for your help. I am currently trying PS3 Video 9 from Red Kawa running in a virtual XP session.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

Which of those commands were you running when you got the message about not being able to open the intermediate h264 file? That I would only expect if your target mode was mp4, since that's where it:

- splits mkv into .h264 / .ac3
- change the header in the h264 (if necessary) to indicate High@4.1 profile
- transcode .ac3 into raw .wav then to .aac with neroaacenc
- uses mp4box to re-mux the .h264 and .aac into an .mp4 container

Do you get an error going to .avi? If so, it should be a different one...
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

reply to deblin
$ /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp
Checking input file sanity...
Reading mkv info...
Changing h.264 stream's level_idc header...
Cannot open temporary h264 file

and:

$ /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -target mp4 -tmp /sdb3/tmp
Checking input file sanity...
Extracting mkv file...
Re-encoding h.264 elementa stream (this may take a while)...
mv: cannot stat `/sdb3/tmp/tmp.h264': No such file or directory
Use of uninitialized value in multiplication (*) at /home/johnz/mkv4ps3.pl line 425.
Re-encoding of h264 stream failed.

The /sdb3/tmp directory contains three files:

tmp.ac3 303.6MB
tmp.idx 59.4KB
tmp.sub 4.0MB

Hope this helps.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

Ahh ok, kind of a "bug" on my part. If you specify -target mp4, it assumes you want to re-encode the h264 stream.

Try:

/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -tmp /sdb3/tmp

If that still doesn't work, try running this manually and paste the output:

mkvextract tracks Ratatouille.mkv 1:rat.h264 2:rat.ac3

That's essentially what it's doing when it targets the mp4 output. It seems like mkvextract isn't working for some reason, either because it's unable to parse the right track #s for the input file or there is perhaps a bug somewhere that this particular mkv is tweaking.
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

Partial success only with mkvextract command:

$ mkvextract tracks Ratatouille.mkv 1:rat.h264 2:rat.ac3
Extracting track 1 with the CodecID 'V_MPEG4/ISO/AVC' to the file 'rat.h264'. Container format: AVC/h.264 elementary stream
Extracting track 2 with the CodecID 'A_AC3' to the file 'rat.ac3'. Container format: Dolby Digital (AC3)
progress: 100%
$

Files created:

rat.ac3 303.6MB
rat.h264 3.7GB


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
Hmm, let me throw some additional debugging/etc into the script and I'll throw up a new version for you.
--
Hello...is there anybody in there?


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

reply to johnzbesko
Hmm, I just realized that I "released" this script back before I had realized that ffmpeg totally hoses the audio channels. I gave up on it and use mplayer and neroaacenc now. I'll update the script to use that instead, might take me a few minutes, but should be able to do it tonight.
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30


edit:
March 31st, @12:01AM

reply to deblin
Thank you. It's getting late. I can work on this project tomorrow. Some additional information:

Running Kubuntu Gutsy, 32 bit.
AMD64 X2 Dual Core 3800+
3GB RAM

/sdb2 is NTFS 6.86GB free
/sdb3 is XFS 4.87GB free
/home is reiserfs 13.5GB free


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

You're welcome, glad to help!

Ok, I added a -v option (verbose). I also updated it to use neroAacEnc (so if you don't have that, get it ).

Here's the link to the updated script:

»pflog.net/mkv4ps3.tgz

Run the same command you ran before, but add -v, e.g.:

mkv4ps3.pl -in ... -v

Then paste me the output when you run that.
--
Hello...is there anybody in there?


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

reply to johnzbesko
If you already grabbed it, grab it again. I found for some inputs, mplayer did NOT like the ac3 file. So I'm using ffmpeg to dump the ac3 to wav, then using the wav as input to mplayer to change the channel mappings.
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

reply to deblin
~$ /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.avi -target avi -tmp /sdb3/tmp
Checking input file sanity...
Use of uninitialized value in numeric gt (>) at /home/johnz/mkv4ps3.pl line 185.
Use of uninitialized value in modulus (%) at /home/johnz/mkv4ps3.pl line 208.
Reading mkv info...
Error, could not determine input MKV fps

$ /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -target mp4 -tmp /sdb3/tmp
Checking input file sanity...
Use of uninitialized value in numeric gt (>) at /home/johnz/mkv4ps3.pl line 185.
Use of uninitialized value in modulus (%) at /home/johnz/mkv4ps3.pl line 208.
Extracting mkv file...
Error, mkvextract failed! output:

Error: Invalid Invalid track ID in argument '%s'.
ID in argument '-1:/sdb3/tmp/tmp.ac3'.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

Hmm, looks like the output from your mkvinfo is not what mine is, as it's unable to parse out the necessary information.

Grab the script again (I just updated it), and run it like this exact command (don't include -target mp4):

/home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -tmp /sdb3/tmp -v

Then paste the output.

Right now, using the .wav as an intermediate file for the encoding with nero is causing the channel mapping to get screwed up. Looking into that, but for now, I'd like to find out why it's completely not working for you. In the mean time, I'll work on getting the channel mapping fixed.
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

reply to deblin
$ /home/johnz/mkv4ps3.pl -in Ratatouille.mkv -out Ratatouille.mp4 -tmp /sdb3/tmp -v
Checking input file sanity...
Running: mkvinfo "Ratatouille.mkv" 2>&1
Extracting mkv file...
Running: mkvinfo "Ratatouille.mkv" 2>&1
Running: mkvextract tracks "Ratatouille.mkv" 3:/sdb3/tmp/tmp.ac3 5:/sdb3/tmp/tmp.h264 2>&1
Changing h.264 stream's level_idc header...
Cannot open temporary h264 file
$

Hmm, same as a previous error. "tmp.h264" does not exist. Given that I had success with:

$ mkvextract tracks Ratatouille.mkv 1:rat.h264 2:rat.ac3

is it possible to "patch-in" the rat.h264 and rat.ac3 files into your script so it can move on to the next step? I also notice that your script extracts:

3:/sdb3/tmp/tmp.ac3 5:/sdb3/tmp/tmp.h264

and the successful command extracts:

1:rat.h264 2:rat.ac3

Are the wrong tracks being extracted? Is the full path name screwing it up?? Is tmp a bad choice of temporary filename? I am lost :-(


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

It looks like the multiple audio tracks are confusing the script. Can you run:

mkvinfo Ratatouille.mkv > rat
gzip rat

Then attach rat.gz to this thread, and I'll fix the parsing algorithm to properly handle cases where the mkv has multiple audio tracks.
--
Hello...is there anybody in there?

johnzbesko

join:2008-03-30

reply to deblin
rat.gz 975 bytes
Attached as requested.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
Thanks, I updated the script and it should parse the mkvinfo output properly now.

Please grab it again and give it a shot!
--
Hello...is there anybody in there?


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

ANOTHER new version This one _should_ work for matroska files with DTS audio tracks. Testing it out now, seems to be working ok.
--
Hello...is there anybody in there?
-
Forums » Tech and Talk » OS and Software » All Things UnixSSH over WAN »
« Nice CPU %-age  
page: 1 · 2 · 3


Saturday, 30-Aug 08:21:34 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 9 years online! © 1999-2008 dslreports.com.
page compression OFF
Most commented news this week
· [333] Comcast 250GB Cap Goes Live October 1
· [223] FBI To Allow Warrantless Investigations
· [159] Industry Reacts To Comcast Cap Plans
· [130] AT&T Thanks Democrats For Telecom Immunity
· [123] Time Warner Cable Cripples TiVO, Gets FCC Fine
· [120] Why Run FTTH When You Can Pretend You Do?
· [74] Friday Open Thread
· [67] Telus CAPS 'Unlimited' EVDO Data Plans
· [65] Game Publishers Follow The RIAA's Lead
· [60] Qwest Defends Not Running FTTH
Most people now reading
· Going to Wire My House for CAT5e [Home Repair & Improvement]
· Bandwidth Monitor for Computers-Suggestions? [Comcast HSI]
· Comcast has new Acceptable Use Policy besides the 250GB cap [Comcast HSI]
· Steele vs Paypal - Hoax or Not - You Make the Call [Spam, Scam and Phishbusters]
· HP Broadcom Wireless Driver Updates [Wireless Networking]
· AVG 8 EXTREMELY slow? [Security]
· If anyone wants to see pictures [Home Repair & Improvement]
· What happens with returns at supermarkets [General Questions]
· [iPhone] Did I Buy A Fake iPhone? [All things Macintosh]
· Battlegrounds Auto-queue, Auto-Join Add-ons [World of Warcraft]