[PATCH 1/4] av_d2q: Add a special case for |value| > MAX and |value| < 1/MAX
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavutil/rational.c | 2 ++ tests/ref/fate/parseutils | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libavutil/rational.c b/libavutil/rational.c index 912abc3..62473b4 100644 --- a/libavutil/rational.c +++ b/libavutil/rational.c @@ -115,6 +115,8 @@ AVRational av_d2q(double d, int max) exponent = FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); den = 1LL << (61 - exponent); av_reduce(&a.num, &a.den, llrint(d * den), den, max); + if ((!a.num || !a.den) && d && max>0 && max<INT_MAX) + av_reduce(&a.num, &a.den, llrint(d * den), den, INT_MAX); return a; } diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils index 5fa3bf4..1482452 100644 --- a/tests/ref/fate/parseutils +++ b/tests/ref/fate/parseutils @@ -21,7 +21,7 @@ Testing av_parse_video_rate() '.23' -> 23/100 OK '-.23' -> -23/100 ERROR '-0.234' -> -117/500 ERROR -'-0.0000001' -> 0/1 ERROR +'-0.0000001' -> -1/10000000 ERROR ' 21332.2324 ' -> 917286/43 OK ' -21332.2324 ' -> -917286/43 ERROR -- 1.7.9.5
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index faf3186..f446daf 100755 --- a/configure +++ b/configure @@ -1510,6 +1510,7 @@ HAVE_LIST=" struct_sockaddr_in6 struct_sockaddr_sa_len struct_sockaddr_storage + struct_stat_st_mtim_tv_nsec struct_v4l2_frmivalenum_discrete symver_asm_label symver_gnu_asm @@ -3912,6 +3913,7 @@ check_func mprotect check_func ${malloc_prefix}posix_memalign && enable posix_memalign check_func_headers malloc.h _aligned_malloc && enable aligned_malloc check_func setrlimit +check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE check_func strerror_r check_func sched_getaffinity check_builtin sync_val_compare_and_swap "" "int *ptr; int oldval, newval; __sync_val_compare_and_swap(ptr, oldval, newval)" -- 1.7.9.5
On Sat, May 25, 2013 at 03:58:02PM +0200, Michael Niedermayer wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- configure | 2 ++ 1 file changed, 2 insertions(+)
applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavformat/img2dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 666138b..b847d6c 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -226,9 +226,9 @@ static int img_read_header(AVFormatContext *s1) } if (s->ts_from_file) - avpriv_set_pts_info(st, 60, 1, 1); + avpriv_set_pts_info(st, 64, 1, 1); else - avpriv_set_pts_info(st, 60, s->framerate.den, s->framerate.num); + avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); if (s->width && s->height) { st->codec->width = s->width; -- 1.7.9.5
On Sat, May 25, 2013 at 03:58:03PM +0200, Michael Niedermayer wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavformat/img2dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavformat/img2dec.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index b847d6c..ea4ee0f 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define _BSD_SOURCE #include <sys/stat.h> #include "libavutil/avstring.h" #include "libavutil/log.h" @@ -225,7 +226,13 @@ static int img_read_header(AVFormatContext *s1) st->need_parsing = AVSTREAM_PARSE_FULL; } - if (s->ts_from_file) + if (s->ts_from_file == 2) { +#if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n"); + return AVERROR(ENOSYS); +#endif + avpriv_set_pts_info(st, 64, 1, 1000000000); + } else if (s->ts_from_file) avpriv_set_pts_info(st, 64, 1, 1); else avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); @@ -393,6 +400,10 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) if (stat(filename, &img_stat)) return AVERROR(EIO); pkt->pts = (int64_t)img_stat.st_mtime; +#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + if (s->ts_from_file == 2) + pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec; +#endif av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME); } else if (!s->is_pipe) { pkt->pts = s->pts; @@ -467,7 +478,7 @@ static const AVOption options[] = { { "start_number_range", "set range for looking at the first sequence number", OFFSET(start_number_range), AV_OPT_TYPE_INT, {.i64 = 5}, 1, INT_MAX, DEC }, { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC }, - { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, DEC }, + { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, DEC }, { NULL }, }; -- 1.7.9.5
Great, didn't know about it. Looks this feature is not documented well (absent in man). This feature of ts_from_name=2 should be documented. -- Andrey Utkin
On Sat, May 25, 2013 at 03:58:04PM +0200, Michael Niedermayer wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavformat/img2dec.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index b847d6c..ea4ee0f 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _BSD_SOURCE #include <sys/stat.h> #include "libavutil/avstring.h" #include "libavutil/log.h" @@ -225,7 +226,13 @@ static int img_read_header(AVFormatContext *s1) st->need_parsing = AVSTREAM_PARSE_FULL; }
- if (s->ts_from_file) + if (s->ts_from_file == 2) { +#if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n"); + return AVERROR(ENOSYS); +#endif + avpriv_set_pts_info(st, 64, 1, 1000000000); + } else if (s->ts_from_file) avpriv_set_pts_info(st, 64, 1, 1); else avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); @@ -393,6 +400,10 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) if (stat(filename, &img_stat)) return AVERROR(EIO); pkt->pts = (int64_t)img_stat.st_mtime; +#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + if (s->ts_from_file == 2) + pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec; +#endif av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME); } else if (!s->is_pipe) { pkt->pts = s->pts; @@ -467,7 +478,7 @@ static const AVOption options[] = { { "start_number_range", "set range for looking at the first sequence number", OFFSET(start_number_range), AV_OPT_TYPE_INT, {.i64 = 5}, 1, INT_MAX, DEC }, { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC }, - { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, DEC }, + { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, DEC }, { NULL },
0, 1 and 2 are not intuitive, especially without a documentation update. Could you add some const? Use case examples would be welcome. How does this behave when you mix this with -vsync cfr/vfr? -- Clément B.
On Mon, May 27, 2013 at 11:24:02PM +0200, Clément Bœsch wrote:
On Sat, May 25, 2013 at 03:58:04PM +0200, Michael Niedermayer wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavformat/img2dec.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index b847d6c..ea4ee0f 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _BSD_SOURCE #include <sys/stat.h> #include "libavutil/avstring.h" #include "libavutil/log.h" @@ -225,7 +226,13 @@ static int img_read_header(AVFormatContext *s1) st->need_parsing = AVSTREAM_PARSE_FULL; }
- if (s->ts_from_file) + if (s->ts_from_file == 2) { +#if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n"); + return AVERROR(ENOSYS); +#endif + avpriv_set_pts_info(st, 64, 1, 1000000000); + } else if (s->ts_from_file) avpriv_set_pts_info(st, 64, 1, 1); else avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); @@ -393,6 +400,10 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) if (stat(filename, &img_stat)) return AVERROR(EIO); pkt->pts = (int64_t)img_stat.st_mtime; +#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + if (s->ts_from_file == 2) + pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec; +#endif av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME); } else if (!s->is_pipe) { pkt->pts = s->pts; @@ -467,7 +478,7 @@ static const AVOption options[] = { { "start_number_range", "set range for looking at the first sequence number", OFFSET(start_number_range), AV_OPT_TYPE_INT, {.i64 = 5}, 1, INT_MAX, DEC }, { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC }, - { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, DEC }, + { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, DEC }, { NULL },
0, 1 and 2 are not intuitive, especially without a documentation update. Could you add some const?
added and applied
Use case examples would be welcome. How does this behave when you mix this with -vsync cfr/vfr?
it should behave the same as any other input with timestamps in nanosecond precission [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Its not that you shouldnt use gotos but rather that you should write readable code and code with gotos often but not always is less readable
On Sat, May 25, 2013 at 03:58:01PM +0200, Michael Niedermayer wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavutil/rational.c | 2 ++ tests/ref/fate/parseutils | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB it is not once nor twice but times without number that the same ideas make their appearance in the world. -- Aristotle
participants (3)
-
Andrey Utkin -
Clément Bœsch -
Michael Niedermayer