CasparCG / server

CasparCG Server is a Windows and Linux software used to play out professional graphics, audio and video to multiple outputs. It has been in 24/7 broadcast production since 2006. Ready-to-use downloads are available under the Releases tab https://casparcg.com.
GNU General Public License v3.0
911 stars 268 forks source link

Bug: Files created with Caspar are not playable in Caspar #1550

Open Sidonai-1 opened 3 months ago

Sidonai-1 commented 3 months ago

Observed Behavior

I tried to record MP4 and MOV files, the recording works and is playable by VLC and Premiere 2024.

add 1 file test4.mp4

[2024-06-25 16:34:38.749] [info]    Received message from 127.0.0.1: add 1 file test4.mp4\r\n
[2024-06-25 16:34:38.750] [info]    ffmpeg[test4.mp4] Initialized.
[2024-06-25 16:34:38.750] [info]    Sent message to 127.0.0.1:202 ADD OK\r\n
[2024-06-25 16:34:38.816] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] using SAR=1/1
[2024-06-25 16:34:38.816] [info]    
[2024-06-25 16:34:38.817] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[2024-06-25 16:34:38.817] [info]    
[2024-06-25 16:34:38.834] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] profile High 4:2:2, level 5.1, 4:2:2, 8-bit
[2024-06-25 16:34:38.834] [info]    
[2024-06-25 16:34:38.834] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] 264 - core 164 r3099 e067ab0 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=67 lookahead_threads=16 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[2024-06-25 16:34:38.834] [info]    
[2024-06-25 16:34:38.848] [info]    [ffmpeg] [aac @ 0000023B91C36C80] Using a PCE to encode channel layout "hexadecagonal"
[2024-06-25 16:34:38.848] [info]    
[2024-06-25 16:35:06.885] [info]    Received message from 127.0.0.1: remove 1 file test4.mp4\r\n
[2024-06-25 16:35:06.886] [info]    Sent message to 127.0.0.1:202 REMOVE OK\r\n
[2024-06-25 16:35:06.886] [info]    ffmpeg[test4.mp4] Uninitialized.
[2024-06-25 16:35:07.890] [info]    [ffmpeg] [aac @ 0000023B91C36C80] Qavg: 51076.703
[2024-06-25 16:35:07.890] [info]    
[2024-06-25 16:35:07.907] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] frame I:3     Avg QP:10.80  size: 65027
[2024-06-25 16:35:07.907] [info]    
[2024-06-25 16:35:07.907] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] frame P:202   Avg QP:20.92  size:  9984
[2024-06-25 16:35:07.907] [info]    
[2024-06-25 16:35:07.907] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] frame B:498   Avg QP:26.54  size:  4816
[2024-06-25 16:35:07.907] [info]    
[2024-06-25 16:35:07.907] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] consecutive B-frames:  1.1%  2.8% 31.2% 64.9%
[2024-06-25 16:35:07.907] [info]    
[2024-06-25 16:35:07.907] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] mb I  I16..4: 87.3%  8.1%  4.7%
[2024-06-25 16:35:07.907] [info]    
[2024-06-25 16:35:07.908] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] mb P  I16..4:  2.8%  2.2%  0.3%  P16..4:  0.4%  0.3%  0.1%  0.0%  0.0%    skip:94.0%
[2024-06-25 16:35:07.908] [info]    
[2024-06-25 16:35:07.908] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] mb B  I16..4:  0.9%  0.7%  0.0%  B16..8:  1.3%  0.3%  0.0%  direct: 1.1%  skip:95.8%  L0:49.9% L1:46.0% BI: 4.0%
[2024-06-25 16:35:07.908] [info]    
[2024-06-25 16:35:07.908] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] 8x8 transform intra:37.1% inter:20.4%
[2024-06-25 16:35:07.908] [info]    
[2024-06-25 16:35:07.908] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] coded y,uvDC,uvAC intra: 15.9% 57.9% 5.9% inter: 0.1% 1.4% 0.1%
[2024-06-25 16:35:07.908] [info]    
[2024-06-25 16:35:07.908] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] i16 v,h,dc,p: 48% 15%  3% 34%
[2024-06-25 16:35:07.908] [info]    
[2024-06-25 16:35:07.908] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 35% 17%  6%  5%  5%  6%  5%  2%
[2024-06-25 16:35:07.908] [info]    
[2024-06-25 16:35:07.909] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 18% 24%  8%  7%  6%  6%  5%  3%
[2024-06-25 16:35:07.909] [info]    
[2024-06-25 16:35:07.909] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] i8c dc,h,v,p: 37% 14%  7% 43%
[2024-06-25 16:35:07.909] [info]    
[2024-06-25 16:35:07.909] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] Weighted P-Frames: Y:0.0% UV:0.0%
[2024-06-25 16:35:07.909] [info]    
[2024-06-25 16:35:07.909] [info]    [ffmpeg] [libx264 @ 0000023B91C37480] kb/s:1311.63
[2024-06-25 16:35:07.909] [info]    
[2024-06-25 16:35:08.341] [info]    ffmpeg[test4.mp4] Uninitialized.

However, Caspar can't play those same files. Invalid channel layout 0 seems to be the cause.

[2024-06-25 16:35:42.084] [info]    Received message from 127.0.0.1: PLAY 1-20 "test4.mp4" MIX 8 LINEAR RIGHT     Loop \r\n
[2024-06-25 16:35:42.090] [info]    Sent message to 127.0.0.1:202 PLAY OK\r\n
[2024-06-25 16:35:42.199] [error]   [ffmpeg] [in_1 @ 0000023B9086FD00] Invalid channel layout 0.
[2024-06-25 16:35:42.199] [error]   
[2024-06-25 16:35:42.205] [error]   Exception: D:\a\server\server\src\modules\ffmpeg\producer\av_producer.cpp(497): Throw in function auto __cdecl caspar::ffmpeg::Filter::{ctor}::<lambda_3d78c5b404e263a57fa623a88f5ad9cb>::operator ()(void) const
[2024-06-25 16:35:42.205] [error]   Dynamic exception type: class boost::exception_detail::clone_impl<struct caspar::ffmpeg::ffmpeg_error_t>
[2024-06-25 16:35:42.205] [error]   [struct boost::errinfo_api_function_ * __ptr64] = avfilter_graph_create_filter( &source, avfilter_get_by_name("abuffer"), name.c_str(), args.c_str(), nullptr, graph.get())
[2024-06-25 16:35:42.205] [error]   [struct boost::errinfo_errno_ * __ptr64] = 22, "Invalid argument"
[2024-06-25 16:35:42.205] [error]   [struct caspar::ffmpeg::tag_ffmpeg_errn_info * __ptr64] = -22
[2024-06-25 16:35:42.205] [error]   [struct caspar::tag_stacktrace_info * __ptr64] =  0# 0x00007FF6A7053427 in casparcg
[2024-06-25 16:35:42.205] [error]    1# 0x00007FF6A707F7C6 in casparcg
[2024-06-25 16:35:42.205] [error]    2# 0x00007FF6A71BF38E in casparcg
[2024-06-25 16:35:42.205] [error]    3# 0x00007FF6A71BB32F in casparcg
[2024-06-25 16:35:42.205] [error]    4# 0x00007FF6A71C26D9 in casparcg
[2024-06-25 16:35:42.205] [error]    5# 0x00007FF6A71C3256 in casparcg
[2024-06-25 16:35:42.205] [error]    6# 0x00007FF6A71BF767 in casparcg
[2024-06-25 16:35:42.205] [error]    7# 0x00007FF6A728CD93 in casparcg
[2024-06-25 16:35:42.205] [error]    8# configthreadlocale in ucrtbase
[2024-06-25 16:35:42.205] [error]    9# BaseThreadInitThunk in KERNEL32
[2024-06-25 16:35:42.205] [error]   10# RtlUserThreadStart in ntdll
[2024-06-25 16:35:42.205] [error]   
[2024-06-25 16:35:42.205] [error]   

[2024-06-25 16:35:42.205] [error]    0# 0x00007FF6A7053427 in casparcg
[2024-06-25 16:35:42.205] [error]    1# 0x00007FF6A7052EAA in casparcg
[2024-06-25 16:35:42.205] [error]    2# 0x00007FF6A73350E7 in casparcg
[2024-06-25 16:35:42.205] [error]    3# 0x00007FF8CE271080 in VCRUNTIME140_1
[2024-06-25 16:35:42.205] [error]    4# _NLG_Return2 in VCRUNTIME140_1
[2024-06-25 16:35:42.205] [error]    5# RtlCaptureContext2 in ntdll
[2024-06-25 16:35:42.205] [error]    6# 0x00007FF6A71BF767 in casparcg
[2024-06-25 16:35:42.205] [error]    7# 0x00007FF6A728CD93 in casparcg
[2024-06-25 16:35:42.205] [error]    8# configthreadlocale in ucrtbase
[2024-06-25 16:35:42.205] [error]    9# BaseThreadInitThunk in KERNEL32
[2024-06-25 16:35:42.205] [error]   10# RtlUserThreadStart in ntdll
[2024-06-25 16:35:42.205] [error]   

Environment

Sidonai-1 commented 3 months ago

Also I cannot find how to record in qtrle with alpha.

When I add -c:v qtrle it says "unused"

Edit: Nevermind, using the long label for the qtrle codec works: add 1-1 FILE test.mov -codec:v qtrle, but they have the same issue I mention above when playing.

Sidonai-1 commented 2 months ago

I tried playing those files with version 2.0.7 and they play no problem.

Sidonai-1 commented 2 weeks ago

Problem seems to be a lack of ffmpeg parameters when creating the file. It plays fine when declaring the format option:

add 1 file test3.mp4 -format mpegts Mediainfo:

General
ID                                       : 1 (0x1)
Complete name                            : C:\APP_VID\MEDIA\test3.mp4
Format                                   : MPEG-TS
File size                                : 6.47 MiB
Duration                                 : 15 s 420 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 3 515 kb/s
FileExtension_Invalid                    : ts m2t m2s m4t m4s tmf ts tp trp ty

Video
ID                                       : 256 (0x100)
Menu ID                                  : 1 (0x1)
Format                                   : MPEG Video
Format version                           : Version 2
Format profile                           : 4:2:2@High
Format settings, BVOP                    : No
Format settings, Matrix                  : Default
Format settings, GOP                     : N=12
Codec ID                                 : 2
Duration                                 : 15 s 440 ms
Bit rate mode                            : Variable
Bit rate                                 : 2 953 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 50.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:2
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.028
Time code of first frame                 : 00:00:00:00
Time code source                         : Group of pictures header
GOP, Open/Closed                         : Open
GOP, Open/Closed of first frame          : Closed
Stream size                              : 5.44 MiB (84%)

Audio
ID                                       : 257 (0x101)
Menu ID                                  : 1 (0x1)
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Codec ID                                 : 3
Duration                                 : 15 s 456 ms
Bit rate mode                            : Constant
Bit rate                                 : 384 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Frame rate                               : 41.667 FPS (1152 SPF)
Compression mode                         : Lossy
Delay relative to video                  : -10 ms
Stream size                              : 724 KiB (11%)

Menu
ID                                       : 4096 (0x1000)
Menu ID                                  : 1 (0x1)
Format                                   : MPEG Video / MPEG Audio
Duration                                 : 15 s 420 ms
List                                     : 256 (0x100) (MPEG Video) / 257 (0x101) (MPEG Audio)
Service name                             : Service01
Service provider                         : FFmpeg
Service type                             : digital television

The unplayable file created with only add 1 file test5.mp4 has this info:

General
Complete name                            : C:\APP_VID\MEDIA\test5.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 1.80 MiB
Duration                                 : 18 s 280 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 828 kb/s
Writing application                      : Lavf59.27.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High 4:2:2@L4.2
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 18 s 260 ms
Bit rate                                 : 322 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 50.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:2
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.003
Stream size                              : 718 KiB (39%)
Writing library                          : x264 core 164 r3099 e067ab0
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=2 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=18 / lookahead_threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=10 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 18 s 280 ms
Source duration                          : 18 s 301 ms
Source_Duration_LastFrame                : -3 ms
Bit rate mode                            : Variable
Bit rate                                 : 495 kb/s
Maximum bit rate                         : 1 044 kb/s
Channel(s)                               : 16 channels
Channel layout                           : ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 1.08 MiB (60%)
Source stream size                       : 1.08 MiB (60%)
Default                                  : Yes
Alternate group                          : 1

Given that it's coming from a default state of ffmpeg format when you don't specify it, I'm not sure if it's a bug.

@Julusian feel free to close it if you think it's not a fixable bug on Caspar.

Edit: To fix the QTRLE files we have to specify some audio codec, for example -codec:a ac3_fixed or ac3, so it all seems to be related to the default audio codec being unable to set a proper channal layout or codec, hence Mediainfo displaying ?????????? on 'Channel Layout'.

The example that worked for me: add 1 FILE test_alfa.mov -codec:v qtrle -codec:a ac3_fixed

Sidonai-1 commented 2 weeks ago

Applying an audio filter for a set number of audio channels seems to fix the issue as well: -filter:a pan=2c|c0=c2|c1=c3

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 9 s 700 ms
Source duration                          : 9 s 721 ms
Source_Duration_LastFrame                : -7 ms
Bit rate mode                            : Variable
Bit rate                                 : 15.4 kb/s
Maximum bit rate                         : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 18.1 KiB (0%)
Source stream size                       : 18.3 KiB (0%)
Default                                  : Yes
Alternate group                          : 1

I tested mp4 and qtrle and both seem to play nicely with the following creation commands:

add 1-100 file test3.mp4 -filter:a pan=2c|c0=c2|c1=c3

add 1-100 FILE test_alfa.mov -codec:v qtrle -filter:a pan=2c|c0=c2|c1=c3

I do not know how well the audio is preserved after this. I have not tested audio retention/quality on the files.