2017-08-29 Fred Gleason <fredg@paravelsystems.com>

* Added '--bitrate=', '--format=', '--normalization-level=',
	'--quality=' and '--samplerate=' switches to rdrender(1).
This commit is contained in:
Fred Gleason 2017-08-29 11:22:40 -04:00
parent 0da7f0acff
commit adece83242
5 changed files with 409 additions and 73 deletions

View File

@ -15979,3 +15979,6 @@
* Updated the rdrender(1) man page.
2017-08-29 Fred Gleason <fredg@paravelsystems.com>
* Added an '--ignore-stops' switch to rdrender(1).
2017-08-29 Fred Gleason <fredg@paravelsystems.com>
* Added '--bitrate=', '--format=', '--normalization-level=',
'--quality=' and '--samplerate=' switches to rdrender(1).

View File

@ -30,7 +30,11 @@
<refsynopsisdiv id='synopsis'>
<cmdsynopsis>
<command>rdrender</command>
<arg choice='opt'><replaceable>OPTIONS</replaceable></arg>
<arg choice='opt'><replaceable>GENERAL OPTS</replaceable></arg>
<arg choice='opt'><replaceable>RENDERING OPTS</replaceable></arg>
<arg choice='opt'><replaceable>AUDIO OPTS</replaceable></arg>
<arg choice='req'><replaceable>logname</replaceable></arg>
<arg choice='req'><replaceable>output-file</replaceable></arg>
<sbr/>
</cmdsynopsis>
</refsynopsisdiv>
@ -38,12 +42,141 @@
<refsect1 id='description'><title>Description</title>
<para>
<command>rdrender</command><manvolnum>1</manvolnum> can be used to render
an existing Rivendell log as a single audio WAV file.
an existing Rivendell log as a single audio file, thus enabling playback
of the rendered content independently of Rivendell.
</para>
<para>
Three different types of options can be given to
<command>rdrender</command><manvolnum>1</manvolnum>: General,
which affect the operation of the program itself, Rendering,
which control how a log is virtually &quot;played&quot; and Audio,
which control the format of the resulting audio file. Each group of
options is documented separately below.
</para>
</refsect1>
<refsect1 id='options'><title>Options</title>
<refsect1 id='general;_options'><title>General Options</title>
<variablelist remap='TP'>
<varlistentry>
<term>
<option>--verbose</option>
</term>
<listitem>
<para>
Be verbose. Among other things, this will cause
<command>rdrender</command><manvolnum>1</manvolnum> to print
a disposition for each log event encountered to standard error.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id='rendering_options'><title>Rendering Options</title>
<variablelist remap='TP'>
<varlistentry>
<term>
<option>--first-line=</option><replaceable>lineno</replaceable>
</term>
<listitem>
<para>
Start rendering the log at line <replaceable>lineno</replaceable>.
This option is mutually exclusive with the
<option>--first-time</option> option, below.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--first-time=</option><replaceable>HH:MM:SS</replaceable>
</term>
<listitem>
<para>
Start rendering the log at the event having a hard-start time
of <replaceable>HH:MM:SS</replaceable>. This option is mutually
exclusive with the <option>--first-line</option> option, above.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--ignore-stops</option>
</term>
<listitem>
<para>
Treat any STOP transitions encountered as if they were PLAY
transitions. If not given, a STOP transition will cause rendering
of the log to be terminated at the point where the STOP was
encountered.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--last-line=</option><replaceable>lineno</replaceable>
</term>
<listitem>
<para>
Stop rendering the log at line <replaceable>lineno</replaceable>-1.
This option is mutually exclusive with the
<option>--last-time</option> option, below.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--last-time=</option><replaceable>HH:MM:SS</replaceable>
</term>
<listitem>
<para>
Stop rendering the log at the event having a hard-start time of
<replaceable>HH:MM:SS</replaceable>.
This option is mutually exclusive with the
<option>--last-line</option> option, above.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--start-time=</option><replaceable>HH:MM:SS</replaceable>
</term>
<listitem>
<para>
Render the log as if it had been started at a time of
<replaceable>HH:MM:SS</replaceable> (useful for ensuring that
dayparted carts play as expected). If not given, the current
system time will be used.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id='audio_options'><title>Audio Options</title>
<variablelist remap='TP'>
<varlistentry>
<term>
<option>--bitrate=</option><replaceable>rate</replaceable>
</term>
<listitem>
<para>
Specify the bitrate to use, in <replaceable>rate</replaceable>
bits per second. Default value is 256000 bits/sec.
</para>
<para>
This setting is meaningful only when used with the
<userinput>MP2</userinput> or <userinput>MP3</userinput> formats.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--channels=</option><replaceable>chans</replaceable>
@ -59,93 +192,103 @@
<varlistentry>
<term>
<option>--first-line=</option><replaceable>lineno</replaceable>
<option>--format=</option><replaceable>format</replaceable>
</term>
<listitem>
<para>
Start the rendered file with line <replaceable>lineno</replaceable>.
This option is mutually exclusive with the
<option>--first-time</option> option, below.
Specify the file and audio encoding format to be used. The
following values for <replaceable>format</replaceable> are
recognized:
</para>
<variablelist>
<varlistentry>
<term><userinput>FLAC</userinput></term>
<listitem>
<para>Free Lossless Audio Codec (.flac)</para>
</listitem>
</varlistentry>
<varlistentry>
<term><userinput>MP2</userinput></term>
<listitem>
<para>MPEG-1 Layer 2 (.mp2)</para>
</listitem>
</varlistentry>
<varlistentry>
<term><userinput>MP3</userinput></term>
<listitem>
<para>MPEG-1 Layer 3 (.mp3)</para>
</listitem>
</varlistentry>
<varlistentry>
<term><userinput>PCM16</userinput></term>
<listitem>
<para>PCM16 audio in a WAV file format (.wav)</para>
</listitem>
</varlistentry>
<varlistentry>
<term><userinput>PCM24</userinput></term>
<listitem>
<para>PCM24 audio in a WAV file format (.wav)</para>
</listitem>
</varlistentry>
<varlistentry>
<term><userinput>VORBIS</userinput></term>
<listitem>
<para>OggVorbis (.ogg)</para>
</listitem>
</varlistentry>
</variablelist>
<para>
Default value is <userinput>PCM16</userinput>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--first-time=</option><replaceable>HH:MM:SS</replaceable>
<option>--normalization-level=</option><replaceable>level</replaceable>
</term>
<listitem>
<para>
Start the rendered file with the event having a hard-start time
of <replaceable>HH:MM:SS</replaceable>. This option is mutually
exclusive with the <option>--first-line</option> option, above.
Peak normalize the audio to <replaceable>level</replaceable> dBFS.
Default value is <userinput>0</userinput>, which will disable
peak normalization.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--ignore-stops</option>
<option>--quality=</option><replaceable>qual</replaceable>
</term>
<listitem>
<para>
Treat any STOP transitions encountered as if they were PLAY.
If not given, a STOP transition will cause rendering of the log
to be terminated at that point.
Specify the quality level to use, in the range
<userinput>-1</userinput> through <userinput>10</userinput>,
inclusive. Default value is <userinput>3</userinput>.
</para>
<para>
This setting is meaningful only when used with the
<userinput>VORBIS</userinput> format.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--last-line=</option><replaceable>lineno</replaceable>
<option>--samplerate=</option><replaceable>rate</replaceable>
</term>
<listitem>
<para>
End the rendered file with line <replaceable>lineno</replaceable>-1.
This option is mutually exclusive with the
<option>--last-time</option> option, below.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--last-time=</option><replaceable>HH:MM:SS</replaceable>
</term>
<listitem>
<para>
End the rendered file with the event immediately prior to the
one having a hard-start time of <replaceable>HH:MM:SS</replaceable>.
This option is mutually exclusive with the
<option>--last-line</option> option, above.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--start-time=</option><replaceable>HH:MM:SS</replaceable>
</term>
<listitem>
<para>
Render the log as if it had been started at a time of
<replaceable>HH:MM:SS</replaceable>. (Useful for ensuring that
dayparted carts play as expected). If not given, the current
system time will be used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--verbose</option>
</term>
<listitem>
<para>
Be verbose. Among other things, this will cause
<command>rdrender</command><manvolnum>1</manvolnum> to print
a disposition for each log event encountered to standard error.
Specify the sample rate to use, in <replaceable>rate</replaceable>
samples per second. Default value is the sample rate configured
in <computeroutput>System Settings</computeroutput> in
<command>rdadmin</command><manvolnum>1</manvolnum>.
</para>
</listitem>
</varlistentry>
@ -153,5 +296,15 @@
</variablelist>
</refsect1>
<refsect1 id='bugs'><title>Bugs</title>
<para>
<command>rdrender</command><manvolnum>1</manvolnum> makes no attempt to
interpret hard-start time values beyond allowing them to be
used to flag the start and end of rendering. (See the
<option>--first-time</option> and <option>--last-time</option> rendering
options).
</para>
</refsect1>
</refentry>

View File

@ -18,6 +18,7 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <errno.h>
#include <math.h>
#include <stdio.h>
@ -25,6 +26,7 @@
#include <rdcart.h>
#include <rdcut.h>
#include <rdconf.h>
#include <rdlog.h>
#include <rdlog_event.h>
#include <rdlog_line.h>
@ -38,7 +40,7 @@ int MainObject::MainLoop()
QString warnings="";
//
// Open Endpoints
// Open Log
//
RDLog *log=new RDLog(render_logname);
if(!log->exists()) {
@ -48,16 +50,53 @@ int MainObject::MainLoop()
RDLogEvent *log_event=new RDLogEvent(RDLog::tableName(render_logname));
log_event->load();
//
// Open Output File
//
SF_INFO sf_info;
SNDFILE *sf_out;
FILE *f;
char tempdir[PATH_MAX];
memset(&sf_info,0,sizeof(sf_info));
sf_info.samplerate=render_system->sampleRate();
sf_info.channels=render_channels;
sf_info.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
SNDFILE *sf_out=sf_open(render_output_filename,SFM_WRITE,&sf_info);
if(sf_out==NULL) {
fprintf(stderr,"rdrender: unable to open output file [%s]\n",
sf_strerror(sf_out));
return 1;
if(render_settings.format()==RDSettings::Pcm16) {
sf_info.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
}
else {
sf_info.format=SF_FORMAT_WAV|SF_FORMAT_PCM_24;
}
if(render_settings_modified) {
//
// 2nd pass will be needed, so just create a placeholder for now
// and then output to a temp file
//
Verbose("Pass 1 of 2");
if((f=fopen(render_output_filename,"w"))==NULL) {
fprintf(stderr,"rdrender: unable to open output file [%s]\n",
strerror(errno));
return 1;
}
fclose(f);
strncpy(tempdir,RDTempDir()+"/rdrenderXXXXXX",PATH_MAX);
render_temp_output_filename=QString(mkdtemp(tempdir))+"/log.wav";
sf_out=sf_open(render_temp_output_filename,SFM_WRITE,&sf_info);
if(sf_out==NULL) {
fprintf(stderr,"rdrender: unable to open temporary file \"%s\" [%s]\n",
(const char *)render_temp_output_filename,
sf_strerror(sf_out));
return 1;
}
Verbose("Using temporary file \""+render_temp_output_filename+"\".");
}
else {
Verbose("Pass 1 of 1");
sf_out=sf_open(render_output_filename,SFM_WRITE,&sf_info);
if(sf_out==NULL) {
fprintf(stderr,"rdrender: unable to open output file [%s]\n",
sf_strerror(sf_out));
return 1;
}
}
//
@ -165,13 +204,28 @@ int MainObject::MainLoop()
}
}
}
sf_close(sf_out);
//
// Process 2nd Pass
//
if(render_settings_modified) {
QString err_msg;
bool ok=false;
Verbose("Pass 2 of 2");
ok=ConvertAudio(render_temp_output_filename,render_output_filename,
&render_settings,&err_msg);
DeleteCutFile(render_temp_output_filename);
if(!ok) {
fprintf(stderr,"rdrender: unable to convert output [%s]\n",
(const char *)err_msg);
}
return 1;
}
fprintf(stderr,"%s",(const char *)warnings);
fflush(stderr);
//
// Clean up
//
sf_close(sf_out);
return 0;
}

View File

@ -27,6 +27,7 @@
#include <qfile.h>
#include <rd.h>
#include <rdaudioconvert.h>
#include <rdaudioexport.h>
#include <rdcart.h>
#include <rdcmd_switch.h>
@ -46,6 +47,17 @@ MainObject::MainObject(QObject *parent)
render_last_line=-1;
render_ignore_stops=false;
//
// Initialize Audio Settings
//
render_settings.setChannels(RDRENDER_DEFAULT_CHANNELS);
render_settings.setSampleRate(0);
render_settings.setFormat(RDRENDER_DEFAULT_FORMAT);
render_settings.setBitRate(RDRENDER_DEFAULT_BITRATE);
render_settings.setQuality(RDRENDER_DEFAULT_BITRATE);
render_settings.setNormalizationLevel(RDRENDER_DEFAULT_NORMALIZATION_LEVEL);
render_settings_modified=false;
//
// Read Command Options
//
@ -67,6 +79,15 @@ MainObject::MainObject(QObject *parent)
render_verbose=true;
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--bitrate") {
render_settings.setBitRate(cmd->value(i).toUInt(&ok));
if(!ok) {
fprintf(stderr,"rdrender: invalid --bitrate argument\n");
exit(1);
}
render_settings_modified=true;
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--channels") {
render_channels=cmd->value(i).toUInt(&ok);
if((!ok)||(render_channels>2)) {
@ -75,6 +96,44 @@ MainObject::MainObject(QObject *parent)
}
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--format") {
QString format=cmd->value(i);
ok=false;
if(format.lower()=="flac") {
render_settings.setFormat(RDSettings::Flac);
render_settings_modified=true;
ok=true;
}
if(format.lower()=="mp2") {
render_settings.setFormat(RDSettings::MpegL2);
render_settings_modified=true;
ok=true;
}
if(format.lower()=="mp3") {
render_settings.setFormat(RDSettings::MpegL3);
render_settings_modified=true;
ok=true;
}
if(format.lower()=="pcm16") {
render_settings.setFormat(RDSettings::Pcm16);
ok=true;
}
if(format.lower()=="pcm24") {
render_settings.setFormat(RDSettings::Pcm24);
ok=true;
}
if(format.lower()=="vorbis") {
render_settings.setFormat(RDSettings::OggVorbis);
render_settings_modified=true;
ok=true;
}
if(!ok) {
fprintf(stderr,"rdrender: unknown --format \"%s\"\n",
(const char *)format);
exit(1);
}
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--first-line") {
render_first_line=cmd->value(i).toInt(&ok);
if((!ok)|(render_first_line<0)) {
@ -111,6 +170,33 @@ MainObject::MainObject(QObject *parent)
}
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--normalization-level") {
render_settings.setNormalizationLevel(cmd->value(i).toInt(&ok));
if(!ok) {
fprintf(stderr,"rdrender: invalid --normalization-level argument\n");
exit(1);
}
render_settings_modified=true;
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--quality") {
render_settings.setQuality(cmd->value(i).toUInt(&ok));
if(!ok) {
fprintf(stderr,"rdrender: invalid --quality argument\n");
exit(1);
}
render_settings_modified=true;
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--samplerate") {
render_settings.setSampleRate(cmd->value(i).toUInt(&ok));
if(!ok) {
fprintf(stderr,"rdrender: invalid --samplerate argument\n");
exit(1);
}
render_settings_modified=true;
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--start-time") {
render_start_time=QTime::fromString(cmd->value(i));
if(!render_start_time.isValid()) {
@ -126,9 +212,14 @@ MainObject::MainObject(QObject *parent)
}
if((render_last_line>=0)&&(render_first_line>=0)&&
(render_last_line<render_last_line)) {
fprintf(stderr,"--last-line must be greater than --first-line\n");
fprintf(stderr,"rdrender: --last-line must be greater than --first-line\n");
exit(1);
}
if(!RDAudioConvert::settingsValid(&render_settings)) {
fprintf(stderr,"rdrender: invalid audio settings\n");
exit(1);
}
render_logname=cmd->key(cmd->keys()-2);
render_output_filename=cmd->key(cmd->keys()-1);
if(render_start_time.isNull()) {
@ -172,6 +263,9 @@ MainObject::MainObject(QObject *parent)
// System Configuration
//
render_system=new RDSystem();
if(render_settings.sampleRate()==0) {
render_settings.setSampleRate(render_system->sampleRate());
}
//
// Station Configuration
@ -241,7 +335,12 @@ bool MainObject::GetCutFile(const QString &cutname,int start_pt,int end_pt,
conv->setCartNumber(RDCut::cartNumber(cutname));
conv->setCutNumber(RDCut::cutNumber(cutname));
RDSettings s;
s.setFormat(RDSettings::Pcm16);
if(render_settings.format()==RDSettings::Pcm16) {
s.setFormat(RDSettings::Pcm16);
}
else {
s.setFormat(RDSettings::Pcm24);
}
s.setSampleRate(render_system->sampleRate());
s.setChannels(render_channels);
s.setNormalizationLevel(0);
@ -275,6 +374,23 @@ void MainObject::DeleteCutFile(const QString &dest_filename) const
}
bool MainObject::ConvertAudio(const QString &srcfile,const QString &dstfile,
RDSettings *s,QString *err_msg)
{
RDAudioConvert::ErrorCode err_code;
RDAudioConvert *conv=new RDAudioConvert(render_station->name(),this);
conv->setSourceFile(srcfile);
conv->setDestinationFile(dstfile);
conv->setDestinationSettings(s);
err_code=conv->convert();
*err_msg=RDAudioConvert::errorText(err_code);
delete conv;
return err_code==RDAudioConvert::ErrorOk;
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);

View File

@ -31,6 +31,7 @@
#include <rdconfig.h>
#include <rddb.h>
#include <rdripc.h>
#include <rdsettings.h>
#include <rdstation.h>
#include <rdsystem.h>
#include <rduser.h>
@ -38,6 +39,10 @@
#include "logline.h"
#define RDRENDER_DEFAULT_CHANNELS 2
#define RDRENDER_DEFAULT_FORMAT RDSettings::Pcm16
#define RDRENDER_DEFAULT_BITRATE 256000
#define RDRENDER_DEFAULT_QUALITY 3
#define RDRENDER_DEFAULT_NORMALIZATION_LEVEL 0
#define RDRENDER_USAGE "[options] <logname> <output-file>\n"
class MainObject : public QObject
@ -59,9 +64,12 @@ class MainObject : public QObject
bool GetCutFile(const QString &cutname,int start_pt,int end_pt,
QString *dest_filename) const;
void DeleteCutFile(const QString &dest_filename) const;
bool ConvertAudio(const QString &srcfile,const QString &dstfile,
RDSettings *s,QString *err_msg);
bool render_verbose;
QString render_logname;
QString render_output_filename;
QString render_temp_output_filename;
unsigned render_channels;
QTime render_start_time;
int render_first_line;
@ -69,6 +77,8 @@ class MainObject : public QObject
QTime render_first_time;
QTime render_last_time;
bool render_ignore_stops;
RDSettings render_settings;
bool render_settings_modified;
RDRipc *render_ripc;
RDStation *render_station;
RDSystem *render_system;