-
-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add detection of container/video_codec/audio_codec compatibility for live file streaming or transcoding #384
Conversation
Added container detection to generate transcode task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor change.
Need to consider the performance impact of running ffprobe when streaming scenes that don't require transcode.
We can probably go ahead with this version and evaluate the performance impact, and add the container field if we deem it too much of a problem.
Container info added to DB. |
Can you please rebase against |
* take into account container in generate transcodes task * add container info to DB * increment appSchema to 5
I'm seeing regression in behaviour for some combinations. It appears that previous combinations (tested with mp4/flv combination) that did not work for me now appear to work, but they do not allow seeking. That may be a limitation somewhere for this scenario. However, I noticed that on the current version in Chrome, the mp4/matroska combination works correctly with seeking, but in this PR, the seeking is disabled. |
Yes as i stated at the beginning i wanted the browser detection mainly for matroska and Chromium based browsers. What do you think about adding an extra conf option to "force" mkv as supported? Some files are non seekable anyway though and i don't think there is a way to fix that for live streaming ( only fully transcoding deals with that) |
Yep, I'd like this. The seeking stuff is because |
Pushed a fix for edit adding as an extra fix for cases where live transcoding fails when ffmpeg doesn't support the audio codec ( as a fix transcode only the video part) |
Is |
…rted/unknown audio codecs
No. I just haven't yet bothered to add it to the gitignore file. Doesn't matter. |
When I set the force mkv to true, the mkv files are not transcoded as expected, but the seeking doesn't work - regardless of where you seek to, it starts from the start of the file. |
Does it print anything when you play those mkvs? |
The same files stream directly and correctly with the dev version. There is no log entry indicating that the file is being transcoded, so I'm confident that it is not. When it does transcode (when the checkbox is cleared), the seeking works correctly. |
Can you try reloading the page with player / restarting stash after you save the configuration with the mkv as forced? The only thing i can think of is that you get a cached response for the |
You are correct. Refreshing the page fixes the issue. We may want to consider resetting the cache when setting those flags. I also noticed that when I forced the mkv support, I didn't get sound on my particular video. The audio coded was ac3. I haven't yet checked if other ac3 videos work. Note that this happens with the current version as well, so not something introduced by your change. Unchecking the force mkv flag transcodes the file so the audio is present. One other possibility, could we determine codec/container support on the client-side browser and send that down as a parameter to the stream request? That might side-step needing to set the flags at all. |
this needs to be added then
mkv supports a lot of audio codecs and ac3 is common in movies, browsers only support aac in mkv i think (not sure about opus or vorbis). If we need it then i have to extend the combo check to the audio codec also and transcode as needed. |
Added checks for audio codec / player compatibility. |
A possible future iteration to investigate (not necessary for this PR): https://www.nomensa.com/blog/2011/detecting-browser-compatibility-html5-video-and-audio And this stack overflow answer: https://stackoverflow.com/a/7451727/695786 Determine from the client-side if the video is directly streamable, if not then do request to Forgot to mention what is actually working. This fixed streaming the files which were previously not working for me. I'll do another review pass and test with the latest build as soon as I'm able. |
I think those solutions are too much trouble for little gain. They move the selection code from the server to the client. The extra code in the server side is used also to make "better" decisions for the transcode part ( copy or transcode a stream when needed instead of the whole video ) . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly style-based feedback now.
Seems to test well in my environment. Only wrinkle is that I don't think the MKV setting change impacts until I reloaded the page.
The reload is only once though when you change the settings anyway. I didn't have to change / look back at the mkv settings since i started the PR for example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks and tests ok.
…live file streaming or transcoding (stashapp#384) * add forceMKV, forceHEVC config options * drop audio stream instead of trying to transcode for ffmpeg unsupported/unknown audio codecs
…live file streaming or transcoding (stashapp#384) * add forceMKV, forceHEVC config options * drop audio stream instead of trying to transcode for ffmpeg unsupported/unknown audio codecs
Fixes #354
As it is now stash only selects which files are "streamable" by using the video_codec information from ffprobe stored in DB. In some files while the codec is indeed supported by the browser/jwplayer the container isn't and thus instead of live transcoding the files we get the error message from #354
the container isn't stored in the database so we either need to store it or simply call ffprobe before we begin the streaming of a media file. For now i chose to go with the second option and it doesn't seem to add any measurable player startup delay
a combination of valid codec/container pairs is used in addition to the codec validation. mp4 and webm seem to be the "safe" choises for containers so i whitelisted those
ffprobe treats webm and matroska as the same which is problematic for firefox and probably a lot more browsers (chrome doesn't have a problem). I had to use a "magic_file" reader to determine the actual container (reads 4kb of the file, no measurable delay here either) for this case .
As it is now all the error cases from #354 get live transcoded ok.
TODO / TBD
Browser Detection ( EDIT not to be implemented , the user agent header is way too abused to make a consistent identification of the web browser )
We could detect which browser is used and adjust the valid combinations accordingly ( user agent header is available in routes_scene ,i left a TODO there ). For example chrome (and probably most chromium browsers ) suppports matroska as a container for h264 while firefox doesn't. Prior to this PR mkv and h264 played directly in chrome while after this fix (as it is now) the files will get live transcodedA force matroska option was implemented instead
Transcode generation ( EDIT completed)
I haven't touched the file transcode code yet.If we adjust it over there then there should be a new profile that copys the video stream and doesn't reencode as the codec is supported and only the container isn't. Something likeffmpeg -i input h264_media_file.avi -c:v copy .... output.mp4
Transcoded files (mp4) are generated correctly when the codec/container is not supported. For h264 files the video stream is directly copied avoiding time and quality loss.
Stream copy profile ( EDIT not to be implemented , the main benefit would be h264 encoded files but the resulting mp4 file will not be fully seekable )
Same as above for files that the container is not supported but the codec is. Instead of live transcoding using the webm live stream profile is it possible to stream only
copying
the video stream? Most use cases would be h264 in mpegts,flv,avi that the video could be copied to mp4 ( no reduction in quality compared to transcoding and almost no cpu usage ) .EDIT streaming is possible by copying the video stream but for h264 (mkv,flv,ts,avi) the resulting mp4 file won't be fully seekable (the duration keeps increasing till the file is fully loaded to the player).
Is this ok or should we transcode this cases also to vp9.webm ?EDIT After some more testing the fragmented mp4 (for the h264 mkv,flv,ts,avi ) that is not fully seekable is not acceptable imo.
Despite transcoding and loosing a bit in quality the file seeking/seek to sprite of the webm encoded file makes a better user experience.
Add container as an extra field to the scenes table. ( EDIT completed)
Is a cleaner solution
For new users it should be fairly easy to implement, it's a bit more tricky for users with existing DBs and more complex to implement than the current solution.A single scan is needed to populate the format field (container) for already existing files.
Audio codec (EDIT completed)
Is it worth the extra complexity / code to check for valid audio codec ? I didn't see any issues with files playing the video part and not the audio.