Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically generate list of arguments for ffmpeg in C
    primarykey
    data
    text
    <p>I'm currently writing a video conversion daemon in C. It calls ffmpeg using execvp.</p> <p>I've created a struct called "ffmpeg_job" that represents a conversion job to be completed. I'd like to dynamically allocate the arguments to ffmpeg for each job, so that I can free one of these structs and its list of arguments after the job is completed.</p> <p>I started writing the function that dynamically allocates the list of arguments, but I feel like the way I'm going about it is quite naive. The code is below.</p> <p>Is there a better way to do this?</p> <p>EDIT: I'm thinking now that I will have a static string list of arguments for each level of quality, then sprintf into it and strtok it into a char **</p> <pre><code>char ** generate_arguments( char *filepath, ph5v_format format, ph5v_quality quality) { char ** arguments; if (format == ph5v_MP4) { mp4_arguments = { "-i", "%%INPUT FILEPATH 1", "-vcodec", "libx264", "-preset", "%%X264 PRESET 5", "-b:v", "%%VIDEO BITRATE 7", "-strict", "-2", "-acodec", "aac", "-b:a", "%%AUDIO BITRATE 13", "-ar", "%%AUDIO SAMPLERATE 15", "-ac", "2", "-y", "%%OUTPUT FILEPATH 19" } arguments = malloc(sizeof(char*) * 20); int i; for (i = 0; i &lt; 20; i++) { if (i == 1) { char *argument = malloc(strlen(filepath) + 1); strcpy(argument, filepath); arguments[1] = argument; } else if (i == 5) { if (quality == ph5v_LOW || quality == ph5v_MEDIUM) { char *argument = malloc(strlen("fast") + 1); strcpy(argument, "fast"); arguments[5] = argument; } else if (quality == ph5v_HIGH || quality == ph5v_ULTRA ) { char *argument = malloc(strlen("medium") + 1); strcpy(argument, "medium"); arguments[5] = argument; } } else if (i == 7) { if (quality == . . . </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload