2

Using FFmpeg, I want to update the PTS field with the time the frame was actual captured. I'm doing it with the following FFmpeg command (the "copyts" flag does the job):

ffmpeg -re -f v4l2 -copyts -i /dev/video0 -c:v libx264 -intra -f mpegts -mpegts_copyts 1 udp://192.168.10.199:1234

However, it only works with a small help... I had to edit the v4l2.c file:

static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
{
   ...
   ...
   ...

   pkt->pts = buf_ts.tv_sec * INT64_C(1000000) + buf_ts.tv_usec; 

   pkt->pts &= 0x1ffffffff;  /*modified by me*/                                            
   pkt->dts = 0;             /*modified by me*/

   av_log(ctx, AV_LOG_ERROR, "pts: %lld, dts: %lld\n", pkt->pts, pkt->dts);       
   convert_timestamp(ctx, &pkt->pts);                                             

   return pkt->size;                                                                                                                                               
}

Of course, I don't want to modify the function...

Any idea of to use the "copyts" flag so it will work without editing the function mmap_read_frame() ?

I'm using the latest FFmpeg source. Without my modifications I get this:

Output #0, mpegts, to 'udp://192.168.10.55:1234':
  Metadata:
    encoder         : Lavf58.35.100
    Stream #0:0: Video: h264 (cedrus264), nv12, 1280x720, q=2-31, 200 kb/s, 10 fps, 90k tbn, 10 tbc
    Metadata:
      encoder         : Lavc58.64.101 cedrus264
frame=    1 fps=0.2 q=-0.0 Lsize=      28kB time=59652:19:24.70 bitrate=   0.0kbits/s speed=4.82e+07x    
video:27kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.599154%
J.M.
  • 472
  • 1
  • 6
  • 15
  • What happens without the modifications? And are you using a build from the latest source? – Gyan Nov 27 '19 at 15:44
  • I'm using the latest souce. Without my modifications the ffmpeg get stuck... (frame =1, fps=0.0, .....) – J.M. Nov 28 '19 at 14:36

0 Answers0