Merge pull request #3456 from exuvo/master

ffmpeg change
pull/3462/head
Isaac Connor 2022-04-03 14:59:35 -04:00 committed by GitHub
commit 717dfff0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 25 deletions

View File

@ -325,7 +325,7 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
//dump_sidedata(NULL, st, " ");
}
int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt) {
int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat sample_fmt) {
const enum AVSampleFormat *p = codec->sample_fmts;
while (*p != AV_SAMPLE_FMT_NONE) {

View File

@ -217,7 +217,7 @@ void zm_dump_codecpar(const AVCodecParameters *par);
#define zm_av_frame_alloc() av_frame_alloc()
int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt);
int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat sample_fmt);
enum AVPixelFormat fix_deprecated_pix_fmt(enum AVPixelFormat );
bool is_video_stream(const AVStream *);

View File

@ -353,7 +353,7 @@ int FfmpegCamera::OpenFfmpeg() {
Debug(3, "Found video stream at index %d, audio stream at index %d",
mVideoStreamId, mAudioStreamId);
AVCodec *mVideoCodec = nullptr;
const AVCodec *mVideoCodec = nullptr;
if (mVideoStream->codecpar->codec_id == AV_CODEC_ID_H264) {
if ((mVideoCodec = avcodec_find_decoder_by_name("h264_mmal")) == nullptr) {
Debug(1, "Failed to find decoder (h264_mmal)");
@ -494,7 +494,7 @@ int FfmpegCamera::OpenFfmpeg() {
} // end if have audio stream
if ( mAudioStreamId >= 0 ) {
AVCodec *mAudioCodec = nullptr;
const AVCodec *mAudioCodec = nullptr;
if (!(mAudioCodec = avcodec_find_decoder(mAudioStream->codecpar->codec_id))) {
Debug(1, "Can't find codec for audio stream from %s", mPath.c_str());
} else {

View File

@ -41,7 +41,7 @@ class FFmpeg_Input {
private:
typedef struct {
AVCodecContext *context;
AVCodec *codec;
const AVCodec *codec;
int frame_count;
} stream;

View File

@ -97,16 +97,11 @@ int VideoStream::SetupCodec(
// Not sure what this value should be really...
ofc->packet_size = width*height;
Debug(1,"Setting packet_size to %d", ofc->packet_size);
if (of->video_codec == AV_CODEC_ID_NONE) {
// RTP does not have a default codec in ffmpeg <= 0.8.
of->video_codec = AV_CODEC_ID_MPEG4;
}
}
_AVCODECID codec_id = of->video_codec;
if (codec_name) {
AVCodec *a = avcodec_find_encoder_by_name(codec_name);
const AVCodec *a = avcodec_find_encoder_by_name(codec_name);
if (a) {
codec_id = a->id;
Debug(1, "Using codec \"%s\"", codec_name);
@ -488,7 +483,7 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size,
pkt->flags |= AV_PKT_FLAG_KEY;
pkt->stream_index = ost->index;
pkt->data = (uint8_t *)opicture_ptr;
pkt->size = sizeof (AVPicture);
pkt->size = 8 + 4;
got_packet = 1;
} else {
opicture_ptr->pts = codec_context->frame_number;

View File

@ -40,11 +40,11 @@ protected:
const char *format;
const char *codec_name;
enum _AVPIXELFORMAT pf;
AVOutputFormat *of;
const AVOutputFormat *of;
AVFormatContext *ofc;
AVStream *ost;
AVCodecContext *codec_context;
AVCodec *codec;
const AVCodec *codec;
AVFrame *opicture;
AVFrame *tmp_opicture;
uint8_t *video_outbuf;

View File

@ -181,7 +181,7 @@ int RemoteCameraRtsp::PrimeCapture() {
avcodec_parameters_to_context(mVideoCodecContext, mFormatContext->streams[mVideoStreamId]->codecpar);
// Find the decoder for the video stream
AVCodec *codec = avcodec_find_decoder(mVideoCodecContext->codec_id);
const AVCodec *codec = avcodec_find_decoder(mVideoCodecContext->codec_id);
if ( codec == nullptr ) {
Error("Unable to locate codec %d decoder", mVideoCodecContext->codec_id);
return -1;

View File

@ -56,6 +56,8 @@ VideoStore::CodecData VideoStore::codec_data[] = {
{ AV_CODEC_ID_H264, "h264", "libx264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P },
{ AV_CODEC_ID_MJPEG, "mjpeg", "mjpeg", AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ422P },
#endif
{ AV_CODEC_ID_VP9, "vp9", "libvpx-vp9", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },
{ AV_CODEC_ID_AV1, "av1", "libsvtav1", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },
};
VideoStore::VideoStore(
@ -136,8 +138,8 @@ bool VideoStore::open() {
oc->metadata = pmetadata;
out_format = oc->oformat;
out_format->flags |= AVFMT_TS_NONSTRICT; // allow non increasing dts
AVCodec *video_out_codec = nullptr;
oc->flags |= AVFMT_TS_NONSTRICT; // allow non increasing dts
const AVCodec *video_out_codec = nullptr;
AVDictionary *opts = nullptr;
std::string Options = monitor->GetEncoderOptions();
@ -1216,18 +1218,22 @@ int VideoStore::write_packet(AVPacket *pkt, AVStream *stream) {
pkt->stream_index = stream->index;
if (pkt->dts == AV_NOPTS_VALUE) {
Debug(1, "undef dts, fixing by setting to stream cur_dts %" PRId64, stream->cur_dts);
pkt->dts = stream->cur_dts;
} else if (pkt->dts < stream->cur_dts) {
Error("undefined dts");
// Debug(1, "undef dts, fixing by setting to stream cur_dts %" PRId64, stream->cur_dts);
// pkt->dts = stream->cur_dts;
/* } else if (pkt->dts < stream->cur_dts) {
Debug(1, "non increasing dts, fixing. our dts %" PRId64 " stream cur_dts %" PRId64, pkt->dts, stream->cur_dts);
pkt->dts = stream->cur_dts;
pkt->dts = stream->cur_dts;*/
}
if (pkt->dts > pkt->pts) {
Debug(1,
Warning("pkt.dts(%" PRId64 ") must be <= pkt.pts(%" PRId64 ")."
"Decompression must happen before presentation.",
pkt->dts, pkt->pts);
/* Debug(1,
"pkt.dts(%" PRId64 ") must be <= pkt.pts(%" PRId64 ")."
"Decompression must happen before presentation.",
pkt->dts, pkt->pts);
pkt->dts, pkt->pts);*/
pkt->pts = pkt->dts;
}

View File

@ -38,7 +38,7 @@ class VideoStore {
CodecData *chosen_codec_data;
Monitor *monitor;
AVOutputFormat *out_format;
const AVOutputFormat *out_format;
AVFormatContext *oc;
AVStream *video_out_stream;
AVStream *audio_out_stream;
@ -52,7 +52,7 @@ class VideoStore {
const AVCodec *audio_in_codec;
AVCodecContext *audio_in_ctx;
// The following are used when encoding the audio stream to AAC
AVCodec *audio_out_codec;
const AVCodec *audio_out_codec;
AVCodecContext *audio_out_ctx;
// Move this into the object so that we aren't constantly allocating/deallocating it on the stack
AVPacket opkt;

View File

@ -189,12 +189,24 @@ function initPage() {
encoder_dropdown[0].options[0].selected = 1;
option.selected = false;
}
} else if ( this.value == 167 /* vp9 */ ) {
option.disabled = !(option.value.includes('vp9'));
if ( option.disabled && option.selected ) {
encoder_dropdown[0].options[0].selected = 1;
option.selected = false;
}
} else if ( this.value == 173 /* hevc */ ) {
option.disabled = !(option.value.includes('hevc') || option.value.includes('265') );
if ( option.disabled && option.selected ) {
encoder_dropdown[0].options[0].selected = 1;
option.selected = false;
}
} else if ( this.value == 226 /* av1 */ ) {
option.disabled = !(option.value.includes('av1'));
if ( option.disabled && option.selected ) {
encoder_dropdown[0].options[0].selected = 1;
option.selected = false;
}
} else {
option.disabled = false;
}

View File

@ -1058,6 +1058,8 @@ $videowriter_codecs = array(
'0' => translate('Auto'),
'27' => 'h264',
'173' => 'h265/hevc',
'167' => 'vp9',
'226' => 'av1',
);
echo htmlSelect('newMonitor[OutputCodec]', $videowriter_codecs, $monitor->OutputCodec());
?>
@ -1077,6 +1079,8 @@ $videowriter_encoders = array(
'libx265' => 'libx265',
'hevc_nvenc' => 'hevc_nvenc',
'hevc_vaapi' => 'hevc_vaapi',
'libvpx-vp9' => 'libvpx-vp9',
'libsvtav1' => 'libsvtav1',
);
echo htmlSelect('newMonitor[Encoder]', $videowriter_encoders, $monitor->Encoder());?></td></tr>
<tr class="OutputContainer">
@ -1087,6 +1091,7 @@ $videowriter_containers = array(
'' => translate('Auto'),
'mp4' => 'mp4',
'mkv' => 'mkv',
'webm' => 'webm',
);
echo htmlSelect('newMonitor[OutputContainer]', $videowriter_containers, $monitor->OutputContainer());
?>