Skip to content

Commit

Permalink
Fix transcoding to high resolutions.
Browse files Browse the repository at this point in the history
When the transcoder loaded the recording profile, the max width and
height fields were not being set properly so transcoding profiles
with high resolutions were instead limited to 768x576.  Since these
max values are set the ImageSize ctor, changing them after the fact
is a bit invasive.  Rather than using a RecordingProfile variable
in Transcode and trying to change the values after the fact, this patch
fixes the issue by using a RecordingProfile pointer and creating an
instance allowing us to tell the constructor that the profile we're
going to load is a transcoder profile and the max resolution values
(and any other transcoder-specific values or limits) should be
set correctly.

Fixes #11348.
  • Loading branch information
cpinkham committed Jun 24, 2013
1 parent feb2e0f commit 2c9bc10
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
65 changes: 34 additions & 31 deletions mythtv/programs/mythtranscode/transcode.cpp
Expand Up @@ -45,6 +45,7 @@ using namespace std;

Transcode::Transcode(ProgramInfo *pginfo) :
m_proginfo(pginfo),
m_recProfile(new RecordingProfile("Transcoders")),
keyframedist(30),
nvr(NULL),
ctx(NULL),
Expand Down Expand Up @@ -75,6 +76,8 @@ Transcode::~Transcode()
delete fifow;
if (kfa_table)
delete kfa_table;
if (m_recProfile)
delete m_recProfile;
}
void Transcode::ReencoderAddKFA(long curframe, long lastkey, long num_keyframes)
{
Expand Down Expand Up @@ -106,16 +109,16 @@ bool Transcode::GetProfile(QString profileName, QString encodingType,
LOG(VB_GENERAL, LOG_NOTICE,
QString("Transcode: Looking for autodetect profile: %1")
.arg(autoProfileName));
result = profile.loadByGroup(autoProfileName, "Transcoders");
result = m_recProfile->loadByGroup(autoProfileName, "Transcoders");

if (!result && encodingType == "MPEG-2")
{
result = profile.loadByGroup("MPEG2", "Transcoders");
result = m_recProfile->loadByGroup("MPEG2", "Transcoders");
autoProfileName = "MPEG2";
}
if (!result && (encodingType == "MPEG-4" || encodingType == "RTjpeg"))
{
result = profile.loadByGroup("RTjpeg/MPEG4",
result = m_recProfile->loadByGroup("RTjpeg/MPEG4",
"Transcoders");
autoProfileName = "RTjpeg/MPEG4";
}
Expand All @@ -139,8 +142,8 @@ bool Transcode::GetProfile(QString profileName, QString encodingType,
profileID = profileName.toInt(&isNum);
// If a bad profile is specified, there will be trouble
if (isNum && profileID > 0)
profile.loadByID(profileID);
else if (!profile.loadByGroup(profileName, "Transcoders"))
m_recProfile->loadByID(profileID);
else if (!m_recProfile->loadByGroup(profileName, "Transcoders"))
{
LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find profile #: %1")
.arg(profileName));
Expand All @@ -159,9 +162,9 @@ void Transcode::SetPlayerContext(PlayerContext *player_ctx)
ctx = player_ctx;
}

static QString get_str_option(RecordingProfile &profile, const QString &name)
static QString get_str_option(RecordingProfile *profile, const QString &name)
{
const Setting *setting = profile.byName(name);
const Setting *setting = profile->byName(name);
if (setting)
return setting->getValue();

Expand All @@ -171,7 +174,7 @@ static QString get_str_option(RecordingProfile &profile, const QString &name)
return QString::null;
}

static int get_int_option(RecordingProfile &profile, const QString &name)
static int get_int_option(RecordingProfile *profile, const QString &name)
{
QString ret_str = get_str_option(profile, name);
if (ret_str.isEmpty())
Expand Down Expand Up @@ -624,31 +627,31 @@ int Transcode::TranscodeFile(const QString &inputname,
}
}

vidsetting = get_str_option(profile, "videocodec");
audsetting = get_str_option(profile, "audiocodec");
vidfilters = get_str_option(profile, "transcodefilters");
vidsetting = get_str_option(m_recProfile, "videocodec");
audsetting = get_str_option(m_recProfile, "audiocodec");
vidfilters = get_str_option(m_recProfile, "transcodefilters");

if (encodingType == "MPEG-2" &&
get_int_option(profile, "transcodelossless"))
get_int_option(m_recProfile, "transcodelossless"))
{
LOG(VB_GENERAL, LOG_NOTICE, "Switching to MPEG-2 transcoder.");
SetPlayerContext(NULL);
return REENCODE_MPEG2TRANS;
}

// Recorder setup
if (get_int_option(profile, "transcodelossless"))
if (get_int_option(m_recProfile, "transcodelossless"))
{
vidsetting = encodingType;
audsetting = "MP3";
}
else if (get_int_option(profile, "transcoderesize"))
else if (get_int_option(m_recProfile, "transcoderesize"))
{
int actualHeight = (video_height == 1088 ? 1080 : video_height);

GetPlayer()->SetVideoFilters(vidfilters);
newWidth = get_int_option(profile, "width");
newHeight = get_int_option(profile, "height");
newWidth = get_int_option(m_recProfile, "width");
newHeight = get_int_option(m_recProfile, "height");

// If height or width are 0, then we need to calculate them
if (newHeight == 0 && newWidth > 0)
Expand Down Expand Up @@ -698,35 +701,35 @@ int Transcode::TranscodeFile(const QString &inputname,
{
nvr->SetOption("videocodec", "mpeg4");

nvr->SetIntOption(&profile, "mpeg4bitrate");
nvr->SetIntOption(&profile, "scalebitrate");
nvr->SetIntOption(&profile, "mpeg4maxquality");
nvr->SetIntOption(&profile, "mpeg4minquality");
nvr->SetIntOption(&profile, "mpeg4qualdiff");
nvr->SetIntOption(&profile, "mpeg4optionvhq");
nvr->SetIntOption(&profile, "mpeg4option4mv");
nvr->SetIntOption(m_recProfile, "mpeg4bitrate");
nvr->SetIntOption(m_recProfile, "scalebitrate");
nvr->SetIntOption(m_recProfile, "mpeg4maxquality");
nvr->SetIntOption(m_recProfile, "mpeg4minquality");
nvr->SetIntOption(m_recProfile, "mpeg4qualdiff");
nvr->SetIntOption(m_recProfile, "mpeg4optionvhq");
nvr->SetIntOption(m_recProfile, "mpeg4option4mv");
#ifdef USING_FFMPEG_THREADS
nvr->SetIntOption(profile, "encodingthreadcount");
nvr->SetIntOption(m_recProfile, "encodingthreadcount");
#endif
}
else if ((vidsetting == "MPEG-2") ||
(recorderOptionsMap["videocodec"] == "mpeg2video"))
{
nvr->SetOption("videocodec", "mpeg2video");

nvr->SetIntOption(&profile, "mpeg2bitrate");
nvr->SetIntOption(&profile, "scalebitrate");
nvr->SetIntOption(m_recProfile, "mpeg2bitrate");
nvr->SetIntOption(m_recProfile, "scalebitrate");
#ifdef USING_FFMPEG_THREADS
nvr->SetIntOption(&profile, "encodingthreadcount");
nvr->SetIntOption(m_recProfile, "encodingthreadcount");
#endif
}
else if ((vidsetting == "RTjpeg") ||
(recorderOptionsMap["videocodec"] == "rtjpeg"))
{
nvr->SetOption("videocodec", "rtjpeg");
nvr->SetIntOption(&profile, "rtjpegquality");
nvr->SetIntOption(&profile, "rtjpegchromafilter");
nvr->SetIntOption(&profile, "rtjpeglumafilter");
nvr->SetIntOption(m_recProfile, "rtjpegquality");
nvr->SetIntOption(m_recProfile, "rtjpegchromafilter");
nvr->SetIntOption(m_recProfile, "rtjpeglumafilter");
}
else if (vidsetting.isEmpty())
{
Expand All @@ -748,7 +751,7 @@ int Transcode::TranscodeFile(const QString &inputname,
if (audsetting == "MP3")
{
nvr->SetOption("audiocompression", 1);
nvr->SetIntOption(&profile, "mp3quality");
nvr->SetIntOption(m_recProfile, "mp3quality");
copyaudio = true;
}
else if (audsetting == "Uncompressed")
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtranscode/transcode.h
Expand Up @@ -48,7 +48,7 @@ class Transcode : public QObject

private:
ProgramInfo *m_proginfo;
RecordingProfile profile;
RecordingProfile *m_recProfile;
int keyframedist;
NuppelVideoRecorder *nvr;
PlayerContext *ctx;
Expand Down

0 comments on commit 2c9bc10

Please sign in to comment.