wiki:TranscodingErrors

Version 1 (modified by anna, 7 years ago) (diff)

--

i have been doing a bit of research on the sync issues we have found when Indytube converts WMV files into FLV (using mencoder).

This issue is documented here on the EngageMedia webdev tracker, but probably needs moving over to Plumi:  http://trac.engagemedia.org/projects/ticket/475

I now think that rather than looking at telecine we could look at the option of duplicate frames settings, and also use a method of obtaining an average frame rate from mencoder and passing that back to mencoder as the input frame rate.

Below I have pasted excerpts from a few web pages I was looking at. I'll try to find the time soon to go through and make sense of it all, but for now these are my notes.

There are also a couple of hints for maintaining aspect ratios but avoiding stretching or squeezing of the video to 320:240

Cheers, Anna

CHANGES TO MENCODER OPTIONS

  • - - - - - - - -

 http://www.anythingbutipod.com/forum/showthread.php?s=ffacb1bb9f07eaf0bb0204d814cb5fd9&t=17321&page=2

Found if you change "-vf scale=320:240" to read: "-vf scale=320:-2,crop=320:240"... Mencoder will automatically pick the correct aspect ratio for your video based on the width of 320, and the crop command will make sure it never exceeds 320x240 so the player won't reject it.

That way you dont get stretched out videos

  • - - - - - - - -

Ok, here's a further evolution of my Mencoder options for making video for the DV...

Quote: mencoder [in_file] -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:keyint=250:threads= 2 -oac mp3lame -lameopts cbr:br=128 -ffourcc XVID -vf scale=320:-2,crop=320:240,expand=320:240 -af resample=44100:0:0 -o [out_file] To explain the video filters a bit, basically, it first scales the movie to 320x[whatever needs to be for correct aspect], then if the Y aspect is > 240, it will crop & center the video at 320x240.... last if the video is smaller than 320x240, I found the player would show green blocks and bizzare colors, so I added the expand parameter... so if your video was, for example 320x180... it would make it 320x240 and auto-center the video. In doing this, I found that would solve the strange video problems with videos that were smaller than 320x240.

I also found that it's best to use a constant bit rate for the audio, or you'll get the out of sync audio problem if you seek around the video.

One more item to note on the command line, there is "threads=2"... this is to speed up the encoding for dual-core processors or hyper-threaded processors. If you just have a regular processor, you'll want to set that to 1, or it may make your encoding time even slower.

With these settings, video seems to average around 300megs/hour of play, and I find the quality to be quite good.

If anyone finds ways to optimize this even more, do feel free to share it

AUDIO BITRATE CHANGE TO CBR CONSTANT BITRATE - SYNC ISSUES

TRY THIS METHOD FOR AVOIDING STRETCHED VIDEOS (COMPARE TO METHOD ABOVE)

RESAMPLE AUDIO RATE? COULD HELP...

WHAT IS V4MV??

  • - - - - - - - - - -

Code:

mencoder $TEMP_DRIVE/dump.vob -aid $aid -oac mp3lame -lameopts cbr:br=128 -srate 44100 -af resample=44100:0:1 -af volume=20 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vbitrate=600:threads=2 -vf scale=320:-2,crop=320:240,expand=320:240,harddup -noskip -skiplimit 1 -ffourcc XVID -o $name.avi

Most of this is familiar. I change the resample to not use linear interpolation though I doubt it makes that much of a difference. I bump up the volume 20db since movies from the DVD directly seem to be much more quiet than music files. 16 to 20 is about where music and the movie sound about the same level. I add mbd=2 instead of vhq (mbd=1) because I'm more concerned with quality over rate for this situation. Trell does something similar, just look at the man page. I had v4mv in there as well but I'm testing without it currently. My bitrate is lower here as a balance with quality. The key thing for DVD is harddup and noskip skiplimit. You may notice an issue where it says "Duplicate frames detected". A normal encode will have video running twice as fast as audio because each of those frames is dropped. This will force those duplicate frames to be encoded and now your audio and video will be in sync. Finally $name is another var from my script.

HARDDUP NOSKIP SKIP LIMIT - DUPLICATE FRAMES - COULD HELP WITH SYNC

2-PASS ENCODING - CAN HELP WITH SYNC

  • - - - - - - - - - -

I find that if you're reencoding WMV files in particular, you can get alot of sync issues with audio. Try adding -ofps to the command line, and give it the frame rate of the input video. Alot of times with WMV/ASX the frame-rate is variable, so it causes audio to go out of sync. Giving -ofps # will create a video with a fixed frame-rate. Most video clips are like 24, 25, 29.97, 30 fps.... so try those, or if you know the input video frame-rate just give it to mencoder when you encode it (i.e. -ofps 25)

See if that helps with sync issues

  • - -- - - - - - - - - - - - -

TWO PASS SCRIPT EXAMPLE

#!/bin/bash # # insig_encode.sh # # Usage: insig_encode.sh inputfile # It will write a new video file called inputfile-insignia.avi #

FILE=$1 OUT=echo -n "$FILE" | sed 's/\.[a-zA-Z0-9]\+$/-insignia.avi/'

echo echo "Processing input file $FILE..." echo

rm -f divx2pass.log 2>/dev/null

nice -n 19 \ mencoder "$FILE" \ -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:keyint=250:threads= 2:vpass=1 \ -oac copy \ -ffourcc XVID \ -vf scale=320:-2,crop=320:240,expand=320:240 \ -o "$OUT"

nice -n 19 \ mencoder "$FILE" \ -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:keyint=250:threads= 2:vpass=2 \ -oac copy \ -ffourcc XVID \ -vf scale=320:-2,crop=320:240,expand=320:240 \ -o "$OUT"

  • - - - - - - - - --- - - - - - - - - -

 http://lists.mplayerhq.hu/pipermail/mencoder-users/2006-August/003858.html

On 8/12/06, RC <rcooley at spamcop.net> wrote:

On Fri, 11 Aug 2006 16:43:33 +0800 "howard chen" <howachen at gmail.com> wrote:

I really want a sample command to convert files to FLV, that "preserve 100% A/V sync".

There's really no possible way to guarantee perfect sync with EVERY type of input. They vary far too much. Human intervention is sometimes going to be required. (FLV has nothing to do with it)

Look through the docs and mailing lists for tips on fixing A/V sync issues.

My source is WMV files with difference frame-rate. If I provided the correct framerate as the "-ofps" during encoding, the A/V sync will be correct. If I put "30" for all files, the A/V sync has little problem (not serious as I added the "harddup", only a few ms audio/video de-sync). I assume Mencoder will auto correct the sync for me by dropping or duplicating frame? Maybe this caused the problem.

Another problem is I can't get the source frame rate data via "-identify" command. I need to use windows media player to open the file and get the frame rate. And use that frame rate to encode, but too complicated, not suitable for batch processing.

If using FFmpeg, the problem of A/V sync is acceptable no matter what the source frame-rate, but using Mencoder, the difference is bigger. I assume they are using the same lavac codec? The command of FFmpeg is more simple and I wonder if it is possible to get the same effect as FFmpeg using Mencoder as Mencoder is better for processing WMV.

Thanks for any comment.

SAME THREAD

On 8/12/06, RC <rcooley at spamcop.net> wrote:

On Sat, 12 Aug 2006 10:57:23 +0800 "howard chen" <howachen at gmail.com> wrote:

I assume Mencoder will auto correct the sync for me by dropping or duplicating frame?

As long as you don't use -noskip or -mc 0... Yes, as best it can.

Another problem is I can't get the source frame rate data via "-identify" command.

Covered multiple times by me on these lists lately.

If using FFmpeg, the problem of A/V sync is acceptable no matter what the source frame-rate, but using Mencoder, the difference is bigger.

And you've never bothered to include the command-lines you're trying to use with either one, so what do you expect anyone to tell you?

sorry first...

for mencoder, i use:

/usr/local/mplayer/bin/mencoder /tmp/3.wmv -oac mp3lame -vf scale=320:240,harddup -lavcopts vcodec=flv:vbitrate=200:cbp:mv0:mbd=2:trell:v4mv:predia=2:dia=2:last_pred=3 -of lavf -lameopts br=64 -ovc lavc -ofps 25 -srate 22050 -o /tmp/out.flv

for ffmpeg, i use:

