dslreports logo
 
    All Forums Hot Topics Gallery
spc
Search similar:


uniqs
64532

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

1 edit

pflog

MVM

[SOLVED] ffmpeg mkv to xvid/ac3

The xbox 360 now supports divx and xvid, and I'm trying to convert transcode a Matroska (h.264/ac3) file to avi (xvid(mpeg4-part2)/ac3), and I'm having problems with the audio and video being out of sync. Playback on the xbox 360 has the video running at what looks like 2x/3x fast forward.

Here's the command line I'm using:

ffmpeg -i test.mkv -vcodec mpeg4 -vtag XVID -acodec copy test.avi

If I try to copy it over and play it back on my windows laptop with ffdshow installed, I get a message from "AVI Chunk Viewer" stating:
quote:
This AVI file was not prepared for sequential reading, the alternative 'Avi Splitter' will now let the default one handle it. The complete reinterleaving of this file is strongly recommended before burning it onto a slow media like cd-rom.
If I use -acodec libmp3lame, that is:

ffmpeg -i test.mkv -vcodec mpeg4 -vtag XVID -acodec libmp3lame -ac 2 -ab 192k test.avi

It plays back on the xbox 360 and my laptop just fine.

Prior to xvid/divx support, I was using h.264/aac MOV files, but that is limited to 2-channel aac audio. I was hoping to use the avi container with xvid so that I can use the 5.1 ac3 audio in the original file.

Anyone know why the audio and video are out of sync when I use -acodec copy? If I use -acodec ac3 -ab 384k, I have the same problem (normal sound, fast forward video).

mwc
Premium Member
join:2005-04-11
Waterloo, ON

mwc

Premium Member

Re: ffmpeg mkv to xvid/ac3

Doesn't the 360 support H.264 video? Why not leave it in that format. Also, the .MOV format is the basis for the .mp4 container. It's a pretty solid container, and seems to be supported on your 360. It should have no trouble containing an AC3 stream.

On the other hand, AVI is a contender for worst container being used today. Next time you mux something into an AVI container using ffmpeg, check out the multiplexing overhead that's reported.

If possible, try putting your AC3 audio stream into an mp4 container, assuming your 360 can handle that. The format can.

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

That's the problem, the 360 only supports 2-channel AAC in the MOV container.
ghost16825
Use security metrics
Premium Member
join:2003-08-26

ghost16825 to pflog

Premium Member

to pflog
Try mkvextract-ing both video and audio and then mixing both the audio and video together into xvid with ffmpeg, but don't use -acodec/vcodec copy in the process.

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

said by ghost16825:

Try mkvextract-ing both video and audio and then mixing both the audio and video together into xvid with ffmpeg, but don't use -acodec/vcodec copy in the process.
Thanks for the suggestion, I'll give that a shot! So basically, mkvextract to .h264 and .ac3, then use ffmpeg and -map to bring them together into an avi/xvid container? Should I try transcoding the h264 to mpeg4/xvid before I mux them?
pflog

pflog to ghost16825

MVM

to ghost16825
I tried:

ffmpeg -i test.h264 -i test.ac3 -map 0.0 -map 1.0 -vcodec mpeg4 -vtag xvid -acodec ac3 -ab 384k -ac 6 test.avi

But it just hangs (gets like 2 frames in) and I have to ctrl-z it and kill it (ctrl-c doesn't work, 'q' doesn't work). :/
pflog

pflog to ghost16825

MVM

to ghost16825
Same problem with the resulting video:

- split to .h264 / . ac3
- ffmpeg -i ... -map ... -vtag xvid

I'm going to try using an mp4 container with xvid video and ac3 audio (if that's possible).
pflog

pflog to ghost16825

MVM

to ghost16825
Ok this mencoder command produces an xvid AVI with ac3 that works on the xbox 360:

mencoder test.mkv -ovc xvid -xvidencopts bitrate=3000 -oac copy -o test2.avi

However, it's slow as hell. Like 5 fps...this is on a quad core Q6600. I don't think xvid supports threads, either.

This definitely smells like an ffmpeg avi muxing problem.
pflog

pflog

MVM

Ok I have a workaround for this, which is fast:

step 1:

mencoder test.mkv -ovc lavc -lavcopts vcodec=mpeg4:threads=8:vbitrate=3000 -oac copy -o test.avi
ffmpeg -i test.avi -vcodec copy -vtag xvid -acodec copy final.avi

So basically use mencoder to encode to mpeg4/ac3, then use ffmpeg to tag it xvid so the xbox 360 is happy.

DeHackEd
Bill Ate Tux's Rocket
join:2000-12-07

DeHackEd

Member

mencoder -ffourcc xvid ....

As for speed, xvid defaults to some decent quality settings at the expense of encoding speed. Check the manual page for what tweakables are available.

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

Thanks, just found that as well, which avoids the ffmpeg step.

Unfortunately, I can't do this in one step with mencoder with the mkv as input, because a little ways in, I get:
quote:
Too many audio packets in the buffer: (4100 in 10496000 bytes). Maybe you are playing a non-interleaved stream/file or the codec failed? For AVI files, try to force non-interleaved mode with the -ni option.
This is when I have -oac copy. I'm trying now with -oac lavc -lavcopts codec=ac3, so far so good.
pflog

1 edit

1 recommendation

pflog

MVM

Re: [SOLVED] ffmpeg mkv to xvid/ac3

For archive purposes and for anyone else wanting to convert an mkv file to an avi that will play back on the xbox 360, here is what I found works:

bash code:
mencoder $input -ffourcc XVID -ovc lavc -lavcopts vcodec=mpeg4:threads=8:vbitrate=$vbitrate:cmp=2:subcmp=2:trell=yes:v4mv=yes:mbd=2 -oac lavc -lavcopts acodec=ac3:abitrate=384 -channels 6 -o $output

These options are for a higher quality video, so if you want about 50% faster processing time, you can remove:

cmp=2:subcmp=2:trell=yes:v4mv=yes:mbd=2

LilYoda
Feline with squirel personality disorder
Premium Member
join:2004-09-02
Mountains

LilYoda to pflog

Premium Member

to pflog
I know I'm coming late in the thread, but there is also a small tool to change the ffourcc in an avi file. I think it's called "cfourcc"

dawguk
@net-serv.co.uk

dawguk to pflog

Anon

to pflog
Hi,

I have used your mencoder command on a number of my .mkv files, and my Xbox 360 doesn't appear to want to play them still (in fact, it purely refuses to acknowledge their existence). Yes, I also have the latest live patch.

I thought that perhaps it was a filename issue (changed from .avi to .mov), and this allowed the 360 to acknowledge the files, but still wouldn't play them.

I am using your command exactly, and sharing the files using ushare, apparently with no luck. I'm sorry to ask this again, but can you 100% confirm that these new files work on your 360? If not, I suspect something may be up with my console, and I'll try again.

Thanks for any help,
D

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

1 recommendation

pflog

MVM

I did have a problem with a very large mkv file. For shits and giggles, I downloaded an mkv rip of a bluray movie and waited the 1-2 hours for it to transcode. It would not play it back. However, if I interrupted the transcode towards the beginning, it would play. Just a warning there.

As to your problem, it's actually a problem with ushare or rather what it advertises the mime-type for .avi. You'll need to recompile ushare manually, but what you want to do is change the following line:

  { "avi",  UPNP_VIDEO, "http-get:*:video/x-msvideo:"},
 

to:

  { "avi",   UPNP_VIDEO, "http-get:*:video/x-ms-wmv:"},
 

This will trick the 360 into seeing the .avi files. The default mime setting in ushare is more generic and doesn't play nice with the 360.
gentux
join:2004-09-05
Natick, MA

gentux to mwc

Member

to mwc

Re: ffmpeg mkv to xvid/ac3

said by mwc:

If possible, try putting your AC3 audio stream into an mp4 container, assuming your 360 can handle that. The format can.
mp4 does not support ac3 audio

LilYoda
Feline with squirel personality disorder
Premium Member
join:2004-09-02
Mountains

LilYoda

Premium Member

You sure? I saw a bunch of divx and xvid files with ac3 audio...

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

said by LilYoda:

You sure? I saw a bunch of divx and xvid files with ac3 audio...
xvid and divx are typically in an AVI container...
gentux
join:2004-09-05
Natick, MA

gentux to pflog

Member

to pflog
said by pflog:

However, it's slow as hell. Like 5 fps...this is on a quad core Q6600. I don't think xvid supports threads, either.
Xvid does support threads, however last I checked it was only available in the svn version of xvid. To enable it in mplayer you need to compile xvid from svn and then mplayer.

dawguk
@as15444.net

dawguk to pflog

Anon

to pflog

Re: [SOLVED] ffmpeg mkv to xvid/ac3

@devlin - many thanks INDEED for your help with this.

I was quietly tearing my hair out, because mplayer said it was just fine, encoded absolutely correctly, etc.

I'm just off now to get and recompile ushare - I'm currently running a Yum copy - so cross fingers! I'll report back on progress, and much praising.

Thanks again,
D
dawguk
join:2007-12-11
united kingd

1 recommendation

dawguk to pflog

Member

to pflog
OK, so I've decided to register, because I guess it's the right thing to do :)

I've just grabbed the latest version of ushare from the geexbox mercurial, and taken a look at the mime.c file before making it.

The mime type entry in there for avi files is currently as follows:

{ "avi",   UPNP_VIDEO, "http-get:*:video/avi:"}
 

and the entry for wmv files is:

{ "wmv",   UPNP_VIDEO, "http-get:*:video/x-ms-wmv:"}
 

Would this indicate to you that this latest version (1.1a) has already "fixed" this mime type, or would this still need changing?

Sorry for my complete misunderstanding of mime types!

Cheers,
D

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

You still want to change the "avi" line to video/x-ms-wmv. I know it seems weird registering an avi as a wmv, but that's the trick to making the 360 see the files
pflog

