[FFmpeg-user] Frame rates and video accelerated

chieppa at elmaxsrl.it chieppa at elmaxsrl.it
Mon Feb 9 21:10:58 CET 2015


   Dear Sir,
   Yes, is Annex B compliant.
   I take the raw H264 from camera. In this example is a Sony IPELA.
   Below the code that receives the raw data from the camera, via RTSP (as I said I use Live555):
   unsigned int num = 0;
       shared_ptr<vector<char> > imageNAL = make_shared<vector<char> >();
       char const* sPropPar = _fSubsession.fmtp_spropparametersets();
       if(sPropPar == nullptr || strlen(sPropPar) == 0) envir()<<"\n***spropparameterssteds NULL***\n";
       SPropRecord *sps = parseSPropParameterSets(sPropPar, num);
        for(register unsigned k = 0; k < num; ++k) {
           if(sps[k].sPropLength == 0) {
               envir()<<"\n***SPS NULL***\n";
               continue;
           }
       unsigned nalUnitSize = sps[k].sPropLength;
       unsigned char* nalUnitBytes = sps[k].sPropBytes;
       //write  the SPS & PPS
       imageNAL->push_back(0x00);
       imageNAL->push_back(0x00);
       imageNAL->push_back(0x00);
       imageNAL->push_back(0x01);
       for(register unsigned i = 0; i < nalUnitSize; i++) {
           imageNAL->push_back(static_cast<char>(nalUnitBytes[i]));
       }
            //#define DEBUG_PPS
            /*#ifdef DEBUG_PPS
            std::cout<<std::endl<<"DUMP SSP PPS"<<std::endl;
            for(unsigned index = 0; index < imagePPS_SPS->size(); index++) {
               std::cout<<std::hex<<(static_cast<unsigned int>(imageNAL->at(index)) & 0xFF)<<" ";
            }
            std::cout<<std::endl;
            #endif*/
       }
       //----------------------------------------------------------
        //write the NAL payload
       imageNAL->push_back(0x00);
       imageNAL->push_back(0x00);
       imageNAL->push_back(0x00);
       imageNAL->push_back(0x01);
       if(frameSize >= DUMMY_SINK_RECEIVE_BUFFER_SIZE_H264) {
           frameSize = DUMMY_SINK_RECEIVE_BUFFER_SIZE_H264-1;
           envir()<<"\n***Discard bytes exceed framesize***\n";
       }
       for(register unsigned i = 0; i < frameSize; i++) {
           imageNAL->push_back(_fReceiveBuffer[i]);
       } 
   I save the H264 taken in a file. I take about 10 sec. when an intrution is detected.
   I'm pretty sure that the raw H264 hasn't the timestamps.

   Then I prepare the command to launch by sw the FFMPEG:
     ffmpeg -y -i IMAGE_FILE.h264 -vf scale=960:-1 -c:v mpeg4 -q:v 1 IMAGE_FILE.mp4

   the result is:
   Â
   ffmpeg version N-66745-g0578623 Copyright (c) 2000-2014 the FFmpeg developers
     built on Oct  9 2014 02:15:39 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
     configuration: --prefix=HOME/ffmpeg_build --bindir=/home/cchieppa/bin
     libavutil      54. 10.100 / 54. 10.100
     libavcodec     56.  4.101 / 56.  4.101
     libavformat    56.  9.100 / 56.  9.100
     libavdevice    56.  1.100 / 56.  1.100
     libavfilter     5.  1.103 /  5.  1.103
     libswscale      3.  1.100 /  3.  1.100
     libswresample   1.  1.100 /  1.  1.100
   Input #0, h264, from '/home/cchieppa/Documents/VideoHUB5/image_SONY.h264':
     Duration: N/A, bitrate: N/A
       Stream #0:0: Video: h264 (Baseline), yuv420p, 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
   Output #0, mp4, to '/home/cchieppa/Documents/VideoHUB5/image_SONY.mp4':
     Metadata:
       encoder         : Lavf56.9.100
       Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 960x540, q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc
       Metadata:
         encoder         : Lavc56.4.101 mpeg4
   Stream mapping:
     Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
   Press [q] to stop, [?] for help
   frame=  336 fps= 41 q=1.0 Lsize=   11566kB time=00:00:13.88 bitrate=6826.1kbits/s
   video:11563kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.020902%

   In this case, the MP4 is too fast: I see the seconds on the video that go around x2 times fast.
   I don't understand why.
   Thank you
   Cristiano

   Da ffmpeg-user-bounces at ffmpeg.org

   A "FFmpeg user questions" ffmpeg-user at ffmpeg.org

   Cc

   Data Mon, 9 Feb 2015 19:24:20 +0100

   Oggetto Re: [FFmpeg-user] Frame rates and video accelerated

   > On Sat, Feb 7, 2015 at 6:05 PM, Cristiano Chieppa

   > <cristiano.chieppa at gmail.com> wrote:

   > > I save the raw frames (NALs) in a file (some frames grabbed from a camera) and I invoke the ffmpeg from the sw - like a batch program - to encode the raw H264 in MP4.

   > > The conversion works well.

   >

   > Out of curiosity, how exactly are you doing it? Is the file basically

   > an Annex B stream?

   >

   > > Sometimes, under circumstance that I’m not able to understand, I see that the generated mp4 video is like “accelerated”: the speed is very fast compare with the real stream.

   > > Is there a way to invoke ffmpeg and tell him, as a parameter, the timestamp of each grabbed frames to get the real synchronized video?

   >

   > ffmpeg -r 25 -i input output

   >

   > This is how you force the frame rate.

   >

   > Actually, when you do "ffmpeg -i input -c:v libx264 output.h264", the

   > output file indicates the frame rate when you read it back in with

   > "ffmpeg -i output.h264". And when you force a different frame rate,

   > with for example "ffmpeg -i input -c:v libx264 -r 12 output.h264",

   > this frame rate change is visible when doing "ffmpeg -i output.h264".

   > This is due to the timing information being written into the Sequence

   > Parameter Set (SPS).

   > _______________________________________________

   > ffmpeg-user mailing list

   > ffmpeg-user at ffmpeg.org

   > http://ffmpeg.org/mailman/listinfo/ffmpeg-user


More information about the ffmpeg-user mailing list