I have a problem with titles of video files created by TVHeadend both after running recording manually and through autorec. In example default recording profile has those options (file /home/hts/.hts/tvheadend/dvr/config/6af31fd6d023c41ef1d86191c0f6fac6):

{
        "enabled": true,
        "name": "",
        "profile": "cce0555725b5723a396327f3fc49f135",
        "pri": 0,
        "retention-days": 2147483646,
        "removal-days": 2147483647,
        "remove-after-playback": 0,
        "pre-extra-time": 1,
        "post-extra-time": 1,
        "clone": true,
        "rerecord-errors": 0,
        "complex-scheduling": false,
        "fetch-artwork": false,
        "fetch-artwork-known-broadcasts-allow-unknown": false,
        "storage": "/home/hts/multimedia/tv",
        "storage-mfree": 1000,
        "storage-mused": 0,
        "directory-permissions": "0775",
        "file-permissions": "0664",
        "charset": "UNICODE",
        "pathname": "%F_$t$n.$x",
        "cache": 1,
        "day-dir": false,
        "channel-dir": false,
        "title-dir": false,
        "format-tvmovies-subdir": "tvmovies",
        "format-tvshows-subdir": "tvshows",
        "channel-in-title": false,
        "date-in-title": true,
        "time-in-title": false,
        "episode-in-title": false,
        "subtitle-in-title": false,
        "omit-title": false,
        "clean-title": true,
        "whitespace-in-title": false,
        "windows-compatible-filenames": true,
        "tag-files": true,
        "epg-update-window": 86400,
        "epg-running": false,
        "autorec-maxcount": 50,
        "autorec-maxsched": 0,
        "record": 0,
        "skip-commercials": true,
        "warm-time": 0
}

Of course this setup was generated with WebGUI. Despite:

Format string/Pathname specification: "%F_$t$n.$x"

recording creates a file /home/hts/multimedia/tv/2 which is a valid video.
Here's a part of tvheadend log during that recording:

2024-03-15 19:35:47.272 [  DEBUG]:dvr: File "/home/hts/multimedia/tv/2" -- Nie ma takiego pliku ani katalogu -- Using for recording
2024-03-15 19:35:47.287 [   INFO]:dvr: /home/hts/multimedia/tv/2 from adapter: "Afatech AF9033 (DVB-T) #0 : DVB-T #0", network: "kablowka", mux: "490MHz", 
provider: "DOLSAT", service: "Polsat Film HD"

(Nie ma takiego pliku ani katalogu - there is no file or directory of that name)

When I try to record anything else without deleting that file, recording fails with that info in log:

2024-03-15 19:54:37.940 [  DEBUG]:dvr: Overwrite protection, file "/home/hts/multimedia/tv/2" exists
2024-03-15 19:54:37.940 [  ERROR]:dvr: unable to create unique name (missing $n in format string?)
2024-03-15 19:54:37.940 [  ERROR]:dvr: Recording error: "Rodzina zastępcza": Unable to create file

despite presence of '$n' in format string.

Sometimes it creates filename with only '2', another times something like '__2'.
Autorec is unusable, because after creation of first file, it won't create another.

What can cause this?

TVHeadend version Build: 4.3-2299~g79aaa1434 (2024-03-09T22:47:20+0000)on Debian Bookworm.

Has it worked previously or is this a new installation?

I think I always had some problems with it, even on previous version. This current version was upgraded with old configuration, but I also created new recording profile and it still won't work as intended.

Here is screenshot of configuration of default profile:

Here is screenshot of some new profile used for autorec:

Did you self-compile Tvheadend or did you download it from some repository?

    Flole
    From repository:

    $ cat /etc/apt/sources.list.d/tvheadend-tvheadend.list
    # Source: Tvheadend
    # Site: https://tvheadend.org
    # Repository: Tvheadend / Tvheadend
    # Description: Tvheadend is the leading TV streaming server and recorder for Linux, FreeBSD and Android supporting DVB-S, DVB-S2, DVB-C, DVB-T, DVB-T2, ATSC, ISDB-T, IPTV, SAT>IP and HDHomeRun as input sources.
    
    
    deb [signed-by=/usr/share/keyrings/tvheadend-tvheadend-archive-keyring.gpg] https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian bookworm main
    
    deb-src [signed-by=/usr/share/keyrings/tvheadend-tvheadend-archive-keyring.gpg] https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian bookworm main

    Have you tried using an easier pattern? Something like test.$x to see if $x is evaluated properly? If that works keep adding some options like $t and $n to see if that issue appears at some point.

      Flole
      ok, I tried that format string: test.$t. It generated file: 't' :

      2024-03-15 20:31:24.476 [  DEBUG]:dvr: File "/home/hts/multimedia/tv/t" -- Nie ma takiego pliku ani katalogu -- Using for recording

      Now, format string ABCD.$x: filename: 'A'
      Format string Z1234 : filename: 'Z'
      Looks like it uses first char of format string. But previously sometimes it was preceded by '__' (double underscore)

        What type of file system are you trying to store the recordings on? You could try storing them in /tmp for testing.

          Flole
          it is ext4 in LVM volume.
          OK, I'll try /tmp

          Flole
          Still the same problem:

          2024-03-15 20:44:24.492 [  DEBUG]:dvr: File "/tmp/Z" -- Nie ma takiego pliku ani katalogu -- Using for recording

            seth777
            for the record: I disabled all options in Filename/Tagging section and it's still the same:

            Flole
            I tried to add almost all subsystems to "Trace subsystems" section in Configuration/Debugging:
            START,STOP,CRASH,main,tprof,qprof,CPU,thread,tvhpoll,time,spawn,fsmonitor,lock,uuid,idnode,url,tcp,rtsp,settings,config,access,cron,dbus,avahi,bonjour,api,htsp,htsp-sub,htsp-req,htsp-ans,imagecache,tbl,tbl-base,tbl-csa,tbl-eit,tbl-time,tbl-atsc,tbl-pass,tbl-satip,fastscan,pcr,parser,TS,globalheaders,tsfix,hevc,muxer,pass,audioes,mkv,service,channel,subscription,service-mapper,bouquet,esfilter,profile,descrambler,descrambler-emm,caclient,csa,capmt,cwc,cccam,dvbcam,dvr,dvr-inotify,epg,epgdb,epggrab,charset,dvb,mpegts,muxsched,libav,transcode,iptv,iptv-pcr,iptv-sub,linuxdvb,diseqc,en50221,en50494,satip,satips,tvhdhomerun,psip,opentv,pyepg,xmltv,webui,timeshift,scanfile,tsfile,tsdebug,codec,vaapi,ddci
            but unfortunately it failed to indicate what is wrong.

            Hmm, should I create a bug ticket?

            Flole
            On the top of all this, when I tried to delete this test recordings in WEBGUI/Digital Recorder/Finished Recordings, TVHeadend crashed:

            2024-03-15 21:43:27.712 [  DEBUG]:settings: saving to /home/hts/.hts/tvheadend/input/dvb/networks/e53033af9590a31901d09978264c4c9e/config
            2024-03-15 21:43:30.077 [   INFO]:dvr: delete entry 64382b0cbf690bd093bcb582a192bdd3 "Galileo" on "Fokus TV" start time 2024-03-15 19:59:00, scheduled for recording by "superanckij", retention "On file removal" removal "Forever"
            2024-03-15 21:43:30.078 [  ALERT]:CRASH: Signal: 11 in PRG: /usr/bin/tvheadend (4.3-2299~g79aaa1434) [b95784df316b884e8407397deda6130512f06560] CWD: /  
            2024-03-15 21:43:30.078 [  ALERT]:CRASH: Fault address 0x1 (Address not mapped)
            2024-03-15 21:43:30.078 [  ALERT]:CRASH: Loaded libraries: linux-vdso.so.1 /lib/x86_64-linux-gnu/libdvbcsa.so.1 /lib/x86_64-linux-gnu/libssl.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3 /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/liburiparser.so.1 /lib/x86_64-linux-gnu/libavahi-common.so.3 /lib/x86_64-linux-gnu/libavahi-client.so.3 /lib/x86_64-linux-gnu/libdbus-1.so.3 /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libmvec.so.1 /lib/x86_64-linux-gnu/libstdc++.so.6 /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libsystemd.so.0 /lib64/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libcap.so.2 /lib/x86_64-linux-gnu/libgcrypt.so.20 /lib/x86_64-linux-gnu/liblzma.so.5 /lib/x86_64-linux-gnu/libzstd.so.1 /lib/x86_64-linux-gnu/liblz4.so.1 /lib/x86_64-linux-gnu/libgpg-error.so.0 /lib/x86_64-linux-gnu/libnss_compat.so.2 /lib/x86_64-linux-gnu/libnss_nis.so.2 /lib/x86_64-linux-gnu/libnsl.so.2 /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libtirpc.so.3 /li
            2024-03-15 21:43:30.078 [  ALERT]:CRASH: Register dump [23]: 00007fcba9c70020000055a586ab9bd0b69d391f52b499a000007fcbbafb0148000055a5846b1200000055a586ab9521000055a5846b1230000055a58432f93100007fcba9c70020000055a5844a003400007fcba9c7008000007fcba9c70020000000000000fdff000000000000000000000000000003ff00007fcba9c70020000055a5834a3eaf0000000000010246002b0000000000330000000000000006000000000000000efffffffe7ffbba130000000000000001
            2024-03-15 21:43:30.078 [  ALERT]:CRASH: STACKTRACE
            2024-03-15 21:43:30.149 [  ALERT]:CRASH: ??:0 0x55a58344514e 0x55a5831fe000
            2024-03-15 21:43:30.221 [  ALERT]:CRASH: ??:0 0x7fcbbae5b050 0x7fcbbae1f000
            2024-03-15 21:43:30.296 [  ALERT]:CRASH: ??:0 0x55a5834a3eaf 0x55a5831fe000
            2024-03-15 21:43:30.367 [  ALERT]:CRASH: ??:0 0x55a583401950 0x55a5831fe000
            2024-03-15 21:43:30.439 [  ALERT]:CRASH: ??:0 0x55a5834929f5 0x55a5831fe000
            2024-03-15 21:43:30.512 [  ALERT]:CRASH: ??:0 0x55a583492f21 0x55a5831fe000
            2024-03-15 21:43:30.584 [  ALERT]:CRASH: ??:0 0x55a58347378f 0x55a5831fe000
            2024-03-15 21:43:30.655 [  ALERT]:CRASH: ??:0 0x55a583479249 0x55a5831fe000
            2024-03-15 21:43:30.728 [  ALERT]:CRASH: ??:0 0x55a5834ae500 0x55a5831fe000
            2024-03-15 21:43:30.801 [  ALERT]:CRASH: ??:0 0x55a5834102c8 0x55a5831fe000
            2024-03-15 21:43:30.874 [  ALERT]:CRASH: ??:0 0x55a583411a97 0x55a5831fe000
            2024-03-15 21:43:30.947 [  ALERT]:CRASH: ??:0 0x55a583410be1 0x55a5831fe000
            2024-03-15 21:43:31.023 [  ALERT]:CRASH: ??:0 0x55a583411f03 0x55a5831fe000
            2024-03-15 21:43:31.098 [  ALERT]:CRASH: ??:0 0x55a583412204 0x55a5831fe000
            2024-03-15 21:43:31.172 [  ALERT]:CRASH: ??:0 0x55a58340782c 0x55a5831fe000
            2024-03-15 21:43:31.247 [  ALERT]:CRASH: ??:0 0x55a583402b89 0x55a5831fe000
            2024-03-15 21:43:31.320 [  ALERT]:CRASH: ??:0 0x7fcbbaea8134 0x7fcbbae1f000

            Unless you install the tvheadend-dbg package those crashdumps are useless as they don't say anything.

            If you want to open a bug report it needs to contain precise information on how to reproduce it on a clean install, and if it can't be reproduced or if further debugging doesn't lead to anything it will just be closed again. Once someone else is also affected, that's a different story, but right now it only seems to affect your system for some reason. Do you have any experience debugging with gdb?

              Flole
              Unfortunately, I don't. I'm looking into this just now. Looks like this kind of low-code debugging can be very complicated.

              I can point you in the right direction where you're likely to see something. I'd suggest to do a b dvr_rec.c:1188 to break in line 1188 of that file, then c to continue. Start the recording and it will break where we want it to. Then look at ptmp by doing p *ptmp and it should tell you what's in it. You can also do a bt full to look at basically everything that's available. You could then do s to execute a single line of code and look at s then (p *s).

                Flole
                ok, I installed tvheadend-dbg
                stopped tvheadend.service, then i launched
                gdb --args /usr/bin/tvheadend -f -p /run/tvheadend.pid -u hts -g video --nosyslog --nostderr --logfile /home/hts/tmp/tvheadend.log (line from tvheadend.service)
                gdb started:

                GNU gdb (Debian 13.1-3) 13.1
                Copyright (C) 2023 Free Software Foundation, Inc.
                License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
                This is free software: you are free to change and redistribute it.
                There is NO WARRANTY, to the extent permitted by law.
                Type "show copying" and "show warranty" for details.
                This GDB was configured as "x86_64-linux-gnu".
                Type "show configuration" for configuration details.
                For bug reporting instructions, please see:
                <https://www.gnu.org/software/gdb/bugs/>.
                Find the GDB manual and other documentation resources online at:
                    <http://www.gnu.org/software/gdb/documentation/>.
                
                For help, type "help".
                Type "apropos word" to search for commands related to "word"...
                Reading symbols from /usr/bin/tvheadend...
                Reading symbols from /usr/lib/debug//usr/bin/tvheadend...

                Then i pasted b dvr_rec.c:1188 (breakpoint in dvr_rec at line 1188):
                Breakpoint 1 at 0x29afd8: file src/dvr/dvr_rec.c, line 1188.
                Next c:
                The program is not being run. Hmmm. I tailing tvheadend log on another window and it looks like it is running.
                I'm starting recording on webgui... And it's saved a file correctly! Logfile:
                dvr: File "/home/hts/multimedia/tv/Z1234" -- Nie ma takiego pliku ani katalogu -- Using for recording
                Format string is currently: Z1234$n, storage path: /home/hts/multimedia/tv/
                Shit.
                I'm trying another record... And whole system froze. I had to do hard reset.
                Goddammit.

                You still had Tvheadend running, just not from gdb. You could leave it running and attach by specifying the pid, like this (it gets the pid, passes it to gdb and attaches to Tvheadend then)

                gdb tvheadend $(pidof tvheadend)

                Also you upgraded to the latest version, that could have fixed the issue.

                  Flole
                  I don't really know how, but it looks like you are right - in system logs there is line that tvheadend service is running

                  After system started, modified format string to %F_$t$n.$x and started some recording:
                  2024-03-15 22:52:29.137 [ DEBUG]:dvr: File "/home/hts/multimedia/tv/2024-03-15_Tenet.ts" -- Nie ma takiego pliku ani katalogu -- Using for recording
                  Then I stopped it, and started again:

                  2024-03-15 22:53:40.153 [  DEBUG]:dvr: Overwrite protection, file "/home/hts/multimedia/tv/2" exists
                  2024-03-15 22:53:40.154 [  ERROR]:dvr: unable to create unique name (missing $n in format string?)
                  2024-03-15 22:53:40.154 [  ERROR]:dvr: Recording error: "Tenet": Unable to create file

                  looks like a problem is still persisting.
                  I'll try to execute gdb steps once again.

                    seth777 That's...... Odd.... So it worked on the first recording and broke on the second? Does it always work on the first recording after a restart? Then you might be facing a memory corruption and valgrind could catch that. But I'm just guessing right now, gdb should tell us more.