PDA

View Full Version : HowTo muxliplex m4v video (Xvid) + 5.1 ac3 audio with ffmpeg properly?


Selur
11th December 2010, 12:03
I did the following:
1. Extract ac3 audio:
mplayer -v -mc 0 -vc dummy -nocorrect-pts -aid 128 dvd://1 -dvd-device "D:\ElephantsDream\VIDEO_TS" -chapter 1-1 -dumpaudio -dumpfile "D:\Encoding Output\audio.ac3"
2. Xvid 1stPass:
mencoder -dvd-device "D:\ElephantsDream\VIDEO_TS" dvd://1 -chapter 1-1 -noskip -vc mpeg12 -vf scale,format=i420 -forcedsubsonly -noautosub -nosound -mc 0 -lavdopts threads=8 -fps 25 -aspect 1.7775:1 -ovc xvid -xvidencopts pass=1:bitrate=8776:turbo:profile=unrestricted:me_quality=6:min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31:max_key_interval=250:quant_type=h263:max_bframes=2:bquant_ratio=150:bquant_offset=100:bf_threshold=0:vhq=2:bvhq=1:curve_compression_high=0:curve_compression_low=0:overflow_control_strength=10:max_overflow_improvement=10:max_overflow_degradation=10:trellis:noqpel:nogmc:nocartoon:chroma_opt:chroma_me:nointerlacing:keyframe_boost=10:kfthreshold=1:kfreduction=20:par=ext:par_width=16:par_height=11:closed_gop:nopacked:threads=0 -passlogfile "D:\Encoding Output\StatFile.stats" -o NUL
3. Xvid 2nd Pass:
mencoder -dvd-device "D:\ElephantsDream\VIDEO_TS" dvd://1 -chapter 1-1 -noskip -vc mpeg12 -vf scale,format=i420 -forcedsubsonly -noautosub -nosound -mc 0 -lavdopts threads=8 -fps 25 -aspect 1.7775:1 -ovc xvid -xvidencopts pass=2:bitrate=8776:profile=unrestricted:me_quality=6:min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31:max_key_interval=250:quant_type=h263:max_bframes=2:bquant_ratio=150:bquant_offset=100:bf_threshold=0:vhq=2:bvhq=1:curve_compression_high=0:curve_compression_low=0:overflow_control_strength=10:max_overflow_improvement=10:max_overflow_degradation=10:trellis:noqpel:nogmc:nocartoon:chroma_opt:chroma_me:nointerlacing:keyframe_boost=10:kfthreshold=1:kfreduction=20:par=ext:par_width=16:par_height=11:closed_gop:nopacked:threads=0 -passlogfile "D:\Encoding Output\StatFile.stats" -of rawvideo -o "D:\Encoding Output\video.m4v"
4. delete "D:\Encoding Output\StatFile.stats" Datei

Here comes the problem.

5. Audio&Video multiplexing:
ffmpeg -y -i "D:\Encoding Output\video.m4v" -i "D:\Encoding Output\audio.ac3" -vcodec copy -acodec copy -map 0:0 -map 1:0 "D:\Encoding Output\test.avi"
or
ffmpeg -y -i "D:\Encoding Output\video.m4v" -i "D:\Encoding Output\audio.ac3" -vcodec copy -acodec copy "D:\Encoding Output\test.avi"
-> Audio seems to be broken and File length equals audio + video length; video plays fine

Since the audio plays fine and mediainfo "D:\Encoding Output\audio.ac3" doesn't show any problems:
General
Complete name : D:\Encoding Output\audio.ac3
Format : AC-3
Format/Info : Audio Coding 3
File size : 1.41 MiB
Duration : 26s 368ms
Overall bit rate : 448 Kbps

Audio
Format : AC-3
Format/Info : Audio Coding 3
Mode extension : CM (complete main)
Duration : 26s 368ms
Bit rate mode : Constant
Bit rate : 448 Kbps
Channel(s) : 6 channels
Channel positions : Front: L C R, Side: L R, LFE
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 1.41 MiB (100%) I assume, the audio is okay and the problem lies with the muxing call.

Seems like ffmpeg chooses a wrong audio codec id during muxing:
MediaInfo.exe "d:\Encoding Output\test.avi"
General
Complete name : d:\Encoding Output\test.avi
Format : AVI
Format/Info : Audio Video Interleave
File size : 13.3 MiB
Duration : 26s 520ms
Overall bit rate : 4 192 Kbps
Writing application : Lavf52.87.1

Video
ID : 0
Format : MPEG-4 Visual
Format profile : Advanced Simple@L5
Format settings, BVOP : Yes
Format settings, QPel : No
Format settings, GMC : No warppoints
Format settings, Matrix : Default (H.263)
Codec ID : FMP4
Duration : 26s 520ms
Bit rate : 3 732 Kbps
Width : 720 pixels
Height : 576 pixels
Display aspect ratio : 16:9
Frame rate : 25.000 fps
Standard : PAL
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.360
Stream size : 11.8 MiB (89%)
Writing library : XviD 1.2.1 (UTC 2008-12-04)

Audio
ID : 1
Format : AC-3
Format/Info : Audio Coding 3
Codec ID : 00001000-0000-0020-8000-00AA00389B71]
Duration : 26s 400ms
Bit rate : 448 Kbps
Channel(s) : 6 channels
Channel positions : Front: L C R, Side: L R, LFE
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 1.41 MiB (11%)
Interleave, duration : 32 ms (0.80 video frame)

For reproduction I uploaded (http://selur.bplaced.net/test.zip) (ca. 13MB) the video.m4v and audio.ac3.

Does anyone know if this is a ffmpeg bug, if my muxing call is broken or if I went wrong somewhere else?


Cu Selur

kitsaros2000
11th December 2010, 12:45
i have the same problem when i encode ac3 5.1 into avi container.
For example : ffmpeg -i "D:\Avs\taudio6.avs" -vcodec mpeg4 -vtag DX50 -b 1000k -acodec ac3 -ar 48000 -ab 640k "test.avi"
if the ac3 is 2ch then it is ok but on 6ch ac3 i get Codec ID : 00001000-0000-0020-8000-00AA00389B71

Selur
11th December 2010, 12:59
setting -f for each file doesn't help either:
ffmpeg -y -f m4v -i "D:\Encoding Output\video.m4v" -f ac3 -i "D:\Encoding Output\audio.ac3" -vcodec copy -acodec copy -f avi "D:\Encoding Output\test.avi"

seems to be around for quiet a while, see:
http://roundup.ffmpeg.org/issue1650
http://roundup.ffmpeg.org/issue1498
but I'm a bit confused if this is now considered a bug or not :/

=> seems to work with ffmpeg SVN-r25935

kitsaros2000
13th December 2010, 01:02
even that version (svn 25935) does not work i used the latest version from here : http://ffmpeg.arrozcru.org/autobuilds/
i already saw these two issues . The solution right now is to use another container like mkv or mp4.

Selur
13th December 2010, 07:37
Strange, me too, but I simply used to multiplex and to reencode and multiplex.

The solution right now is to use another container like mkv or mp4.
Not really a solution, if you aim for an avi. ;)

I just rechecked: muxing does work in some strange way,..
- mpc-hc shows two audio streams (media info only shows one)
- mplayer only plays strange noise
- file is asynch
=> so it's still broken :(

Cu Selur

b66pak
13th December 2010, 10:22
then just use avi...why do you use m4v?
_

Selur
13th December 2010, 10:26
You mean using .avi instead of .m4v for the xvid output will fix the .ac3 problem in ffmpeg?
(will try later)

tested with:
mplayer -v -mc 0 -vc dummy -nocorrect-pts -aid 128 dvd://1 -dvd-device "D:\TestDVD" -chapter 1-1 -dumpaudio -dumpfile "D:\Encoding Output\audio DELAY -80ms_en.ac3"
mencoder -dvd-device "D:\TestDVD" dvd://1 -chapter 1-1 -noskip -vc mpeg12 -field-dominance -1 -vf scale,format=i420,yadif=0 -forcedsubsonly -noautosub -nosound -mc 0 -lavdopts threads=8 -fps 25 -aspect 1.7775:1 -ovc xvid -xvidencopts fixed_quant=3:profile=unrestricted:me_quality=6:min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31:max_key_interval=250:quant_type=h263:max_bframes=2:bquant_ratio=150:bquant_offset=100:bf_threshold=0:vhq=2:bvhq=1:curve_compression_high=0:curve_compression_low=0:overflow_control_strength=10:max_overflow_improvement=10:max_overflow_degradation=10:trellis:noqpel:nogmc:nocartoon:chroma_opt:chroma_me:nointerlacing:par=ext:par_width=16:par_height=11:closed_gop:nopacked:threads=0 -ffourcc XVID -of avi -o "D:\Encoding Output\video.avi"
ffmpeg -i "D:\Encoding Output\video.avi" -vtag xvid -i "D:\Encoding Output\audio DELAY -80ms.ac3" -vcodec copy -acodec copy -map 0:0 -map 1:0 "D:\Encoding Output\test.avi"
-> still 00001000-0000-0020-8000-00AA00389B71 doesn't seem like it helped
(I know on Windows I could use Avi-Mux gui to mux .avi and .ac3, but since I'm looking for a command line based way that works on windows and linux Avi-Mux gui isn't really an option + tagging isn't supported by Avi-Mux gui )

Cu Selur

kitsaros2000
13th December 2010, 13:13
the video length becomes double after the re-encode process . boh :(
@Selur : Yes if you use the mkv or the mp4 container as output you get no errors on vlc and you get the correct video legnth.
If you choose the avi container on kmplayer will "work" the avi with double length, but VLC will complain (audio : undf)
Infact i think that is a MUXING problem

b66pak
13th December 2010, 13:24
use mencoder for the muxing too..
_

Selur
13th December 2010, 15:25
How can one handle audio delay with mencoder? (especially when having multiple audio streams and a single video stream?)

b66pak
13th December 2010, 16:02
by fixing the delay before muxing...
_

Selur
14th December 2010, 08:11
Does mencoder allow to multiplex more than one audiostream? (seems like only one is possible)

Thanks for the help so far, but atm. mencoder doesn't really look like a solution for me.

Cu Selur

Ps.: neither ffmpeg or mencoder allow splitting by size while muxing :(

b66pak
14th December 2010, 18:39
what about this (http://forum.doom9.org/showthread.php?p=1462792#post1462792) linux tools?
_

Selur
15th December 2010, 07:16
avisplit -> needs remuxing of every file after the first once splitting is done.
avimerge -> will have a look at it,.. -> linux only + no stream delay

Audio delay with mencoder seems to work:mencoder -mc 0 -noskip -delay 0.08 "d:\Encoding Output\video.avi" -audiofile "d:\Encoding Output\audio DELAY -80ms.ac3" -audio-demuxer 20 -rawaudio format=0x2000:bitrate=448000:channels=6:rate=48000 -ovc copy -oac copy -of avi -o "d:\Encoding Output\test.avi" but only with one audiofile.