ffmpeg -i /tmp/3.wmv -y -ab 64 -ar 22050 -b 200 -r 25 -s 320*240 /tmp/out.flv

i found that the A/V sync of mencoder is a little bit out of sync (very little, BUT noticable), while ffmpeg is okay. Of coz I can use ffmpeg, but ffmpeg's support of WMV is not as good as Mencoder...

Thanks for any comment...

SAME THREAD

On 8/13/06, RC <rcooley at spamcop.net> wrote:

On Sat, 12 Aug 2006 14:52:27 +0800 "howard chen" <howachen at gmail.com> wrote:

i found that the A/V sync of mencoder is a little bit out of sync (very little, BUT noticable), while ffmpeg is okay.

Well, you might try different values for -mc, 0/0.001/0.1/1/10.

If it's a fixed-offset sync issue, you could use one of mencoder's audio delay options. _

Hi,

I have tried the -mc 0, thing seems better!

but according to the manual:

you may have to switch to basic A/V sync with the -mc 0 option, or

put this in >>your ~/.mplayer/mencoder config file, as long as you are only working with good >>sources

my wmv is of coz not a good source, also, i may also need to encode other files such as mov, 3gp, mpeg automatically via command line, is it safe to use "-mc 0" in all the conversion ?

another choice I found is to get the correct framerate first, and encode using this as the "ofps", is this choice better than using "-mc 0" if I need to handle various files with unknown framerate?

p.s. in order to get the FR, i use -identify -vo null -benchmark test.wmv, the mplayer play the file once (real time) and return the average fps, is it possible to get the FR faster?

sorry for too many questions....

thanks.

SAME THREAD

On Sun, 13 Aug 2006 16:05:29 +0800 "howard chen" <howachen at gmail.com> wrote:

is it safe to use "-mc 0" in all the conversion ?

Nope.

another choice I found is to get the correct framerate first, and encode using this as the "ofps", is this choice better than using "-mc 0" if I need to handle various files with unknown framerate?

You only need to detect the framerate before-hand with WMV files to begin with. I don't think any other (common) format uses variable fps.

is it possible to get the FR faster?

-nosound -speed 100 will probably help.

SAME THREAD

On 8/14/06, RC <rcooley at spamcop.net> wrote:

On Sun, 13 Aug 2006 16:05:29 +0800 "howard chen" <howachen at gmail.com> wrote:

is it safe to use "-mc 0" in all the conversion ?

Nope.

another choice I found is to get the correct framerate first, and encode using this as the "ofps", is this choice better than using "-mc 0" if I need to handle various files with unknown framerate?

You only need to detect the framerate before-hand with WMV files to begin with. I don't think any other (common) format uses variable fps.

sorry, i am not clear what you say. Is that mean I only need to check the fps of wmv files for the "ofps" option, for other file, e.g. mov or 3gp, I can use a fixed "ofps"

is it possible to get the FR faster?

-nosound -speed 100 will probably help.

if used -nosound, i can get the average fps, e.g

ID_FILENAME=d:\Temp\2.wmv ID_DEMUXER=asf ID_VIDEO_FORMAT=WMV2 ID_VIDEO_BITRATE=0 ID_VIDEO_WIDTH=320 ID_VIDEO_HEIGHT=240 ID_VIDEO_FPS=1000.000 ID_VIDEO_ASPECT=0.0000 ID_AUDIO_CODEC=ffwmav2 ID_AUDIO_FORMAT=353 ID_AUDIO_BITRATE=64032 ID_AUDIO_RATE=48000 ID_AUDIO_NCH=2 ID_LENGTH=37.00

BENCHMARKs: VC: 1.954s VO: 0.000s A: 0.000s Sys: 0.062s = 2.016s BENCHMARK%: VC: 96.9246% VO: 0.0000% A: 0.0000% Sys: 3.0754% = 100.0000%

Otherwise, i can get

BENCHMARKs: VC: 0.092s VO: 0.000s A: 0.032s Sys: 33.595s = 33.719s BENCHMARK%: VC: 0.2728% VO: 0.0000% A: 0.0949% Sys: 99.6323% = 100.0000% BENCHMARKn: disp: 502 (14.89 fps) drop: 3 (0%) total: 505 (14.98 fps)

i.e. 15 fps

Thanks.

SAME THREAD

On Mon, 14 Aug 2006 10:32:13 +0800 "howard chen" <howachen at gmail.com> wrote:

Is that mean I only need to check the fps of wmv files for the "ofps" option,

Yes.

for other file, e.g. mov or 3gp, I can use a fixed "ofps"

For every other file, you don't need an -ofps value.

SAME THREAD

On 8/14/06, RC <rcooley at spamcop.net> wrote:

On Mon, 14 Aug 2006 10:32:13 +0800 "howard chen" <howachen at gmail.com> wrote:

Is that mean I only need to check the fps of wmv files for the "ofps" option,

Yes.

for other file, e.g. mov or 3gp, I can use a fixed "ofps"

For every other file, you don't need an -ofps value. _

Okay, i got your point.

Final question: is there no quick way to get the framerate of a wmv file unless you play the whole file second-by-second?

i.e. -nosound -speed 100 didn't provided the average fps

Thanks.

SAME THREAD

On Mon, 14 Aug 2006 16:08:34 +0800 "howard chen" <howachen at gmail.com> wrote:

  1. i can't get the total number of frame

Add "-v"

SAME THREAD

the ffmpeg can determine the average fps of my wmv file during encoding, so i doubt the need to play the whole file in order to get the average fps.

  • - - - - - - - - - - - -- - - - -- - - - -

another THREAD  http://lists.mplayerhq.hu/pipermail/mencoder-users/2006-July/003663.html

Hi,

When using the option : "-noskip -mc 0" in converting a wmv file to a flv file, I found that the audio stream is a little bit faster then the video stream...

COMMAND:

/usr/local/mplayer/bin/mencoder tv.wmv -o tv.flv -of lavf -oac mp3lame -lameopts abr:br=32 -ovc lavc -lavcopts vcodec=flv:vbitrate=300:cbp:mv0:mbd=2:trell:v4mv:predia=2:dia=2:last_pred=3 -srate 22050 -noskip -mc 0 -ofps 25

However, when I removed the "-noskip -mc 0", the result flv is okay (correct a/v synchronization).

COMMAND:

/usr/local/mplayer/bin/mencoder tv.wmv -o tv.flv -of lavf -oac mp3lame -lameopts abr:br=32 -ovc lavc -lavcopts vcodec=flv:vbitrate=300:cbp:mv0:mbd=2:trell:v4mv:predia=2:dia=2:last_pred=3 -srate 22050 -ofps 25

The drawback is many warning messages...

i.e. ... ... Skipping frame! Pos: 275.3s 8233f (99%) 114fps Trem: 0min 11mb A-V:0.052 [296:32] ...

Did anyone have this problem before?

Regards, Ming

Tsz Ming WONG wrote:

Hi!

When using the option : "-noskip -mc 0" in converting a wmv file to a flv file, I found that the audio stream is a little bit faster then the video stream...

[...]

Skipping frame! Pos: 275.3s 8233f (99%) 114fps Trem: 0min 11mb A-V:0.052 [296:32] ...

Did anyone have this problem before?

Yes, I did the same :)

The error is to use "-noskip" with mencoder. You receive the "skipping frame" message because the output frames per second is less that the input (maybe you are converting an NTSC file -with 30fps- to PAL -25 fps-). Mencoder must throw one frame each 5 to adjust the framerate.

If you use the "-noskip" option, mencoder will put all the 30 frames, but will set the output FPS to 25, so the picture will be played a little slower, and the audio will get more and more desinchronized.

SAME THREAD

Hi all,

Consider if I never know the input framerate of the wmv, what are the best settings to convert to a wmv to flv ? For example, YouTube? allow people to upload wmv and convert to flv, different users must have different framerate of wmv files being uploaded, how they tackle this kind of problems?

Is that the only solution is not to use "-noskip -mc 0" and end up with many ugly warnings...?

Btw, anyone know the tools behind YouTube? ? Seems Google Video also use mencoder or ffmpeg?

Regards, Ming

SAME THREAD

Tsz Ming WONG wrote:

Hi!

Consider if I never know the input framerate of the wmv, what are the

best

settings to convert to a wmv to flv ? For example, YouTube? allow

people to

upload wmv and convert to flv, different users must have different framerate of wmv files being uploaded, how they tackle this kind of problems?

When using -noskip with mencoder you can have more problems than the mismatch with FPS, so I strongly recomend to never use it unless you know what are you doing.

Is that the only solution is not to use "-noskip -mc 0" and end up with many ugly warnings...?

Well, you can use:

mencoder -options-you-need | grep -v Skipping

:)

Btw, anyone know the tools behind YouTube? ? Seems Google Video also use mencoder or ffmpeg?

No idea :?

SAME THREAD

Originally I thought that we should always use "-mc 0 and -noskip" in all the cases (becoz many examples in the web always have this!), however, this is not true.

according to the manual:

....Therefore, you may have to switch to basic A/V sync with the -mc 0 option, or put this in your ~/.mplayer/mencoder config file, as long

as you

are only working with good sources

&

...Therefore, using -noskip is not in general recommended.

regards, ming

SAME THREAD

On Fri, 7 Jul 2006 21:34:13 +0800 "Tsz Ming WONG" <tszming at gmail.com> wrote:

For example, YouTube? allow people to upload wmv and convert to flv, different users must have different framerate of wmv files being uploaded, how they tackle this kind of problems?

Run mplayer on the file first (you can use -identify -vo null -benchmark, etc), and read the output to determine how long the video is (exactly) and how many frames it has.

Divide the total number of frames by the length (in seconds) of the video, to get the framerate in FPS.

You can either use that as your "-ofps" value, OR you can decide which _normal_ fps value the video is closest to (24, 25, 30, etc) and use that instead. You'll still get some warnings, but far fewer.

SAME THREAD

On Tue, 11 Jul 2006 10:04:43 -0700 Jon Drukman <jsd at cluttered.com> wrote:

i made the file myself so i know that it is 29.97 fps.

What you mean is that the input was 29.97fps. Once WMV has chewed on it, it's VFR. The difference is probably because of duplicate (unchanged) frames.

28.90 fps is not what i would consider close.

And? If you don't like it, don't use this method.

i would expect obvious a/v sync errors with that sort of mismatch after a minute or two.

You can use ANY -ofps value and not get A/V sync errors. -ofps doesn't work the way you seem to think.

SAME THREAD

On Tue, 11 Jul 2006 17:57:59 -0700 Jon Drukman <jsd at cluttered.com> wrote:

i have no idea what ofps does so you're probably right. please enlighten me.

It skips/duplicates frames in the output file to match the rate you specify. It has many uses. It should be explained in the docs.

SAME THREAD

On Fri, Jul 07, 2006 at 07:11:20PM +0800, Tsz Ming WONG wrote:

Hi,

When using the option : "-noskip -mc 0" in converting a wmv file to a flv file, I found that the audio stream is a little bit faster then the video stream...

COMMAND:

/usr/local/mplayer/bin/mencoder tv.wmv -o tv.flv -of lavf -oac mp3lame -lameopts abr:br=32 -ovc lavc -lavcopts

vcodec=flv:vbitrate=300:cbp:mv0:mbd=2:trell:v4mv:predia=2:dia=2:last_pred=3

-srate 22050 -noskip -mc 0 -ofps 25

However, when I removed the "-noskip -mc 0", the result flv is okay

(correct

a/v synchronization).

Of course -noskip -mc 0 will give a/v desync unless the input frames exactly match the chosen output framerate. What else could it do?

My guess is that you've chosen the wrong output framerate. Either the wmv file is a different framerate or it's "supposed to be 25" but slightly off. Since wmv doesn't have a nominal framerate or timebase, only millisecond timestamps, you'll have to play around and guess the framerate until you get one that works, or give up on using -noskip and -mc 0.

Rich

  • - - - -

 http://neilhan.blogspot.com/2006/10/mplayer-mencoder-converting-videos-to.html

#mencoder $1 -o $2 -ofps 15 -of lavf \

-oac mp3lame -lameopts abr:br=64 -srate 22050 -ovc lavc \ -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \ -lavcopts vcodec=flv:keyint=25:vbitrate=300:mbd=2:mv0\ :trell:v4mv:cbp:last_pred=3 \ -vf harddup,expand=:::::4/3,scale=320:240 \ -msglevel all=4 -mc 0/10

  • - - - - - - - -