Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Linux, Mac OS X, & Co

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th November 2010, 04:58   #1  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
xbox 360 compatible avi from blu-ray mkv

Have successfully converted from a blu-ray mkv but had some issues along the way.

First I tried ffmpeg

ffmpeg -i input.mkv -threads 8 -acodec ac3 -ac 6 -ab 640k -vtag XVID -vcodec mpeg4 -sameq -maxrate 25000k -bufsize 5000k output.avi

but the output resulted in out of sync audio/video when converting from DTS-HD audio and h.264 video from handbrake.

so then I separated the files individually as I could not find another program to convert DTS-HD audio.

for video
ffmpeg -i input.mkv -threads 8 -an -vtag XVID -vcodec mpeg4 -sameq -maxrate 25000k -bufsize 5000k output.avi

You need the rate limit or else or you xbox 360 will stutter try to replicate the quality of h.264. I choose the buffer randomly as I'm no expert since to it needs one to limit the rate.

for audio
ffmpeg -i input.mkv -vn -threads 8 -acodec ac3 -ac 6 -f ac3 -ab 640k output.ac3

I tried muxing them through avidemux but when I shared them through upnp on xbmc to my xbox 360 I could not fast forward. I muxed them instead through a wine set up of virtualdub and it worked perfect. I'm trying to figure out what the difference is so I can do it all under linux without wine. Anyone else have any feedback or another way let me know.

You need to get to xvid avi or else you can't do surround sound with a 360 and my goal was to do this while losing as little quality as possible. My end result was a 9 gig file at full 1080P with Dolby Digital (although I counldn't check the channel mapping as I currently don't have a 5.1 system).
boykillsworld is offline   Reply With Quote
Old 11th November 2010, 11:05   #2  |  Link
nm
Registered User
 
Join Date: Mar 2005
Location: Finland
Posts: 2,643
Quote:
Originally Posted by boykillsworld View Post
I tried muxing them through avidemux but when I shared them through upnp on xbmc to my xbox 360 I could not fast forward. I muxed them instead through a wine set up of virtualdub and it worked perfect. I'm trying to figure out what the difference is so I can do it all under linux without wine. Anyone else have any feedback or another way let me know.
Try muxing with ffmpeg:
Code:
ffmpeg -i video.avi -vcodec copy -i audio.ac3 -acodec copy output.avi
nm is offline   Reply With Quote
Old 12th November 2010, 00:46   #3  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
Same result converting then muxing with ffmpeg.
boykillsworld is offline   Reply With Quote
Old 12th November 2010, 09:08   #4  |  Link
nm
Registered User
 
Join Date: Mar 2005
Location: Finland
Posts: 2,643
Then there's MEncoder. It has a tweakable A/V sync method, so it should work with some settings at least.

You could also try muxing with MEncoder.

Last edited by nm; 12th November 2010 at 09:12.
nm is offline   Reply With Quote
Old 16th November 2010, 01:43   #5  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
When I try to use mencoder with ac3 I get Failed to open audio demuxer. I did the same when I put the ac3 in an avi container by itself. It does work fine with mp3 though. I did however get this to work. This is what I did.

for video
ffmpeg -i input.mkv -threads 8 -an -vtag XVID -vcodec mpeg4 -sameq -maxrate 25000k -bufsize 5000k output.avi

for audio
ffmpeg -i input.mkv -vn -threads 8 -acodec ac3 -ac 6 -f ac3 -ab 640k output.ac3

mux step 1

avidemux --load video.avi --external-ac3 audio.ac3 --audio-map --save tmp.avi

results in avi that can't be fast forward so final step

mux step 2
mencoder -ovc copy -oac copy -mc 0 -noskip -o final.avi tmp.avi

Result works perfect.

A little overcomplicated and seems somewhat unnecessary but gets the job done.

now just have to figure out how to hard code forced PGS subtitles and I should be off to the races with all my movies

