# Live Video Transmuxing/Transcoding: FFmpeg vs TwitchTranscoder, Part II

DevFeed: [Live Video Transmuxing/Transcoding: FFmpeg vs TwitchTranscoder, Part II](<https://devfeed.tech/articles/live-video-transmuxing-transcoding-ffmpeg-vs-twitchtranscoder-part-ii-20453.md>)

Original publisher: [Read original article](<https://medium.com/twitch-news/live-video-transmuxing-transcoding-ffmpeg-vs-twitchtranscoder-part-ii-4973f475f8a3?source=rss----3ae745429979--engineering>)

Author: Yueshi Shen

Published: 2017-10-23T21:08:55Z

Content type: article

Language: en

Sources: [Twitch](<https://devfeed.tech/sources/twitch.md>)

Topics: [FFmpeg (Fast Forward Moving Picture Experts Group)](<https://devfeed.tech/topics/ffmpeg.md>), [Transcodings](<https://devfeed.tech/topics/transcodings.md>), [Code](<https://devfeed.tech/topics/code.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [C](<https://devfeed.tech/topics/c.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [decoding](<https://devfeed.tech/tags/decoding.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [ffmpeg](<https://devfeed.tech/tags/ffmpeg.md>), [files](<https://devfeed.tech/tags/files.md>), [function](<https://devfeed.tech/tags/function.md>), [loops](<https://devfeed.tech/tags/loops.md>), [message-queue](<https://devfeed.tech/tags/message-queue.md>), [programming](<https://devfeed.tech/tags/programming.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threading](<https://devfeed.tech/tags/threading.md>), [threads](<https://devfeed.tech/tags/threads.md>), [video](<https://devfeed.tech/tags/video.md>)

## AI overview

This second part of a two-part series examines FFmpeg Release 3.3's threading model and transcoding pipeline for a one-input, multiple-output scenario. It traces how FFmpeg orchestrates I/O, filtering, decoding, encoding, and output processing, and reports that the number of input files determines input-thread creation, so a one-input scenario uses a single thread.

## Source excerpt

By: Jeff Gong, Software Engineer, jeffgon@twitch.tv Sahil Dhanju, Software Engineer Intern Chih-Chiang Lu, Senior Software Engineer, chihchil@twitch.tv Yueshi Shen, Principal Research Engineer, yshen@twitch.tv Special thanks go to: Christopher Kennedy, Staff Video Engineer at Crunchyroll/Ellation John Nichols, Principal Software Engineer at Xilinx, jnichol@xilinx.com for their information on FFmpeg and reviewing this article. Note: This is the second part of a 2-part series. Make sure you read Part 1 first. FFmpeg's 1-In-N-Out Pipeline. Why doesn't it handle the technical issues discussed earlier? How does FFmpeg programmatically deal with instances where a single input stream is required to generate multiple transcoded and/or transmuxed outputs? We went directly into the latest FFmpeg Release 3.3. source code in order to understand its threading model and transcoding pipeline. In the top-level ffmpeg.c file, the transcode() function (line 4544) loops and repeatedly calls transcode_step() (line 4478) until its inputs are completely processed, or until the user interrupts the execution. Transcode_step() wraps the main pipeline and orchestrates file I/O, filtering, decoding and encoding amongst many other immediate steps. During the initial setup phase, init_input_threads() (line 4020) is called, and based on the number of input files, a number of new threads may be spawned to process the input. if (nb_input_files == 1) { return 0;}for (i = 0; i < nb_input_files; i++) { ... ret = av_thread_message_queue_alloc(&f->in_thread_queue, f->thread_queue_size, sizeof(AVPacket)); // line 4033} In line 4033, we see that the number of threads spawned is solely determined by the number of inputs. This means FFmpeg will process a 1-in-N-out scenario using only a single thread. In get_input_packet() (line 4055), the multithreaded companion function get_input_packet_mt() (line 4047) is only called if the number of input files is greater than one. get_input_packet_mt() can read input