# FFMPEG Scripts (Sharing)

**URL:** <https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [September 11, 2015, 3:26am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332 "2015-09-11T03:26:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![igowas](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/igowas/32/84717_2.png) [@igowas](https://forums.plex.tv/u/igowas)\
**Post date:** [September 11, 2015, 3:26am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/1 "2015-09-11T03:26:02Z")

</div>

Hi everyone !  
I would like to create a new topic with a list of your FFMPEG scripts that you are using for converting your video files and get them working correctly on different client devices. Feel free to share your scripts 😃

---

<div class="post-metadata">

**Author:** ![igowas](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/igowas/32/84717_2.png) [@igowas](https://forums.plex.tv/u/igowas)\
**Post date:** [September 11, 2015, 3:33am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/2 "2015-09-11T03:33:11Z")

</div>

Here is a script I devlopped with a friend of mine. Im using it to remux my avi and mp4 files to mkv container. this is not for converting video and audio.  
Language used: Python

Before running this script on your librairie please test it before with 2 or 3 files. This script will delete the sources files one by one once remuxing is done.

How to use:

1. Create a Python file with the code provided bellow.
2. Call the script and add the directory path of your videos.

Per example: script.py d:\

---

<div class="post-metadata">

**Author:** ![ngovil21](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@ngovil21](https://forums.plex.tv/u/ngovil21)\
**Post date:** [September 15, 2015, 4:35am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/3 "2015-09-15T04:35:15Z")

</div>

Here’s my script to remux mkv files to mp4 if the video is h264, otherwise it will transcode using ffmpeg. Converts audio to AAC. This is meant to get files playable in most devices. The formats can be changed so you could use it for almost any container. Also has options to extract subtitles in certain languages. I compiled my own version of ffmpeg with libfdk\_aac, which can’t be distributed, but you can find versions with lib\_faac.

Coded in Python. Run with the files or directories to convert as arguments. It will search recursively and look for files that end in video format extensions.

Change Extension to .py

Before running set the remover variable to False to ensure your files aren’t deleted.

Example Usage:

python.exe mp4ffmpeg.py File1.mkv D:/Video/Movies File2.avi

---

<div class="post-metadata">

**Author:** ![Dariz](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Dariz](https://forums.plex.tv/u/Dariz)\
**Post date:** [September 15, 2015, 8:41am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/4 "2015-09-15T08:41:19Z")

</div>

I’m new to all this ffmpeg stuff. But it happens that I download videos with audio\_ts and video splitted up.

Is there a script or way, I can convert all these into a single .mkv file, for use by Plex?

---

<div class="post-metadata">

**Author:** ![igowas](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/igowas/32/84717_2.png) [@igowas](https://forums.plex.tv/u/igowas)\
**Post date:** [September 15, 2015, 11:52pm UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/5 "2015-09-15T23:52:07Z")

</div>

> @Dariz said:  
> I’m new to all this ffmpeg stuff. But it happens that I download videos with audio\_ts and video splitted up.
> 
> Is there a script or way, I can convert all these into a single .mkv file, for use by Plex?

Yes look for the application “makemkv” its free

---

<div class="post-metadata">

**Author:** ![igowas](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/igowas/32/84717_2.png) [@igowas](https://forums.plex.tv/u/igowas)\
**Post date:** [September 15, 2015, 11:53pm UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/6 "2015-09-15T23:53:46Z")

</div>

> @ngovil21 said:  
> Here’s my script to remux mkv files to mp4 if the video is h264, otherwise it will transcode using ffmpeg. Converts audio to AAC. This is meant to get files playable in most devices. The formats can be changed so you could use it for almost any container. Also has options to extract subtitles in certain languages. I compiled my own version of ffmpeg with libfdk\_aac, which can’t be distributed, but you can find versions with lib\_faac.
> 
> Coded in Python. Run with the files or directories to convert as arguments. It will search recursively and look for files that end in video format extensions.
> 
> Change Extension to .py
> 
> Before running set the remover variable to False to ensure your files aren’t deleted.
> 
> Example Usage:
> 
> python.exe mp4ffmpeg.py File1.mkv D:/Video/Movies File2.avi

Does it work if I use it for a mkv file with more than 1 audio track ?

---

<div class="post-metadata">

**Author:** ![ngovil21](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@ngovil21](https://forums.plex.tv/u/ngovil21)\
**Post date:** [September 16, 2015, 12:38am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/7 "2015-09-16T00:38:38Z")

</div>

@igowas  
It should work if you set the audio codec to copy. If you want to transcode the audio, then it will need the audio tracks to be mapped, I think. Currently if it transcodes, it will only get the first audio track. You can add -map 0 as a parameter to get all of the streams.

Check here on how to use map:  
[http://ffmpeg.org/ffmpeg.html#Advanced-options](http://ffmpeg.org/ffmpeg.html#Advanced-options)

---

<div class="post-metadata">

**Author:** ![igowas](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/igowas/32/84717_2.png) [@igowas](https://forums.plex.tv/u/igowas)\
**Post date:** [September 16, 2015, 12:58am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/8 "2015-09-16T00:58:58Z")

</div>

> @ngovil21  
> Cool I give it a try !

---

<div class="post-metadata">

**Author:** ![Satalink](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/satalink/32/338908_2.png) [@Satalink](https://forums.plex.tv/u/Satalink)\
**Post date:** [October 19, 2016, 12:33am UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/9 "2016-10-19T00:33:20Z")

</div>

FFMPEG script to convert to HEVC/H265 for Plex … output Direct Plays on 4K/UHD devices over LAN/WiFi. Written in PHP.

[http://satalink.blogspot.com/2016/10/ffmpeg-hevch265-tivo-bolt-direct-play.html](http://satalink.blogspot.com/2016/10/ffmpeg-hevch265-tivo-bolt-direct-play.html)

---

<div class="post-metadata">

**Author:** ![igowas](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/igowas/32/84717_2.png) [@igowas](https://forums.plex.tv/u/igowas)\
**Post date:** [October 24, 2016, 6:45pm UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/10 "2016-10-24T18:45:39Z")

</div>

> @Satalink said:  
> FFMPEG script to convert to HEVC/H265 for Plex … output Direct Plays on 4K/UHD devices over LAN/WiFi. Written in PHP.
> 
> [http://satalink.blogspot.com/2016/10/ffmpeg-hevch265-tivo-bolt-direct-play.html](http://satalink.blogspot.com/2016/10/ffmpeg-hevch265-tivo-bolt-direct-play.html)

What are the client devices you are using to direct play a x265 file. I tried with a powerfull server and the CPU usage was really too high. ( Chrome cast, roku and Web are not really good for x265 )

---

<div class="post-metadata">

**Author:** ![Collisionc](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/collisionc/32/8371_2.png) [@Collisionc](https://forums.plex.tv/u/Collisionc)\
**Post date:** [October 25, 2016, 5:40pm UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/11 "2016-10-25T17:40:56Z")

</div>

> @Satalink said:  
> FFMPEG script to convert to HEVC/H265 for Plex … output Direct Plays on 4K/UHD devices over LAN/WiFi. Written in PHP.
> 
> [http://satalink.blogspot.com/2016/10/ffmpeg-hevch265-tivo-bolt-direct-play.html](http://satalink.blogspot.com/2016/10/ffmpeg-hevch265-tivo-bolt-direct-play.html)

You should also add -temporal-aq 1 to the list of options to pass to nvenc\_h264 or nvenc\_h265. It is supported in any version of ffmpeg from the last 2-3~ weeks.

Explanation ripped from NVENC\_VideoEncoder\_API\_ProgGuide.pdf, as it’s behind a registration wall on Nvidia’s developer page.

> 8.2 TEMPORAL ADAPTIVE QUANTIZATION (T-AQ)  
> This feature tries to adjust encoding QP based on temporal characteristics of the  
> sequence. Temporal AQ improves the quality of encoded frames by adjusting QP for  
> regions which are constant or have low motion across frames but have high spatial  
> detail, such that they become better reference for future frames. Allocating extra bits to  
> such regions in reference frames is better than allocating them to the residuals in  
> referred frames because it helps improve the overall encoded video quality. If majority  
> of the region within a frame has little or no motion, but has high spatial details (e.g.  
> high-detail non-moving background) enabling temporal AQ will benefit the most.
> 
> One of the potential disadvantages of temporal AQ is that enabling temporal AQ may  
> result in high fluctuation of bits consumed per frame within a GOP. I/P-frames will  
> consume more bits than average P-frame size and B-frames will consume lesser bits.  
> Although target bitrate will be maintained at the GOP level, the frame size will fluctuate  
> from one frame to next within a GOP more than it would without temporal AQ. If a  
> strict CBR profile is required for every frame size within a GOP, it is not recommended  
> to enable temporal AQ. Additionally, since some of the complexity estimation is  
> performed in CUDA, there may be some performance impact when temporal AQ is  
> enabled.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 8, 2020, 7:51pm UTC](https://forums.plex.tv/t/ffmpeg-scripts-sharing/115332/12 "2020-01-08T19:51:15Z")

</div>