Last edited by boykillsworld; 16th November 2010 at 01:54.
boykillsworld is offline   Reply With Quote
Old 16th November 2010, 12:27   #6  |  Link
nm
Registered User
 
Join Date: Mar 2005
Location: Finland
Posts: 2,643
Quote:
Originally Posted by boykillsworld View Post
When I try to use mencoder with ac3 I get Failed to open audio demuxer. I did the same when I put the ac3 in an avi container by itself.
It works for me with r32396. Which MEncoder version or package did you try?


But actually, I meant encoding everything with MEncoder, which should work with pretty much any version:

Code:
mencoder -ovc lavc -oac lavc -channels 6 -lavdopts threads=8
-lavcopts vcodec=mpeg4:vqscale=3:vrc_maxrate=25000:vrc_buf_size=5000:acodec=ac3:abitrate=640 input.mkv -o out.avi
For fast H.264 decoding, get a MEncoder binary that has been linked against ffmpeg-mt.

Quote:
now just have to figure out how to hard code forced PGS subtitles and I should be off to the races with all my movies
With Mencoder: -slang eng -vf expand=::::1

If language selection fails, try with -demuxer lavf or use -sid SID (where SID is a numerical ID printed by mplayer -v). You'll need a recent MEncoder version since PGS support was added last summer.

Last edited by nm; 16th November 2010 at 12:30.
nm is offline   Reply With Quote
Old 19th November 2010, 02:05   #7  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
Running MEncoder SVN-r29978-4.4.1

Doing it in one step with mencoder resulted in no sound with stuttering video in xbmc didn't even bother with 360. I'm running ElementOS on my HTPC which is based off Ubuntu 9.10. I could not locate a more updated SVN on a PPA and compiling from scratch is a pain that I haven't experienced since Fedora 5. I'm going to stick with the couple extra commands.
boykillsworld is offline   Reply With Quote
Old 19th November 2010, 12:28   #8  |  Link
nm
Registered User
 
Join Date: Mar 2005
Location: Finland
Posts: 2,643
Quote:
Originally Posted by boykillsworld View Post
Running MEncoder SVN-r29978-4.4.1
[...]
I could not locate a more updated SVN on a PPA and compiling from scratch is a pain that I haven't experienced since Fedora 5
Compiling MPlayer/MEncoder is pretty easy:

Code:
sudo apt-get remove mplayer mencoder
sudo apt-get install subversion
sudo apt-get build-dep mplayer

svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd mplayer
./configure
make
sudo make install
Quote:
I'm going to stick with the couple extra commands.
You'll need MEncoder for hardcoding the subtitles even if you end up encoding audio separately.
nm is offline   Reply With Quote
Old 21st November 2010, 14:47   #9  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
Same result with latest svn video stuttered and audio didn't work. The weird parts is if I play the clip as it is encoding the sound works fine. Anything I can run it through to analyze it.
boykillsworld is offline   Reply With Quote
Old 21st November 2010, 15:10   #10  |  Link
nm
Registered User
 
Join Date: Mar 2005
Location: Finland
Posts: 2,643
Quote:
Originally Posted by boykillsworld View Post
Same result with latest svn video stuttered and audio didn't work. The weird parts is if I play the clip as it is encoding the sound works fine.
Maybe it's an incompatibility between libavcodec's AC-3 encoder and MEncoder's AVI muxer. Try muxing with libavformat: -of lavf -lavfopts format=avi

What happens if you remux the output AVI with MEncoder like you did with the Avidemux output?

Quote:
Anything I can run it through to analyze it.
Avinaptic might tell something if you compare to a good stream.
nm is offline   Reply With Quote
Old 21st November 2010, 20:41   #11  |  Link
setarip_old
Registered User
 
setarip_old's Avatar
 
Join Date: Aug 2005
Posts: 16,270
@boykillsworld

Hi!

(If you can work in Windows) Have you tried "multiAVCHD"?
setarip_old is offline   Reply With Quote
Old 25th November 2010, 01:26   #12  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
Ok for subtitles this is what I did

