Bug 466232

Summary: Subtitles are drawn from wrong source when rendering projects in batch mode
Product: [Applications] kdenlive Reporter: Terry Hancock <digitante>
Component: Rendering & ExportAssignee: Jean-Baptiste Mardelle <jb>
Status: RESOLVED FIXED    
Severity: normal CC: digitante
Priority: NOR    
Version First Reported In: 22.12.2   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 23.04.0
Sentry Crash Report:

Description Terry Hancock 2023-02-22 09:00:03 UTC
SUMMARY

The SRT subtitling feature renders correct subtitles in the editor when viewing the project. However, if one uses the "generate script" feature in the rendering panel to create rendering jobs, and then attempts to queue these for later batch processing, they do not retrieve the subtitles from the correct source.

The rendering process should pull them from the appropriate SRT sidecar file for each project to be rendered.  Instead, what happens, is that the SRT file is pulled from the CURRENTLY-OPEN Kdenlive project in the editor. 

STEPS TO REPRODUCE

1. Create a video project in Kdenlive.
2. Create subtitles.
3. Open rendering panel
4. Generate MLT script to render the project
5. Save
6. Repeat steps 1-5 for a 2nd project
7. Queue the two scripts for rendering and render (note that the 2nd project is open in the editor at this point)

OBSERVED RESULT
Both rendered videos will use the subtitles from the 2ND project (so the 1ST project's subtitles will be wrong).

Alternatively, if a new/empty Kdenlive project session is used to queue the batch rendering jobs, the files will have NO subtitles. If an unrelated project with SRT subtitles is open in the editor used to queue the jobs, that project's subtitles will appear in the rendered output. Etc.

EXPECTED RESULT
Each project should be rendered with the subtitles belonging to that project (which can be found in the .kdenlive.srt sidecar file stored beside each of them on the filesystem).

SOFTWARE/OS VERSIONS
Ubuntu Studio 20.04.
Originally discovered in Kdenlive 20.12. 
Same behavior verified in 22.12.2 AppImage package.

ADDITIONAL INFORMATION
Examining the actual MLT scripts with an editor, the only SRT file reference I could find is to a temporary file (i.e. /tmp/<hash>.srt ). There's no reference to the correct sidecar file, although it is present beside the Kdenlive project file.

I feel like this violates an encapsulation principle, in that I expect batched MLT jobs to be self-sufficient, not relying on information from the currently-open Kdenlive project. This seems to be true for other features, and the batch rendering feature seems to be useless without this expectation.
Comment 1 Terry Hancock 2023-02-25 03:28:35 UTC
I did find a work-around:
Since the MLT files have only the one reference to the SRT file source, it's possible to simply replace the temporary file listed with the correct sidecar SRT file from the projects directory, using a text editor. Once corrected, the batch runner will generate the videos with the correct subtitles, regardless of what project is open in Kdenlive. It's a bit of a hassle, but much better than running the jobs one-by-one.

This sidecar SRT files exists after the first save of the project file after the subtitles have been added, so presumably some kind of hook could be used to update the script generate on what SRT file to reference, when the project is saved.
Comment 2 Jean-Baptiste Mardelle 2023-02-25 10:14:07 UTC
Git commit 449508c5eb9fcc3b9821bf18dd8b4277afc1d508 by Jean-Baptiste Mardelle.
Committed on 25/02/2023 at 10:13.
Pushed by mardelle into branch 'master'.

Fix script rendering subtitles broken
FIXED-IN: 23.04.0

M  +10   -1    src/bin/model/subtitlemodel.cpp
M  +7    -2    src/bin/model/subtitlemodel.hpp
M  +25   -12   src/dialogs/renderwidget.cpp
M  +2    -1    src/dialogs/renderwidget.h
M  +1    -0    src/dialogs/speechdialog.cpp
M  +27   -2    src/doc/kdenlivedoc.cpp
M  +6    -1    src/doc/kdenlivedoc.h
M  +1    -0    src/monitor/monitor.cpp
M  +5    -1    src/project/projectmanager.cpp

https://invent.kde.org/multimedia/kdenlive/commit/449508c5eb9fcc3b9821bf18dd8b4277afc1d508