Log in

View Full Version : How to convert .mpg (MPEG-2) to H.264 easily?


Pages : 1 [2]

nm
7th December 2008, 21:57
I have used ProjectX to convert the TS file into m2v/mp2 files and loaded them into Avidemux. That's a bit of a tricky process because I needed to load the m2v video (drag & drop, easy) and then add the separate audio file later. Of course the open dialogue was not preset to the video file's directory so I had to search it first.
ProjectX can also mux both streams to MPEG-TS.

The TS file is 1.2 GB large. How can I provide you a sample of the first few seconds, which is enough to test it?
Cut with ProjectX.

Would it e.g. be okay to simply truncate the file at a certain number of bytes? (I could write a little programme for that.)
That should also work well enough.

LonelyPixel
7th December 2008, 22:56
I have tried to convert the TS file to TS in ProjectX, but it would just do nothing and immediately report success. Not sure what it did there. But I can only operate the File,Add and QuickStart/prepare buttons, the rest looks a bit complicated...

Okay, I'll try to cut the file tomorrow and upload it for you.

PS: I'm currently converting a lengthier video from m2v/ac3 to x264/aac with Avidemux, once I've found a file that works and played a little with different bitrates/options. Strange thing: The file has 23 minutes. It reports 28 minutes elapsed, 21 minutes remaining and 24 frames/second. I only come to the result of 12 frames/second... Time goes linear, so the fps must be wrong. Strange programme, a little out of time: plays sound at half speed, computes double frame rates... :confused:

nm
7th December 2008, 23:11
PS: I'm currently converting a lengthier video from m2v/ac3 to x264/aac with Avidemux, once I've found a file that works and played a little with different bitrates/options. Strange thing: The file has 23 minutes. It reports 28 minutes elapsed, 21 minutes remaining and 24 frames/second. I only come to the result of 12 frames/second... Time goes linear, so the fps must be wrong. Strange programme, a little out of time: plays sound at half speed, computes double frame rates... :confused:
Well, these problems are probably related to each other and maybe triggered by your MPEG-TS streams, if that's what you used as source video in this attempt too.

LonelyPixel
8th December 2008, 07:10
No, the video with the wrong frame rate display while processing is perfectly fine. No audio problems here. That's only the other file.

nm
8th December 2008, 12:42
Audio playing at half speed and in other case video doing the same thing sounds related to me. Avidemux may be confused from something in the input and tries to keep sync either way.

But we'll see once you post samples of both source streams.

LonelyPixel
8th December 2008, 17:57
Sorry, how can I cut a video with ProjectX? I don't see how that should be possible. I'm using version 0.90.3 but it seems to be pretty recent... from 2006 or so. 0.90.4 doesn't work, it only comes as source and the build script fails. I'm now continuing to work on truncating the file.

nm
8th December 2008, 18:19
There are links to a pre-built 0.90.4 version (http://students.washington.edu/cdobrich/ProjectX_0.90.4.zip) at http://avidemux.org/admWiki/index.php?title=Project_X

The CVS version has a few fixes and new features, but you should be fine with 0.90.4.

To cut, launch ProjectX and File->Add the source file. Use the slider below the video preview image to select a position and the "+" button on a purple background at the center of the window to add a cut mark. For example, move to the beginning of the video, push the + button, move a few minutes forward and push it again. Now the cut view between the preview image and the position slider should show a green interval (which is kept while cutting) at the beginning of the video and red for the rest.

Then, push the "prepare ..." button to open the ProcessWindow. Select action "to TS" and press the play/pause button at top left. Output for "/path/to/input.ts" should be "/path/to/input.new.ts".

LonelyPixel
8th December 2008, 18:23
You can find the first TS example here:
http://unclassified.de/tmp/demo1_30mb.ts (30 MB)

I can observe the following behaviour with this file:
* When playing with MPC, everything is okay until ~ sec. 25 when the sound stops to play. (Not sure how well MPC can handle transport streams with changing audio codecs, if that's the case here.)
* When playing/processing with Avidemux, everything is okay until ~ sec. 25 when the sound continues to play at half speed. Both within Avidemux and any player that's to play the resulting file.

I cannot provide a sample of the file that leads to wrong processing status info (double processing frame rate displayed than actually working) because the TS has a leading of ~ 5 minutes that I've cut away, but the resulting file is m2v/ac3 which I'm not sure how to cut. Only to clarify things: Encoding and playback with that second file is perfectly okay, it's only the info displayed during the encoding process that's wrong. It displays ~ 24 fps but is only encoding at ~ 12 fps. Minor issue, not really relevant cause the time displayed (elapsed, remaining) seems accurate. Probably this info is wrong on all files.

nm
8th December 2008, 20:34
You can find the first TS example here:
http://unclassified.de/tmp/demo1_30mb.ts (30 MB)

I can observe the following behaviour with this file:
* When playing with MPC, everything is okay until ~ sec. 25 when the sound stops to play. (Not sure how well MPC can handle transport streams with changing audio codecs, if that's the case here.)
* When playing/processing with Avidemux, everything is okay until ~ sec. 25 when the sound continues to play at half speed. Both within Avidemux and any player that's to play the resulting file.
The audio gets changed from mono to stereo and seems that Avidemux can't handle that. HandBrake fails too, although a bit differently. MPlayer doesn't seem to have problems, so GUIs built on top of MEncoder may work better. However, such audio format changes only happen between programs, so if you separate the programs and cut commercials out, there should be no problems.

One way to work around this problem would be to demux video and audio with ProjectX and set it to decode MPEG audio to WAV (PreSettings->audio->decode MPEG Layer1,2 to PCM). Then load the .m2v video to Avidemux and add the .mp2.wav audio (Audio->Main Track).

You may want to report this bug if you continue to use Avidemux.

Only to clarify things: Encoding and playback with that second file is perfectly okay, it's only the info displayed during the encoding process that's wrong. It displays ~ 24 fps but is only encoding at ~ 12 fps. Minor issue, not really relevant cause the time displayed (elapsed, remaining) seems accurate. Probably this info is wrong on all files.
Okay, now I understood the issue, but I see the right fps. Did you notice that the fps and frame position displays are updated every half seconds, not every second?

LonelyPixel
8th December 2008, 21:35
Cutting programmes and commercials doesn't necessarily cut exactly at audio format or video aspect ratio changes. How can I even select multiple cuts in Avidemux? I only see one A and B markers, no cut list. Is there an alternative cut mode opposed to the single-scene mode that I can see right now? I.e. not selecting the region(s) to keep but instead the regions to cut out and keep all the rest. The latter mode is especially useful for cutting commercials. I think I'm gonna keep Avidemux for transcoding to x264 or something else, 'cause it's much better than DVDx. :) But I think I'm not going to transcode all my TV recordings. They're just good in MPEG-2, anything else is worse at similar or lower bitrates. So I'm going to further investigate Avidemux' capabilities in frame-accurate multi-cut MPEG-2 editing with that "Smart Copy" mode. TS/MPG in, MPG out.

Yes, the status is updated every 0.5 seconds. I have just tested it and the reported processing frame rate is exactly the double of what it's really doing.

nm
8th December 2008, 21:54
Cutting programmes and commercials doesn't necessarily cut exactly at audio format or video aspect ratio changes. How can I even select multiple cuts in Avidemux? I only see one A and B markers, no cut list. Is there an alternative cut mode opposed to the single-scene mode that I can see right now? I.e. not selecting the region(s) to keep but instead the regions to cut out and keep all the rest. The latter mode is especially useful for cutting commercials.
It cuts stuff out by default. Select region, Edit->Cut/Delete. Repeat.

I think I'm gonna keep Avidemux for transcoding to x264 or something else, 'cause it's much better than DVDx. :) But I think I'm not going to transcode all my TV recordings. They're just good in MPEG-2, anything else is worse at similar or lower bitrates.
x264 should be able to keep similar quality at significantly lower bitrates when the source is progressive or when you deinterlace it. (At least if you are happy with half-rate deinterlacing, for full 50/60 fps framerate it may be a better idea to keep the original source and deinterlace on playback).

Yes, the status is updated every 0.5 seconds. I have just tested it and the reported processing frame rate is exactly the double of what it's really doing.
Strange, I only tried CRF encoding though, maybe it works differently in 2-pass mode.

LonelyPixel
8th December 2008, 22:01
Edit,Cut - thanks.

I've encoded a TV-Recording to x264 with 2-pass, avg bitrate 3000 and 5000, pixel aspect ratio as input (was 16:9). The only filter is yadif in mode 1. Then I played the original and encoded video in MPC and paused at the very same frames to compare them in detail. I could find several situations where a lot of details were lost or softened in x264. The entire files with 3000/5000 kbps are 533/872 MB, the original m2v/ac3 is 1198 MB. Also, processing time takes 4x real time, on my now overclocked Core2Duo 1,8/2,3 GHz. Transcoding is good for giving smaller versions of recordings away, but for my personal "home cinema" (= desktop computer...) I can't justify the effort.

nm
8th December 2008, 22:48
I've encoded a TV-Recording to x264 with 2-pass, avg bitrate 3000 and 5000, pixel aspect ratio as input (was 16:9). The only filter is yadif in mode 1.
Yadif in mode 1 and 3 is a full-rate (bob) deinterlacer. 0 and 2 are half-rate. Bobbing is useful for keeping the motion fluidity of sports and live shows, but movies and newer TV series are usually progressive video originating from 24 fps film or digital sources. Deinterlacing progressive video is a waste of time, space and sometimes quality.

If you have lots of interlaced recordings, you could also try encoding them as interlaced. However, there may be signaling issues with the x264 library included in Avidemux. Some decoders expect additional SEI messages to deinterlace automatically (http://forum.doom9.org/showthread.php?t=137432) and this requires a patched x264.

It's also a good idea to use CRF instead of 2-pass mode if you don't need the output to be of certain size (to fit a DVD for example).

nm
9th December 2008, 01:38
I've encoded a TV-Recording to x264 with 2-pass, avg bitrate 3000 and 5000, pixel aspect ratio as input (was 16:9). The only filter is yadif in mode 1. Then I played the original and encoded video in MPC and paused at the very same frames to compare them in detail. I could find several situations where a lot of details were lost or softened in x264.
I played around a bit with Avidemux and your sample. The loss of details was probably caused by input postprocessing (mostly deblocking) which seems to be enabled by default in Avidemux for some reason. Your DVB source has quite good quality, so deblocking will only smooth details out. Disable horizontal and vertical deblocking in the video preferences tab and set the strength to 0. Then set the same values in current settings (Video->Postprocessing (F4)).

I did a few sample encodes (http://www.cs.helsinki.fi/u/mikkila/video/avidemux/) with high quality x264 settings (5-8 fps on a 2 GHz Core 2 Duo). Although encoding as interlaced is a bit more efficient than bobbing before encoding, I'm rather pleased with the 50 fps yadif=1 results at crf 23. That would be good enough for my taste: practically transparent when played back and takes less than half the space of the original MPEG-2. As to the crf 20 samples, I can see differences in the noise patterns compared to the original, but actual details aren't lost. The crf 26 sample can be easily told apart from the source, but it is still quite watchable, IMO. I would probably use crf 25 for less important stuff when encoding with yadif=1.

LonelyPixel
10th December 2008, 17:26
Yadif in mode 1 and 3 is a full-rate (bob) deinterlacer. 0 and 2 are half-rate. Bobbing is useful for keeping the motion fluidity of sports and live shows, but movies and newer TV series are usually progressive video originating from 24 fps film or digital sources.
What is half-/full-rate? And the shows I have recently recorded are all interlaced. All German DVB-S TV seems interlaced. Is there any TV station that's finally broadcasting SDTV with progressive encoding? Does that even work, I mean all traditional camera and TV equipment works interlaced. If anything would be transmitted progressive, it would break anything, right? So I wouldn't expect progressive encoding on TV until HDTV comes around, which is still far away.

If you have lots of interlaced recordings, you could also try encoding them as interlaced.
Yeah, doesn't work. I've tried myself and watched your samples: It doesn't run well at all on playback. Jumps around wildly.

It's also a good idea to use CRF instead of 2-pass mode if you don't need the output to be of certain size (to fit a DVD for example).
Okay, I'll try that again. CRF 20 looks promising. Not so much CRF 26...

LonelyPixel
10th December 2008, 17:30
Disable horizontal and vertical deblocking in the video preferences tab and set the strength to 0.
Done.

I'm rather pleased with the 50 fps yadif=1 results at crf 23
I see, I get a video with 50 fps when I use yadif mode=1? Your 50 fps samples look a considerably smoother (in motion, not picture details) than the 25 fps ones.

BTW, also with CRF encoding, the displayed process frame rate is too high. It just displayed me ~ 24 fps but was actually working at ~ 12 fps. Seems it doesn't come from 2-pass.

nm
10th December 2008, 19:11
I see, I get a video with 50 fps when I use yadif mode=1?
Yes. The output is 25 fps in modes 0 and 2 and 50 fps in modes 1 and 3 for a 25i source. In 25 fps modes, part of the temporal information from the interlaced source is lost.

BTW, also with CRF encoding, the displayed process frame rate is too high. It just displayed me ~ 24 fps but was actually working at ~ 12 fps. Seems it doesn't come from 2-pass.
I still haven't seen this. How do you calculate the correct fps? Does the same thing happen if you don't use any filters (especially yadif or other deinterlacers that may double the framerate).

LonelyPixel
10th December 2008, 19:23
Arr, you tell it. Of course I've calculated wrong... we have 50 fps in the resulting video, not 25 as in the source! Sure, then the displayed rate is correct. Stupid me.

So, converting from 25 fps to 50 fps during encoding is actually (almost) doubling the data volume, resulting in larger video files, correct?

nm
10th December 2008, 19:40
What is half-/full-rate? And the shows I have recently recorded are all interlaced. All German DVB-S TV seems interlaced. Is there any TV station that's finally broadcasting SDTV with progressive encoding? Does that even work, I mean all traditional camera and TV equipment works interlaced. If anything would be transmitted progressive, it would break anything, right? So I wouldn't expect progressive encoding on TV until HDTV comes around, which is still far away.
Well, here in Finland most movies and newer series that originate from 24 fps progressive sources are broadcast as 25 fps progressive video with speeded up audio. The MPEG-2 video may be coded as interlaced but both fields are from the same time position, so practically it's progressive and doesn't require actual deinterlacing, only weaving. There are no obvious interlacing patterns visible (faint blocky patterns may appear in flat areas if the bitrate is low, but these can be ignored).

24 fps film sources may also be pulled down for PAL (2:2:2:2:2:2:2:2:2:2:2:3). This may be rather annoying to reverse and requires an IVTC filter instead of a deinterlacer.

25i/50p stuff shot with video cameras is broadcast as interlaced 576i25. This includes some series, news, sports, live events and most commercials. Personally I rarely watch this stuff, so I just deinterlace the video to 25 fps and lose some of the motion fluidity.

Yeah, doesn't work. I've tried myself and watched your samples: It doesn't run well at all on playback. Jumps around wildly.
Apparently your player/decoder does deinterlace but it just gets the field order wrong. This could be fixed by swapping the fields with one of the Avidemux filters. However, some other player/decoder combination might still not work properly. The correct fix is harder to accomplish with Avidemux since one would need a custom-built libx264 and parameters for the field order exposed in the GUI.

nm
10th December 2008, 19:58
So, converting from 25 fps to 50 fps during encoding is actually (almost) doubling the data volume, resulting in larger video files, correct?
Yes, more bitrate is needed to keep the same quality within a frozen frame. However, such a straightforward comparison is not the whole truth since there is also more motion information in the 50 fps output. At higher bitrates, a 50 fps encode is much better than a 25 fps one even when both are done at the same bitrate.

If you are fine with choppier playback, use 25 fps. For example, talking heads probably don't require 50 fps but soccer may need it.