first encode with mencoder and select sid for subs
step 1

Code:
mencoder -ffourcc XVID -slang eng -ovc lavc -of lavf -lavfopts format=avi -oac lavc -channels 6 -lavdopts threads=8 -lavcopts 
vcodec=mpeg4:vqscale=1:vrc_maxrate=25000:vrc_buf_size=5000:acodec=ac3:abitrate=640 -sid SID movie.mkv -o movie.avi
I found for some movies I didn't need subs so I turned them off with the -forcedsubsonly
step 1 alt

Code:
mencoder -ffourcc XVID -forcedsubsonly -ovc lavc -of lavf -lavfopts format=avi -oac lavc -channels 6 -lavdopts threads=8 -lavcopts 
vcodec=mpeg4:vqscale=1:vrc_maxrate=25000:vrc_buf_size=5000:acodec=ac3:abitrate=640 movie.mkv -o movietmp.avi
step 2
Audio is out of sink and this is fixed with avidemux
Code:
avidemux --load movietmp.avi --save movietmp2.avi
step 3
Everything works fine except for some reason you can't fastforword with the 360 so
Code:
mencoder -ovc copy -oac copy -mc 0 -noskip  -o movie.avi movietmp2.avi
I goofed with trying different options on small chunks of movies to fix the audio sync but even when I got it to work in a segment it always messed up when I did the entire movie. Really don't know what that means but I have this and it does work. I choose to go with lavf because if not auido is completely broken but this is also fixed with avidemux.

Another thing I find strange is that mencoder and ffmpeg seem to be limited to 100% cpu usage but I have 4 cpus so it could use 400%. The 100% seems spread across the processors with the 8 threads but it would be nice to increase the encoding speed.

Last edited by boykillsworld; 22nd December 2010 at 04:24.
boykillsworld is offline   Reply With Quote
Old 25th November 2010, 11:15   #13  |  Link
nm
Registered User
 
Join Date: Mar 2005
Location: Finland
Posts: 2,643
Quote:
Originally Posted by boykillsworld View Post
Another thing I find strange is that mencoder and ffmpeg seem to be limited to 100% cpu usage but I have 4 cpus so it could use 400%. The 100% seems spread across the processors with the 8 threads but it would be nice to increase the encoding speed.
You need to link MEncoder against ffmpeg-mt instead of ffmpeg for fast H.264 decoding. Adding threads to MPEG-4 ASP encoding (-lavcopts threads=4:...) might also help a bit.

Edit: simple instructions to build MPlayer/MEncoder SVN with ffmpeg-mt git.

Code:
sudo apt-get remove mplayer mencoder
sudo apt-get install subversion git
sudo apt-get build-dep mplayer

# Get MPlayer
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

cd mplayer

# Get ffmpeg-mt:
git clone git://gitorious.org/~astrange/ffmpeg/ffmpeg-mt.git

# Copy libswscale to ffmpeg-mt
cp -a ffmpeg/libswscale ffmpeg-mt/

# Replace ffmpeg by ffmpeg-mt
mv ffmpeg ffmpeg.orig
mv ffmpeg-mt ffmpeg

# Build MPlayer and MEncoder
./configure
make

# Install
sudo make install

Last edited by nm; 25th November 2010 at 14:03.
nm is offline   Reply With Quote
Old 27th November 2010, 02:10   #14  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
Compiled and installed fine but got a floating point exception when trying to use this with ffmpeg-mt so went back to standard ffmpeg. Adding threads worked ok though got me to 120% cpu usage and 18.5 fps. Its not so bad though as I encode 3 at once doing this at night.

Thanks for your help nm.
boykillsworld is offline   Reply With Quote
Old 21st December 2010, 07:45   #15  |  Link
Andevellicus
Registered User
 
Join Date: Dec 2010
Posts: 2
boykillsworld,

First of all, great work. I found your guide extremely useful. A buddy of mine and I came up with this script to sort of automate the process:


