summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-09-19 13:25:51 +0100
committerTim Redfern <tim@eclectronics.org>2013-09-19 13:25:51 +0100
commitcb4b17f617e998fb64cf20e13bd05b5f31f240ce (patch)
treef9eb2bb15e9d8f207b1512b4da37da7ac991fd52 /rotord
parentb57c742e2df5c8f495a3b4dbf4a9e56a4aab9f7e (diff)
reduce bit rate
Diffstat (limited to 'rotord')
-rw-r--r--rotord/src/graph.cpp2
-rw-r--r--rotord/src/graph.h9
-rw-r--r--rotord/src/libavwrapper.cpp47
-rw-r--r--rotord/src/libavwrapper.h7
-rw-r--r--rotord/src/rendercontext.cpp19
5 files changed, 56 insertions, 28 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp
index eada044..0cc36de 100644
--- a/rotord/src/graph.cpp
+++ b/rotord/src/graph.cpp
@@ -98,7 +98,7 @@ bool Graph::video_render(const string &output_filename,const float framerate) {
}
//
//setup defaults
- int bitRate=5000000;
+
AVCodecID codecId=AV_CODEC_ID_H264; //MPEG4;
std::string container;
Poco::StringTokenizer t(output_filename,".");
diff --git a/rotord/src/graph.h b/rotord/src/graph.h
index 58861ac..cc531cd 100644
--- a/rotord/src/graph.h
+++ b/rotord/src/graph.h
@@ -20,6 +20,7 @@ namespace Rotor {
Graph(const string& _uid,const string& _desc){
init(_uid,_desc);
audio_loaded=false;
+ bitRate=1000000;
};
void init(const string& _uid,const string& _desc){
uid=_uid;
@@ -54,6 +55,13 @@ namespace Rotor {
bool print_features(xmlIO &XML,string &node);
bool load_audio(const string &filename,vector<Audio_processor*> processors);
bool load_video(const string &nodeID,const string &filename);//can be performance or clip
+ bool set_bitrate(int b){
+ if (b>64000){
+ bitRate=b;
+ return true;
+ }
+ else return false;
+ }
bool loaded;
float duration;
float framerate;
@@ -63,6 +71,7 @@ namespace Rotor {
string audio_filename;
bool cancelled;
float progress;
+ int bitRate;
private:
int outW,outH;
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp
index 65bbeb5..406adb1 100644
--- a/rotord/src/libavwrapper.cpp
+++ b/rotord/src/libavwrapper.cpp
@@ -168,9 +168,22 @@ bool libav::exporter::record(std::string filename){
video_st->time_base = video_st->codec->time_base;
//audioStream->time_base = codecCtx->time_base; //???has the capability of crashing
- video_st->codec->gop_size = 10; /* emit one intra frame every ten frames */
+ video_st->codec->gop_size = 75; /* emit one intra frame every ten frames */
video_st->codec->pix_fmt = PIX_FMT_YUV420P;
+
+ //video_st->codec->bit_rate = bitRate; //need to deal with resolution etc
+ //video_st->codec->rc_max_rate = bitRate;
+ //video_st->codec->rc_min_rate = 0;
+
+ //how to set profile????? 190913
+ //this causes a crash
+ //av_opt_set(video_st->codec->priv_data,"profile",FF_PROFILE_H264_CONSTRAINED_BASELINE, 0);
+ //
+ // http://libav-users.943685.n4.nabble.com/Libav-user-encoding-bitrate-wrong-td4433740.html
+ // http://libav-users.943685.n4.nabble.com/Libav-user-H264-encoding-set-target-average-bitrate-td3912529.html
+ // http://trac.ffmpeg.org/wiki/x264EncodingGuide
+
// Now that all the parameters are set, we can open the audio and
// * video codecs and allocate the necessary encode buffers. //
if (video_st)
@@ -195,27 +208,13 @@ bool libav::exporter::record(std::string filename){
}
}
-<<<<<<< HEAD
AVDictionary *opts = NULL; // "create" an empty dictionary
+ av_dict_set(opts, "movflags", "empty_moov", 0);
- // Write the stream header, if any. //
- int ret = avformat_write_header(oc, &opts);
-=======
- ///
- /// trying to change the moov atom 170913
-
- //MOVMuxContext *mov = oc->priv_data;
- //mov->flags |= FF_MOV_FLAG_FRAGMENT;
- //AVDictionary* options;
- //av_dict_set(&options, "vprofile", "baseline", 0);
-
- ///
- ///
// Write the stream header, if any. //
- int ret = avformat_write_header(oc, NULL); //&options); //
->>>>>>> e8bfadcde7063ebaac5c8121747109dd574abf61
+ int ret = avformat_write_header(oc, &opts);
if (ret < 0) {
std::cerr <<"Error occurred when opening output file:" <<endl; // av_err2str(ret) << std::endl;
return false;
@@ -355,10 +354,18 @@ AVStream* libav::exporter::add_stream(AVFormatContext *oc, AVCodec **codec,enum
case AVMEDIA_TYPE_VIDEO:
c->codec_id = codec_id;
- c->bit_rate = 400000; //need to deal with resolution etc
+ c->bit_rate = bitRate; //need to deal with resolution etc
+
+ c->rc_max_rate = bitRate;
+ c->rc_min_rate = 0;
+ //c->rc_buffer_size = Profile()->m_videoMaxVopSize; //??
+
+
// Resolution must be a multiple of two. //
- c->width = 352;
- c->height = 288;
+ //c->width = 352;
+ //c->height = 288;
+
+
// timebase: This is the fundamental unit of time (in seconds) in terms
// * of which frame timestamps are represented. For fixed-fps content,
// * timebase should be 1/framerate and timestamp increments should be
diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h
index 8ce22eb..77832a7 100644
--- a/rotord/src/libavwrapper.h
+++ b/rotord/src/libavwrapper.h
@@ -14,13 +14,6 @@ extern "C" {
#include <libavutil/pixfmt.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
-<<<<<<< HEAD
- // ?????????
-//#include <libavformat/movenc.h>
-=======
- //?????????
- //#include <libavformat/movenc.h>
->>>>>>> e8bfadcde7063ebaac5c8121747109dd574abf61
}
#include <string>
diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp
index 718d6ae..39cd8d2 100644
--- a/rotord/src/rendercontext.cpp
+++ b/rotord/src/rendercontext.cpp
@@ -115,6 +115,25 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H
}
}
}
+ if (command.commands[1]=="bitrate") {
+ if (command.method=="PUT") {
+ int b=toInt(command.body);
+ if (graph.set_bitrate(b)){
+ logger.information("bitrate set to "+command.body);
+ XML.addValue("status","bitrate set to "+command.body);
+ status=HTTPResponse::HTTP_OK;
+ }
+ else {
+ logger.error("ERROR: Could not set bitrate set to "+command.body);
+ XML.addValue("error","Could not set bitrate set to "+command.body);
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ logger.error("ERROR: Bad request");
+ XML.addValue("error","Bad request");
+ }
+ }
if (command.commands[1]=="audio") {
if (command.method=="PUT") { //get audio file location and initiate analysis
if (command.body!="") {