| 53 | === Scripting your command line parameters === |
| 54 | If building complex filtergraphs the command line can get very messy so it can help to break things down into manageable pieces. However one needs to be careful when joining them all together to avoid issues due to your shell and escaped characters. |
| 55 | |
| 56 | The following example shows a sample bash script containing a filtergraph of one chain with three filters; yadif, scale and drawtext. |
| 57 | {{{ |
| 58 | #!/bin/bash |
| 59 | # ffmpeg test script |
| 60 | |
| 61 | path="/path/to/file/" |
| 62 | |
| 63 | in_file="in.mp4" |
| 64 | out_file="out.mp4" |
| 65 | |
| 66 | cd $path |
| 67 | |
| 68 | filter="-vf \"yadif=0:-1:0, scale=400:226, drawtext=fontfile=/usr/share/fonts/truetype/DroidSans.ttf: \ |
| 69 | text='tod- %X'':x=(w-text_w)/2:y=H-60 :fontcolor=white :box=1:boxcolor=0x00000000@1\"" |
| 70 | codec="-vcodec libx264 -pix_fmt yuv420p -b:v 700k -r 25 -maxrate 700k -bufsize 5097k" |
| 71 | |
| 72 | command_line="ffmpeg -i $in_file $filter $codec -an $out_file" |
| 73 | |
| 74 | echo $command_line |
| 75 | eval $command_line |
| 76 | exit |
| 77 | }}} |
| 78 | Note that the double quotes " around the whole filtergraph have been escaped \" and the filtergraph spans more than one line, the echo command shows the full command as it is executed. Useful for debugging. |
| 79 | |
| 80 | The {{{eval}}} invocation of the $command_line variable is required to avoid loss of the embedded escaped quotes which occurs if it is absent. Other shells may behave differently. |