[FFmpeg-user] -stream_loop cuts first few seconds

Geraldo Ramos geraldorneto at gmail.com
Thu Dec 29 14:21:17 EET 2016


Hi,

I'm trying to create an infinite loop from a mp4 video file, add some
complex filters and then broadcast as a live stream. My code works great
but after the first loop, the beginning of the video gets cut (a few
seconds).

I tried to include ''-fflags +genpts' before and after the stream_loop call
but it doesn't fix it and doesn't seem to make any difference.

Any suggestions?

Here is my code (I'm using the fluent nodejs ffmpeg library). I think this
issue is related to ffmpeg and not to the library itself.


ffmpeg(video)
    .inputOptions('-stream_loop '+stream_loop)
    .fps(24)
    .complexFilter([
        'movie=overlay1.png[watermark]','aresample=44100',
"[0:v]scale=640:360[vid1]", {
        filter: 'overlay', options: { x: '0', y: 0 },
        inputs: ['vid1','watermark'], outputs: 'merged'},
        {
        filter: 'drawtext',
        inputs: 'merged', outputs: 'draw1',
        options: {
          fontfile:'./opensansbold.ttf',
          textfile: '1.txt',
          fontsize: 15,
          fontcolor: '#5f5f5f',
          reload: 1,
          x: 510,
          y: 315
        }
      },
      {
      filter: 'drawtext',
      inputs: 'draw1', outputs: 'final',
      options: {
        fontfile:'./opensansbold.ttf',
        textfile: '2.txt',
        fontsize: 15,
        fontcolor: '#5f5f5f',
        reload: 1,
        x: 68,
        y: 315
      }}],'final')
    .videoBitrate('800k')
    .videoCodec('libx264')
    // .fps(24)
    .audioBitrate('128k')
    .audioCodec('aac')
    .audioFrequency(44100)
    .audioChannels(2)
    .flvmeta()
    .format('flv')

  .on('error', function(err) {
    if(ended){
      endStream("Ended successfully", "2", 'none', true)
    }else{
      endStream("Ended with error", "2", 'none', true)}
    console.log(err);
    console.log('Task ended with forced error '+message.token);
    callback()
    setTimeout(function () {
    process.exit(0)
  }, 20000);

  })
  .on('end', function() {
    endStream("Ended successfully", "5", "Ended after ffmpeg total time",
"none", true)
    console.log('Task ended successfully after all available period, from
user '+message.token);
    setTimeout(function () {
      process.exit(0)
    }, 20000);


  })

  .save(message.rtmpServer)


Thanks in advance,

Geraldo


More information about the ffmpeg-user mailing list