@@ -48,6 +48,7 @@ extern "C" {
48
48
#include " webcam.h"
49
49
#include " grabdisplay.h"
50
50
#include " vncclient.h"
51
+ #include " ffmpegsrc.h"
51
52
52
53
// #include <linux/videodev2.h>
53
54
@@ -2114,7 +2115,7 @@ class TSEncaspulator
2114
2115
int64_t *pcr_list = NULL ;
2115
2116
uint8_t *out = NULL ;
2116
2117
size_t fn = 0 ;
2117
- #define MAX_SIZE_PICTURE 256000
2118
+ #define MAX_SIZE_PICTURE 512000
2118
2119
uint8_t *InternalBuffer;// [MAX_SIZE_PICTURE];
2119
2120
uint8_t PictureHeader[5000 ];
2120
2121
int PictureHeaderSize=0 ;
@@ -2317,7 +2318,7 @@ class TSEncaspulator
2317
2318
// #define FILLER_OVERHEAD (NALU_OVERHEAD+1)
2318
2319
// ----------------------- END FROM X264 ----------------------
2319
2320
2320
-
2321
+ if (TimeToTransmitFrameUs< 5 ) TimeToTransmitFrameUs= 5 ; // Mini 1ms for 1 frame
2321
2322
if (previous_cpb_final_arrival_time==0 ) previous_cpb_final_arrival_time=((key_frame-1 )*FrameDuration)*90LL *300LL ;
2322
2323
2323
2324
tsframe.cpb_initial_arrival_time =previous_cpb_final_arrival_time;
@@ -2681,8 +2682,8 @@ class CameraTots
2681
2682
OMX_VIDEO_AVCProfileConstrainedBaseline
2682
2683
*/
2683
2684
2684
- encoder.setProfileLevel (OMX_VIDEO_AVCProfileBaseline );// OMX_VIDEO_AVCProfileHigh);
2685
- // encoder.setLevelExtension(1500 );
2685
+ encoder.setProfileLevel (OMX_VIDEO_AVCProfileHigh );// OMX_VIDEO_AVCProfileHigh);
2686
+ // encoder.setLevelExtension(VideoBitrate/1000 );
2686
2687
// With Main Profile : have more skipped frame
2687
2688
tsencoder.SetOutput (FileName,Udp);
2688
2689
tsencoder.ConstructTsTree (VideoBitrate,TsBitrate,PMTPid,sdt,fps,1 );
@@ -2691,7 +2692,7 @@ class CameraTots
2691
2692
// encoder.setPeakRate(VideoBitrate*1.1);
2692
2693
// encoder.setDQP(10); // Normally to 2
2693
2694
encoder.setQPLimits (1 ,51 ); // To have high bitrate even at low fps and size : for Now a MUST
2694
- encoder.setAdvanceddAVC ();
2695
+ // encoder.setAdvanceddAVC();
2695
2696
// encoder.setMaxFrameLimits(TsBitrate*1.5/fps);
2696
2697
2697
2698
}
@@ -3014,6 +3015,7 @@ class PictureTots
3014
3015
Webcam *pwebcam;
3015
3016
GrabDisplay *pgrabdisplay;
3016
3017
VncClient *pvncclient;
3018
+ ffmpegsrc *pffmpeg;
3017
3019
struct timespec InitTime;
3018
3020
FILE *AudioIn=NULL ;
3019
3021
@@ -3023,6 +3025,7 @@ static const int Mode_PATTERN=0;
3023
3025
static const int Mode_V4L2=1 ;
3024
3026
static const int Mode_GRABDISPLAY=2 ;
3025
3027
static const int Mode_VNCCLIENT=3 ;
3028
+ static const int Mode_FFMPEG=4 ;
3026
3029
public:
3027
3030
void Init (VideoFromat &VideoFormat,char *FileName,char *Udp,int VideoBitrate,int TsBitrate,int SetDelayPts,int PMTPid,char * sdt,int fps=25 ,int IDRPeriod=100 ,int RowBySlice=0 ,int EnableMotionVectors=0 ,int ModeInput=Mode_PATTERN,char *Extra=NULL )
3028
3031
{
@@ -3067,25 +3070,26 @@ static const int Mode_VNCCLIENT=3;
3067
3070
printf (" Resizer input = %d x %d\n " ,DisplayWidth,DisplayHeight);
3068
3071
resizer.setupOutputPort (DisplayWidth,DisplayHeight,VideoFormat, OMX_COLOR_Format32bitABGR8888);
3069
3072
}
3073
+ if (Mode==Mode_FFMPEG)
3074
+ {
3075
+
3076
+ pffmpeg=new ffmpegsrc (Extra);
3077
+ int CamWidth,CamHeight;
3078
+ pffmpeg->GetVideoSize (CamWidth,CamHeight);
3079
+ resizer.setupOutputPort (((CamWidth+31 )>>5 )<<5 ,((CamHeight+15 )>>4 )<<4 ,VideoFormat,OMX_COLOR_FormatYUV420PackedPlanar);
3080
+ }
3081
+
3070
3082
// resizer.setupOutputPort(VideoFormat,OMX_COLOR_Format32bitABGR8888);//OK
3071
3083
3072
3084
// configuring encoders
3073
3085
3074
3086
// VideoFromat vfResized = VideoFormat;
3075
3087
3076
- if (VideoBitrate<150000 )
3077
- {
3078
- printf (" Using QP constant\n " );
3079
- encoder.setupOutputPort (VideoFormat,VideoBitrate*2 ,fps);
3080
- encoder.setQFromBitrate (VideoBitrate,fps,CurrentVideoFormat.width ,CurrentVideoFormat.height );
3081
-
3082
- }
3083
- else
3084
- {
3088
+
3085
3089
encoder.setupOutputPort (VideoFormat,VideoBitrate,fps);
3086
3090
encoder.setBitrate (VideoBitrate,OMX_Video_ControlRateVariable/* OMX_Video_ControlRateConstant*/ );
3087
3091
3088
- }
3092
+
3089
3093
3090
3094
// OMX_Video_ControlRateDisable seems not supported !!!
3091
3095
encoder.setCodec (OMX_VIDEO_CodingAVC);
@@ -3098,10 +3102,11 @@ static const int Mode_VNCCLIENT=3;
3098
3102
// encoder.setQP(20,20);
3099
3103
encoder.setLowLatency ();
3100
3104
// encoder.setSeparateNAL();
3105
+ encoder.setMinizeFragmentation (); // Minimize frag seems to block at high resolution : to inspect*/
3106
+
3101
3107
if (RowBySlice)
3102
- encoder.setMultiSlice (RowBySlice);
3103
- else
3104
- encoder.setMinizeFragmentation ();
3108
+ encoder.setMultiSlice (RowBySlice,OMX_VIDEO_IntraRefreshCyclic/* OMX_VIDEO_IntraRefreshBoth*/ );
3109
+
3105
3110
// encoder.setEED();
3106
3111
3107
3112
/* OMX_VIDEO_AVCProfileBaseline = 0x01, //< Baseline profile
@@ -3110,7 +3115,7 @@ static const int Mode_VNCCLIENT=3;
3110
3115
OMX_VIDEO_AVCProfileHigh = 0x08, //< High profile
3111
3116
OMX_VIDEO_AVCProfileConstrainedBaseline
3112
3117
*/
3113
- encoder.setProfileLevel (OMX_VIDEO_AVCProfileMain );
3118
+ encoder.setProfileLevel (OMX_VIDEO_AVCProfileHigh );
3114
3119
encoder.setQPLimits (1 ,51 ); // To have high bitrate even at low fps and size : for Now a MUST
3115
3120
// With Main Profile : have more skipped frame
3116
3121
tsencoder.SetOutput (FileName,Udp);
@@ -3154,7 +3159,10 @@ static const int Mode_VNCCLIENT=3;
3154
3159
{
3155
3160
pvncclient->SetOmxBuffer ((unsigned char *)resizer.inBuffer ().data ());
3156
3161
}
3157
-
3162
+ if (Mode==Mode_FFMPEG)
3163
+ {
3164
+ pffmpeg->SetOmxBuffer ((unsigned char *)resizer.inBuffer ().data ());
3165
+ }
3158
3166
printf (" Allocsize= %d\n " ,resizer.inBuffer ().allocSize ());
3159
3167
encoder.allocBuffers (false );// Only Bufout
3160
3168
@@ -3489,6 +3497,16 @@ else
3489
3497
// printf("DiffFrame %d\n",FrameDiff);
3490
3498
}
3491
3499
}
3500
+ if (Mode==Mode_FFMPEG)
3501
+ {
3502
+
3503
+ if (!pffmpeg->read_frame (2 )){want_quit=1 ;return ;};
3504
+
3505
+ filledLen=PictureBuffer.allocSize ();
3506
+ usleep_exactly (1e6 /Videofps);
3507
+ // V4L2_read_frame(PictureBuffer.data(),&filledLen);
3508
+ // usleep_exactly(1e6/(Videofps*2));
3509
+ }
3492
3510
PictureBuffer.setDatasize (filledLen);
3493
3511
PictureBuffer.setFilled (false );
3494
3512
resizer.callEmptyThisBuffer ();
@@ -3522,6 +3540,10 @@ else
3522
3540
if (Mode==Mode_VNCCLIENT)
3523
3541
{
3524
3542
free (pvncclient);
3543
+ }
3544
+ if (Mode==Mode_FFMPEG)
3545
+ {
3546
+ free (pffmpeg);
3525
3547
}
3526
3548
// return the last full buffer back to the encoder component
3527
3549
{
@@ -3625,7 +3647,8 @@ int main(int argc, char **argv)
3625
3647
#define PATTERN 1
3626
3648
#define USB_CAMERA 2
3627
3649
#define DISPLAY 3
3628
- #define VNC 4
3650
+ #define VNC 4
3651
+ #define FFMPEG 5
3629
3652
int TypeInput=CAMERA;
3630
3653
3631
3654
while (1 )
@@ -3769,7 +3792,9 @@ else
3769
3792
if (ExtraArg==NULL ) ExtraArg=" /dev/video0" ;break ;
3770
3793
case DISPLAY:PictureMode=PictureTots::Mode_GRABDISPLAY;break ;
3771
3794
case VNC:PictureMode=PictureTots::Mode_VNCCLIENT;
3772
- if (ExtraArg==NULL ) {printf (" IP of VNCServer should be set with -e option\n " );exit (0 );}
3795
+ if (ExtraArg==NULL ) {printf (" IP of VNCServer should be set with -e option\n " );exit (0 );}break ;
3796
+ case FFMPEG:PictureMode=PictureTots::Mode_FFMPEG;
3797
+
3773
3798
3774
3799
}
3775
3800
picturetots = new PictureTots;
0 commit comments