Forked from gtgt/00-ffmpeg_random_segment_format.patch
Created
October 31, 2016 04:58
-
-
Save MythodeaLoL/ee799b6b1b7310d230c2cfd1bd1e93ff to your computer and use it in GitHub Desktop.
ffmpeg - random filename segment patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libavformat/utils.c b/libavformat/utils.c | |
index 17ae300..7ff8c22 100644 | |
--- a/libavformat/utils.c | |
+++ b/libavformat/utils.c | |
@@ -3809,6 +3809,36 @@ uint64_t ff_ntp_time(void) | |
return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; | |
} | |
+static char *randstring(size_t length) { | |
+ | |
+ static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
+ char *randomString; | |
+ | |
+ if (length) { | |
+ randomString = malloc(sizeof(char) * (length +1)); | |
+ | |
+ if (randomString) { | |
+ for (int n = 0;n < length;n++) { | |
+ int key = rand() % (int)(sizeof(charset) -1); | |
+ randomString[n] = charset[key]; | |
+ } | |
+ | |
+ randomString[length] = '\0'; | |
+ } | |
+ } | |
+ | |
+ return randomString; | |
+} | |
+ | |
+/** | |
+ * Random filename usage | |
+ * | |
+ * use "%<size>r" at -segment_format. <size> is the length of random string generated, for example: "%20r" | |
+ * | |
+ * command example: | |
+ * ffmpeg -i $1 -r 25 -c:a libfaac -ab:a 128k -ac:a 2 -c:v mpeg2video -s:v 640x360 -aspect:v 16:9 -map 0 -f segment -segment_time 120 -segment_list $2.m3u8 -segment_format mpegts "$2-%20r.ts" | |
+ */ | |
+ | |
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number) | |
{ | |
const char *p; | |
@@ -3829,7 +3859,6 @@ int av_get_frame_filename(char *buf, int buf_size, const char *path, int number) | |
nd = nd * 10 + *p++ - '0'; | |
c = *p++; | |
} while (av_isdigit(c)); | |
- | |
switch (c) { | |
case '%': | |
goto addchar; | |
@@ -3846,6 +3875,17 @@ int av_get_frame_filename(char *buf, int buf_size, const char *path, int number) | |
memcpy(q, buf1, len); | |
q += len; | |
break; | |
+ case 'r': | |
+ percentd_found = 1; | |
+ if (number < 0) | |
+ nd += 1; | |
+ snprintf(buf1, sizeof(buf1), "%s", randstring(nd)); | |
+ len = strlen(buf1); | |
+ if ((q - buf + len) > buf_size - 1) | |
+ goto fail; | |
+ memcpy(q, buf1, len); | |
+ q += len; | |
+ goto addchar; | |
default: | |
goto fail; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIR=$(dirname $0) | |
mkdir -p $DIR/build | |
PREFIX=$DIR/build | |
./configure --extra-version=static --prefix=$PREFIX --libdir=$PREFIX/lib --shlibdir=$PREFIX/lib --mandir=$PREFIX/share/man --disable-shared --enable-static \ | |
--optflags='-O2 -march=native -pipe -static' --extra-cflags='-O2 -march=native -pipe -static' --extra-cxxflags='-O2 -march=native -pipe -static' \ | |
--enable-gpl --enable-postproc --enable-avfilter --enable-avresample --disable-stripping --enable-version3 --enable-nonfree --enable-indev=v4l2 --enable-outdev=v4l2 --enable-indev=alsa --disable-indev=oss \ | |
--disable-indev=jack --enable-outdev=alsa --disable-outdev=oss --disable-outdev=sdl --enable-version3 --enable-bzlib --disable-runtime-cpudetect --disable-debug --disable-doc --disable-gnutls --enable-hardcoded-tables \ | |
--enable-iconv --enable-network --disable-openssl --enable-ffplay --enable-ffserver --enable-vaapi --enable-vdpau --enable-zlib --enable-libvo-aacenc --disable-libvo-amrwbenc --enable-libmp3lame --disable-libaacplus --enable-libfaac \ | |
--enable-libtheora --disable-libtwolame --disable-libwavpack --disable-libwebp --enable-libx264 --disable-libx265 --enable-libxvid --disable-libcdio --disable-libiec61883 --disable-libdc1394 --disable-libcaca --enable-openal \ | |
--enable-opengl --enable-libv4l2 --disable-libpulse --enable-x11grab --disable-libflite --disable-frei0r --disable-fontconfig --disable-ladspa --disable-libass --disable-libfreetype --disable-libsoxr --enable-pthreads \ | |
--enable-libopencore-amrwb --enable-libopencore-amrnb --disable-libfdk-aac --disable-libopenjpeg --disable-libbluray --disable-libcelt --disable-libgme --disable-libgsm --disable-libmodplug --enable-libopus --disable-libquvi \ | |
--enable-librtmp --disable-libssh --disable-libschroedinger --enable-libspeex --enable-libvorbis --enable-libvpx --disable-libzvbi --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-neon --disable-vfp --disable-mips32r2 \ | |
--disable-mipsdspr1 --disable-mipsdspr2 --disable-mipsfpu --disable-altivec --disable-avx --disable-avx2 --enable-pic --disable-asm --cpu=host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#/bin/bash | |
[[ $1 && $2 ]] || exit 1 | |
DIR=$(dirname $0) | |
$DIR/ffmpeg -i $1 -r 25 -c:a libfaac -ab:a 128k -ac:a 2 -c:v mpeg2video -s:v 640x360 -aspect:v 16:9 -map 0 -f segment -segment_time 120 -segment_list $2.m3u8 -segment_format mpegts "$2-%20r.ts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment