[FFmpeg-devel] Patch: fix timestamp handling problem
Hi all, I find that the latest ffmpeg could not handle timestamp propertly for some inputs. After some digging, I finally catch first exception in commit 8f6f232. The problem was introduced by applying the new decode API -- avcodec_send_packet() and avcodec_receive_frame(). Since the new decoding flow detect input ending by the return value of avcodec_receive_frame(). It should restore the stream dts/pts after last call to avcodec_receive_frame(), that last call return a null output and break the while loop. Otherwise, stream dts/pts would be set to next_dts/next_pts. Bellow is the patch, which is also attached. From c9e552ebadf20acfd6296fc760ac8b825cc9b1fd Mon Sep 17 00:00:00 2001 From: "jeff.zheng" <163j...@163.com> Date: Sun, 9 Apr 2017 19:47:59 +0800 Subject: [PATCH] ffmpeg: fix timestamp handling problem The problem was introduced in commit 8f6f232 by appling the new decode API. Stream dts/pts should be set to the value of last decoded packet of the stream rather than next_dts/next_pts. --- ffmpeg.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/ffmpeg.c b/ffmpeg.c index e4b94b2fa0..66156b5394 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2615,12 +2615,16 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo ist->next_pts = ist->pts = ist->dts; } +int64_t last_pts = ist->pts; +int64_t last_dts = ist->dts; // while we have more to decode or while the decoder did output something on EOF while (ist->decoding_needed) { int64_t duration = 0; int got_output = 0; int decode_failed = 0; +last_pts = ist->pts; +last_dts = ist->dts; ist->pts = ist->next_pts; ist->dts = ist->next_dts; @@ -2699,6 +2703,8 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo repeating = 1; } +ist->pts = last_pts; +ist->dts = last_dts; /* after flushing, send an EOF on all the filter inputs attached to the stream */ /* except when looping we need to flush but not to send an EOF */ -- 2.11.0 (Apple Git-81) Thanks! Jeff.Zheng 0001-ffmpeg-fix-timestamp-handling-problem.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Why not integrate libyuv as a scale filter
Hi there, It seems like libyuv has better performace on scaling than libswscale. So I'm wondering is there anyone has tried integrating libyuv as a scale filter before. I mean link it as a 3rd party lib, and then call it's API through a wrap filter. Just like how libavcodec use libx264. If not, why? Is there any licensee issue? Effort worth pay on it? Thanks, Jogh ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Why not integrate libyuv as a scale filter
--enable-libopenh264 --enable-encoder=libx264 --enable-encoder=libopenh264 --enable-encoder=aac --enable-encoder=libfdk_aac --enable-encoder=libspeex --enable-encoder=mjpeg --enable-encoder=mp3 --disable-decoders --enable-decoder=aac --enable-decoder=ac3 --enable-decoder=flv --enable-decoder=h264 --enable-decoder=mp3 --enable-decoder=libfdk_aac --enable-decoder=hevc --enable-decoder=mjpeg --enable-decoder='pcm*' --disable-muxers --enable-muxer=mpegts --enable-muxer=mp4 --enable-muxer=flv --enable-muxer=mp3 --disable-demuxers --enable-demuxer=aac --enable-demuxer=concat --enable-demuxer=ac3 --enable-demuxer=flv --enable-demuxer=hls --enable-demuxer=live_flv --enable-demuxer=mp4 --enable-demuxer=mov --enable-demuxer=mp3 --enable-demuxer=mpegts --enable-demuxer=mjpeg --enable-demuxer='pcm*' --disable-parsers --enable-parser=aac --enable-parser=ac3 --enable-parser=h264 --enable-parser=hevc --disable-protocols --enable-protocol=file --enable-protocol=http --enable-protocol=tls_openssl --enable-protocol=https --enable-protocol=rtmp --enable-protocol=rtmpt --enable-protocol=concat --disable-filters --enable-filter=buffer --enable-filter=buffersink --enable-filter=abuffer --enable-filter=abuffersink --enable-filter=scale --enable-filter=crop --enable-filter=copy --enable-filter=transpose --enable-filter=movie --enable-filter=format --enable-filter='anull*' --enable-filter=aresample --enable-filter=trim --enable-filter=atrim --enable-filter=concat --enable-filter=null --enable-filter='frame*' --enable-filter=fps --enable-filter=overlay --enable-filter=aformat --enable-filter=hflip --enable-filter=vflip --enable-filter=afade --enable-filter=amix --enable-filter=volume --enable-filter=reverse --enable-filter=amovie --enable-filter=atempo --disable-hwaccels --disable-bsfs --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb libavutil 55. 28.100 / 55. 28.100 libavcodec 57. 48.101 / 57. 48.101 libavformat57. 41.100 / 57. 41.100 libavfilter 6. 47.100 / 6. 47.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100 Thanks, Jogh At 2018-07-25 02:54:27, "Carl Eugen Hoyos" wrote: >2018-07-23 16:39 GMT+02:00, Jeff <163j...@163.com>: > >> It seems like libyuv has better performace on scaling >> than libswscale. > >Which platform did you test? > >Iirc, libswscale supports slices but the scale filter does not, >so there is a possibility to improve the performance (from a >user's perspective). > >Carl Eugen >___ >ffmpeg-devel mailing list >ffmpeg-devel@ffmpeg.org >http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] libavformat/rtpdec_mpeg: handle bare ADTS packets with explicit decoder config
When SDP specifies a decoder config, there may not be any AU headers provided by the sender. This can result in rtp_parse_mp4_au failing and aac_parse_packet reporting "Error parsing AU headers." and no audio is recovered from the stream. This commit modifies aac_parse_header to check for an explicit decoder config set by the sdp parser (e.g. a:fmtp # config=hexvalue). If it has and there is an ADTS header present, it skips the header and copies the RTP payload directly as an AAC packet. This resolves an issue observed with some inexpensive IP cameras. Signed-off-by: Jeff Mahoney --- libavformat/rtpdec_mpeg4.c | 34 +- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 34c7950bcc..dd0ced790e 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -176,7 +176,7 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, int flags) { int ret; - +AVCodecParameters *par = st->codecpar; if (!buf) { if (data->cur_au_index > data->nb_au_headers) { @@ -204,6 +204,38 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, return 1; } +/* Check for an explicit decoder config (e.g. SDP a:fmtp... config=) */ +if (par->extradata && len > 7) { +/* + * Start of ADTS header - syncword + * If present skip the header and copy the entire payload as AAC data + */ +if (buf[0] == 0xff && (buf[1] & 0xf0) == 0xf0) { +/* + * The ADTS header is 7 or 9 bytes depending on whether + * the protection absent bit is set. If it is unset, a 16-bit CRC + * is appended to the header. + */ +size_t header_size = 7 + ((buf[1] & 0x01) ? 0 : 2); +if (len < header_size) { +ac_log(ctx, AV_LOG_ERROR, "Error parsing ADTS header\n"); +return -1; +} + +buf += header_size; +len -= header_size; + +if ((ret = av_new_packet(pkt, len)) < 0) { +av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); +return ret; +} +memcpy(pkt->data, buf, len); +pkt->stream_index = st->index; + +return 0; +} +} + if (rtp_parse_mp4_au(data, buf, len)) { av_log(ctx, AV_LOG_ERROR, "Error parsing AU headers\n"); return -1; -- 2.33.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] libavformat/rtpdec_mpeg: handle bare ADTS packets with explicit decoder config
Hi folks - Just wanted to follow up on this patch. Is it obviously wrong, it doesn't scratch a common itch, or... ? I've tested the camera connection and ran the patched code through FATE. The frigate container I'm using has audio disabled entirely since it's unreliable on many devices and this fixes it for at least some. I'd prefer to get the patch (in this iteration or after review/resubmit cycles) landed so the container stack can pull it in. I've been in the Linux world long enough to know I can't expect free review, but if I've missed something in the process I'd appreciate some feedback. Thanks, -Jeff On 10/2/21 6:53 PM, Jeff Mahoney wrote: > When SDP specifies a decoder config, there may not be any AU headers > provided by the sender. This can result in rtp_parse_mp4_au failing > and aac_parse_packet reporting "Error parsing AU headers." and no audio > is recovered from the stream. > > This commit modifies aac_parse_header to check for an explicit decoder config > set by the sdp parser (e.g. a:fmtp # config=hexvalue). If it has and there > is an ADTS header present, it skips the header and copies the RTP > payload directly as an AAC packet. > > This resolves an issue observed with some inexpensive IP cameras. > > Signed-off-by: Jeff Mahoney > --- > libavformat/rtpdec_mpeg4.c | 34 +- > 1 file changed, 33 insertions(+), 1 deletion(-) > > diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c > index 34c7950bcc..dd0ced790e 100644 > --- a/libavformat/rtpdec_mpeg4.c > +++ b/libavformat/rtpdec_mpeg4.c > @@ -176,7 +176,7 @@ static int aac_parse_packet(AVFormatContext *ctx, > PayloadContext *data, > int flags) > { > int ret; > - > +AVCodecParameters *par = st->codecpar; > > if (!buf) { > if (data->cur_au_index > data->nb_au_headers) { > @@ -204,6 +204,38 @@ static int aac_parse_packet(AVFormatContext *ctx, > PayloadContext *data, > return 1; > } > > +/* Check for an explicit decoder config (e.g. SDP a:fmtp... config=) */ > +if (par->extradata && len > 7) { > +/* > + * Start of ADTS header - syncword > + * If present skip the header and copy the entire payload as AAC data > + */ > +if (buf[0] == 0xff && (buf[1] & 0xf0) == 0xf0) { > +/* > + * The ADTS header is 7 or 9 bytes depending on whether > + * the protection absent bit is set. If it is unset, a 16-bit > CRC > + * is appended to the header. > + */ > +size_t header_size = 7 + ((buf[1] & 0x01) ? 0 : 2); > +if (len < header_size) { > +ac_log(ctx, AV_LOG_ERROR, "Error parsing ADTS header\n"); > +return -1; > +} > + > +buf += header_size; > +len -= header_size; > + > +if ((ret = av_new_packet(pkt, len)) < 0) { > +av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); > +return ret; > + } > +memcpy(pkt->data, buf, len); > +pkt->stream_index = st->index; > + > +return 0; > +} > +} > + > if (rtp_parse_mp4_au(data, buf, len)) { > av_log(ctx, AV_LOG_ERROR, "Error parsing AU headers\n"); > return -1; > -- -- Jeff Mahoney OpenPGP_signature Description: OpenPGP digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] libavformat/rtpdec_mpeg: handle bare ADTS packets with explicit decoder config
On 10/17/21 21:28, lance.lmw...@gmail.com wrote: > On Fri, Oct 01, 2021 at 06:53:23PM -0400, Jeff Mahoney wrote: >> When SDP specifies a decoder config, there may not be any AU headers >> provided by the sender. This can result in rtp_parse_mp4_au failing >> and aac_parse_packet reporting "Error parsing AU headers." and no audio >> is recovered from the stream. >> >> This commit modifies aac_parse_header to check for an explicit decoder config >> set by the sdp parser (e.g. a:fmtp # config=hexvalue). If it has and there >> is an ADTS header present, it skips the header and copies the RTP >> payload directly as an AAC packet. >> >> This resolves an issue observed with some inexpensive IP cameras. >> >> Signed-off-by: Jeff Mahoney >> --- >> libavformat/rtpdec_mpeg4.c | 34 +- >> 1 file changed, 33 insertions(+), 1 deletion(-) >> >> diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c >> index 34c7950bcc..dd0ced790e 100644 >> --- a/libavformat/rtpdec_mpeg4.c >> +++ b/libavformat/rtpdec_mpeg4.c >> @@ -176,7 +176,7 @@ static int aac_parse_packet(AVFormatContext *ctx, >> PayloadContext *data, >> int flags) >> { >> int ret; >> - >> +AVCodecParameters *par = st->codecpar; >> >> if (!buf) { >> if (data->cur_au_index > data->nb_au_headers) { >> @@ -204,6 +204,38 @@ static int aac_parse_packet(AVFormatContext *ctx, >> PayloadContext *data, >> return 1; >> } >> >> +/* Check for an explicit decoder config (e.g. SDP a:fmtp... config=) */ >> +if (par->extradata && len > 7) { >> +/* >> + * Start of ADTS header - syncword >> + * If present skip the header and copy the entire payload as AAC >> data >> + */ >> +if (buf[0] == 0xff && (buf[1] & 0xf0) == 0xf0) { >> +/* >> + * The ADTS header is 7 or 9 bytes depending on whether >> + * the protection absent bit is set. If it is unset, a 16-bit >> CRC >> + * is appended to the header. >> + */ >> +size_t header_size = 7 + ((buf[1] & 0x01) ? 0 : 2); >> +if (len < header_size) { >> +ac_log(ctx, AV_LOG_ERROR, "Error parsing ADTS header\n"); >> +return -1; >> +} > > I prefer to use avpriv_adts_header_parse() for ADTS header parse. Thanks, Lance. This wasn't in the master branch when I posted this. It's much cleaner and I'm happy to adapt to it. -Jeff >> + >> +buf += header_size; >> +len -= header_size; >> + >> +if ((ret = av_new_packet(pkt, len)) < 0) { >> +av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); >> +return ret; >> +} >> +memcpy(pkt->data, buf, len); >> +pkt->stream_index = st->index; >> + >> +return 0; >> +} >> +} >> + >> if (rtp_parse_mp4_au(data, buf, len)) { >> av_log(ctx, AV_LOG_ERROR, "Error parsing AU headers\n"); >> return -1; >> -- >> 2.33.0 >> >> ___ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel >> >> To unsubscribe, visit link above, or email >> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". > -- Jeff Mahoney ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] libavformat/rtpdec_mpeg: handle bare ADTS packets with explicit decoder config
When SDP specifies a decoder config, there may not be any AU headers provided by the sender. This can result in rtp_parse_mp4_au failing and aac_parse_packet reporting "Error parsing AU headers." and no audio is recovered from the stream. This commit modifies aac_parse_header to check for an explicit decoder config set by the sdp parser (e.g. a:fmtp # config=hexvalue). If it has and there is an ADTS header present, it skips the header and copies the RTP payload directly as an AAC packet. This resolves an issue observed with some inexpensive IP cameras. Signed-off-by: Jeff Mahoney --- libavformat/rtpdec_mpeg4.c | 37 - 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 34c7950bcc..13d0770dd6 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -32,6 +32,8 @@ #include "libavutil/attributes.h" #include "libavutil/avstring.h" #include "libavcodec/get_bits.h" +#include "libavcodec/adts_header.h" +#include "libavcodec/adts_parser.h" #define MAX_AAC_HBR_FRAME_SIZE 8191 @@ -176,7 +178,7 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, int flags) { int ret; - +AVCodecParameters *par = st->codecpar; if (!buf) { if (data->cur_au_index > data->nb_au_headers) { @@ -204,6 +206,39 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, return 1; } +/* Check for an explicit decoder config (e.g. SDP a:fmtp... config=) */ +if (par->extradata && len > 7) { +AACADTSHeaderInfo *header; + +/* + * Check for ADTS header + * If present skip the header and copy the entire payload as AAC data + */ +ret = avpriv_adts_header_parse(&header, buf, len); +if (!ret) { +buf += AV_AAC_ADTS_HEADER_SIZE; +len -= AV_AAC_ADTS_HEADER_SIZE; + +/* Skip 16-bit CRC if present */ +if (!header->crc_absent) { +buf += 2; +len -= 2; +} +av_free(header); + +ret = av_new_packet(pkt, len); +if (ret < 0) { +av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); +return ret; +} + +memcpy(pkt->data, buf, len); +pkt->stream_index = st->index; + +return 0; +} +} + if (rtp_parse_mp4_au(data, buf, len)) { av_log(ctx, AV_LOG_ERROR, "Error parsing AU headers\n"); return -1; -- 2.33.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] ffplay -fs fix (ticket #3964)
On MS Windows, 'ffplay.exe -fs' does not start fullscreen. Behavior on linux is correct. On Windows, the initial placement of the SDL screen triggers the SDL_VIDEORESIZE event. This executes the code in the event_loop which calls SDL_SetVideoMode with the SDL_RESIZEABLE bit set. On linux the resize event does not occur. I can see an obvious flicker on my laptop as the initial fullscreen window is replaced by the normal window. I don't see it on my faster desktop system. The fix is simple - don't execute SDL_SetVideoMode in the event_loop if is_full_screen is set. Diff for ffplay version N-66289-gb76d613 diff original/ffplay.c fixed/ffplay.c 3469,3470c3469,3471 < screen = SDL_SetVideoMode(FFMIN(16383, event.resize.w), event.resize.h, 0, < SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); --- > if (!is_full_screen) > screen = SDL_SetVideoMode(FFMIN(16383, event.resize.w), event.resize.h, 0, > SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] ffplay -fs fix (ticket #3964)
Your patch works. Thanks, Jeff At 01:19 PM 9/22/2014, you wrote: On Fri, 19 Sep 2014, Jeff Dwork wrote: On MS Windows, 'ffplay.exe -fs' does not start fullscreen. Behavior on linux is correct. On Windows, the initial placement of the SDL screen triggers the SDL_VIDEORESIZE event. This executes the code in the event_loop which calls SDL_SetVideoMode with the SDL_RESIZEABLE bit set. On linux the resize event does not occur. I can see an obvious flicker on my laptop as the initial fullscreen window is replaced by the normal window. I don't see it on my faster desktop system. The fix is simple - don't execute SDL_SetVideoMode in the event_loop if is_full_screen is set. Diff for ffplay version N-66289-gb76d613 diff original/ffplay.c fixed/ffplay.c 3469,3470c3469,3471 < screen = SDL_SetVideoMode(FFMIN(16383, event.resize.w), event.resize.h, 0, < SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); --- if (!is_full_screen) screen = SDL_SetVideoMode(FFMIN(16383, event.resize.w), event.resize.h, 0, SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); I'd rather fix this a bit differently, could you please try the attached patch? Thanks, Marton ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] OpenCV filter should be built as C++, and C builds fail since OpenCV 3.4.1
Hello, Please see the bug report at https://github.com/opencv/opencv/issues/10963 , which discusses OpenCV's failure to build as pure C since upstream version 3.4.1, and also discusses how all modules that use OpenCV 2 or later should be compiled as C++ to avoid esoteric issues and serious breakages. There is a large amount of discussion there that I don't want to needlessly duplicate and/or badly summarize here, but the high-level overview is that it seems that ffmpeg will need to convert avfilter/vf_opencv.c to build as C++ if the OpenCV filter is going to continue to work. The current situation is affecting many prominent projects like VLC. Thanks, Jeff -- Jeff Cook jeff.c...@strongstrata.com ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel