digitalFAQ.com Forum

digitalFAQ.com Forum (https://www.digitalfaq.com/forum/)
-   Edit Video, Audio (https://www.digitalfaq.com/forum/video-editing/)
-   -   Software to repair broken MPEG stream? (https://www.digitalfaq.com/forum/video-editing/3360-software-repair-broken.html)

gopher 08-08-2011 07:07 AM

Software to repair broken MPEG stream?
 
Hey folks
i have encoded a few vhs tapes to mpegts with an adtec edje2000 realtime network video encoder.
The encoder works great and produces great quality mpeg video that is compatiable with dvd format without re-encoding

the original capture i used ffmpeg

Code:

ffmpeg udp://224.0.1.250:2000 -format mpegts -acodec copy -vcodec copy tape1.ts
ffprobe shows the file as
Code:

Input #0, mpegts, from 'tape.ts':
  Duration: 00:35:53.49, start: 1.400000, bitrate: 8827 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0.0[0x100]: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 8000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x101](eng): Audio: mp2, 48000 Hz, stereo, s16, 192 kb/s

The problem i have is there are parts of the video where the tape is damaged, or when the sceens change and the encoder drops out for a few frames. This causes the audio and video to go out of sync. I have ordered a TBC to deal with this, but in the meantime i would like to fix the sync with software.

I cut up the file with mpegstreamclip to dump the transports stream into the different mpg files for each chapter. I made sure "fix timecode breaks" and "fix stream with data breaks" were both selected. here is the ffprobe for the files

Code:

Input #0, mpeg, from './track01.mpg':
Duration: 00:10:22.07, start: 1.000000, bitrate: 8147 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 8000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16, 192 kb/s

ok soo far so good.


i tried to process the file with dvdauthor but got this

Code:

#VIDEO_FORMAT=NTSC dvdauthor -o dvd/ -t ./track01.mpg
DVDAuthor::dvdauthor, version 0.7.0.
Build options: gnugetopt imagemagick iconv freetype fribidi fontconfig
Send bug reports to <dvdauthor-users@lists.sourceforge.net>

INFO: default video format is NTSC
INFO: dvdauthor creating VTS
STAT: Picking VTS 01

STAT: Processing ./track01.mpg...
WARN: Skipping sector, waiting for first VOBU...
WARN: Skipping sector, waiting for first VOBU...
WARN: Skipping sector, waiting for first VOBU...
WARN: Skipping sector, waiting for first VOBU...
WARN: Skipping sector, waiting for first VOBU...

Sooo i realize i shoulded exported the video as headed mpg in streamclip. but i didnt know.

so i fixed it with mencoder

Code:

mencoder ../track01.mpg -of mpeg -oac copy -ovc copy -mpegopts format=dvd:tsaf -vf harddup -o ./track01_copy.mpg

MEncoder 1.0rc4-4.5.2 (C) 2000-2010 MPlayer Team
success: format: 0  data: 0x0 - 0x25c38453
MPEG-PS file format detected.
VIDEO:  MPEG2  720x480  (aspect 2)  29.970 fps  8000.0 kbps (1000.0 kbyte/s)
[V] filefmt:2  fourcc:0x10000002  size:720x480  fps:29.970  ftime:=0.0334
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 48000 Hz, 2 ch, s16le, 192.0 kbit/12.50% (ratio: 24000->192000)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
PACKET SIZE: 2048 bytes, deltascr: 43885
videocodec: framecopy (720x480 24bpp fourcc=10000002)
audiocodec: framecopy (format=50 chans=2 rate=48000 bits=16 B/s=24000 sample-1)
Limiting audio preload to 0.4s.
Increasing audio density to 4.
Writing header...
INITV: 0.200, 0.167, fps: 29.970
Pos:  0.7s    21f ( 0%)  0.00fps Trem:  0min  0mb  A-V:0.067 [0:192]
Skipping frame!
--- ( ALOT OF THESE MESSAGES )
1 duplicate frame(s)!
Writing index...32f (100%) 897.56fps Trem:  0min 613mb  A-V:-0.060 [7945:192]
Overhead: 1.763% (11148904 / 632555928)
Writing header...
Video stream: 7945.732 kbit/s  (993216 B/s)  size: 617636208 bytes  621.855 secs  18532 frames
Audio stream:  192.000 kbit/s  (24000 B/s)  size: 14924736 bytes  621.864 secs

my ffprobe at this point shows

Code:

Input #0, mpeg, from 'track01_copy.mpg':
  Duration: 00:10:21.82, start: 0.233367, bitrate: 8281 kb/s
    Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 8000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16, 192 kb/s

i then used dvd author to create the dvd structure

Code:

VIDEO_FORMAT=NTSC dvdauthor -o dvd/ -t ./track01_copy.mpg
DVDAuthor::dvdauthor, version 0.7.0.
Build options: gnugetopt imagemagick iconv freetype fribidi fontconfig
Send bug reports to <dvdauthor-users@lists.sourceforge.net>

INFO: default video format is NTSC
INFO: dvdauthor creating VTS
STAT: Picking VTS 01

STAT: Processing ./track01_copy.mpg...
STAT: VOBU 1232 at 610MB, 1 PGCs
INFO: Video pts = 0.231 .. 622.086
INFO: Audio[8] pts = 0.231 .. 621.903
STAT: VOBU 1238 at 613MB, 1 PGCs
CHAPTERS: VTS[1/1] 0.000
INFO: Generating VTS with the following video attributes:
INFO: MPEG version: mpeg2
INFO: TV standard: ntsc
INFO: Aspect ratio: 4:3
INFO: Resolution: 720x480
INFO: Audio ch 0 format: mp2/2ch,  48khz 20bps

STAT: fixed 1238 VOBUs

I then add the table of contents

Code:

VIDEO_FORMAT=NTSC dvdauthor -o dvd/ -T
DVDAuthor::dvdauthor, version 0.7.0.
Build options: gnugetopt imagemagick iconv freetype fribidi fontconfig
Send bug reports to <dvdauthor-users@lists.sourceforge.net>

INFO: default video format is NTSC
INFO: dvdauthor creating table of contents
INFO: Scanning dvd/VIDEO_TS/VTS_01_0.IFO


If i burn the dvd or play in VLC the are a some spots where the video is still damaged and freezes because and the audio/video becomes out of sync.
Is there any software that can sanitize a mpeg ts/ps and replace areas of damaged video with blank video or something? seems as all programs can detect the errors, but none can handle them?

admin 08-08-2011 07:31 AM

Take a look at Restream. Some of its "fixer" abilities are mentioned here: Correct MPEG Field Order (Fix MPEG with Restream)
Download here: http://www.digitalfaq.com/forum/vide...eg-repair.html

It will probably stay glitchy-looking, however. To fully remove or hide stream errors, you'll have to manually repaint the bad frames. No software exists to automatically fix this, because it would honestly take some kind of AI (artificial intelligence) to be able to determine what is "noise" vs what is simply a busy frame of content.

Another tool that works, with varying success, is PVAStrumento, a discontinued tool. (Official site.) All this one really does it drop video frames when the accompanying audio goes out of sync. That was a common problem in past years, with certain stream sources (DVB) and really crappy MPEG-1/MPEG-2 capturing software (PowerVCR II, for example).

gopher 08-08-2011 07:57 AM

I split the video into elementary streams with mpegstreamclip and ran the video through restreamer

I selected correct sequence extension length and reset timestamps

remuxed shows the following

Code:

$ mplex -f 8 -o 01_remuxed.mpg ./01.m2v ./01.mpa
  INFO: [mplex] mplex version 1.9.0 (2.2.7 $Date: 2006/02/01 22:23:01 $)
  INFO: [mplex] File ./01_larry_guitar.0.m2v looks like an MPEG Video stream.
  INFO: [mplex] File ./01.mpa looks like an MPEG Audio stream.
  INFO: [mplex] Video stream 0: profile 8 selected - ignoring non-standard options!
  INFO: [mplex] Found 1 audio streams and 1 video streams
  INFO: [mplex] Selecting dvdauthor DVD output profile
  INFO: [mplex] Multiplexing video program stream!
  INFO: [mplex] Scanning for header info: Video stream e0 (./01.m2v)
  INFO: [mplex] VIDEO STREAM: e0
  INFO: [mplex] Frame width    : 720
  INFO: [mplex] Frame height    : 480
  INFO: [mplex] Aspect ratio    : 4:3 display
  INFO: [mplex] Picture rate    : 29.970 frames/sec
  INFO: [mplex] Bit rate        : 8000000 bits/sec
  INFO: [mplex] Vbv buffer size : 229376 bytes
  INFO: [mplex] CSPF            : 0
  INFO: [mplex] Scanning for header info: Audio stream c0 (./01.mpa)
  INFO: [mplex] MPEG AUDIO STREAM: c0
  INFO: [mplex] Audio version  : 1.0
  INFO: [mplex] Layer          :        2
  INFO: [mplex] CRC checksums  :      no
  INFO: [mplex] Bit rate      :    24576 bytes/sec (192 kbit/sec)
  INFO: [mplex] Frequency      :    48000 Hz
  INFO: [mplex] Mode          :        0 stereo
  INFO: [mplex] Mode extension :        3
  INFO: [mplex] Copyright bit  :        0 no copyright
  INFO: [mplex] Original/Copy  :        0 copy
  INFO: [mplex] Emphasis      :        0 none
  INFO: [mplex] SYSTEMS/PROGRAM stream:
  INFO: [mplex] rough-guess multiplexed stream data rate    : 8365848
  INFO: [mplex] target data-rate specified              : 10080000
  INFO: [mplex] Setting specified specified data rate: 10080000
  INFO: [mplex] Run-in delay = 9009 Video delay = 9009 Audio delay = 12012
  INFO: [mplex] New sequence commences...
  INFO: [mplex] Video e0: buf=      0 frame=000000 sector=00000000
  INFO: [mplex] Audio c0: buf=      0 frame=000000 sector=00000000
++ WARN: [mplex] Stream e0: data will arrive too late sent(SCR)=9069 required(DTS)=9009
++ WARN: [mplex] Video e0: buf= 123512 frame=000000 sector=00000061
++ WARN: [mplex] Audio c0: buf=      0 frame=000000 sector=00000000
  INFO: [mplex] Scanned to end AU 18597
  INFO: [mplex] STREAM e0 completed
  INFO: [mplex] STREAM c0 completed
  INFO: [mplex] Multiplex completion at SCR=55982080.It will probably stay glitchy-looking, however. To fully remove or hide stream errors, you'll have to manually repaint the bad frames. No software exists to automatically fix this, because it would honestly take some kind of AI (artificial intelligence) to be able to determine what is "noise" vs what is simply a busy frame of content.

  INFO: [mplex] Video e0: completed
  INFO: [mplex] Audio c0: completed
  INFO: [mplex] VIDEO_STATISTICS: e0
  INFO: [mplex] Video Stream length:  617664502 bytes
  INFO: [mplex] Sequence headers:    1216
  INFO: [mplex] Sequence ends  :        1
  INFO: [mplex] No. Pictures    :    18598
  INFO: [mplex] No. Groups      :    1238
  INFO: [mplex] No. I Frames    :    1238 avg. size109568 bytes
  INFO: [mplex] No. P Frames    :    5008 avg. size 44485 bytes
  INFO: [mplex] No. B Frames    :    12352 avg. size 20987 bytes
  INFO: [mplex] Average bit-rate :  7962400 bits/sec
  INFO: [mplex] Peak bit-rate    : 11535200  bits/sec
  INFO: [mplex] BUFFERING min 15 Buf max 235543
  INFO: [mplex] AUDIO_STATISTICS: c0
  INFO: [mplex] Audio stream length 14928192 bytes.
  INFO: [mplex] Syncwords      :    25917
  INFO: [mplex] Frames        :    25917 padded
  INFO: [mplex] Frames        :        0 unpadded
  INFO: [mplex] BUFFERING min 15 Buf max 587
**ERROR: [mplex] MUX STATUS: Frame data under-runs detected!


video plays smoother, but audio sync is bad perhaps worse after the point of damaged frames

this is a sample of vlc errors
Code:

00 motion_type at 0 1
ac-tex damaged at 0 16
invalid mb type in P Frame at 4 17
invalid mb type in P Frame at 3 18
00 motion_type at 7 19
00 motion_type at 13 20
00 motion_type at 0 21
00 motion_type at 13 22
00 motion_type at 25 23
invalid mb type in P Frame at 13 24
ac-tex damaged at 7 25
invalid cbp at 0 26
slice mismatch
00 motion_type at 9 28
ac-tex damaged at 8 29

humm ... any ideas?

EDIT
i just reread your post. I dont have a real good understanding of mpeg2
isnt there a timecode in the mpeg2 that it can resync to? If theres a skipor if it see the same errors vlc sees, rewrite the bad frames with black frames?

admin 08-08-2011 09:46 PM

There are lot of ways to build MPEG streams, and not all of them are able to compensate for glitches. For example, a common problem caused by dropped frames during MPEG captures is audio sync, because the audio doesn't also drop. So you end up with a audio file that is longer than the video, yet muxed together as a complete mess.

Broadcasted long-GOP transport streams generally dump bad data and resume with in-sync content at the next good received packet. (However, from time to time, you will find low-budget channels or re-broadcast ops that use bad gear/methods, and can show a channel for hours out of sync!)

Once a mess is created, you'd have to fix this manually.
Or with a computer, using a kind of AI that doesn't yet exist, and can perform to the same level as a human.

A common problem is also converting TS to program stream, which is known to muck up the a/v sync. That's the reason PVAStrumento was created, even if it did work poorly, and comes from an era where that was a bigger problem. The MPEG goes from bad to worse.

You're not alone -- I ruined a video capture about 7 years ago, from live TV. At least you still have the original tape, and can make another attempt. From what I can gather in your first post, it looks like the unstable analog stream, possibly mixed with your choice of capture software/method, caused it. That's exactly how this used to happen, back in 2001-2004.

Your capture appliance looks nice, so it may be mostly isolated to the computer hardware and capture software, as well as the already-mentioned lack of TBC (unstable analog input). How fast is this computer? MPEG encoding can really stress a CPU and system I/O (hard drive). That may be the cause of your drops.

Did you read the Guide for Dropped Frames & Audio Sync Errors? That may be worth reading.

Are you sure your gigabit ethernet is up to the task? Short CAT6 cables, for example, will help. Same for having a quality ethernet card in the computer.

It's obvious you're getting lost data in the chain of hardware. It may simply be due to analog loss, where the TBC would fix it. Or it could be cumulative errors, between a mix of analog and computer (drives, CPU, ethernet, etc). And that's always the most frustrating type of error -- the accumulated ones. The only thing worse than that are cascading errors, which can look like cumulative errors early into troubleshooting.

gopher 08-08-2011 11:10 PM

mr admin. thanks for the reply.
i spent my entire day goofin around. im gonna take a break from this until my TBC i just bought on ebay comes in the mail.
I think im loosing data when the tracking on the vcr goes wacky and the encoder stops encoding. Also i am going to try a direct connection from the network encoder directly to the PC with a crossover cable. The udp multicast traffic put out by this thing is massive and my switch might not be up to the task ( IGMP ). the tbc is a sony mpu-f100a, hope it works


All times are GMT -5. The time now is 07:57 AM

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.