LinuxAnswers DiscussionThis forum is to discuss articles posted to LinuxAnswers.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have a question. Because I have an avi-file that is getting unsynced when encoding to mpg.
I think the reason is because the sound begin about 1.25 secs after the video. So in the avi, it's synced, but not when it's encoded.
Out-of-sync video is the biggest problem I'm trying to solve. Sometimes the sync problem can be fixed during multiplexing, but only if the audio and video are off by the same amount throughout the video. In my experience, this almost never happens - the sync problems usually seem to be caused by too-fast or too-slow video. When the frame rate is reported wrong, or is variable, there are problems.
In theory, however, if mplayer can play the original version correctly, then there has to be some way to convert it correctly. My goal is to make tovid's output exactly match what you would see and hear if you played the original file in mplayer (disregarding denoising/resizing). Sounds easy, right? Not really.
In the meantime, if you think your output video is out of sync by the same amount throughout the video, you can do the following:
Edit the tovid script, and comment out these two near the bottom (lines 675 and 676 in Version 0.14):
Then, encode normally. When encoding completes, you will have a .m2v (or .m1v) and .mpa file. You can multiplex these together manually, and try to adjust sync, using this command:
Use '-f 8' for DVD, '-f 1' for VCD, '-f 4' for SVCD. In place of '1234ms', use the amount of milliseconds that you think they are out of sync by. I think this is an audio delay, so 1500ms would make the audio come 1.5 seconds later. You can use negative numbers if it goes the wrong way.
And just in case someone who have the same problem as me and discovers this thread, the file was episode 4 in season 4 of Smallville. And to my human-senses, it seems like the manual sync-value should be "-O -1435ms" for this file
I think that info should be on the tovid webpage somewhere, cause you know its a a problem that will pop up more than anyone wants it to.
Where did you get the smallville episode? tvtorrents.net, suprnova.org? I want the exact name of it since there are couple of different ones (HDTV, vcd, etc). Then i will try it and see if i get the sync problem too.
/edit: nevermind, i am sure it was the HDTV one since thats the only one thats a .avi.
I've had a minor victory. It hasn't been tested too much yet, but I went back on my previous statement that I wouldn't use mencoder to encode MPEG; I've managed to get mencoder to output mpeg1 and mpeg2 video. I've figured out some of the reasons it was flaky before (wrong framerate format, for one: it will accept "30000/1001" but not "29.97") and it seems to have stabilized now. Mencoder is doing all resizing, letterboxing, frame rate adjustment, denoising, and encoding with a single command. No FIFOs or piping.
Significantly faster encoding time. For the 30-second DVD clip, new approach: 58 seconds; old approach: 1 minute 37 seconds.
Smaller file size. A 30-second DVD-format video encoded with tovid 0.14 was 12MB; the same video, same format encoded with the new method is 4.8MB. It remains to be seen whether this will apply in general, though.
Less complexity. The script is now about 80 lines shorter. yuvfps, yuvscaler, and mpeg2enc are not used at all now. mp2enc is still used to encode audio, and mplex is still used for multiplexing, so the mjpegtools dependency remains.
This theory is untested, but the new approach should resolve all framerate and sync problems. The -fps and -twopass options will not be needed any more.
Quality is very slightly, almost imperceptibly worse. I could only tell the difference by comparing individual frames at extreme close-up. This might be solved by additional quality-enhancing options.
I know it sounds too good to be true, and it just might be - I've only tested it so far on a couple video clips. The alterations to the script are so severe, I don't think I can safely introduce this as an encoding option to future versions; if any of you would like to help me test it, email me (wapcaplet99 at yahoo dot com) and I will send you a copy. If it tests out okay, this will become the basis for version 0.15.
Well I went over the script DVDDUP, created to copy DVD's that Wapcaplet sent to me.
It seems to to the exact same thing my method does, except for 2 things that annoy me a bit.
1) I have 5 dependencies for my script. He has 9.
2) His ripping and shrinking method is way slower than mine. The scripts warns that the process will take a few hours to complete. My method takes around 5 min to rip, 15 min to shrink and 20-25 min to burn a 2x speed. So It's around 45 minute for good quality.
The script is very well structured though and well documented. I might use some of it's structure features to make my script more understandable.
I will keep my original plan and keep fast and simple.
As I suspected - too good to be true. After some more testing, here are some additional disadvantages to using mencoder for encoding:
Frame rate problems are not fixed; in fact, they're substantially worse.
There is no way to control the output bitrate. vbitrate, vrc_maxrate, vrc_minrate, and vrc_eq=1 (explicitly specifying constant bitrate) all seem to be totally ignored when encoding to mpeg1 or mpeg2. Makes VCD impossible, since it must be 1150kbps; can't control quality of other formats either.
Output aspect ratio is wrong, even when it's explicitly specified. Aspect ratio always ends up as 1:1 (though it still sometimes plays back correctly).
Other header info is either not written or incorrectly specified; resulting files are reported with 0 bitrate, 0 duration, 0.0 aspect ratio.
Copious quantities of cryptic error messages in some cases.
So, clearly, faster encoding and smaller files are not worth all this. Back to the drawing board
I recently found out that mpeg2 audio is against the DVD standard for NTSC. I've been using it all this time, assuming it was okay (since it worked in my DVD player). NTSC players are only required (by the standard) to have AC-3 decoders, while PAL players are only required to have MP2 audio decoders. Looks like another small wrinkle in the PAL/NTSC conversion.
It's probably not a very big deal, but I've decided to try going with AC-3 audio for NTSC. Some nice advantages to AC-3: mencoder is able to decode Dolby surround from stereo audio files that contain it, and can also generate a subwoofer channel from the existing audio. MP2 can supposedly contain 5.1 surround, but mp2enc does not support encoding of it. Best of all, for normal stereo audio, AC-3 is the same bitrate as MP2 (at roughly the same quality, I assume; 192kbps is considered adequate, while I've been using 224kbps for MP2 all this time).
Well you are right. I hadn't noticed in all those post, but you never mentionned ac3 before, hahahaha!
Mp2 is in effect a NTSC standard but only for VCD and SVCD. For DVD actually you can have AC3 stereo(192 kbps), AC3 dolby 5.1 (384kbps or 448kbps), DTS and finally the good old LPCM (1536 kps), but that last one takes a lot of space for an audio track.
For example I use the following metthod to encode to AC3 stereo using FFMPEG:
From an avi video: ffmpeg -i video.avi -ac 2 -ab 192 -ar 48000 audio.ac3
From an audio track : ffmpeg -i audio.wav -ac 2 -ab 192 -ar 48000 audio.ac3
Usually 95% of the time I always deal with the audio stream and the video separately. Only at the end of a project will I multiplex them together for the standard needed. Many reasons for this approach, one of them because a lot of movies out there are encoded with variable bitrate MP3, witch is known to cause a lot of AV sync issues.
Another is that in my experience it avoids bad sync problems.
Also even more avi movies today have the original untouch sountrack in them i.e AC3 6 channel 448kbps. Those are my favorites. You get the original quality and no processing is needed. You need to extract it only as is.
I've fixed a couple of small bugs (including that one at the end about "-v unary operator expected") and re-posted version 0.14 to sourceforge. I also changed the "makempg" script - I accidentally included the wrong one last time. This one is more useful, but still very basic. Not worth doing a new release for
I think I've got AC3 encoding working pretty well (after some initial confusion - a side note, if you multiplex two AC3 streams together without any video, you get some weird results!) Can't figure out how to normalize the audio just yet (since mencoder won't take a .wav as input). By the way, are you guys using the normalize option at all? I barely ever use it, but it may come in handy someday, so I'll make sure to get AC3 working with it before release. MP2 is automatically used for PAL, and for (S)VCD, so we should be a little bit closer to conforming to DVD standards now.
Added a new '-help' option to see advanced usage options; also added an '-audiodelay' advanced option for delaying the audio, when audio and video are out of sync.
Also, rather than trying to burden the already-complex tovid script with tons of user-interaction stuff, I've made a new script, 'tovid-interactive' that guides the user through encoding by prompting for formats and stuff. It then calls tovid to do the encoding. Nothing fancy, but it'll do for now.
Steel_J: thanks for your comments on AC3; they are quite helpful. You are definitely more familiar with the standards than I am.
sk545 and Mysil2: I got your emails, but unfortunately there's nothing useful I can email you right now. I'll send you something once I get closer to release, so I can use you as guinea-pigs!
Originally posted by wapcaplet
sk545 and Mysil2: I got your emails, but unfortunately there's nothing useful I can email you right now. I'll send you something once I get closer to release, so I can use you as guinea-pigs! [/B]