Click here to Skip to main content
15,112,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am developing a video capture application using Directshow and saving the captured video in Mpeg-2 using Microsoft MPEG-2 Encoder.My application looks like this:

Decklink Video Capture ->

Microsoft MPEG-2 Encoder -> File Writer(.mpg)

Decklink Audio Capture ->

Everything works fine with encoder's default settings.But I want to change some settings e.g. : video bit rate, audio sample rate, etc.
I've read all about MS MPEG-2 Encoder from MSDN :
http://msdn.microsoft.com/en-us/library/dd390678(v=VS.85).aspx,
and I know that these settings can all be adjusted in <b>ICodecAPI</b> interface,but I need help because I'm not sure how to use the <b>ICodecAPI</b> in my code.

Can anyone help me with example or sample code how to do that?

Thank you in advance.
Posted
Updated 30-Aug-11 2:28am
v2
Comments
Sergey Alexandrovich Kryukov 30-Aug-11 11:18am
   
I'm just curious, why stone-age MPEG-2, not MPEG-4? I would understand if you do it to author DVD-video playable on minimal stand-along players, but you want to produce .mpg (in what container format?)...

Also, due to wide use in stand-along players and related market, MPEG-2 is protected by all kinds of licensing limitations.
--SA
dejmk 31-Aug-11 6:36am
   
You are right about old MPEG-2 format. But my input video signal is SD,pal 720x576 and I don't see a reason to capture in MPEG-4.

Reading those docs, it looks to be a simple case of QI'ing the mpeg2 encoder interface for ICodecAPI and then using that interface?

The audio sample rate is accessed using the AVAudioSampleRate guid and the video bitrate with AVEncCommonMaxBitRate and AVEncCommonMeanBitRate

or, have I misunderstood your question?
   
I working with multimedia for a lot of years.

There are 2 microsoft ways to encode mpeg-2 one is using the separate video and audio encoders (also provided by Microsoft) and usage of Muxer with embedded audio and video encoders.
Here is the issues:

The microsoft mpeg-2 video encoder (same issues as I checked with audio):
- the bitrate changes not available I actually try to modify most common options - no luck.
- timestamps are broken - if you use the encoding from capture device or other source who handle the delivering timing this ecoders are works - otherwise forget abt them (the time stamp they produce is the dts only and not pts) even if you use your own muxer system you will get a lot's of issues with that.

The Mpeg-2 encoder with muxing embedded.
Works properly for audio and video input.
- the issue is that it can provide NULL as format block - your output filter should takes care of that.
- once I need to handle decoding h.264 and encode into mpeg-2 it works proper mostly with usage of Microsoft DTV Video Decoder filter for decoding video (Note: this filter is also not good - lot's of reasons) - actually some decoders were not handled NULL format.

Configuring encoder - for m - no luck.
Example the way you can try to :

C++
if (m_pMpeg2Muxer)
	{
		ICodecAPI * pCodecAPI;
		if (SUCCEEDED(m_pMpeg2Muxer->QueryInterface(IID_ICodecAPI,(void**)&pCodecAPI)))
		{
			_variant_t _value;
			if (m_lVideoBitrate > 0)
			{
				_value = m_lVideoBitrate;
				if (FAILED(pCodecAPI->SetValue(&CODECAPI_AVEncCommonMeanBitRate,&_value)))
				{
					m_lVideoBitrate = 0;
				}
			}
			if (m_lVideoBitrate <= 0)
			{
				if (SUCCEEDED(pCodecAPI->GetDefaultValue(&CODECAPI_AVEncCommonMeanBitRate,&_value)))
				{
					m_lVideoBitrate = _value;
					pCodecAPI->SetValue(&CODECAPI_AVEncCommonMeanBitRate,&_value);
				}
			}
			pCodecAPI->Release();
		}
	}
	return NOERROR;


Suggestions: not use the Microsoft Mpeg-2 stuff if you want to handle the all properties of encoding.

Regards,
Sonic.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900