title: Use ffmpeg to edit metadata titles for multiple files
body: <p>I'd like to be able to add/edit video metadata titles to multiple files at once or with a single command, but I don't know how to tell ffmpeg to do this.</p>
  <p>I read a <a href="http://ubuntuforums.org/showthread.php?t=2078361" rel="nofollow noreferrer">similar post on the Ubuntu Forums</a>, but I have never used string manipulation in Linux before, so the commands I'm seeing in the post are way out of my comprehension at the moment, and much of the discussion goes over my head.</p>
  <p>I've got all of my video files in a filename format that includes the show name, the episode number, and episode title. For example:</p>
  <blockquote>
  <p>show_name - episode_number - episode_title.extension</p>
  <p>Bleach - 001 - A Shinigami Is Born!.avi</p>
  </blockquote>
  <p>Is there a simple way to read the title and episode number from the filename and put it into a metadata tag without having to go through each and every file manually?</p>
  <p>EDIT 1: So I found out that I can iterate through files in a directory, and echo the filename, and I was told by a friend to try bash to parse the strings and return values from that to use in the ffmpeg command line. The problem is, I have absolutely no idea how to do this. The string manipulation in bash is very confusing on first look, and I can't seem to get it to output what I want into my variables. My test bash:</p>
  <pre><code> for file in &quot;Bleach - 206 - The Past Chapter Begins! The Truth from 110 Years Ago.mkv&quot;; do   extension=${file##*.} showName=${file%% *} episode=${file:9:3}; echo Extension: $extension Show: $showName Episode: $episode;    done
  </code></pre>
  <p>That outputs</p>
  <blockquote>
  <p>Extension: mkv Show: Bleach Episode: 206</p>
  </blockquote>
  <p>Which are all the variables I'm going to need, I just don't know how to move those to be run in ffmpeg now.</p>
  <p>EDIT 2: I believe I was able, through much trial and error, to find a bash command that would do exactly what I wanted.</p>
  <pre><code>for file in *; do   newname=${file:0:-4}_2 ext=${file##*.} filename=${file} showname=${file%% *} episode=${file:9:3} nameext=${file##*- } title=${nameext%.*};     ffmpeg -i &quot;$filename&quot; -metadata title=&quot;$title&quot; -metadata track=$episode -metadata album=$showname -c copy &quot;$newname.$ext&quot;;    mv -f &quot;$newname.$ext&quot; &quot;$filename&quot;;    done
  </code></pre>
  <p>This lets me parse the information from the filename, copy it to some variables, and then run ffmpeg using those variables. It outputs to a second file, then moves that file to the original location, overwriting the original. One could remove that section out if you're not sure about how it's going to parse your files, but I'm glad I was able to get a solution that works for me.</p>