Code:
#!/bin/bash
# Used for transcoding files.
# Arguments should be as follows:
# $0            -i  [required]   -o <optional>   $3 <optional>
# transcode.sh  original file    new file name   mencoder flags
# Any deviation from the above shold report an error.

cleanUp() {
   if [[ -f ${oFileTmp} || -f ${nFileTmp} ]]; then
       rm ${oFileTmp} ${nFileTmp} > /dev/null 2>&1
   fi;
}

usage() {
    echo "Usage: transcode -i INFILE -o <NewFileName> <Additional MEncoder Parameters>..."
}

nFile=""
nFileTmp="nTmp.avi"
oFile=""
oFileTmp="oTmp.avi"
mencoderParameters=""
decodeParameters="\
    -ffourcc XVID \
    -forcedsubsonly \
    -subfont-text-scale 2 \
    -ovc lavc \
    -of lavf \
    -lavfopts format=avi \
    -oac lavc \
    -channels 6 \
    -ofps 23.976 \
    -lavcopts vcodec=mpeg4:vqscale=1:vrc_maxrate=15000:vrc_buf_size=5000:acodec=ac3:abitrate=640:threads=6:cmp=2:subcmp=2:trell=yes:v4mv=yes:mbd=2 \
    "

encodeParameters="\
    -ovc copy \
    -oac copy \
    -mc 0 \
    -noskip \
    "

# Ensure proper usage
if [ $# -lt 1 ]; then
    usage
    exit 1
fi

# Parsing command line parameters.
# -o specifies the name of the output file, other mencoder flags
# are parsed and passed to mencoder.
until [ -z "$1" ] ; do
    case "$1" in
        -o)
            oFile="$2"
            oFile=${oFile%.avi}
            shift
            ;;
        -i)
            nFile="$2"
            shift
            ;;
        -*)
            if [ "$2" = "-*" ]; then
                mencoderParameters="$mencoderParameters $1"
            else
                mencoderParameters="$mencoderParameters $1 $2"
                shift
            fi
            ;;
        *)
             echo "Unrecognized option: $1"
             usage
             exit 1
            ;;
    esac
    shift
done


# Run some sanity checks.
# Make sure we managed to get an input file.
if [ -z "$nFile" ]; then
    echo "No input file specified."
    usage
    exit 1
fi

# Make sure the file exists.
if [ ! -f "$nFile" ]; then
    echo "Input file \"$nFile\" does not exist."
    usage
    exit 1
fi

# If no outfile was specified, use the infile
if [ -z $oFile ]; then
    oFile=${nFile}
fi

# Make it so we don't have a .mkv.avi filename.
oFile=${oFile%.???}

echo "Infile: $nFile"
echo "Outfile: $oFile.avi"
echo "MEncoder params: $mencoderParameters"

# Do preliminary clean-up, can't hurt (in case things are left
# sitting around from the last run...
cleanUp

# Note the use of && between commands to ensure execution completion
# before moving on to the next command.  While all of these must
# complete sequentially, error checking isn't done between steps
# at this time.  It's just assumed you have permissions and space.

echo "The following commands will be invoked:"
echo - mencoder "${nFile}" ${decodeParameters} ${mencoderParameters} -o ${nFileTmp} &&
echo - avidemux2_cli --load ${nFileTmp} --save ${oFileTmp} &&
echo - mencoder ${encodeParameters} -o "${oFile}.avi" ${oFileTmp}

mencoder "${nFile}" ${decodeParameters} ${mencoderParameters} -o ${nFileTmp} &&
avidemux2_cli --load ${nFileTmp} --save ${oFileTmp} &&
mencoder ${encodeParameters} -o "${oFile}.avi" ${oFileTmp}

if [ $? -ne 0 ]; then
    echo "Conversation failed between mencoders & avidemux."
    exit 1
fi

# Clean-up and exit.
cleanUp
exit 0
Just one comment - I haven't had much success with vrc_maxrate=25000 and vrc_buf_size=5000, my box stutters on a few complex scenes, so I had to tone it down to vrc_maxrate=15000 and vrc_buf_size=5000 - it seems mine can handle up to roughly 20MBits/s, not more.

Since I'm running a wireless network at home, I don't have the luxury of streaming over the network. I dump the files onto a 2TB external USB harddrive that I've formatted with HFS+ (I love the irony of having a Mac OS filesystem hooked up to a Microsoft device) - this way I'm able to dump files >4 GB on it and the Xbox plays nice.

Anyway, much appreciate the time and effort you put into figuring this stuff out.

~ A

Last edited by Andevellicus; 21st December 2010 at 07:56.
Andevellicus is offline   Reply With Quote
Old 22nd December 2010, 04:17   #16  |  Link
boykillsworld
Registered User
 
Join Date: Aug 2010
Posts: 15
I'm glad someone got some use out of this.

I go through a month of trying to figure out how to do this and converted 10 movies. Then the new Call of Duty comes out and I RROD my Xbox. Granted I purchased it broken for $75 then X-clamp fixed it with Arctic Silver and got two years out of it. Guess that isn't bad for an Xbox from 2006. I'll see if I can bring it back to life during my Christmas vacation.

I guess I'm not surprised if you had to rate limit it further. My original clips were previously compressed with handbrake which may have smoothed it out some. Your limit may be the result of a slow external drive also. I believe 100 mb/s ethernet is actually slower than usb 2.0, however, I think Microsofts implementation of HPS+ may be piss poor. Although, I do not know how you would ever prove this.

I have a script similar to this for converting blu-ray. It grabs the largest video track then sends that through handbrake as a high profile mkv and muxes in all English audo and subtitles. I launch it from the record button on my remote control and it takes like 8 hours.

Last edited by boykillsworld; 22nd December 2010 at 04:36.
boykillsworld is offline   Reply With Quote
Old 4th January 2011, 23:31   #17  |  Link
Andevellicus
Registered User
 
Join Date: Dec 2010
Posts: 2
Few more notes: Apparently the Xbox has some issues with ODML and improper indexing which can cause momentary stuttering as well as an inability to skip back after a certain point in the movie. Long story short, the work around is to include -noodml in the mencoder flags, and then to rebuild the ODML index explicity. Thus here are the commands that I issue:

This decodes the video sans ODML:
Code:
mencoder "${nFile}" \
    -noodml \
    -ffourcc XVID \
    -subfont-text-scale 3 \
    -ovc lavc \
    -of lavf \
    -lavfopts format=avi \
    -lavcopts vcodec=mpeg4:vqscale=1:vrc_maxrate=15000:vrc_buf_size=5000:acodec=ac3:abitrate=640:threads=8:cmp=2:subcmp=2:trell=yes:v4mv=yes:mbd=2
    -oac lavc \
    -channels 6 \
    -ofps 23.976 \
    -o ${iFileTmp}

Explicitly rebuild the ODML index using the -idx option:
Code:
mencoder ${iFileTmp} \
    -ovc copy \
    -oac copy \
    -mc 0 \
    -noskip \
    -idx -o ${nFileTmp}

Fix A/V sync:
Code:
avidemux2_cli --load ${nFileTmp} --save ${oFileTmp}

Ensure fast forwarding and rewinding:
Code:
mencoder \
    -ovc copy \
    -oac copy \
    -mc 0 \
    -noskip \
    -o "${oFile}.avi" ${oFileTmp}

Replace ${nFile}, ${iFileTmp}, ${nFileTmp}, ${oFileTmp}, and ${oFile} with actual file names. Some of this is redundant (for instance I haven't bothered to see if instead of doing two mencoder copies I can just rebuild the index in the last step, but this works for me.

Thanks again for all the help.

~ A
Andevellicus is offline   Reply With Quote
Reply

Tags
360, mkv, xbox, xvid. linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:38.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.