Opened 17 years ago

Closed 14 years ago

#2972 closed task (wontfix)

Enhance Software encoder to support other codecs and container formats.

Reported by: cpinkham Owned by: cpinkham
Priority: minor Milestone: unknown
Component: MythTV - Recording Version: head
Severity: low Keywords:
Cc: Ticket locked: no

Description

This ticket is being created to track committing of patches related to enhancing the software encoding side of MythTV to support additional codecs and container formats. Initially this will only be things like MPEG-2 video in a MPEG-PS file, but could be expanded on later.

This support is still a ways off. I have a partially working patch on my system, but also have several patches that are precursors to this support that have been sitting on my system for a while now. Some of these are minor and can stand alone so I wanted to be able to get them out of my tree and in SVN while also tracking them as part of the bigger picture.

Change History (20)

comment:1 Changed 17 years ago by cpinkham

(In [12617]) Move the avformat assist functions out from avformatdecoder.cpp into separate avfringbuffer.cpp/h files so we can use them elsewhere (like in the software encoder). Fill out the write function which was a stub previously.

open_avf -> AVF_Open read_avf -> AVF_Read write_avf -> AVF_Write seek_avf -> AVF_Seek close_avf -> AVF_Close

rbuffer_protocol -> AVF_RingBuffer_Protocol

avf_write_packet -> AVF_Write_Packet avf_read_packet -> AVF_Read_Packet avf_seek_packet -> AVF_Seek_Packet

Create a AVFRingBuffer wrapper class which keeps track of the RingBuffer? being used so it can be used as the URLContext priv_data instead of the AvFormatDecoder? instance itself.

References #2972.

comment:2 Changed 17 years ago by cpinkham

(In [13465]) Add the fourcc code for MPEG2 video to a few places. References #2972.

comment:3 Changed 17 years ago by cpinkham

(In [13475]) Add the ability to capture MPEG-2 video from the go7007 driver. The setting to enable this is currently commented out in recordingprofile.cpp. To turn it on to test, uncomment the following line around line number 825 in libs/libmythtv/recordingprofile.cpp.

codecName->addSelection("MPEG-2");

I get lots of "concealing ... MV errors" and "end mismatch" warnings from libavcodec's decoder when I turn this on even though the video appears to play fine, so I'm leaving this commented out by default for now. It is mainly being added so I can progress further on other related work. Mplayer plays the resulting MPEG-2/MP3 .nuv file fine as well but with the same warnings when I use "mplayer -vc ffmpeg12,mpeg12" to force the libavcodec decoder.

This commit renames the mpeg4scalebitrate setting to scalebitrate so it can be reused for both MPEG-4 and MPEG-2 encoding. The old setting is left in the codecparams table to maintain the ability to rollback to an older version.

References #2972.

One step closer to writing out container formats other than .nuv (like mpeg-ps)

comment:4 Changed 17 years ago by cpinkham

(In [13476]) Rename a few variables and one method to reflect that they are for the video codec since we'll have a set for audio eventually.

codec -> videocodec mpa_ctx -> mpa_vidctx mpa_codec -> mpa_vidcodec SetupAVCodec() -> SetupAVCodecVideo()

References #2972.

comment:5 Changed 17 years ago by cpinkham

(In [13477]) Missed 2 "codec" -> "videocodec" changes in [13476].

References #2972.

comment:6 Changed 17 years ago by cpinkham

(In [13509]) Rename a few variables and methods in the NuppelDecoder? related to libavcodec to indicate that they are for video since there will be accompanying audio versions a little later. No functional changes in this commit.

mpa_ctx -> mpa_vidctx; mpa_codec -> mpa_vidcodec; InitAVCodec() -> InitAVCodecVideo(); CloseAVCodec() -> CloseAVCodecVideo();

References #2972.

comment:7 Changed 17 years ago by cpinkham

(In [13510]) Fix the lossy side of mythtranscode to convert over audio packets one-for-one in the output when encoding. Previously if a second audio packet came in while another was still in the buffer, they both would get encoded in a single packet in the output. The Lame decoder appears to handle this fine, but libavcodec does not. The guys on ffmpeg-devel have said we shouldn't have 2 MP3 frames in the same audio packet, so this patch fixes mythtranscode so it doesn't combine the two.

This problem manifests itself if you transcode a file to .nuv using mythtranscode and later tried to use another libavcodec program to transcode it again. libavcodec would ignore the second frame of audio in the packet and your audio would play fast or skip depending on the player.

This will not fix old recordings, the fix for that is in libavcodec which I will commit separately. I am waiting on the guys at ffmpeg-devel for a little guidance in submitting a patch upstream to them, in case they want to solve the problem differently than I have. In order to use another libavcodec program to transcode one of these 'broken' nuv files, upstream will have to be fixed. I am going to fix our copy of libavcodec because I have another patch related to #2972 that uses libavcodec for decoding mp3.

References #2972.

comment:8 Changed 17 years ago by cpinkham

(In [13511]) Put in a (temporary) patch in libavcodec to allow decoding packets with multiple MP3 frames in them. Previously the MP3 decoder's decode_frame() function would indicate that it had consumed all the data in the packet and would cause the MythTV decoder code to ignore the rest of the packet. Now, decode_frame will indicate how much data it consumed so our decoder can recall the libavcodec routine if necessary.

I am waiting on the guys at ffmpeg-devel for a little guidance in submitting a patch upstream to them, in case they want to solve the problem differently than I have. In order to use another libavcodec program to transcode one of these 'broken' nuv files, upstream will have to be fixed. Once upstream is fixed, then this patch can be reverted.

References #2972. The fix for the MythTV issue creating these out of spec packets was fixed in [13510].

comment:9 Changed 17 years ago by cpinkham

(In [13512]) Modify NuppelDecoder? to use libavcodec to decode the MP3 audio instead of using lame directly.

Also add the ability to decode AC3 audio in the nuppel file if present. SVN HEAD can not currently write AC3 to a nuppel file, but that is something else I have a patch in my tree for. This is leading to allowing maintaining the AC3 audio when transcoding from MPEG-2/.mpg to MPEG-4/.nuv.

If you notice any audio issues when playing nuppel files, try reverting this patch to see if it cures the issue. I have tested this with transcoded and 'new' nuppel files generated directly from NuppelVideoRecorder? and everything seems to be working correctly.

References #2972.

comment:10 Changed 17 years ago by cpinkham

(In [13523]) Revert the libavcodec/mpegaudiodec.c patch I made in [13511] in favor of the 1-line fix that the ffmpeg guys made in their SVN tree after I contacted them. This way we don't have to merge in the change later when we resync again.

I'm leaving in an if statement to squelch most of the "incorrect frame size" messages since these will occur very very frequently when playing an old .nuv file that was transcoded with mythtranscode before I committed [13510]. We can remove this if statement at a later time if we want to or maintain it in our libavcodec tree for a while if we want so people's logs don't fill up with these warnings.

References #2972.

comment:11 Changed 17 years ago by cpinkham

(In [13571]) Fix a buffer overflow in [13510] caused by not resetting a counter in AudioReencodeBuffer::Reset() in the transcoder during lossless .nuv transcoding.

Closes #3538 and references #2972.

comment:12 Changed 16 years ago by cpinkham

(In [15102]) Cleanup a couple minor things related to software encoding out of my tree. Should have no impact on current usage.

References #2972.

comment:13 Changed 16 years ago by cpinkham

(In [16535]) Allow mythtranscode to write its output to stdout if the output filename given on the command line is '-'. This has the side-effect of turning off all verbose output (effectively "-v none") because VERBOSE logs to stdout.

References #2972.

comment:14 Changed 16 years ago by cpinkham

(In [16536]) Add a --recorderOptions (or -ro) parameter for the lossy side of mythtranscode to allow overriding recordingprofile settings from the database. For example:

mythtranscode -i infile.mpg -p autodetect -ro width=320,height=240 -o out.nuv

References #2972.

comment:15 Changed 16 years ago by cpinkham

(In [16537]) That's what I get for moving a couple lines of code and not doing better regression testing.

Bugfix for [16535]. I wasn't turning off the verbose output soon enough so the output file was garbled.

References #2972.

comment:16 Changed 16 years ago by cpinkham

(In [16538]) Allow GO7007/ConvertX users to encode video as MPEG-2 in their .nuv files. This code has not been widely tested, but was added way back in [13475]. Recording and playback appeared to work fine, there were just a lot of warnings from the decoder. Allowing users to use MPEG-2 will get the code some wider testing as well as allowing people to convert to DVD format without having to reencode the video if it was recorded in a compatible MPEG-2 format to begin with.

Refs #2972.

comment:17 Changed 15 years ago by Dibblah

Status: newassigned

comment:18 Changed 15 years ago by cpinkham

(In [20321]) Initialize (URLContext*)->priv_data in AVF_Open() in case one of the other AVF_* functions gets called before we can allocate a AVFRingBuffer and assign it. This can happen if we use libavformat/aviobuf.c's url_fopen() which calls avio.c's url_open() which calls url_open_protocol(). The URLContext isn't allocated until url_open_protocol() gets called, but url_open_protocol immediately tries to do a url_seek() (aka AVF_Seek()) which depend(s|ed) on priv_data already being pointed to an AVFRingBuffer.

The bug didn't affect current usage, but showed up as a segfault when writing files using libavformat via our RingBuffer? class.

References #2972.

comment:19 Changed 14 years ago by stuartm

Component: mythtvMythTV - Recording

comment:20 Changed 14 years ago by cpinkham

Resolution: wontfix
Status: assignedclosed

Close this 3-year-old self-task since I doubt I'll be working on it anytime soon and others may get to it before me. If anyone wants to look at my latest patch I made the last time I updated it to trunk a year ago, just shoot me an email.

Feature request without a (completed) patch, no soup for you!! :)

Note: See TracTickets for help on using tickets.