Skip to content

Instantly share code, notes, and snippets.

@rdp
Created September 22, 2016 15:52
Show Gist options
  • Save rdp/e518616f2a702367ae5a922b56e09e04 to your computer and use it in GitHub Desktop.
Save rdp/e518616f2a702367ae5a922b56e09e04 to your computer and use it in GitHub Desktop.
diff --git a/go_protocol_local.bat b/go_protocol_local.bat
index 161a8a7..5bc2a09 100644
--- a/go_protocol_local.bat
+++ b/go_protocol_local.bat
@@ -4,7 +4,7 @@ echo "this does not do a rebuild"
del myfile
del ksl.2hr.ts
@rem -analyzeduration 1G -probesize 1G
-.\ffmpeg_g.exe -local_buffer_size 500M -debug 1 -loglevel info -receiver_component "Hauppauge WinTV 885 TS Capture" -tune_freq 651250 -dtv a -dump_graph_filename dump.grf -i dshowbda:video="Hauppauge WinTV 885 BDA Tuner/Demod" -t 86400 -r 10 -s 100x100 -y out.mp4 -loglevel debug
+.\ffmpeg_g.exe -local_buffer_size 500M -debug 1 -loglevel info -receiver_component "Hauppauge WinTV 885 TS Capture" -tune_freq 615250 -dtv a -dump_graph_filename dump.grf -i dshowbda:video="Hauppauge WinTV 885 BDA Tuner/Demod" -t 86400 -r 10 -s 100x100 -y out.mp4 -loglevel debug
@rem 86400 1 day
@rem 604800 7 days
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 285bb16..fafabb2 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2670,6 +2670,11 @@ void av_dump_format(AVFormatContext *ic,
int av_get_frame_filename(char *buf, int buf_size,
const char *path, int number);
+
+int av_get_frame_filename2(char *buf, int buf_size,
+ const char *path, int number, int64_t ts);
+
+
/**
* Check whether filename actually is a numbered sequence generator.
*
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 9291802..d76cbba 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -84,10 +84,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
VideoMuxData *img = s->priv_data;
AVIOContext *pb[4];
char filename[1024];
- AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
+ AVStream *stream = s->streams[ pkt->stream_index ];
+ AVCodecContext *codec = stream->codec;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(codec->pix_fmt);
int i;
int nb_renames = 0;
+ int64_t ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q);
if (!img->is_pipe) {
if (img->update) {
@@ -101,7 +103,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n");
return AVERROR(EINVAL);
}
- } else if (av_get_frame_filename(filename, sizeof(filename), img->path, img->img_number) < 0 &&
+ } else if (av_get_frame_filename2(filename, sizeof(filename), img->path, img->img_number, ts) < 0 &&
img->img_number > 1) {
av_log(s, AV_LOG_ERROR,
"Could not get frame filename number %d from pattern '%s' (either set updatefirst or use a pattern like %%03d within the filename pattern)\n",
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 6bf2fd1..06d5653 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3955,15 +3955,29 @@ uint64_t ff_ntp_time(void)
return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
}
-int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
+
+
+int av_get_frame_filename(char *buf, int buf_size,
+ const char *path, int number)
+{
+ /*
+ * old versions don't support timestamps in filename (%t)
+ * so just pass 0 as the frame timestamp
+ */
+ return av_get_frame_filename2(buf, buf_size, path, number, 0);
+}
+
+int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int64_t ts)
{
const char *p;
char *q, buf1[20], c;
- int nd, len, percentd_found;
+ int nd, len, percentd_found, percent_t_found;
+ int hours, mins, secs, ms;
q = buf;
p = path;
percentd_found = 0;
+ percent_t_found = 0;
for (;;) {
c = *p++;
if (c == '\0')
@@ -3992,6 +4006,34 @@ int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
memcpy(q, buf1, len);
q += len;
break;
+ case 't':
+ if (percent_t_found) {
+ av_log(NULL, AV_LOG_ERROR, "double %%t not allowed");
+ goto fail;
+ }
+ if (ts < 1) {
+ av_log(NULL, AV_LOG_ERROR, "%%t no ts");
+ goto fail;
+ }
+ percent_t_found = 1;
+ ms = ts % (AV_TIME_BASE / 1000);
+ ts /= AV_TIME_BASE;
+
+ secs = ts % 60;
+ ts /= 60;
+ mins = ts % 60;
+ ts /= 60;
+ hours = ts;
+ snprintf(buf1, sizeof(buf1),
+ "%02d.%02d.%02d.%03d", hours, mins, secs, ms);
+ len = strlen(buf1);
+ if ((q - buf + len) > buf_size - 1) {
+ av_log(NULL, AV_LOG_ERROR, "%%t size failure");
+ goto fail;
+ }
+ memcpy(q, buf1, len);
+ q += len;
+ break;
default:
goto fail;
}
@@ -4001,7 +4043,7 @@ addchar:
*q++ = c;
}
}
- if (!percentd_found)
+ if (!percentd_found && !percent_t_found)
goto fail;
*q = '\0';
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment