From faa229e67c8a8bbef3655c67553ee4a59de810c0 Mon Sep 17 00:00:00 2001 From: vivook Date: Thu, 24 Dec 2020 08:24:04 +0000 Subject: [PATCH 1/5] Add no merge option --- src/hls.c | 12 +++++++- src/hls.h | 2 +- src/main.c | 90 ++++++------------------------------------------------ src/misc.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++- src/misc.h | 4 +++ 5 files changed, 105 insertions(+), 84 deletions(-) diff --git a/src/hls.c b/src/hls.c index a007b8f..f803e95 100644 --- a/src/hls.c +++ b/src/hls.c @@ -1551,7 +1551,7 @@ uint8_t * find_first_ts_packet(ByteBuffer_t *buf) { return NULL; } -int download_hls(write_ctx_t *out_ctx, hls_media_playlist_t *me, hls_media_playlist_t *me_audio) +int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool merge) { MSG_VERBOSE("Downloading segments.\n"); MSG_API("{\"d_t\":\"vod\"}\n"); // d_t - download type @@ -1568,6 +1568,16 @@ int download_hls(write_ctx_t *out_ctx, hls_media_playlist_t *me, hls_media_playl struct ByteBuffer seg; struct ByteBuffer seg_audio; + FILE *out_file = get_output_file(); + if (!out_file) { + MSG_ERROR("Failed to open output file!\n"); + return -1; + } + + write_ctx_t out_ctx_ = {priv_write, out_file}; + write_ctx_t *out_ctx = &out_ctx_; + // fclose(out_file); + struct hls_media_segment *ms = me->first_media_segment; struct hls_media_segment *ms_audio = NULL; merge_context_t merge_context; diff --git a/src/hls.h b/src/hls.h index ee1b863..63813b5 100644 --- a/src/hls.h +++ b/src/hls.h @@ -97,7 +97,7 @@ int handle_hls_media_playlist(hls_media_playlist_t *me); int download_live_hls(write_ctx_t *ctx, hls_media_playlist_t *me); bool consecutive_sync_byte(uint8_t *buf, size_t len, uint8_t n); uint8_t * find_first_ts_packet(ByteBuffer_t *buf); -int download_hls(write_ctx_t *ctx, hls_media_playlist_t *me, hls_media_playlist_t *me_audio); +int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool merge); int print_enc_keys(hls_media_playlist_t *me); void print_hls_master_playlist(struct hls_master_playlist *ma); void media_playlist_cleanup(hls_media_playlist_t *me); diff --git a/src/main.c b/src/main.c index c157c76..a145040 100644 --- a/src/main.c +++ b/src/main.c @@ -21,80 +21,6 @@ #include "msg.h" #include "misc.h" -static size_t priv_write(const uint8_t *data, size_t len, void *opaque) { - return fwrite(data, 1, len, opaque); -} - -static bool is_file_exists(const char *filename) -{ -#ifndef _MSC_VER - return access(filename, F_OK) != -1; -#else - struct stat info; - int ret = -1; - - ret = stat(filename, &info); - return 0 == ret; -#endif -} - -static FILE* get_output_file(void) -{ - FILE *pFile = NULL; - - if (hls_args.filename && 0 == strncmp(hls_args.filename, "-", 2)) { - // Set "stdout" to have binary mode: - fflush(stdout); -#if !defined(_MSC_VER) && !defined(__MINGW32__) - pFile = freopen(NULL, "wb", stdout); -#else - if (-1 != setmode(_fileno(stdout), _O_BINARY)) { - pFile = stdout; - } -#endif - fflush(stdout); - } else { - char filename[MAX_FILENAME_LEN]; - if (hls_args.filename) { - strcpy(filename, hls_args.filename); - } - else { - strcpy(filename, "000_hls_output.ts"); - } - - if (is_file_exists(filename)) { - if (hls_args.force_overwrite) { - if (remove(filename) != 0) { - MSG_ERROR("Error overwriting file"); - exit(1); - } - } - else { - char userchoice = '\0'; - MSG_PRINT("File already exists. Overwrite? (y/n) "); - if (scanf("\n%c", &userchoice) && userchoice == 'y') { - if (remove(filename) != 0) { - MSG_ERROR("Error overwriting file"); - exit(1); - } - } - else { - MSG_WARNING("Choose a different filename. Exiting.\n"); - exit(0); - } - } - } - - pFile = fopen(filename, "wb"); - } - - if (pFile == NULL) - { - MSG_ERROR("Error can not open output file\n"); - exit(1); - } - return pFile; -} static bool get_data_with_retry(char *url, char **hlsfile_source, char **finall_url, int tries) { @@ -389,16 +315,18 @@ int main(int argc, char *argv[]) } } else { int ret = -1; - FILE *out_file = get_output_file(); - if (out_file) { - write_ctx_t out_ctx = {priv_write, out_file}; - if (media_playlist.is_endlist) { - ret = download_hls(&out_ctx, &media_playlist, &audio_media_playlist); - } else { + + if (media_playlist.is_endlist) { + ret = download_hls(&media_playlist, &audio_media_playlist, hls_args.skip_merge); + } else { + FILE *out_file = get_output_file(); + if (out_file) { + write_ctx_t out_ctx = {priv_write, out_file}; ret = download_live_hls(&out_ctx, &media_playlist); + fclose(out_file); } - fclose(out_file); } + return ret ? 1 : 0; } diff --git a/src/misc.c b/src/misc.c index 40cc334..11bcab8 100644 --- a/src/misc.c +++ b/src/misc.c @@ -28,6 +28,7 @@ static void print_help(const char *filename) "-A ... Select audio language.\n" "-v ... Verbose more information.\n" "-o ... Choose name of output file (\"-\" alias for stdout).\n" + "-m ... Don't merge output - save individual parts instead.\n" "-u ... Set custom HTTP User-Agent header.\n" "-h ... Set custom HTTP header.\n" "-p ... Set proxy uri.\n" @@ -55,7 +56,7 @@ int parse_argv(int argc, char * const argv[]) int ret = 0; int c = 0; int custom_header_idx = 0; - while ( (c = getopt(argc, argv, "bH:W:A:vqbfFK:ctdo:u:h:s:i:r:w:e:p:k:n:a:C:")) != -1) + while ( (c = getopt(argc, argv, "bH:W:A:vqbfFK:ctdo:mu:h:s:i:r:w:e:p:k:n:a:C:")) != -1) { switch (c) { @@ -114,6 +115,9 @@ int parse_argv(int argc, char * const argv[]) case 'o': hls_args.filename = optarg; break; + case 'm': + hls_args.skip_merge = true; + break; case 't': hls_args.dump_ts_urls = true; break; @@ -253,3 +257,78 @@ char *repl_str(const char *str, const char *from, const char *to) free(pos_cache); return ret; } + +FILE* get_output_file(void) +{ + FILE *pFile = NULL; + + if (hls_args.filename && 0 == strncmp(hls_args.filename, "-", 2)) { + // Set "stdout" to have binary mode: + fflush(stdout); +#if !defined(_MSC_VER) && !defined(__MINGW32__) + pFile = freopen(NULL, "wb", stdout); +#else + if (-1 != setmode(_fileno(stdout), _O_BINARY)) { + pFile = stdout; + } +#endif + fflush(stdout); + } else { + char filename[MAX_FILENAME_LEN]; + if (hls_args.filename) { + strcpy(filename, hls_args.filename); + } + else { + strcpy(filename, "000_hls_output.ts"); + } + + if (is_file_exists(filename)) { + if (hls_args.force_overwrite) { + if (remove(filename) != 0) { + MSG_ERROR("Error overwriting file"); + exit(1); + } + } + else { + char userchoice = '\0'; + MSG_PRINT("File already exists. Overwrite? (y/n) "); + if (scanf("\n%c", &userchoice) && userchoice == 'y') { + if (remove(filename) != 0) { + MSG_ERROR("Error overwriting file"); + exit(1); + } + } + else { + MSG_WARNING("Choose a different filename. Exiting.\n"); + exit(0); + } + } + } + + pFile = fopen(filename, "wb"); + } + + if (pFile == NULL) + { + MSG_ERROR("Error can not open output file\n"); + exit(1); + } + return pFile; +} + +size_t priv_write(const uint8_t *data, size_t len, void *opaque) { + return fwrite(data, 1, len, opaque); +} + +bool is_file_exists(const char *filename) +{ +#ifndef _MSC_VER + return access(filename, F_OK) != -1; +#else + struct stat info; + int ret = -1; + + ret = stat(filename, &info); + return 0 == ret; +#endif +} diff --git a/src/misc.h b/src/misc.h index 069d873..c9cb599 100644 --- a/src/misc.h +++ b/src/misc.h @@ -37,6 +37,7 @@ struct hls_args { bool force_ignoredrm; bool dump_ts_urls; bool dump_dec_cmd; + bool skip_merge; int live_start_offset_sec; int live_duration_sec; int refresh_delay_sec; @@ -60,6 +61,9 @@ extern struct hls_args hls_args; int str_to_bin(uint8_t *data, char *hexstring, int len); int parse_argv(int argc, char * const argv[]); +FILE* get_output_file(void); +size_t priv_write(const uint8_t *data, size_t len, void *opaque); +bool is_file_exists(const char *filename); char *repl_str(const char *str, const char *from, const char *to); From 3cb8bff7ddca2c3eb3726a97f503e96bf5fe6ae1 Mon Sep 17 00:00:00 2001 From: vivook Date: Thu, 24 Dec 2020 09:17:12 +0000 Subject: [PATCH 2/5] Increment filename prefix when not merging --- src/hls.c | 31 +++++++++++++++++++++++++++++-- src/main.c | 5 +++-- src/misc.c | 13 +++++++++---- src/misc.h | 2 +- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/hls.c b/src/hls.c index f803e95..8122c81 100644 --- a/src/hls.c +++ b/src/hls.c @@ -1562,13 +1562,21 @@ int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool set_timeout_session(session, 2L, 3L); assert(session); time_t repTime = 0; + int i = 0; uint64_t downloaded_duration_ms = 0; int64_t download_size = 0; struct ByteBuffer seg; struct ByteBuffer seg_audio; - FILE *out_file = get_output_file(); + char prefix[5]; + if (!merge) { + strcpy(prefix, "000_"); + } else { + strcpy(prefix, ""); + } + + FILE *out_file = get_output_file(prefix); if (!out_file) { MSG_ERROR("Failed to open output file!\n"); return -1; @@ -1576,7 +1584,6 @@ int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool write_ctx_t out_ctx_ = {priv_write, out_file}; write_ctx_t *out_ctx = &out_ctx_; - // fclose(out_file); struct hls_media_segment *ms = me->first_media_segment; struct hls_media_segment *ms_audio = NULL; @@ -1634,10 +1641,30 @@ int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool } ms = ms->next; + + i++; + + if (!merge) { + if (out_file) { + fclose(out_file); + } + + sprintf(prefix, "%03d_", i); + MSG_API("Creating filename with prefix: %s (i=%d)\n", prefix, i); + out_file = get_output_file(prefix); + if (!out_file) { + MSG_ERROR("Failed to open output file!\n"); + return -1; + } + } } MSG_API("{\"t_d\":%u,\"d_d\":%u,\"d_s\":%"PRId64"}\n", (uint32_t)(me->total_duration_ms / 1000), (uint32_t)(downloaded_duration_ms / 1000), download_size); + if (out_file) { + fclose(out_file); + } + if (session) { clean_http_session(session); } diff --git a/src/main.c b/src/main.c index a145040..cb7169b 100644 --- a/src/main.c +++ b/src/main.c @@ -317,9 +317,10 @@ int main(int argc, char *argv[]) int ret = -1; if (media_playlist.is_endlist) { - ret = download_hls(&media_playlist, &audio_media_playlist, hls_args.skip_merge); + ret = download_hls(&media_playlist, &audio_media_playlist, !hls_args.skip_merge); } else { - FILE *out_file = get_output_file(); + char prefix[] = ""; + FILE *out_file = get_output_file(prefix); if (out_file) { write_ctx_t out_ctx = {priv_write, out_file}; ret = download_live_hls(&out_ctx, &media_playlist); diff --git a/src/misc.c b/src/misc.c index 11bcab8..3c0b93a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -258,7 +258,7 @@ char *repl_str(const char *str, const char *from, const char *to) return ret; } -FILE* get_output_file(void) +FILE* get_output_file(char prefix[]) { FILE *pFile = NULL; @@ -274,14 +274,19 @@ FILE* get_output_file(void) #endif fflush(stdout); } else { - char filename[MAX_FILENAME_LEN]; + char filename[MAX_FILENAME_LEN + strlen(prefix) + 1]; + strcpy(filename, prefix); + if (hls_args.filename) { - strcpy(filename, hls_args.filename); + strncat(filename, hls_args.filename, strlen(hls_args.filename)); } else { - strcpy(filename, "000_hls_output.ts"); + char default_filename[] = "hls_output.ts"; + strncat(filename, default_filename, strlen(default_filename)); } + MSG_API("Using output filename: %s\n", filename); + if (is_file_exists(filename)) { if (hls_args.force_overwrite) { if (remove(filename) != 0) { diff --git a/src/misc.h b/src/misc.h index c9cb599..5abf50d 100644 --- a/src/misc.h +++ b/src/misc.h @@ -61,7 +61,7 @@ extern struct hls_args hls_args; int str_to_bin(uint8_t *data, char *hexstring, int len); int parse_argv(int argc, char * const argv[]); -FILE* get_output_file(void); +FILE* get_output_file(char prefix[]); size_t priv_write(const uint8_t *data, size_t len, void *opaque); bool is_file_exists(const char *filename); From 0ad61603c0c0ff2e586c702ad301ab1348e31438 Mon Sep 17 00:00:00 2001 From: vivook Date: Thu, 24 Dec 2020 10:21:27 +0000 Subject: [PATCH 3/5] Allow ignoring HTTP errors --- src/hls.c | 84 +++++++++++++++++++++++++++--------------------------- src/hls.h | 2 +- src/main.c | 3 +- src/misc.c | 8 ++++-- src/misc.h | 1 + 5 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/hls.c b/src/hls.c index 8122c81..2b83fee 100644 --- a/src/hls.c +++ b/src/hls.c @@ -1467,7 +1467,7 @@ static int vod_download_segment(void **psession, hls_media_playlist_t *me, struc int retries = 0; int ret = 0; while (true) { - MSG_PRINT("Downloading part %d\n", ms->sequence_number); + MSG_PRINT("Downloading part %d from %s\n", ms->sequence_number, ms->url); memset(seg, 0x00, sizeof(*seg)); size_t size = 0; @@ -1551,7 +1551,7 @@ uint8_t * find_first_ts_packet(ByteBuffer_t *buf) { return NULL; } -int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool merge) +int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool merge, bool ignore_http_errors) { MSG_VERBOSE("Downloading segments.\n"); MSG_API("{\"d_t\":\"vod\"}\n"); // d_t - download type @@ -1571,7 +1571,7 @@ int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool char prefix[5]; if (!merge) { - strcpy(prefix, "000_"); + sprintf(prefix, "%03d_", i); } else { strcpy(prefix, ""); } @@ -1596,61 +1596,61 @@ int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool } while(ms) { - if (0 != vod_download_segment(&session, me, ms, &seg)) { - break; - } - - uint8_t *first_video_packet = find_first_ts_packet(&seg); - uint8_t *first_audio_packet = NULL; - if (ms_audio) { - if ( 0 != vod_download_segment(&session, me_audio, ms_audio, &seg_audio)) { - break; + if (0 == vod_download_segment(&session, me, ms, &seg)) { + uint8_t *first_video_packet = find_first_ts_packet(&seg); + uint8_t *first_audio_packet = NULL; + if (ms_audio) { + if ( 0 != vod_download_segment(&session, me_audio, ms_audio, &seg_audio)) { + break; + } + first_audio_packet = find_first_ts_packet(&seg_audio); } - first_audio_packet = find_first_ts_packet(&seg_audio); - } - // first segment should be TS for success merge - if (first_video_packet && first_audio_packet) { - size_t video_len = seg.len - (first_video_packet - seg.data); - size_t audio_len = seg_audio.len - (first_audio_packet - seg_audio.data); - - download_size += merge_packets( - &merge_context, - first_video_packet, - video_len, - first_audio_packet, - audio_len - ); - } else { - download_size += out_ctx->write(seg.data, seg.len, out_ctx->opaque); - } + // first segment should be TS for success merge + if (first_video_packet && first_audio_packet) { + size_t video_len = seg.len - (first_video_packet - seg.data); + size_t audio_len = seg_audio.len - (first_audio_packet - seg_audio.data); + + download_size += merge_packets( + &merge_context, + first_video_packet, + video_len, + first_audio_packet, + audio_len + ); + } else { + download_size += out_ctx->write(seg.data, seg.len, out_ctx->opaque); + } - if (ms_audio) { - free(seg_audio.data); - ms_audio = ms_audio->next; - } + if (ms_audio) { + free(seg_audio.data); + ms_audio = ms_audio->next; + } - free(seg.data); + free(seg.data); - downloaded_duration_ms += ms->duration_ms; + downloaded_duration_ms += ms->duration_ms; - time_t curRepTime = time(NULL); - if ((curRepTime - repTime) >= 1) { - MSG_API("{\"t_d\":%u,\"d_d\":%u,\"d_s\":%"PRId64"}\n", (uint32_t)(me->total_duration_ms / 1000), (uint32_t)(downloaded_duration_ms / 1000), download_size); - repTime = curRepTime; + time_t curRepTime = time(NULL); + if ((curRepTime - repTime) >= 1) { + MSG_API("{\"t_d\":%u,\"d_d\":%u,\"d_s\":%"PRId64"}\n", (uint32_t)(me->total_duration_ms / 1000), (uint32_t)(downloaded_duration_ms / 1000), download_size); + repTime = curRepTime; + } + } else if (ignore_http_errors) { + MSG_WARNING("Ignoring error downloading segment %d\n", i+1); + } else { + break; } ms = ms->next; - i++; - if (!merge) { + if (ms && !merge) { if (out_file) { fclose(out_file); } sprintf(prefix, "%03d_", i); - MSG_API("Creating filename with prefix: %s (i=%d)\n", prefix, i); out_file = get_output_file(prefix); if (!out_file) { MSG_ERROR("Failed to open output file!\n"); diff --git a/src/hls.h b/src/hls.h index 63813b5..e07a1d0 100644 --- a/src/hls.h +++ b/src/hls.h @@ -97,7 +97,7 @@ int handle_hls_media_playlist(hls_media_playlist_t *me); int download_live_hls(write_ctx_t *ctx, hls_media_playlist_t *me); bool consecutive_sync_byte(uint8_t *buf, size_t len, uint8_t n); uint8_t * find_first_ts_packet(ByteBuffer_t *buf); -int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool merge); +int download_hls(hls_media_playlist_t *me, hls_media_playlist_t *me_audio, bool merge, bool ignore_http_errors); int print_enc_keys(hls_media_playlist_t *me); void print_hls_master_playlist(struct hls_master_playlist *ma); void media_playlist_cleanup(hls_media_playlist_t *me); diff --git a/src/main.c b/src/main.c index cb7169b..f3303f1 100644 --- a/src/main.c +++ b/src/main.c @@ -317,7 +317,8 @@ int main(int argc, char *argv[]) int ret = -1; if (media_playlist.is_endlist) { - ret = download_hls(&media_playlist, &audio_media_playlist, !hls_args.skip_merge); + ret = download_hls(&media_playlist, &audio_media_playlist, !hls_args.skip_merge, + hls_args.ignore_http_errors); } else { char prefix[] = ""; FILE *out_file = get_output_file(prefix); diff --git a/src/misc.c b/src/misc.c index 3c0b93a..17b5ec5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -42,6 +42,7 @@ static void print_help(const char *filename) "-t ... Print the links to the .ts files.\n" "-s ... Set live start offset in seconds.\n" "-i ... Set live stream download duration in seconds.\n" + "-I ... Ignore HTTP errors.\n" "-e ... Set refresh delay in seconds.\n" "-r ... Set max retries at open.\n" "-w ... Set max download segment retries.\n" @@ -56,7 +57,7 @@ int parse_argv(int argc, char * const argv[]) int ret = 0; int c = 0; int custom_header_idx = 0; - while ( (c = getopt(argc, argv, "bH:W:A:vqbfFK:ctdo:mu:h:s:i:r:w:e:p:k:n:a:C:")) != -1) + while ( (c = getopt(argc, argv, "bH:W:A:vqbfFK:ctdo:mu:h:s:i:Ir:w:e:p:k:n:a:C:")) != -1) { switch (c) { @@ -121,6 +122,9 @@ int parse_argv(int argc, char * const argv[]) case 't': hls_args.dump_ts_urls = true; break; + case 'I': + hls_args.ignore_http_errors = true; + break; case 'd': hls_args.dump_dec_cmd = true; break; @@ -285,7 +289,7 @@ FILE* get_output_file(char prefix[]) strncat(filename, default_filename, strlen(default_filename)); } - MSG_API("Using output filename: %s\n", filename); + MSG_DBG("Using output filename: %s\n", filename); if (is_file_exists(filename)) { if (hls_args.force_overwrite) { diff --git a/src/misc.h b/src/misc.h index 5abf50d..1839e7c 100644 --- a/src/misc.h +++ b/src/misc.h @@ -38,6 +38,7 @@ struct hls_args { bool dump_ts_urls; bool dump_dec_cmd; bool skip_merge; + bool ignore_http_errors; int live_start_offset_sec; int live_duration_sec; int refresh_delay_sec; From b9e8aa2f188df3ac38d6b77274ce7e1b0992c3d3 Mon Sep 17 00:00:00 2001 From: vivook Date: Thu, 24 Dec 2020 10:43:51 +0000 Subject: [PATCH 4/5] Fix adding prefix to filenames --- src/misc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/misc.c b/src/misc.c index 17b5ec5..b78fc4d 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -279,16 +280,20 @@ FILE* get_output_file(char prefix[]) fflush(stdout); } else { char filename[MAX_FILENAME_LEN + strlen(prefix) + 1]; - strcpy(filename, prefix); + char *file_basename = NULL; + file_basename = (char *) malloc(MAX_FILENAME_LEN + strlen(prefix) + 1); if (hls_args.filename) { - strncat(filename, hls_args.filename, strlen(hls_args.filename)); - } - else { - char default_filename[] = "hls_output.ts"; - strncat(filename, default_filename, strlen(default_filename)); + strcpy(filename, dirname(hls_args.filename)); + strcat(filename, "/"); + basename_r(hls_args.filename, file_basename); + } else { + basename_r("hls_output.ts", file_basename); } + strncat(filename, prefix, strlen(prefix)); + strncat(filename, file_basename, strlen(file_basename)); + MSG_DBG("Using output filename: %s\n", filename); if (is_file_exists(filename)) { From c602c30b5d9128043f820f65b6c88b73b2b35945 Mon Sep 17 00:00:00 2001 From: vivook Date: Thu, 24 Dec 2020 10:53:23 +0000 Subject: [PATCH 5/5] Fix linux --- src/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc.c b/src/misc.c index b78fc4d..de2e080 100644 --- a/src/misc.c +++ b/src/misc.c @@ -286,9 +286,9 @@ FILE* get_output_file(char prefix[]) if (hls_args.filename) { strcpy(filename, dirname(hls_args.filename)); strcat(filename, "/"); - basename_r(hls_args.filename, file_basename); + strcpy(file_basename, basename(hls_args.filename)); } else { - basename_r("hls_output.ts", file_basename); + strcpy(file_basename, "hls_output.ts"); } strncat(filename, prefix, strlen(prefix));