pflog to dawguk

MVM

to dawguk
Oh, and welcome to DSLR and ATU!
dawguk
join:2007-12-11
united kingd

dawguk

Member

Okey dokey, thanks for confirmation (and so swiftly!), and the warm welcome
dawguk

dawguk to pflog

Member

to pflog
OK, so after figuring out that my version of glibc-devel was a bit ropey, I eventually got to build my modified version of ushare. Worked a treat, and I can now see all of my avi files on my X360, so thanks heaps for that! However ...

... I've written a script that recurses through directories and mencodes all of my mkv video files to avi. At time of writing, I had mencoded ten complete files, and tested them all. The first one worked on the Xbox, but all subsequent ones didn't, even though I'm using exactly the same encoding method. (by the way, everything plays just fine in mplayer)

I've taken the working file and a non-working file and played the two files with mplayer, written the output to log files, and done a diff on them, the output of which is as follows:

1c1
 
< Playing 01.pixar.the.adventures.of.andre.and.wally.b.1984.x264-esir.mass360-mkv.avi.
---
> Playing 02.pixar.luxo.jr.1986.x264-esir.mass360-mkv.avi.
5c5
< VIDEO:  [DX50]  980x720  24bpp  23.976 fps  2854.9 kbps (348.5 kbyte/s)
---
> VIDEO:  [DX50]  1180x720  24bpp  23.976 fps  2360.1 kbps (288.1 kbyte/s)
21c21
<  VDec: vo config request - 980 x 720 (preferred colorspace: Planar YV12)
---
>  VDec: vo config request - 1180 x 720 (preferred colorspace: Planar YV12)
23,25c23,26
<  Movie-Aspect is 1.36:1 - prescaling to correct movie aspect.
<  VO: [xv] 980x720 => 980x720 Planar YV12 
<  A:1474.3 V:   0.8 A-V:1473.529 ct:  0.075  19/ 19 14% 11%  0.4% 2 0
---
>  Movie-Aspect is 1.64:1 - prescaling to correct movie aspect.
>  VO: [xv] 1180x720 => 1180x720 Planar YV12 
>  A:3047.1 V:   1.9 A-V:3045.257 ct:  0.188  46/ 46 11%  0%  0.6% 1 0
 

The adventure's of wally works, bt the luxo jr doesn't (Xbox reports it as incompatible video file). The only real difference that I can tell, is that the ones that don't work have higher resolutions.

Any ideas what might be happening here?

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

Hmm the only files I've not had luck in playing were very large mkv files from HD-DVD or Bluray rips. These the xbox just reports as an invalid file or "cannot play back this file". I haven't narrowed it down to whether it's a size thing or perhaps it's too high a bitrate.

The bitrate of the one you're unable to play isn't higher than the other (in fact, it's lower!) so I don't think that's it.

It's kind of a trial and error game with the 360, I've found.

One thing I have noticed is that occasionally, the xbox will start telling me files aren't playable/etc, but a reboot of the 360 fixes that. I am guessing you've tried that though?
ZildjianKX
join:2004-08-23
Palo Alto, CA

ZildjianKX to pflog

Member

to pflog
Wow, thanks man. I was looking for a way to do this for my PS3, keeping the AC3 audio track intact, worked perfectly! Quick question, is it normal to have a little bit of pixilation when converting it to the xvid? I used the best quality setting you recommended, but still see a bit of pixilation that wasn't in the original MKV at times. Thanks!

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog

MVM

You might want to try a higher video bitrate (-b). H.264 compression is much better than regular MPEG4 (which is essentially what xvid is). Try bumping the bitrate up 1000k or so, and see if that helps!

edwardandtubs to pflog

Anon

to pflog
Hi,
I've tried converting a couple of mkv's using the command line
mencoder $input -ffourcc XVID -ovc lavc -lavcopts vcodec=mpeg4:threads=8:vbitrate=$vbitrate:cmp=2:subcmp=2:trell=yes:v4mv=yes:mbd=2 -oac lavc -lavcopts acodec=ac3:abitrate=384 -channels 6 -o $output
 

and whilst it converts the mkv to avi successfully, it turns out that the centre audio channel ends up in the rear-right channel

has anyone else had this problem, is there a solution....I really want to watch my HD's with 5.1

habrys
@netcologne.de

habrys

Anon

I've had the same problem with mixed up 5.1 ac3 channels and found a workaround for this somewhere else. Following additional switch to the audio encoding section does the trick: -af channels=6:6:0:0:4:1:1:2:2:3:3:4:5:5

So the original command would look like that:
mencoder $input -ffourcc XVID -ovc lavc -lavcopts vcodec=mpeg4:threads=8:vbitrate=$bitrate:cmp=2:subcmp=2:trell=yes:v4mv=yes:mbd=2 -oac lavc -lavcopts acodec=ac3:abitrate=384 -channels 6 -af channels=6:6:0:0:4:1:1:2:2:3:3:4:5:5 -o $output