[mythtv] problem with replex
D. Hugh Redelmeier
hugh at mimosa.com
Mon Feb 18 07:21:25 UTC 2008
| Date: Mon, 7 Jan 2008 02:26:03 -0500 (EST)
| From: D. Hugh Redelmeier <hugh at mimosa.com>
This is a followup to a report I posted over a month ago.
http://mythtv.org/pipermail/mythtv-dev/2008-January/059419.html
I got no reply on the list or from the author of the original replex
code.
Again, my mythbox started filling up its log file in an infinite loop.
Last time I lost a hundred or two gigs of recorded programs,
displaced by this useless log. This time I caught it before anything
was lost.
The code that is doing this is mythreplex, as invoked by mytharchive.
My system is running MythTV from ATRPMS: 0.20.2
The problem arises during the execution of analyze_audio in replex.c.
This routine is given a chunk of an input mpeg file and is supposed to
look for audio frames within it. It seems to think that any sequence
of four bytes that starts with 13 one bits is a frame.
The main while loop continues until it has processed all bytes that it
has been given.
Why does this loop sometimes not terminate? In certain cases, the
cursor does not advance. Once this happens, the loop is doomed to
repeat the same useless iteration forever.
I have a brute force fix: if the cursor has not advanced through
executing the loop, push it ahead one byte. This does not work for
the cases in the loop body that use "continue" but they didn't bite
me. I have included a patch at the bottom of this message.
The revised mythreplex can process the file that hung the vanila
mythreplex. But it still isn't healthy. After a
bunch of processing, mythreplex terminates with the following error:
Error: THIS IS AN MPEG1 FILE
More details:
The infinite loop came during the execution of this command:
mythreplex --demux --fix_sync -o /space/tmp/work/2/stream -v 224 -a 192 "/space/tmp/work/2/newfile.mpg"
The logged output was:
Reading from /space/tmp/work/2/newfile.mpg
Input file length: 574.57 MB
Checking for TS: confirmed
Video output File is: /space/tmp/work/2/stream.mv2
Audio0 output File is: /space/tmp/work/2/stream0.mp2
STARTING DEMUX
read 1%^M
Audiostream: layer: 1 Bit rate: free Freq: 44.1 kHz frame size: 0 ( 0:00:00.008 )
The last line is repeated forever, all on one line.
My modified version prints this. I've inserted a few newlines.
$ ./mythreplex --demux --fix_sync -o 0 -v 224 -a 192 "/space/tmp/work/2/newfile.mpg"
Reading from /space/tmp/work/2/newfile.mpg
Input file length: 574.57 MB
Checking for TS: confirmed
Video output File is: 0.mv2
Audio0 output File is: 00.mp2
STARTING DEMUX
read 1%^MAudiostream: layer: 1 Bit rate: free Freq: 44.1 kHz frame size: 0 ( 0:00:00.008 )
read 2%^Mread 3%^Mread 4%^MAudiostream: layer: 1 Bit rate: free Freq: 44.1 kHz frame size: 0 ( 0:00:00.008 )
Audiostream: layer: 2 BRate: 56 kb/s Freq: 44.1 kHz frame size: 182 ( 0:00:00.026 )
Audiostream: layer: 3 BRate: 40 kb/s Freq: 32.0 kHz frame size: 0 ( 0:00:00.036 )
read 5%^Mread 6%^Mread 7%^Mread 8%^Mread 9%^Mread 10%^Mread 11%^Mread 12%^Mread 13%^Mread 14%^Mread 15%^M
read 16%^Mread 17%^Mread 18%^Mread 19%^Mread 20%^Mread 21%^Mread 22%^Mread 23%^Mread 24%^Mread 25%^Mread 26%^M
read 27%^Mread 28%^Mread 29%^Mread 30%^Mread 31%^Mread 32%^Mread 33%^Mread 34%^Mread 35%^Mread 36%^Mread 37%^M
read 38%^Mread 39%^Mread 40%^Mread 41%^Mread 42%^Mread 43%^Mread 44%^Mread 45%^Mread 46%^Mread 47%^Mread 48%^M
read 49%^Mread 50%^Mread 51%^Mread 52%^Mread 53%^Mread 54%^Mread 55%^Mread 56%^Mread 57%^Mread 58%^Mread 59%^M
read 60%^Mread 61%^Mread 62%^Mread 63%^Mread 64%^Mread 65%^Mread 66%^M
Error: THIS IS AN MPEG1 FILE
$ echo $?
1
$
/space/tmp/work/2/newfile.mpg is a product of mythtranscode, I think.
Here is the relevant part of the log file:
*************************************************************
Processing file 3056_20071026043000.mpg of type recording
*************************************************************
File type is 'mpeg'
Video codec is 'mpeg2video'
Running mythtranscode --mpeg2 to fix any errors
2008-02-17 08:18:10.842 Using runtime prefix = /usr
2008-02-17 08:18:11.110 New DB connection, total: 1
2008-02-17 08:18:11.136 Enabled verbose msgs: important
2008-02-17 08:18:11.153 New DB connection, total: 2
Mux rate: 3.45 Mbit/s
2008-02-17 08:19:02.597 Opening /space/tmp/work/2/newfile.mpg
Input #0, mpeg, from '/space/tmp/work/2/newfile.mpg':
Duration: 00:29:55.9, start: 0.360000, bitrate: 2683 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 352x480, 3008 kb/s, 29.97 fps(r)
Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, 384 kb/s
0: start_time: 0.034 duration: 161.630
1: start_time: 0.032 duration: 161.542
stream: start_time: 0.360 duration: 1795.913 bitrate=2683 kb/s
2008-02-17 08:19:02.633 Calculating frame count
2008-02-17 08:19:11.457 frames = 53847
2008-02-17 08:19:11.459 duration = 1796
streaminfo.xml :-
<?xml version="1.0" ?>
<!DOCTYPE FILEINFO>
<file duration="1796" filename="/space/tmp/work/2/newfile.mpg" type="mpeg">
<streams count="2">
<video aspectratio="1.33333" bitrate="3008800" codec="mpeg2video" ffmpegindex="0" fps="29.97" height="480" id="480" start_time="0.34122" streamindex="0" width="352"/>
<audio bitrate="384000" channels="2" codec="mp2" ffmpegindex="1" id="448" language="N/A" samplerate="48000" start_time="0.32400" streamindex="1"/>
</streams>
</file>
Preferred audio languages eng and eng
Video id: 0x1e0, Audio1: [1] 0x1c0 (MP2, N/A), Audio2: [-1] - 0x-1 (N/A, N/A)
Splitting MPEG stream into audio and video parts
Running: mythreplex --demux --fix_sync -o /space/tmp/work/2/stream -v 224 -a 192 "/space/tmp/work/2/newfile.mpg"
My version of mythreplex has no trouble dealing with 3056_20071026043000.mpg. It says:
Audiostream: layer: 2 BRate: 384 kb/s Freq: 48.0 kHz frame size: 1152 ( 0:00:00.024 )
starting audio PTS: 0:00:00.189
fixing audio PTS inconsistency - diff: 0:00:00.024 - need to remove 1 frame(s)
fixing audio PTS inconsistency - diff: 0:00:00.024 - need to remove 1 frame(s)
fixing audio PTS inconsistency - diff: 0:00:00.024 - need to add 1 frame(s)
encoding an MP2 audio frame
fixing audio PTS inconsistency - diff: 0:00:00.024 - need to add 1 frame(s)
encoding an MP2 audio frame
Video output File is: 0.mv2
Audio0 output File is: 00.mp2
STARTING DEMUX
===> Why is the file /space/tmp/work/2/newfile.mpg corrupted?
===> what is the correct fix for the infinit loop?
Here are my changes to programs/mythtranscode/replex/replex.c
You can safely ignore the line with CALLS. It is just debugging instrumentation.
--- replex.c.REAL 2006-10-01 07:15:02.000000000 -0400
+++ replex.c 2008-02-17 23:35:56.000000000 -0500
@@ -127,6 +127,7 @@
void analyze_audio( pes_in_t *p, struct replex *rx, int len, int num, int type)
{
+ static long CALLS = 0; CALLS++;
int c=0;
int pos=0;
audio_frame_t *aframe = NULL;
@@ -177,6 +178,8 @@
*apes_abort = 0;
off = ring_rdiff(rbuf, p->ini_pos);
while (c < len){
+ int last_c = c;
+
if ( (pos = find_audio_sync(rbuf, buf, c+off, type, len-c) )
>= 0 ){
if (!aframe->set){
@@ -206,7 +209,10 @@
"starting audio PTS: ");
printpts(*fpts);
fprintf(stderr,"\n");
- } else aframe->set = 0;
+ } else {
+ aframe->set = 0;
+ ring_skip(rbuf,pos+c+off+re);
+ }
}
if (aframe->set && first)
@@ -384,7 +390,9 @@
*apes_abort = len-c;
c=len;
}
- }
+ if (c == last_c)
+ c++; /* force SOME progress */
+ }
}
void analyze_video( pes_in_t *p, struct replex *rx, int len)
================ end ================
More information about the mythtv-dev
mailing list