Georgi Stoyanov
Georgi Stoyanov

Reputation: 644

ffmpeg VBR -> CBR conversion and streaming of MPEG-2 TS video files

I am trying to convert a source VBR SPTS MPEG-2 TS file into CBR using ffmpeg. The code I am using is the following:

#!/bin/bash

pkill ffmpeg

ffmpeg \
        -re -i source.ts -c copy \
        -muxrate 18000K \
        -f mpegts \
        udp://destination_ip:1234?pkt_size=1316

The source VPID bitrate is ~ 10Mbps and the APID is 296Kbps. So according to my understanding this code should deliver 18Mbps CBR where the difference between the muxrate and the bitrate of all the PIDs is filled with null packets.

The problem is that the output is far from perfect. The overall bitrate is semi-CBR at best. It ranges between 12Mbps and 15Mbps and I see a lot of PCR accuracy and PCR repetition errors along with CC errors both on the VPID and APID.

Upvotes: 1

Views: 7434

Answers (2)

Gintaras Stalauskas
Gintaras Stalauskas

Reputation: 11

  1. specify -minrate and -maxrate too.
  2. use -bufsize bigger than bitrate.
  3. set -muxrate value like bufsize.

The final command:

ffmpeg \  
    -re -i source.ts \  
    -b:v 10500k \  
    -minrate 10500k \  
    -maxrate 10500k \  
    -bufsize 18000k \  
    -muxrate 18000k \  
    -f mpegts \  
    udp://destination_ip:1234?pkt_size=1316  

Upvotes: 1

aergistal
aergistal

Reputation: 31209

Some ideas:

  • make sure you have a recent version of ffmpeg because at some point there was a bug which messed up PCR insertion when stream copying
  • if you want constant UDP output you must use the bitrate option like:

    -flush_packets 0 -f mpegts "udp://destination_ip:1234?pkt_size=1316&bitrate=18000000"
    
  • UDP is an unreliable protocol and you might experience packet loss (unfortunately the bitrate option only works for UDP for now AFAIK)
  • if you have a dedicated connection but still experience CC errors check the destination OS max UDP buffer sizes and make sure it can handle 18 Mbps

Upvotes: 4

Related Questions