I'm just getting started with bash scripting and I'm running into an issue. I'm trying to create a script that utilizes FFmpeg to convert files with a .ts extension to .mp4 files. I want to store the name of the converted file in a variable so that I can use it later for a Filebot CLI command. My current script seems to be running fine since FFmpeg completes successfully and gives me the expected .mp4 file. However, Filebot is unable to find the input file, and I can't figure out why. Here's what I have so far:
```bash
#!/usr/bin/env zsh
if [[ "{1##*.}" == "ts" ]]; then
converted_episode="$(ffmpeg -i "$1" "${1%.*}.mp4")"
else
fi
/Applications/FileBot.app/Contents/MacOS/filebot.sh -rename $converted_episode
```
What am I missing?
3 Answers
It’s likely that FFmpeg is outputting a lot of text and you’re accidentally capturing that instead of the file name. If you run FFmpeg normally in the terminal, see what comes out. If it prints an error or info to stderr, that won’t be stored in `converted_episode`. You can also test it by running:
```bash
ffmpeg -i testfile.ts testfile.mp4 2>/dev/null
```
This will help track down any unexpected output you might be saving.
It sounds like you're capturing the standard output from FFmpeg into `converted_episode`, but that’s not what you want. Instead, you should first define the new file name and then use that in your FFmpeg command. Try this:
```bash
converted_episode="${1%.*}.mp4"
ffmpeg -i "$1" "$converted_episode"
```
This way, `converted_episode` will just hold the name of the new .mp4 file, and it should work better with Filebot.
Just a heads up, in your `converted_episode=` line, it looks like you're nesting quotes improperly. The recommendation from another user is cleaner, and it basically separates out the file name assignment from the FFmpeg command, which should fix the issue.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically