Log in

View Full Version : Demuxing TS with MPEG-4 AVC?


Maxiuca
19th March 2006, 19:48
Hi,

Does anyone know how to demux a transport stream with MPEG-4 AVC video stream (HD)? If demuxing is not possible then maybe it would be possible to somehow feed it into avisynth via DirectShow (i've tried but to play with graphedit and try to play it but I did not succeed)

Such TS can be found for example here:
http://www.dvbmagic.de/download.php?nav=Download-Center&downloadid=26

and here:

http://www.dvbmagic.de/download.php?nav=Download-Center&downloadid=27

These clips are produced by a program delivered with KNC ONE TV-Station DVB-S2 Plus, only PC card so far that can capture european AVC HD streams (german Pro7 and Premiere HD)
(http://www.dvbmagic.de/index.php?nav=DVB-Karten&page=hardware%2Fkncone_tvstation_dvbs2.htm)

Both clips are playable with VLC player.

bond
19th March 2006, 21:21
mplayer -dumpvideo -dumpfile raw.264 video.ts

Maxiuca
19th March 2006, 23:20
mplayer -dumpvideo -dumpfile raw.264 video.ts

Thanks, that did the job, but there is a little problem. The file containing raw h264 strean is playable in both mplayer and VLC but cannot be muxed into MP4 container as there are some errors (mp4box):

"Cannot find H264 start code (BitStream Not Compliant)
Error importing prosieben2.264: BitStream Not Compliant"

I think that probably due to the nature of transport streams the video is not cut on an i-frame and that causes the problem.

I was able to mux the raw stream into avi container and I could open it using both VirtualDub and avs using DS Source.

Anyway, the question is: Can I anyhow "repair" this stream and mux it into a mp4 container?

bond
19th March 2006, 23:28
this has been discussed already :search:

you need to cut away the whole garbage before the first SPS/PPS/Keyframe (which is not decodeable anyways)

Maxiuca
19th March 2006, 23:54
this has been discussed already :search:

you need to cut away the whole garbage before the first SPS/PPS/Keyframe (which is not decodeable anyways)

Thanks, I've serched the forum and found your post regarding this problem:
http://forum.doom9.org/showthread.php?t=95381&page=2 I've cut everything before SPS but then when I mux it with mp4box (mp4box -fps 25 -add prosieben2_i-frame.264 prosieben2.264.mp4) I get:

"AVC-H264 import - frame size 1920 x 544 at 25.000 FPS
Adjusting AVC SizeLength to 16 bits"

and then an Windows error saying that mp4box will be closed.

Strange thing is that both mp4box and avc2avi recognize this stream as 1920x544 whereas it is 1920x1088.

bond
20th March 2006, 00:05
make sure to use an uptodate mp4box compile

Maxiuca
20th March 2006, 00:31
I probably have a new one - ver. 0.4.1, but it wasn't the problem of mp4box.

I've found SPS which was followed by PPS but not by a keyframe. I found the fist key frame in the middle of the file, so I had to cut away half of the video. Now it works :)

I've also tried the second video and in that one I found a keyframe near to beggining so only 600kb had to be cut.

Thanks for the information, now I can feed both video into avisynth via DS, but there is still one last tiny little problem: the resulting mp4 file plays well in all players but is seems that bad resolution is set, 1920x544 instead of 1920x1088 (mp4box reports this resolution when it's adding raw stream to mp4 container) and I get only half of the picture in avisynth.

I was able to change it manually (replacing the values using WinHex) but I'm wondering why does this problem appear (maybe it has something to do with interlacing?)

bond
20th March 2006, 00:39
hm maybe an issue because of the interlacing?

Schmendrick
3rd August 2006, 14:18
@Maxiuca:
How did you manually change the faulty 1920x544 resolution to the correct 1920x1088? I have exactly the same problem when converting a raw H.264-stream (demuxed from a TS-file recorded with a DVB-S2-card using DVBstreamexplorer) into an AVI-stream using AVC2AVI.

Nevertheless having PowerDVD6 installed on my system with the AVC/H.264-decoder included still I am able to decode the H.264-file properly using Avisynth. One issue which still remains is to properly resynchronize the converted video with the original audio AC3-stream as both streams apparently are offset by almost 2.5 seconds.

Maxiuca
3rd August 2006, 15:05
Yes, I've used WinHEX to replace 544 with 1088 and it worked perfectly. I think that after it I was even able to open avi file (after conversion) in VirtualDub (with ffdshow VfW h.264 codecs).

BTW. Where did you get your H.264 card? I'm looking for one but the only ones I could find were KNC1 cards on ebay.de for over 300 Euro...

Schmendrick
3rd August 2006, 16:03
Where exactly do you patch to replace 544 for 1088? I guess it must be in hex the sequence of "20 02" replacing with "40 04" but where can you find the location within the H.264 stream? Behind the key frame location?

Well I have sent the people at KNC-One an email message that I already had ordered the card from them a while ago and somehow persuaded them to deliver a DVB-S2-card to me! :-)
For the regular price of € 205,90 (including shipment and tax).

Maxiuca
3rd August 2006, 22:19
I don't remember, but I think that it had to be changed in two places, both near the cut. I've only did it once to see if it's possible to demux the ts produced by knc1 card and then mux it into mp4 container.
I was checking it as I wanted to buy the card. What I didn't know is that it is so hard to buy it :)

Schmendrick
4th August 2006, 07:58
At the beginning of the AVI-file produced by AVC2AVI I have found three locations at the beginning of the file with the byte sequence "20 02". Changing the third location to "40 04" did the trick.

To synchronize a downsized AVC/H.264-stream back with the original AC3-audio-stream the time offset between the audio- and video-track has to be found. Do you or does anybody else has a clue e.g. how to find the PTS-stamps (time codes) within the TS-stream or a demuxed PES-stream? I try to find at least the time offset at the beginning of a recording to compensate it e.g. by correcting the AC3-stream with "AC3-delay corrector". I know that if there are frame drops within the recording that this does not entirely solve the synchronization problem.

Golgot13
4th August 2006, 16:13
May be Xmuxer can demux the elementary stream (H264 and AC3)
with a correct offset (with no delay between video and audio).

Where did you buy your DVB-S2 card? (some shop have not the card)
Do you have a software bundled with your card to decode H264 video?


Golgot13

Schmendrick
4th August 2006, 17:37
No Xmuxer is not able to demux the streams properly and it also has problems to handle AC3 at all.

I bought the KNC One TV-Station DVB-S2 Plus directly from www.knc1.de . It took a while after ordering and after thorough complaint they eventually shiped the card. Just today I have seen that they have anounced an instant shipment of the cards from August 14th on.
The card is shiped together with PowerDVD6 with an included AVC/H.264-decoder. But be aware, like it has been reported, that you'll need a doubleprocessor system with >3 GHz and 1 GB of system RAM to be able to watch the H.264-video seamlessly.