Opened 12 years ago

Closed 12 years ago

#2199 closed defect (fixed)

MtyhArchive failes when encoding transcoded mpeg4 recordings

Reported by: chris@… Owned by: paulh
Priority: minor Milestone: unknown
Component: mytharchive Version:
Severity: medium Keywords:
Cc: Ticket locked: no

Description

It seems that MythArchive? is failing on recordings that have been transcoded using mpeg4. When running the exact same fmpeg command as MythArchive?, which looks like:

ffmpeg -v 1 -i "/mythtv/recordings/The_Young_and_the_Restless_-_2006-08-16,_10-59_AM_-_Jack_and_Gloria_Argue_About_John's_Life_Support.nuv" -r ntsc -target dvd -b 4771 -s 720x480 -acodec ac3 -ab 192 -ac 2 -copyts -aspect 16:9 "/mythtv/tmp/newfile1.mpg"

it results in errors that look like this: Marker bit missing before time_increment_resolution=3946.6kbits/s [mpeg4 @ 0xb7dd87c8]time_base.den==0 [mpeg4 @ 0xb7dd87c8]header damaged Error while decoding stream #0.0 Floating point exception

This error has appears from any recording that was transcoded into mpeg4 using the stock mythtv transcode option.

Change History (13)

comment:1 Changed 12 years ago by anonymous

Priority: majorminor
Severity: highmedium

comment:2 Changed 12 years ago by paulh

Resolution: invalid
Status: newclosed

Is this a problem with MythArchive? as such? Looks more like ffmpeg has problem reading the nuv files produced by mythtranscode.

Does running mytharchivehelper to get the stream info work OK on the file?

mytharchivehelper -i "/mythtv/recordings/The_Young_and_the_Restless_-_2006-08-16,_10-59_AM_-_Jack_and_Gloria_Argue_About_John's_Life_Support.nuv"    
 streaminfo.xml 1

The above should be all on one line.

If it works OK then you need to update ffmpeg to a newer version that uses the latest libavformat and libavcodec libraries.

Marking this as invalid because I think its more of a problem with ffmpeg which is out of my control.

comment:3 Changed 12 years ago by siggy@…

Milestone: 0.20
Priority: minormajor
Resolution: invalid
Status: closedreopened

I'm getting the exact same error on all of my .NUV files. I tried running the mytharchivehelper command mentioned above, the output looks fine:

mytharchivehelper -i "/var/lib/mythtv/recordings/1036_20060713215900.nuv" streaminfo.xml 1
2006-08-29 21:04:41.309 Opening /var/lib/mythtv/recordings/1036_20060713215900.nuv
0: start_time: 0.000 duration: 2.301
1: start_time: 0.000 duration: 2.301
stream: start_time: 0.000 duration: 2300.790 bitrate=1411 kb/s
Input #0, nuv, from '/var/lib/mythtv/recordings/1036_20060713215900.nuv':
  Duration: 00:38:20.7, start: 0.000000, bitrate: 1411 kb/s
  Stream #0.0: Video: mpeg4, yuv420p, 640x480, 29.97 fps(r)
  Stream #0.1: Audio: mp3, 48000 Hz, stereo, 1411 kb/s
2006-08-29 21:04:41.359 Calculating frame count
2006-08-29 21:04:55.300 frames = 59223
2006-08-29 21:04:55.359 duration = 1976

I'm using the latest build of ffmpeg, here's the full output:

ffmpeg -v 1 -i "/var/lib/mythtv/recordings/1036_20060713215900.nuv" -r ntsc -target dvd -b 1526 -s 352x240 -acodec ac3 -ab 128 -ac 2 -copyts -aspect 16:9 "/var/lib/mythtv/recordings/mytharchive//work/1/newfile2.mpg" -map 0:0 -map 0:1
FFmpeg version SVN-r6051, Copyright (c) 2000-2004 Fabrice Bellard
  configuration:
  libavutil version: 49.0.0
  libavcodec version: 51.11.0
  libavformat version: 50.5.0
  built on Aug 22 2006 23:40:32, gcc: 4.1.0 (SUSE Linux)

Seems that stream 0 comes from film source: 1000.00 (1000/1) -> 29.97 (30000/1001)
Input #0, nuv, from '/var/lib/mythtv/recordings/1036_20060713215900.nuv':
  Duration: 00:38:20.7, start: 0.000000, bitrate: 1411 kb/s
  Stream #0.0: Video: mpeg4, yuv420p, 640x480, 29.97 fps(r)
  Stream #0.1: Audio: mp3, 48000 Hz, stereo, 1411 kb/s
Assuming NTSC for target.
Output #0, dvd, to '/var/lib/mythtv/recordings/mytharchive//work/1/newfile2.mpg':
  Stream #0.0: Video: mpeg2video, yuv420p, 352x240, q=2-31, 1526 kb/s, 29.97 fps(c)
  Stream #0.1: Audio: ac3, 48000 Hz, stereo, 128 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
Marker bit missing before time_increment_resolution=1770.5kbits/s
[mpeg4 @ 0x846fa18]time_base.den==0
[mpeg4 @ 0x846fa18]header damaged
Error while decoding stream #0.0
Floating point exception

comment:4 Changed 12 years ago by Isaac Richards

Milestone: 0.20
Priority: majorminor

comment:5 Changed 12 years ago by paulh

Resolution: fixed
Status: reopenedclosed

(In [11019]) ffmpeg has problems reading Myths nuv files and also recordings that have been transcoded to mpeg4 using mythtranscode. This fixes the problem by using mythtranscode to pass the raw audio and video into ffmpeg which then does the re-encoding. It also means that nuv files that aren't in mpeg2 format can also have any commercials removed if a cut list is available.

Fixes #2199.

comment:6 Changed 12 years ago by siggy@…

Resolution: fixed
Status: closedreopened

Thanks for the fix paulh, I'm no longer getting that error, but now I've got a new one:

NameError: global name 'SIGKILL' is not defined

It occurs on line 1364 in mythburn.py:

1364 	    result = runCommand(command)
1365 	    if result != 0:
1366 	        os.kill(PID, SIGKILL)
1367 	        fatalError("Failed while running ffmpeg to re-encode video.\n"
1368 	                   "Command was %s" % command)

I fixed it on my system (SUSE 10.1) by adding this line, but you may find a more elegant way:

1364 	    result = runCommand(command)
1365 	    if result != 0:
 	        SIGKILL = 9
1366 	        os.kill(PID, SIGKILL)
1367 	        fatalError("Failed while running ffmpeg to re-encode video.\n"
1368 	                   "Command was %s" % command)

I'm not sure if I should have started a new ticket for this one, but I'm keeping with this thread just for reference. Thanks again.

comment:7 Changed 12 years ago by paulh

Resolution: fixed
Status: reopenedclosed

(In [11071]) Add the signal module so the script can find the signal constants. Closes #2199.

comment:8 Changed 12 years ago by anonymous

Resolution: fixed
Status: closedreopened

Recommending 2 more changes:

1) I get the following error during transcode:

2006-09-07 15:12:36.903 Using runtime prefix = /usr/local
2006-09-07 15:12:36.919 New DB connection, total: 1
2006-09-07 15:12:36.925 Enabled verbose msgs: important
2006-09-07 15:12:37.027 New DB connection, total: 2
2006-09-07 15:12:37.354 Using protocol version 30 Running ffmpeg: ffmpeg -y -f s16le -ar 48000 -ac 2 -i /var/lib/mythtv/recordings/mytharchive//work/6/audout -f rawvideo -pix_fmt yuv420p -s 640x480 -aspect 1.33333 -r 29.97 -i /var/lib/mythtv/recordings/mytharchive//work/6/vidout -aspect 1.33333 -r 29.97 -s 720x480 -b 4771 -vcodec mpeg2video -qmin 5 -ab 192 -ar 48000 -acodec ac3 -f dvd "/var/lib/mythtv/recordings/mytharchive//work/6/newfile2.mpg"
FFmpeg version SVN-r6051, Copyright (c) 2000-2004 Fabrice Bellard
  configuration:
  libavutil version: 49.0.0
  libavcodec version: 51.11.0
  libavformat version: 50.5.0
  built on Aug 22 2006 23:40:32, gcc: 4.1.0 (SUSE Linux)
/var/lib/mythtv/recordings/mytharchive//work/6/audout: I/O error occured Usually that means that input file is truncated and/or corrupted.
************************************************************
ERROR: Failed while running ffmpeg to re-encode video.
Command was ffmpeg -y -f s16le -ar 48000 -ac 2 -i /var/lib/mythtv/recordings/mytharchive//work/6/audout -f rawvideo -pix_fmt yuv420p -s 640x480 -aspect 1.33333 -r 29.97 -i /var/lib/mythtv/recordings/mytharchive//work/6/vidout -aspect 1.33333 -r 29.97 -s 720x480 -b 4771 -vcodec mpeg2video -qmin 5 -ab 192 -ar 48000 -acodec ac3 -f dvd "/var/lib/mythtv/recordings/mytharchive//work/6/newfile2.mpg"
************************************************************

It ~appears~ to be fixed by changing line 1362 in mythburn.py from:

    time.sleep(2)

to:

    time.sleep(100)

2) The number "1.4" is used as an arbitrary threshold when calculating (height / width) to determine a 16:9 or 4:3 aspect ratio.

Recommend adding a global to mythburn.py:

# if height / width > aspectRatioThreshold, set aspect ratio to 16:9
# if height / width <= aspectRatioThreshold, set aspect ratio to 4:3
aspectRatioThreshold = 1.4

...and replacing all occurrences of "1.4" with "aspectRatioThreshold", or something.

Thanks again.

comment:9 Changed 12 years ago by siggy@…

(oops, forgot to include my address on that last post)

comment:10 Changed 12 years ago by paulh

  1. It would be better to wait for the fifos to be created rather than just put a arbitory sleep() in there I think.
  1. It's not actually the width and height of the video frames that determin the aspect ratio. You could have two files with the same resolution but will be displayed with different AR's. The AR tells the decoder/player how to scale the video to the correct dimensions so it will look right. The 1.4 value is used so we don't have to worry about the precision the AR is stored in or how its been rounded. For example 4:3 could be 1.3333333 or 1.33 or 1.34. I still need to be convinced by this one :-) What values for AR are you seeing that you need to do this?

comment:11 Changed 12 years ago by paulh

(In [11102]) Wait for mythtranscode to create the fifos before trying to run ffmpeg. Refs #2199.

comment:12 Changed 12 years ago by siggy@…

1) Thanks for the fix!

2) The case I run into is that my source video files are 640x480, but using the SP encoding profile when running MythArchive?, they are converted to 720x480 (1.5), which evaluates to 16:9. I solved this issue by setting the DVD Menu AR to 4:3, so the "1.4" threshold is never used. It would be "nice to have" mythburn keep track of the original height/width ratio, but its not a big deal, since everything works fine when you set the DVD Menu AR. My main point was that there's a threshold, "1.4", that appears several times in the script, just thought it would look cleaner to define that threshold globally.

comment:13 Changed 12 years ago by paulh

Resolution: fixed
Status: reopenedclosed

(In [11215]) Fix the final part of #2199 - makes the threshold value used to determin if an aspect ratio should be treated as 4:3 or 16:9 a constant defined at the top of the script. Closes #2199.

Note: See TracTickets for help on using tickets.