NvTranscoder output as a stream instead of file

Hello,

Right now I have the NvTranscoder example setup (altered a bit) and it can take in an input file or stream, decode, encode, and output that all out to a file. However, I would like to output that newly encoded video to a streamable location (e.g. “udp://@225.0.0.20:6060”) instead.

I was following the ffmpeg output-example in which they do this, but I’m unsure how to write the video frames from the packet data I get from the NvEncoder. I have the following code below, but crashes on the av_interleaved_write_frame call:

void write_video_frame(uint8_t *data, int size)
    {
        AVPacket pkt;
        av_init_packet(&pkt);

        pkt.flags |= AV_PKT_FLAG_KEY;
        pkt.stream_index = 0;
        pkt.data = data;
        pkt.size = size;

        av_interleaved_write_frame(outputFormatContext, &pkt);
    }

I get the following log message from ffmpeg: “Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly”

Is the lack of timestamps a characteristic of encoding with nvenc? If so, will this prevent me from writing both video frames and klv data to the same stream due to timing issues?

Can anyone help me out with this or point me in the right direction?

Hi nik.johnson,

I think it will be a good idea to debug libavformat source that prints this log message and figure out what caused this. It seems you have to fill AVPacket and other related objects with correct timestamp values and flags to support streaming in your application. Additionally, you can refer to libavcodec/nvenc.c to see how pts/dts values are set.

Thanks.