Advertisement
Guest User

Untitled

a guest
Mar 29th, 2010
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. From 53056d262dbd878db5e8eb552420f1fd12376c32 Mon Sep 17 00:00:00 2001
  2. From: Alexander Strange <astrange@ithinksw.com>
  3. Date: Mon, 29 Mar 2010 03:48:29 -0400
  4. Subject: [PATCH 1/4] Add missing b-pyramid flag to the "default" libx264 preset
  5.  
  6. ---
  7. ffpresets/libx264-default.ffpreset | 2 +-
  8. 1 files changed, 1 insertions(+), 1 deletions(-)
  9.  
  10. diff --git a/ffpresets/libx264-default.ffpreset b/ffpresets/libx264-default.ffpreset
  11. index 75191e2..039f1d6 100644
  12. --- a/ffpresets/libx264-default.ffpreset
  13. +++ b/ffpresets/libx264-default.ffpreset
  14. @@ -18,5 +18,5 @@ bf=3
  15. refs=3
  16. directpred=1
  17. trellis=1
  18. -flags2=+mixed_refs+wpred+dct8x8+fastpskip
  19. +flags2=+bpyramid+mixed_refs+wpred+dct8x8+fastpskip
  20. wpredp=2
  21. --
  22. 1.7.0.2
  23.  
  24. From 37480b5359d70d5e68b87b277d7925fe136a00d9 Mon Sep 17 00:00:00 2001
  25. From: Alexander Strange <astrange@ithinksw.com>
  26. Date: Mon, 29 Mar 2010 03:13:17 -0400
  27. Subject: [PATCH 2/4] ffmpeg: Move opt_preset() higher up so it can be called from elsewhere
  28.  
  29. ---
  30. ffmpeg.c | 114 +++++++++++++++++++++++++++++++-------------------------------
  31. 1 files changed, 57 insertions(+), 57 deletions(-)
  32.  
  33. diff --git a/ffmpeg.c b/ffmpeg.c
  34. index 951b0da..4ae785e 100644
  35. --- a/ffmpeg.c
  36. +++ b/ffmpeg.c
  37. @@ -3122,6 +3122,63 @@ static void check_audio_video_sub_inputs(int *has_video_ptr, int *has_audio_ptr,
  38. *has_subtitle_ptr = has_subtitle;
  39. }
  40.  
  41. +static int opt_preset(const char *opt, const char *arg)
  42. +{
  43. + FILE *f=NULL;
  44. + char filename[1000], tmp[1000], tmp2[1000], line[1000];
  45. + int i;
  46. + const char *base[2]= { getenv("HOME"),
  47. + FFMPEG_DATADIR,
  48. + };
  49. +
  50. + if (*opt != 'f') {
  51. + for(i=!base[0]; i<2 && !f; i++){
  52. + snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i ? "" : "/.ffmpeg", arg);
  53. + f= fopen(filename, "r");
  54. + if(!f){
  55. + char *codec_name= *opt == 'v' ? video_codec_name :
  56. + *opt == 'a' ? audio_codec_name :
  57. + subtitle_codec_name;
  58. + snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i], i ? "" : "/.ffmpeg", codec_name, arg);
  59. + f= fopen(filename, "r");
  60. + }
  61. + }
  62. + } else {
  63. + av_strlcpy(filename, arg, sizeof(filename));
  64. + f= fopen(filename, "r");
  65. + }
  66. +
  67. + if(!f){
  68. + fprintf(stderr, "File for preset '%s' not found\n", arg);
  69. + av_exit(1);
  70. + }
  71. +
  72. + while(!feof(f)){
  73. + int e= fscanf(f, "%999[^\n]\n", line) - 1;
  74. + if(line[0] == '#' && !e)
  75. + continue;
  76. + e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
  77. + if(e){
  78. + fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line);
  79. + av_exit(1);
  80. + }
  81. + if(!strcmp(tmp, "acodec")){
  82. + opt_audio_codec(tmp2);
  83. + }else if(!strcmp(tmp, "vcodec")){
  84. + opt_video_codec(tmp2);
  85. + }else if(!strcmp(tmp, "scodec")){
  86. + opt_subtitle_codec(tmp2);
  87. + }else if(opt_default(tmp, tmp2) < 0){
  88. + fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
  89. + av_exit(1);
  90. + }
  91. + }
  92. +
  93. + fclose(f);
  94. +
  95. + return 0;
  96. +}
  97. +
  98. static void new_video_stream(AVFormatContext *oc)
  99. {
  100. AVStream *st;
  101. @@ -3884,63 +3941,6 @@ static int opt_bsf(const char *opt, const char *arg)
  102. return 0;
  103. }
  104.  
  105. -static int opt_preset(const char *opt, const char *arg)
  106. -{
  107. - FILE *f=NULL;
  108. - char filename[1000], tmp[1000], tmp2[1000], line[1000];
  109. - int i;
  110. - const char *base[2]= { getenv("HOME"),
  111. - FFMPEG_DATADIR,
  112. - };
  113. -
  114. - if (*opt != 'f') {
  115. - for(i=!base[0]; i<2 && !f; i++){
  116. - snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i ? "" : "/.ffmpeg", arg);
  117. - f= fopen(filename, "r");
  118. - if(!f){
  119. - char *codec_name= *opt == 'v' ? video_codec_name :
  120. - *opt == 'a' ? audio_codec_name :
  121. - subtitle_codec_name;
  122. - snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i], i ? "" : "/.ffmpeg", codec_name, arg);
  123. - f= fopen(filename, "r");
  124. - }
  125. - }
  126. - } else {
  127. - av_strlcpy(filename, arg, sizeof(filename));
  128. - f= fopen(filename, "r");
  129. - }
  130. -
  131. - if(!f){
  132. - fprintf(stderr, "File for preset '%s' not found\n", arg);
  133. - av_exit(1);
  134. - }
  135. -
  136. - while(!feof(f)){
  137. - int e= fscanf(f, "%999[^\n]\n", line) - 1;
  138. - if(line[0] == '#' && !e)
  139. - continue;
  140. - e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
  141. - if(e){
  142. - fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line);
  143. - av_exit(1);
  144. - }
  145. - if(!strcmp(tmp, "acodec")){
  146. - opt_audio_codec(tmp2);
  147. - }else if(!strcmp(tmp, "vcodec")){
  148. - opt_video_codec(tmp2);
  149. - }else if(!strcmp(tmp, "scodec")){
  150. - opt_subtitle_codec(tmp2);
  151. - }else if(opt_default(tmp, tmp2) < 0){
  152. - fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
  153. - av_exit(1);
  154. - }
  155. - }
  156. -
  157. - fclose(f);
  158. -
  159. - return 0;
  160. -}
  161. -
  162. static const OptionDef options[] = {
  163. /* main options */
  164. #include "cmdutils_common_opts.h"
  165. --
  166. 1.7.0.2
  167.  
  168. From 6b9e5db459ae98a3ca61defa1d0474931aae310f Mon Sep 17 00:00:00 2001
  169. From: Alexander Strange <astrange@ithinksw.com>
  170. Date: Mon, 29 Mar 2010 03:46:41 -0400
  171. Subject: [PATCH 3/4] ffmpeg: Adjust new_audio_stream() to allow for future changes
  172.  
  173. ---
  174. ffmpeg.c | 4 ++--
  175. 1 files changed, 2 insertions(+), 2 deletions(-)
  176.  
  177. diff --git a/ffmpeg.c b/ffmpeg.c
  178. index 4ae785e..06a0ea9 100644
  179. --- a/ffmpeg.c
  180. +++ b/ffmpeg.c
  181. @@ -3362,8 +3362,6 @@ static void new_audio_stream(AVFormatContext *oc)
  182. } else {
  183. AVCodec *codec;
  184.  
  185. - set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
  186. -
  187. if (audio_codec_name) {
  188. codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);
  189. codec = avcodec_find_encoder_by_name(audio_codec_name);
  190. @@ -3374,6 +3372,8 @@ static void new_audio_stream(AVFormatContext *oc)
  191. }
  192. audio_enc->codec_id = codec_id;
  193.  
  194. + set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
  195. +
  196. if (audio_qscale > QSCALE_NONE) {
  197. audio_enc->flags |= CODEC_FLAG_QSCALE;
  198. audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
  199. --
  200. 1.7.0.2
  201.  
  202. From 898cc451d3d70d74b5d5cd8fafe98248a21d0b84 Mon Sep 17 00:00:00 2001
  203. From: Alexander Strange <astrange@ithinksw.com>
  204. Date: Mon, 29 Mar 2010 03:14:52 -0400
  205. Subject: [PATCH 4/4] ffmpeg: Look for a preset named "default" if none is specified.
  206.  
  207. This allows specifying per-codec defaults by writing a preset file.
  208. ---
  209. ffmpeg.c | 24 ++++++++++++++++++++++++
  210. 1 files changed, 24 insertions(+), 0 deletions(-)
  211.  
  212. diff --git a/ffmpeg.c b/ffmpeg.c
  213. index 06a0ea9..cd65037 100644
  214. --- a/ffmpeg.c
  215. +++ b/ffmpeg.c
  216. @@ -218,6 +218,10 @@ static int force_fps = 0;
  217. static int pgmyuv_compatibility_hack=0;
  218. static float dts_delta_threshold = 10;
  219.  
  220. +static int used_vpre = 0;
  221. +static int used_apre = 0;
  222. +static int used_spre = 0;
  223. +
  224. static unsigned int sws_flags = SWS_BICUBIC;
  225.  
  226. static int64_t timer_start;
  227. @@ -2751,6 +2755,7 @@ static void opt_codec(int *pstream_copy, char **pcodec_name,
  228.  
  229. static void opt_audio_codec(const char *arg)
  230. {
  231. + used_apre = 0;
  232. opt_codec(&audio_stream_copy, &audio_codec_name, CODEC_TYPE_AUDIO, arg);
  233. }
  234.  
  235. @@ -2774,11 +2779,13 @@ static void opt_video_tag(const char *arg)
  236.  
  237. static void opt_video_codec(const char *arg)
  238. {
  239. + used_vpre = 0;
  240. opt_codec(&video_stream_copy, &video_codec_name, CODEC_TYPE_VIDEO, arg);
  241. }
  242.  
  243. static void opt_subtitle_codec(const char *arg)
  244. {
  245. + used_spre = 0;
  246. opt_codec(&subtitle_stream_copy, &subtitle_codec_name, CODEC_TYPE_SUBTITLE, arg);
  247. }
  248.  
  249. @@ -3149,10 +3156,19 @@ static int opt_preset(const char *opt, const char *arg)
  250. }
  251.  
  252. if(!f){
  253. + if (*opt != 'f' && !strcmp(arg, "default"))
  254. + return 0;
  255. fprintf(stderr, "File for preset '%s' not found\n", arg);
  256. av_exit(1);
  257. }
  258.  
  259. + if (*opt == 'v')
  260. + used_vpre = 1;
  261. + else if (*opt == 'a')
  262. + used_apre = 1;
  263. + else if (*opt == 's')
  264. + used_spre = 1;
  265. +
  266. while(!feof(f)){
  267. int e= fscanf(f, "%999[^\n]\n", line) - 1;
  268. if(line[0] == '#' && !e)
  269. @@ -3229,10 +3245,13 @@ static void new_video_stream(AVFormatContext *oc)
  270. } else {
  271. codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
  272. codec = avcodec_find_encoder(codec_id);
  273. + video_codec_name = av_strdup(codec->name);
  274. }
  275.  
  276. video_enc->codec_id = codec_id;
  277.  
  278. + if (!used_vpre)
  279. + opt_preset("vpre", "default");
  280. set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
  281.  
  282. if (codec && codec->supported_framerates && !force_fps)
  283. @@ -3369,9 +3388,12 @@ static void new_audio_stream(AVFormatContext *oc)
  284. } else {
  285. codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
  286. codec = avcodec_find_encoder(codec_id);
  287. + audio_codec_name = av_strdup(codec->name);
  288. }
  289. audio_enc->codec_id = codec_id;
  290.  
  291. + if (!used_apre)
  292. + opt_preset("apre", "default");
  293. set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
  294.  
  295. if (audio_qscale > QSCALE_NONE) {
  296. @@ -3432,6 +3454,8 @@ static void new_subtitle_stream(AVFormatContext *oc)
  297. if (subtitle_stream_copy) {
  298. st->stream_copy = 1;
  299. } else {
  300. + if (!used_spre)
  301. + opt_preset("spre", "default");
  302. set_context_opts(avcodec_opts[CODEC_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
  303. subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1);
  304. output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);
  305. --
  306. 1.7.0.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement