LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Mencoder AC3 problems (https://www.linuxquestions.org/questions/linux-software-2/mencoder-ac3-problems-774445/)

magoot 12-09-2009 03:57 AM

Mencoder AC3 problems
 
Hello!

I'm trying to convert a bunch of matroska-files to avi (to be able to watch them on my xbox 360). However i can't get ac3-audio to work with mencoder, it always ends up being out of sync and behaving really wierd.

Here is an example file i have been playing with:
Code:

[maggot@~/video] ffmpeg -i testfile.mkv
FFmpeg version SVN-r20428, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  built on Nov  1 2009 10:39:45 with gcc 4.3.4
  configuration: --prefix=/usr --extra-cflags='-Wall -g ' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libtheora --enable-libdc1394 --enable-libspeex --enable-nonfree --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger --enable-avfilter-lavf --enable-libopenjpeg --enable-version3 --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
  libavutil    50. 3. 0 / 50. 3. 0
  libavcodec    52.37. 1 / 52.37. 1
  libavformat  52.39. 2 / 52.39. 2
  libavdevice  52. 2. 0 / 52. 2. 0
  libavfilter    1. 6. 0 /  1. 6. 0
  libswscale    0. 7. 1 /  0. 7. 1
  libpostproc  51. 2. 0 / 51. 2. 0

Seems stream 0 codec frame rate differs from container frame rate: 47.95 (48000/1001) -> 24.00 (24/1)
Input #0, matroska, from 'testfile.mkv':
  Duration: 00:21:27.16, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: h264, yuv420p, 624x352, PAR 1:1 DAR 39:22, 24 tbr, 1k tbn, 47.95 tbc
    Stream #0.1: Audio: aac, 24000 Hz, stereo, s16
At least one output file must be specified
[maggot@~/video]

Then i try to convert it with the following command:
Code:

[maggot@~/video] mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=10000 -oac lavc -lavcopts acodec=ac3:abitrate=640  -channels 2 testfile.mkv -o testfile.avi

MPlayer SVN-r29809 (C) 2000-2009 MPlayer Team
success: format: 0  data: 0x0 - 0x3bb1218
[mkv] Track ID 1: video (V_MPEG4/ISO/AVC), -vid 0
[mkv] Track ID 2: audio (A_AAC), -aid 0, -alang und
[mkv] Will play video track 1.
Matroska file format detected.
VIDEO:  [avc1]  624x352  24bpp  23.976 fps    0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:31  fourcc:0x31637661  size:624x352  fps:23.976  ftime:=0.0417
==========================================================================
Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
FAAD: compressed input bitrate missing, assuming 128kbit/s!
AUDIO: 48000 Hz, 2 ch, s16le, 128.0 kbit/8.33% (ratio: 16000->192000)
Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 0
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
[ac3 @ 0x26e8220]No channel layout specified. The encoder will guess the layout, but it might be incorrect.
Pos:  0.0s      1f ( 0%)  0.00fps Trem:  0min  0mb  A-V:0.000 [0:0]
1 duplicate frame(s)!
Writing header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
Writing header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
Movie-Aspect is 1.77:1 - prescaling to correct movie aspect..004 [0:0]
videocodec: libavcodec (624x352 fourcc=34504d46 [FMP4])
Writing header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
Pos:  0.2s      5f ( 0%)  0.00fps Trem:  0min  0mb  A-V:0.017 [0:0]
1 duplicate frame(s)!
Pos:  3.6s    87f ( 0%)  0.00fps Trem:  4min 259mb  A-V:0.084 [771:640]
Skipping frame!
Pos:1286.4s  30843f (99%) 157.00fps Trem:  0min 362mb  A-V:0.033 [1717:640]
Flushing video frames.
Writing index...
Writing header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.

Video stream: 1717.222 kbit/s  (214652 B/s)  size: 276122581 bytes  1286.368 secs  30843 frames

Audio stream:  640.000 kbit/s  (80000 B/s)  size: 102950400 bytes  1286.880 secs

The result is an avi-file with completley out of sync audio... it starts off nicely and starts to get more and more out of sync. When i jump forward or back in mplayer, the video plays ok, but the audio starts from the beginning every time.

The command line in mplayer looks wierd too, the audio frame count is a lot higher than the video frame count, here is after a couple of seconds playing:
Code:

[maggot@~/video] mplayer testfile.avi
MPlayer SVN-r29809 (C) 2000-2009 MPlayer Team
Can't open joystick device /dev/input/js0: No such file or directory
Can't init input joystick
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing testfile.avi.
AVI file format detected.
[aviheader] Video stream found, -vid 0
[aviheader] Audio stream found, -aid 1
VIDEO:  [FMP4]  624x352  24bpp  23.976 fps  1717.2 kbps (209.6 kbyte/s)
Clip info:
 Software: MEncoder SVN-r29809
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
==========================================================================
==========================================================================
Opening audio decoder: [liba52] AC3 decoding with liba52
No accelerated IMDCT transform found
AUDIO: 48000 Hz, 2 ch, floatle, 640.0 kbit/20.83% (ratio: 80000->384000)
Selected audio codec: [a52] afm: liba52 (AC3-liba52)
==========================================================================
AO: [alsa] 48000Hz 2ch floatle (4 bytes per sample)
Starting playback...
Movie-Aspect is 1.77:1 - prescaling to correct movie aspect.
VO: [xv] 624x352 => 624x352 Planar YV12
A:8191.9 V:  3.5 A-V:8188.420 ct:  0.342  83/ 83  5%  0%  0.4% 0 0
Exiting... (Quit)

(Since this is a file with stereo audio, mp3 would probably work. The reason i want AC3 is because most of the files i try to convert have 5.1 sound, i use this file for testing only simply because it is small)

Anyone know why this is happening? I have tried a bunch of different files with mp3, vorbis, dts, ac3 and so on audio, same problem all the way... seems to be a problem with lavc/ac3 encoding audio?

Any help would be greatly appreciated.
Regards
MagooT

H_TeXMeX_H 12-09-2009 07:19 AM

I would use the most recent version of ffmpeg, and the '-async' option. I don't know of a way to stop a/v desync with mencoder :(

You could try with mencoder using '-oac copy', which would copy the original audio, that might work ... possibly. But if not...

Here's the commands I would run (2 pass):

Code:

ffmpeg -i input.mkv -vcodec libxvid -qscale 5 -s 624x352 -r 23.976 -aspect 39:22 -g 240 -bf 2 -acodec ac3 -ab 160k -ar 24000 -async 24000 -ac 2 -pass 1 -an -f rawvideo -y /dev/null

ffmpeg -i input.mkv -vcodec libxvid -qscale 5 -s 624x352 -r 23.976 -aspect 39:22 -g 240 -bf 2 -acodec ac3 -ab 160k -ar 24000 -async 24000 -ac 2 -pass 2 output.avi

Now, I don't know what a good bitrate would be, but I know for mp3 I always use 160k if you were using that. I would use mp3 over ac3 '-acodec libmp3lame'. If you want instead of '-qscale 5' you can just specify a constant bitrate with '-b 1000k' if you like. But, I prefer VBR for better quality and compression, and if you want better quality then just use a lower qscale. Also, if you don't have libxvid you can replace '-vcodec libxvid' with '-vcodec mpeg4 -vtag xvid' which will result in just about the same thing, maybe even better in some cases.

magoot 12-10-2009 04:53 AM

Thanks a lot, that seems to work really well. Have tried it on a couple of 1080p and 720p trailers, and after tweaking the parameters a bit i'm very pleased :)
-qscale 5 seems to produce a file only slightly larger than the input file, and the quality is pretty decent in my opinion, i tried -qscale 2 which produced a file 4 times as big as the input file, with about identical quality, i'm gonna keep playing a bit and see what i get.

A question about encoding generally, i tried:
-acodec ac3 -ab 640k -ar 48000 -async 48000
for the audio, which caused the audio to slowly go out of sync along the clip, it plays just a bit faster (or was it slower?) than the video.
Just out of curiosity, why is this? Is it a problem to encode audio with higher bitrate than the original audio track?

I don't know so much about these things, just learning as I go :)

H_TeXMeX_H 12-10-2009 05:43 AM

Well, I've only gotten slight a/v desync with ffmpeg if you don't use the original sampling frequency, for example I think it's 24000 in this case. The bitrate shouldn't matter as much, unless it's really really high. Anyway, I usually use mp3 with 160k or 128k (plus original sampling rate) and I have not noticed any a/v desync.

magoot 12-10-2009 02:17 PM

Ok, i tried lowering the bitrate to 192k and that worked for the particular file i was trying to convert.
However now i ran into another bump in the road when running the second pass on this file:
Code:

Seems stream 0 codec frame rate differs from container frame rate: 47.95 (27956/583) -> 23.98 (24000/1001)
Input #0, matroska, from 'xmen-besthd.mkv':
  Duration: 01:44:20.30, start: 0.000000, bitrate: N/A
    Stream #0.0(eng): Video: h264, yuv420p, 1280x544, PAR 1:1 DAR 40:17, 23.98 tbr, 1k tbn, 47.95 tbc
    Stream #0.1(eng): Audio: dca, 48000 Hz, 6 channels, s16
    Stream #0.2(eng): Subtitle: 0x0000
[ac3 @ 0x6c1900]No channel layout specified. The encoder will guess the layout, but it might be incorrect.
Output #0, avi, to 'xmen-besthd.avi':
    Stream #0.0(eng): Video: libxvid, yuv420p, 1280x544 [PAR 1:1 DAR 40:17], q=2-31, pass 2, 200 kb/s, 23.98 tbn, 23.98 tbc
    Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, s16, 192 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
Resampling with input channels greater than 2 unsupported.
Can not resample 6 channels @ 48000 Hz to 6 channels @ 48000 Hz

It seems 6 channels input just isn't supported at this time (running FFmpeg version SVN-r20428), and i can't get the latest svn version to compile...
Any way around this or do i have to wait until support is added? 5.1 would be nice to have.

H_TeXMeX_H 12-10-2009 02:35 PM

Well, I never tried 6 -> 6 channel. But I know that 6 -> 2 works fine. Still even this did not work until I got the latest version of ffmpeg, so before you couldn't even do 6 -> 2. Maybe they'll add support at some point. Have you tried different output audio codecs ?

magoot 12-10-2009 02:43 PM

I just updated to FFmpeg version SVN-r20787 from debian-multimedia.org's sid-repository. Started another run at the same file with 2 channels this time to see if that works... (6 channels didn't work, at least i couldn't run the second pass with this version either).

I have only tried AC3 and MP3 so far, my Xbox 360 seems a bit picky with the formats so i have just kept trying AC3 because i know that works... any suggestions on codecs that support 6 channels i could try out?

H_TeXMeX_H 12-11-2009 04:09 AM

I'm not sure, I don't have a sample video to try it out with.

I would say you might wanna try aften:
Code:

git clone git://aften.git.sourceforge.net/gitroot/aften/aften
http://parumi.wordpress.com/2007/12/...ideo-in-linux/

Don't worry, development is not dead, it's been updated just a few days ago. So I would try to dump the audio to something aften can convert, then mux the result back in with the video.

thealtenbach 07-29-2010 02:17 AM

So I use Divx web player quite a lot to watch videos and usually I have issues with either video or audio but sometimes no audio at all.

I think it's when I play videos with AC3 Support that I get no audio.

I have Perian installed, but their support page says the following:

"Please consider removing obsolete QuickTime Components: FFusion, Xvid Delegate, 3ivX, DivX, DivX Decoder, XviD, msmpeg4v1, msmpeg4v2, AviImporter, EX_M4S2, Casio AVI Importer, AC3 Codec, and MatroskaQT.
Now, in my QT folder (library/quicktime/) I used to have an AC3 filter file, which I deleted, nothing happened. The only file in there is Perian.component"

Is there somewhere else I should look or is that not the issue?

Please help


All times are GMT -5. The time now is 06:38 PM.