ffpyplayer icon indicating copy to clipboard operation
ffpyplayer copied to clipboard

cdg format: cannot find suitable combination for converting to video, tried .mp4, .mkv, .mpg filenames

Open magowiz opened this issue 1 year ago • 0 comments

Hi All, I'm trying to convert a cdg (MP3CDG/Karaoke file) into any sort of more compatible video format, the idea is to mux it then with audio and use a normal video player to play karaoke.

By the way I'm having difficulties to adapt a given example to obtain any kind of most common video format (mkv, mp4, ...) and it seems I cannot match the right combination of options to get something, all I got since now are empty output files or files that are really little and doesn't play.

I'm using ubuntu 23.10, I installed ffmpeg using ubuntu deb and ffpyplayer in a virtual environment using poetry

ffmpeg -i output

$ ffmpeg -i songs/***.cdg                                                    
ffmpeg version 6.0-6ubuntu1 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13 (Ubuntu 13.2.0-2ubuntu1)
  configuration: --prefix=/usr --extra-version=6ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-libjxl --enable-pocketsphinx --enable-librsvg --enable-libvpl --disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Input #0, cdg, from 'songs/*******.cdg':
  Duration: 00:06:41.11, start: 0.000000, bitrate: 57 kb/s
  Stream #0:0: Video: cdgraphics, pal8, 300x216, 300 fps, 300 tbr, 300 tbn

from here I took pix_fmt_in option

ffprobe output for frame rate:

 ffprobe -v 0 -of compact=p=0 -select_streams 0 -show_entries stream=r_frame_rate songs/***.cdg 
r_frame_rate=300/1***.mp3

so it should be 300, 1

python code

In here I tried to detect the right codec iterating each one available on my system, but I didn't find anything valid, In this example you can see mkv file extension as output, but I also tried with no luck also with mp4 and mpg:

import time

import ffpyplayer
import ffmpeg
import bawx_player
from ffpyplayer.player import MediaPlayer
from ffpyplayer.writer import MediaWriter


def kar2video(cdg_file, mp3_file, video_file):
    """Convert karaoke (MP3CDG) file into a MP4 Video.

    Args:
        kar_file: the kar file to convert
        video_file: the name of the resulting file
    """

    # only video
    ff_opts = {'an': True, 'sync': 'video'}
    player = MediaPlayer(cdg_file, ff_opts=ff_opts)
    # wait for size to be initialized (todo: add timeout and check for quitting)
    while player.get_metadata()['src_vid_size'] == (0, 0):
        time.sleep(0.01)

    frame_size = player.get_metadata()['src_vid_size']
    print(frame_size[0], frame_size[1])
    # use the same size as the inputs
    codec = 'zmbv'
    list_of_codecs = ffpyplayer.tools.get_codecs(encode=True, video=True)
    for codec in list_of_codecs:
        try:
            out_opts = {'pix_fmt_in': 'pal8', 'width_in': frame_size[0],
                        'height_in': frame_size[1], 'codec': codec,
                        'frame_rate': (300, 1)
                        }

            writer = MediaWriter(video_file, [out_opts], overwrite=True)
            while 1:
                frame, val = player.get_frame()
                if val == 'eof':
                    break
                elif frame is None:
                    time.sleep(0.01)
                else:
                    img, t = frame
                    writer.write_frame(img=img, pts=t, stream=0)
        except Exception as e:
            print(f"{codec} is not valid, exception {e}")
if __name__ == "__main__":
    kar2video('../songs/***.cdg', '../songs/***.mp3',
              'video.mkv')

python program output

here you can find the output generated by above program:

300 216
a64multi is not valid, exception b'pal8' is not a supported pixel format for codec b'a64multi', the best valid format is gray
a64multi5 is not valid, exception b'pal8' is not a supported pixel format for codec b'a64multi5', the best valid format is gray
alias_pix is not valid, exception b'pal8' is not a supported pixel format for codec b'alias_pix', the best valid format is bgr24
amv is not valid, exception b'pal8' is not a supported pixel format for codec b'amv', the best valid format is yuvj420p
apng is not valid, exception Error writing header: Invalid argument
asv1 is not valid, exception b'pal8' is not a supported pixel format for codec b'asv1', the best valid format is yuv420p
asv2 is not valid, exception b'pal8' is not a supported pixel format for codec b'asv2', the best valid format is yuv420p
avrp is not valid, exception b'pal8' is not a supported pixel format for codec b'avrp', the best valid format is gbrp10le
avui is not valid, exception b'pal8' is not a supported pixel format for codec b'avui', the best valid format is uyvy422
ayuv is not valid, exception b'pal8' is not a supported pixel format for codec b'ayuv', the best valid format is yuva444p
bitpacked is not valid, exception b'pal8' is not a supported pixel format for codec b'bitpacked', the best valid format is yuv422p10le
bmp is not valid, exception Error writing header: Invalid argument
cfhd is not valid, exception b'pal8' is not a supported pixel format for codec b'cfhd', the best valid format is gbrp12le
cinepak is not valid, exception b'pal8' is not a supported pixel format for codec b'cinepak', the best valid format is rgb24
cljr is not valid, exception b'pal8' is not a supported pixel format for codec b'cljr', the best valid format is yuv411p
dnxhd is not valid, exception b'pal8' is not a supported pixel format for codec b'dnxhd', the best valid format is gbrp10le
dpx is not valid, exception b'pal8' is not a supported pixel format for codec b'dpx', the best valid format is rgb24
dvvideo is not valid, exception b'pal8' is not a supported pixel format for codec b'dvvideo', the best valid format is yuv420p
exr is not valid, exception b'pal8' is not a supported pixel format for codec b'exr', the best valid format is gbrpf32le
ffv1 is not valid, exception b'pal8' is not a supported pixel format for codec b'ffv1', the best valid format is bgr0
ffvhuff is not valid, exception b'pal8' is not a supported pixel format for codec b'ffvhuff', the best valid format is gbrp
fits is not valid, exception b'pal8' is not a supported pixel format for codec b'fits', the best valid format is gbrp
flashsv is not valid, exception b'pal8' is not a supported pixel format for codec b'flashsv', the best valid format is bgr24
flashsv2 is not valid, exception b'pal8' is not a supported pixel format for codec b'flashsv2', the best valid format is bgr24
flv is not valid, exception b'pal8' is not a supported pixel format for codec b'flv', the best valid format is yuv420p
gif is not valid, exception Input image doesn't match stream specified parameters.
h261 is not valid, exception b'pal8' is not a supported pixel format for codec b'h261', the best valid format is yuv420p
h263 is not valid, exception b'pal8' is not a supported pixel format for codec b'h263', the best valid format is yuv420p
h263p is not valid, exception b'pal8' is not a supported pixel format for codec b'h263p', the best valid format is yuv420p
hdr is not valid, exception b'pal8' is not a supported pixel format for codec b'hdr', the best valid format is gbrpf32le
huffyuv is not valid, exception b'pal8' is not a supported pixel format for codec b'huffyuv', the best valid format is rgb24
jpeg2000 is not valid, exception Input image doesn't match stream specified parameters.
jpegls is not valid, exception b'pal8' is not a supported pixel format for codec b'jpegls', the best valid format is bgr24
libtheora is not valid, exception b'pal8' is not a supported pixel format for codec b'libtheora', the best valid format is yuv444p
libvpx is not valid, exception b'pal8' is not a supported pixel format for codec b'libvpx', the best valid format is yuv420p
libvpx-vp9 is not valid, exception b'pal8' is not a supported pixel format for codec b'libvpx-vp9', the best valid format is gbrp
libx264 is not valid, exception b'pal8' is not a supported pixel format for codec b'libx264', the best valid format is yuv444p
libx264rgb is not valid, exception b'pal8' is not a supported pixel format for codec b'libx264rgb', the best valid format is bgr24
libx265 is not valid, exception b'pal8' is not a supported pixel format for codec b'libx265', the best valid format is gbrp
ljpeg is not valid, exception b'pal8' is not a supported pixel format for codec b'ljpeg', the best valid format is bgr24
magicyuv is not valid, exception b'pal8' is not a supported pixel format for codec b'magicyuv', the best valid format is gbrp
mjpeg is not valid, exception b'pal8' is not a supported pixel format for codec b'mjpeg', the best valid format is yuvj444p
mpeg1video is not valid, exception 300/1 is not a supported frame rate for codec b'mpeg1video', the                 closest valid rate is 60/1
mpeg2video is not valid, exception 300/1 is not a supported frame rate for codec b'mpeg2video', the                 closest valid rate is 240/1
mpeg4 is not valid, exception b'pal8' is not a supported pixel format for codec b'mpeg4', the best valid format is yuv420p
msmpeg4 is not valid, exception b'pal8' is not a supported pixel format for codec b'msmpeg4', the best valid format is yuv420p
msmpeg4v2 is not valid, exception b'pal8' is not a supported pixel format for codec b'msmpeg4v2', the best valid format is yuv420p
msvideo1 is not valid, exception b'pal8' is not a supported pixel format for codec b'msvideo1', the best valid format is rgb555le
pam is not valid, exception b'pal8' is not a supported pixel format for codec b'pam', the best valid format is rgb24
pbm is not valid, exception b'pal8' is not a supported pixel format for codec b'pbm', the best valid format is monow
pcx is not valid, exception Error writing header: Invalid argument
pfm is not valid, exception b'pal8' is not a supported pixel format for codec b'pfm', the best valid format is gbrpf32le
pgm is not valid, exception b'pal8' is not a supported pixel format for codec b'pgm', the best valid format is gray
pgmyuv is not valid, exception b'pal8' is not a supported pixel format for codec b'pgmyuv', the best valid format is yuv420p
phm is not valid, exception b'pal8' is not a supported pixel format for codec b'phm', the best valid format is gbrpf32le
png is not valid, exception Input image doesn't match stream specified parameters.
ppm is not valid, exception b'pal8' is not a supported pixel format for codec b'ppm', the best valid format is rgb24
prores is not valid, exception b'pal8' is not a supported pixel format for codec b'prores', the best valid format is yuv444p10le
prores_aw is not valid, exception b'pal8' is not a supported pixel format for codec b'prores_aw', the best valid format is yuv444p10le
prores_ks is not valid, exception b'pal8' is not a supported pixel format for codec b'prores_ks', the best valid format is yuv444p10le
qoi is not valid, exception b'pal8' is not a supported pixel format for codec b'qoi', the best valid format is rgb24
qtrle is not valid, exception b'pal8' is not a supported pixel format for codec b'qtrle', the best valid format is rgb24
r10k is not valid, exception b'pal8' is not a supported pixel format for codec b'r10k', the best valid format is gbrp10le
r210 is not valid, exception b'pal8' is not a supported pixel format for codec b'r210', the best valid format is gbrp10le
rawvideo is not valid, exception Error writing header: Invalid argument
roqvideo is not valid, exception b'pal8' is not a supported pixel format for codec b'roqvideo', the best valid format is yuvj444p
rpza is not valid, exception b'pal8' is not a supported pixel format for codec b'rpza', the best valid format is rgb555le
rv10 is not valid, exception b'pal8' is not a supported pixel format for codec b'rv10', the best valid format is yuv420p
rv20 is not valid, exception b'pal8' is not a supported pixel format for codec b'rv20', the best valid format is yuv420p
sgi is not valid, exception b'pal8' is not a supported pixel format for codec b'sgi', the best valid format is rgb24
smc is not valid, exception Input image doesn't match stream specified parameters.
snow is not valid, exception b'pal8' is not a supported pixel format for codec b'snow', the best valid format is yuv444p
speedhq is not valid, exception b'pal8' is not a supported pixel format for codec b'speedhq', the best valid format is yuv444p
sunrast is not valid, exception Error writing header: Invalid argument
svq1 is not valid, exception b'pal8' is not a supported pixel format for codec b'svq1', the best valid format is yuv410p
targa is not valid, exception Input image doesn't match stream specified parameters.
tiff is not valid, exception Input image doesn't match stream specified parameters.
utvideo is not valid, exception b'pal8' is not a supported pixel format for codec b'utvideo', the best valid format is gbrp
v210 is not valid, exception b'pal8' is not a supported pixel format for codec b'v210', the best valid format is yuv422p
v308 is not valid, exception b'pal8' is not a supported pixel format for codec b'v308', the best valid format is yuv444p
v408 is not valid, exception b'pal8' is not a supported pixel format for codec b'v408', the best valid format is yuva444p
v410 is not valid, exception b'pal8' is not a supported pixel format for codec b'v410', the best valid format is yuv444p10le
vbn is not valid, exception b'pal8' is not a supported pixel format for codec b'vbn', the best valid format is rgb24
vc2 is not valid, exception b'pal8' is not a supported pixel format for codec b'vc2', the best valid format is yuv444p
vnull is not valid, exception Error writing header: Invalid argument
wbmp is not valid, exception b'pal8' is not a supported pixel format for codec b'wbmp', the best valid format is monob
wmv1 is not valid, exception b'pal8' is not a supported pixel format for codec b'wmv1', the best valid format is yuv420p
wmv2 is not valid, exception b'pal8' is not a supported pixel format for codec b'wmv2', the best valid format is yuv420p
wrapped_avframe is not valid, exception Error writing header: Invalid argument
xbm is not valid, exception b'pal8' is not a supported pixel format for codec b'xbm', the best valid format is monow
xface is not valid, exception b'pal8' is not a supported pixel format for codec b'xface', the best valid format is monow
xwd is not valid, exception Error writing header: Invalid argument
y41p is not valid, exception b'pal8' is not a supported pixel format for codec b'y41p', the best valid format is yuv411p
yuv4 is not valid, exception b'pal8' is not a supported pixel format for codec b'yuv4', the best valid format is yuv420p
zlib is not valid, exception b'pal8' is not a supported pixel format for codec b'zlib', the best valid format is bgr24
zmbv is not valid, exception Input image doesn't match stream specified parameters.
[matroska @ 0x277fc00] codec apng is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec apng
[matroska @ 0x277fc00] codec bmp is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec bmp
[jpeg2000 @ 0x281ee00] Forcing lossless jp2 for pal8
[matroska @ 0x277fc00] codec pcx is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec pcx
[matroska @ 0x281e400] Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or
If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)
[matroska @ 0x277fc00] codec sunrast is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec sunrast
[matroska @ 0x277fc00] codec vnull is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec vnull
[matroska @ 0x277fc00] codec wrapped_avframe is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec wrapped_avframe
[matroska @ 0x277fc00] codec xwd is not supported by this format
[matroska @ 0x277fc00] No bmp codec tag found for codec xwd

So could you please tell me what else I could try? If needed I will provide further information about my system or other, just ask.

Best regards, magowiz

magowiz avatar Feb 24 '24 15:02 magowiz