This is an example of obtaining video input data from from standard input pipe. Assuming the pipe provides H.264 stream. For example, to capture raw video from V4L2 device, encode it in H.264 and sink into this application:
ffmpeg -f v4l2 -framerate 30 -video_size 640x480 -i /dev/video0 -c libx264 -bsf:v h264_mp4toannexb -f h264 - | ./example
namespace {
bool done = false;
void
LogFunc(Log::Level, const char *msg)
{
fprintf(stderr, "%s\n", msg);
}
void
{
fprintf(stderr, "Streamer status: %d\n", status);
done = true;
}
}
}
int
main(int argc, char **argv)
{
streamerParams.
vehicleId =
"SampleVehicle-1";
streamerParams.
targetUri =
"urtp+connect://127.0.0.1:3341";
if (!vs) {
av_log(0, AV_LOG_ERROR, "Streamer instance creation failed\n");
return 1;
}
av_log(0, AV_LOG_ERROR, "Streamer instance starting failed\n");
return 1;
}
std::freopen(nullptr, "rb", stdin);
if(std::ferror(stdin)) {
av_log(0, AV_LOG_ERROR, "Failed to reopen stdin: %s\n", std::strerror(errno));
return 1;
}
std::size_t n;
uint8_t buf[256];
while(!done && (n = std::fread(buf, 1, sizeof(buf), stdin)) > 0) {
if(std::ferror(stdin) && !std::feof(stdin)) {
av_log(0, AV_LOG_ERROR, "Failed to read stdin: %s\n", std::strerror(errno));
break;
}
av_log(0, AV_LOG_ERROR, "Failed to feed video packet\n");
break;
}
}
return 0;
}