Re: [FFmpeg-devel] [PATCH] add use_localtime option with hlsenc for expand segment filename with localtime

2015-09-01 Thread Michael Niedermayer
On Tue, Sep 01, 2015 at 04:26:01AM +0800, Steven Liu wrote:
> When use %s parameter for the segment filename, it will get error message
> with Invalid
> segment filename template, so add the use_localtime option fix it, the
> default value is
> 14 for the segment filename.
> 
> the test example:
> 
> ./ffmpeg -re -i ~/Movies/objectC/facebook.mp4 -v verbose -c copy -f hls
> -hls_segment_filename test-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb
> aaa.m3u8
> 
> [StevenLiu@localhost ffmpeg]$ cat aaa.m3u8;ll test-*.ts
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-TARGETDURATION:10
> #EXT-X-MEDIA-SEQUENCE:1
> #EXTINF:10.00,
> test-1441052221.ts
> #EXTINF:3.24,
> test-1441052231.ts
> #EXTINF:8.40,
> test-1441052235.ts
> #EXTINF:5.48,
> test-1441052243.ts
> #EXTINF:3.96,
> test-1441052249.ts
> #EXT-X-ENDLIST
> -rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:15 test-1441052131.ts
> -rw-r--r--  1 StevenLiu  staff   495192  9  1 04:15 test-1441052141.ts
> -rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:17 test-1441052212.ts
> -rw-r--r--  1 StevenLiu  staff  1067840  9  1 04:17 test-1441052221.ts
> -rw-r--r--  1 StevenLiu  staff   235564  9  1 04:17 test-1441052231.ts
> -rw-r--r--  1 StevenLiu  staff  1187220  9  1 04:17 test-1441052235.ts
> -rw-r--r--  1 StevenLiu  staff   694848  9  1 04:17 test-1441052243.ts
> -rw-r--r--  1 StevenLiu  staff   526588  9  1 04:17 test-1441052249.ts
> [StevenLiu@localhost ffmpeg]$
> 
> ./ffmpeg -re -i ~/Movies/objectC/facebook.mp4 -v verbose -c copy -f hls
> -hls_segment_filename test-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb
> aaa.m3u8
> 
> [StevenLiu@localhost ffmpeg]$ cat aaa.m3u8;ll aaa-*.ts
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-TARGETDURATION:10
> #EXT-X-MEDIA-SEQUENCE:0
> #EXTINF:10.00,
> aaa-1441052417.ts
> #EXTINF:10.00,
> aaa-1441052427.ts
> #EXTINF:3.24,
> aaa-1441052437.ts
> #EXTINF:8.40,
> aaa-1441052440.ts
> #EXTINF:2.36,
> aaa-1441052449.ts
> #EXT-X-ENDLIST
> -rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:19 aaa-1441052382.ts
> -rw-r--r--  1 StevenLiu  staff   277300  9  1 04:19 aaa-1441052392.ts
> -rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:20 aaa-1441052417.ts
> -rw-r--r--  1 StevenLiu  staff  1067840  9  1 04:20 aaa-1441052427.ts
> -rw-r--r--  1 StevenLiu  staff   235564  9  1 04:20 aaa-1441052437.ts
> -rw-r--r--  1 StevenLiu  staff  1187220  9  1 04:20 aaa-1441052440.ts
> -rw-r--r--  1 StevenLiu  staff   338776  9  1 04:20 aaa-1441052449.ts
> [StevenLiu@localhost ffmpeg]$
> 
> 
> Signed-off-by: LiuQi 
> ---
>  libavformat/hlsenc.c | 28 
>  1 file changed, 24 insertions(+), 4 deletions(-)

applied

thanks

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
conveniently.
New school: Use the highest level language in which the latest supercomputer
can solve the problem without the user falling asleep waiting.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] add use_localtime option with hlsenc for expand segment filename with localtime

2015-08-31 Thread Steven Liu
When use %s parameter for the segment filename, it will get error message
with Invalid
segment filename template, so add the use_localtime option fix it, the
default value is
14 for the segment filename.

the test example:

./ffmpeg -re -i ~/Movies/objectC/facebook.mp4 -v verbose -c copy -f hls
-hls_segment_filename test-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb
aaa.m3u8

[StevenLiu@localhost ffmpeg]$ cat aaa.m3u8;ll test-*.ts
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10.00,
test-1441052221.ts
#EXTINF:3.24,
test-1441052231.ts
#EXTINF:8.40,
test-1441052235.ts
#EXTINF:5.48,
test-1441052243.ts
#EXTINF:3.96,
test-1441052249.ts
#EXT-X-ENDLIST
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:15 test-1441052131.ts
-rw-r--r--  1 StevenLiu  staff   495192  9  1 04:15 test-1441052141.ts
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:17 test-1441052212.ts
-rw-r--r--  1 StevenLiu  staff  1067840  9  1 04:17 test-1441052221.ts
-rw-r--r--  1 StevenLiu  staff   235564  9  1 04:17 test-1441052231.ts
-rw-r--r--  1 StevenLiu  staff  1187220  9  1 04:17 test-1441052235.ts
-rw-r--r--  1 StevenLiu  staff   694848  9  1 04:17 test-1441052243.ts
-rw-r--r--  1 StevenLiu  staff   526588  9  1 04:17 test-1441052249.ts
[StevenLiu@localhost ffmpeg]$

./ffmpeg -re -i ~/Movies/objectC/facebook.mp4 -v verbose -c copy -f hls
-hls_segment_filename test-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb
aaa.m3u8

[StevenLiu@localhost ffmpeg]$ cat aaa.m3u8;ll aaa-*.ts
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.00,
aaa-1441052417.ts
#EXTINF:10.00,
aaa-1441052427.ts
#EXTINF:3.24,
aaa-1441052437.ts
#EXTINF:8.40,
aaa-1441052440.ts
#EXTINF:2.36,
aaa-1441052449.ts
#EXT-X-ENDLIST
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:19 aaa-1441052382.ts
-rw-r--r--  1 StevenLiu  staff   277300  9  1 04:19 aaa-1441052392.ts
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:20 aaa-1441052417.ts
-rw-r--r--  1 StevenLiu  staff  1067840  9  1 04:20 aaa-1441052427.ts
-rw-r--r--  1 StevenLiu  staff   235564  9  1 04:20 aaa-1441052437.ts
-rw-r--r--  1 StevenLiu  staff  1187220  9  1 04:20 aaa-1441052440.ts
-rw-r--r--  1 StevenLiu  staff   338776  9  1 04:20 aaa-1441052449.ts
[StevenLiu@localhost ffmpeg]$


Signed-off-by: LiuQi 
---
 libavformat/hlsenc.c | 28 
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 2c0c6f0..11987c5 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -79,6 +79,7 @@ typedef struct HLSContext {
 uint32_t flags;// enum HLSFlags
 char *segment_filename;

+int use_localtime;  ///< flag to expand filename with localtime
 int allowcache;
 int64_t recording_time;
 int has_video;
@@ -479,9 +480,18 @@ static int hls_start(AVFormatContext *s)
 av_strlcpy(vtt_oc->filename, c->vtt_basename,
   sizeof(vtt_oc->filename));
 } else {
-if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
+   if (c->use_localtime) {
+   time_t now0;
+   struct tm *tm, tmpbuf;
+   time(&now0);
+   tm = localtime_r(&now0, &tmpbuf);
+   if (!strftime(oc->filename, sizeof(oc->filename), c->basename,
tm)) {
+   av_log(oc, AV_LOG_ERROR, "Could not get segment filename
with use_localtime\n");
+   return AVERROR(EINVAL);
+   }
+   } else if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
   c->basename, c->wrap ? c->sequence %
c->wrap : c->sequence) < 0) {
-av_log(oc, AV_LOG_ERROR, "Invalid segment filename template
'%s'\n", c->basename);
+av_log(oc, AV_LOG_ERROR, "Invalid segment filename template
'%s' you can try use -use_localtime 1 with it\n", c->basename);
 return AVERROR(EINVAL);
 }
 if( c->vtt_basename) {
@@ -542,6 +552,7 @@ static int hls_write_header(AVFormatContext *s)
 int ret, i;
 char *p;
 const char *pattern = "%d.ts";
+const char *pattern_localtime_fmt = "-%s.ts";
 const char *vtt_pattern = "%d.vtt";
 AVDictionary *options = NULL;
 int basename_size;
@@ -596,7 +607,11 @@ static int hls_write_header(AVFormatContext *s)
 if (hls->flags & HLS_SINGLE_FILE)
 pattern = ".ts";

-basename_size = strlen(s->filename) + strlen(pattern) + 1;
+if (hls->use_localtime) {
+basename_size = strlen(s->filename) +
strlen(pattern_localtime_fmt) + 1;
+} else {
+basename_size = strlen(s->filename) + strlen(pattern) + 1;
+}
 hls->basename = av_malloc(basename_size);
 if (!hls->basename) {
 ret = AVERROR(ENOMEM);
@@ -608,7 +623,11 @@ static int hls_write_header(AVFormatContext *s)
 p = strrchr(hls->basename, '.');
 if (p)
 *p = '\0';
-av