Converting HLS streams with FFMPEG in ASP.NET Core 5.0 MVC

Overview

I am currently developing a media streaming server using ASP.net Core REST Server, utilizing .NET 5.0 and ASP.net Core MVC.

What I'm Looking For

I require the ability to dynamically reduce the resolution of the original video file, such as converting it from 1080p to 720p. Additionally, I need the capability to transcode the media file into different encodings based on client capabilities.

Methods I've Explored

I have been searching for a library that can accomplish this task, but so far, I have not found one. I initially believed FFMpeg could handle this. I am aware that applications like Plex and Emby are able to achieve this functionality successfully.

C#

public static FileStream GetTranscodedStream(string requestedUser, string path, int targetResolution, int targetBitRate)
{
    // Code snippet omitted for brevity
}

[HttpGet("{tmdb}/{user}/video/transcoded")]
public IActionResult GetMovieStream(string tmdb, string user, int resolution, int bitrate)
{
    // Code snippet omitted for brevity
}

HTML

<link rel="stylesheet" href="/assets/lib/video.js/video-js.css">
    <video id="vid1" class="videojs vjs-default-skin" controls data-setup="{}" preload="auto">
        <source src="http://127.0.0.1:3208/api/get/movies/299687/dcman58/video/transcoded?resolution=480&bitrate=4800" type="application/x-mpegURL">
    </video>

Javascript

var player = videojs('vid1');
player.play();

ERROR

ERROR 416: Range Not Satisfiable "http://127.0.0.1:3208/api/get/movies/299687/dcman58/video/transcoded?resolution=480&bitrate=4800"

Answer №1

Issue lies within this specific line of code:

Response.Headers.Add("Content-Range", $"bytes {0}-{fileSize}/{fileSize}");

You can find more information about the error here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416

It seems like your current approach may be incorrect. FFMPEG encoding must finish completely before you can begin sending any data back to the client. Real-time retrieval of output from FFMPEG is not possible.

The code snippet provided does not clarify if the files have already been converted and stored on disk when attempting to return them. If they have, simply return the file itself without specifying ranges. The use of

"application/x-mpegURL"
in your return will handle everything for you automatically.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for emphasizing matches within a string using JSX

I've implemented a custom autocomplete feature that suggests options based on user input. I want to highlight the characters in the suggestions list that match the input value. For example, if the suggestion list includes "alligator", "lima", and "li ...

Understanding Foreign Keys and Seeds in Entity Framework

Currently, I have 3 tables that are structured as follows: public class Parkings { [Key] public int ParkId { get; set; } [Required] public string StartDate { get; set; } [Required] public string EndDate ...

What could be causing the lock to malfunction when called from asp.net service?

I recently acquired an app that includes a service class being called from an asp.net application in the following manner: class PeopleService : IPeopleService { //... public void SavePerson(Person person) { person.UniqueId = _idGenera ...

Using AngularJS to inject a variable into the standard filter

Currently, I am attempting to develop a custom filter that mimics the functionality of the standard Angular filter in HTML, with the distinction that it accepts a variable as input rather than a fixed value. For instance, within my html document, you may ...

Gatsby Functions: Exceeding payload size limit error - request entity too large

I am currently working on a Gatsby app and utilizing Gatsby Functions to obscure form submissions to an external API. The issue I am facing is that when a user attaches a file in the form, it could potentially surpass the default size limit of 100KB. While ...

Fade in and out of page or div elements with a simple click

I've been dedicating some time to my recruitment website lately. As a beginner in coding, I'm looking for a script that will automatically fade out the Employment review content when clicking on each employment vacancy div and then fade back in w ...

The Threejs Blender exporter is exporting in an incorrect format

I'm attempting to convert a blender model into a threejs JSON format using the provided blender exporter. However, when I try to parse the JSON file, I encounter an error: Uncaught TypeError: Cannot read property 'length' of undefined The ...

Bidirectional Data Binding in AngularJS

In my angular application, there is a dropdown with various values. When a user selects a specific value from the dropdown, I want to display the complete array corresponding to that value. <!doctype html> <html lang="en"> <head> < ...

Each time the Angular children component is reloaded, the user is redirected to localhost:4200

In my Angular project, I encounter an issue with route parameters in children components. While navigating to these child components from the parent is seamless, reloading the child component causes the application to redirect to localhost:4200 and display ...

Create a discord.js bot that can randomly select and send a picture from a collection of images stored on my computer

I'm currently working on a bot that sends random pictures from an array of images stored on my computer. However, I encountered an issue when trying to embed the image, resulting in the following error message: C:\Users\47920\Desktop&bs ...

Bringing together Events and Promises in JS/Node is the key to seamless programming

I am exploring the most effective approach to incorporating events (such as Node's EventEmitter) and promises within a single system. The concept of decoupled components communicating loosely through a central event hub intrigues me. When one componen ...

What is the best way to send a string value from HTML to a JavaScript function as a parameter?

When embedding HTML codes in Java, I encountered an issue where I needed to pass a string value from HTML to a JavaScript function. Initially, I tried using the following code: out.print("<script>init("+macId+")</script>"); However, this meth ...

Steps for launching a fresh script within the current tab

I'm currently working on a project where I have the following code: window.open("http://localhost/xyz.php") When this code runs, it opens the PHP file in a new tab within the same window. However, I'm trying to figure out how to make it open in ...

I need help with this Jquery code - trying to target an element with a specific attribute value. What am I missing here?

I am attempting to selectively add a border around the .L1Cell element where the attribute name parent is equal to Workstation. However, it appears to be applying the border to all .L1Cell elements. Here is the link to the JSFIDDLE $(document).ready(func ...

Which javascript libraries or game engines can be utilized to create a 3D environment with x, y, z coordinates to monitor the movement of objects?

Currently, I am working on developing a basic web application prototype that will showcase the real-time tracking of up to five individual objects within a predefined room. While I have explored the possibility of using three.js for this project, I am wond ...

Is it secure to edit and save user HTML using JavaScript?

Consider this scenario: I've developed a cutting-edge tool for creating forms with Javascript. Users can utilize links to integrate html elements (such as input fields) and leverage TinyMCE for text editing. The data is saved through an autosave featu ...

Is it possible to eliminate the css class prefix when using Modular css in React?

When working with React & NextJS, I have observed that my modular SCSS files are automatically prefixing my classnames with the name of the file. Is there a way to turn off this feature as it is making the DOM structure difficult to interpret? For instanc ...

Variable not accessible in a Typescript forEach loop

I am facing an issue with a foreach loop in my code. I have a new temp array created within the loop, followed by a nested foreach loop. However, when trying to access the temp array inside the nested loop, I encounter a "variable not available" error. le ...

Utilizing client-side properties in an onClick event within Next.js framework

class homeNotLoggedIn extends React.Component { componentDidMount() { function logout(){ localStorage.clear() location.reload() } } render() { return ( <div> < ...

I am unable to access the properties of an undefined element, specifically the 'size' property in Next.js 13

I encountered a problem today while working with Next.js version 13.4 and backend integration. When using searchParams on the server side, I received an error message: "Cannot read properties of undefined (reading 'size')" while destructuring siz ...