vishen / go-chromecast

cli for Google Chromecast, Home devices and Cast Groups
Apache License 2.0
853 stars 84 forks source link

Transcode example in README #163

Open Disonantemus opened 1 year ago

Disonantemus commented 1 year ago

I've tried with no success to cast a file while transcoding. Target: Chromecast 3 | H.264 High Profile up to level 4.2


I've transcoded with success, using this ffmpeg shell script, that was the inspiration:

#!/bin/bash
file1="${1%.*}"
ffmpeg -y -loglevel warning -stats \
-threads auto -async 2 \
-i "$1" \
-fflags +genpts+nofillin \
-strict experimental \
-codec:v libx264 -movflags frag_keyframe+faststart \
-ac 2 -codec:a aac -b:a 192k \
-preset ultrafast -profile:v high -level 4.2 -crf 23 \
-pix_fmt yuv420p \
-f mp4 \
"$file1".mp4

Resulting file cast no problem with:


OS: Arch Linux x86_64 Host: MS-7816 2.0 Kernel: 6.1.14-1-lts Resolution: 1920x1080 WM: dwm Terminal: tmux CPU: Intel i7-4790 (8) @ 3.600GHz GPU: AMD ATI Radeon RX 470/480/570/570X/580/580X/590 Memory: 2705MiB / 15939MiB

vishen commented 1 year ago

Apologies, this transcode command is not one I am 100% familiar with. Is the issue that the transcode command in the example is wrong, or that it doesn't work at all?

error: unable to transcode media: unable to change to appID "CC1AD845": context deadline exceeded

This is an annoying one. We need the Chromecast to be on the Default Receiver App to be able to cast to it, and it looks like it isn't working in this case. Does it work in general if you go go-chromecast load <file>?

Disonantemus commented 1 year ago

Yes, works with this: go-chromecast --first load <file_x264_and_aac.mp4>

Maybe you can try a similar transcode 4 your device that works, then I can try that with mine, as an example.

ManuLinares commented 1 year ago

I don't understand how transcode works. Please could anyone provide an example so I can play unplayable media on Chromecast?

Disonantemus commented 1 year ago
vishen commented 1 year ago

By default, the go-chromecast load command will transcode unplayable files by default. So if you want to let go-chromecast handle that for you, then I suggest using the load command.

The transcode command is used when you want to do the transcoding manually, if the default behaviour in go-chromecast load doesn't work, or you want something different then you can use go-chromecast transcode, but you will need to know the command and arguments already. https://github.com/vishen/go-chromecast/blob/master/application/application.go#L1158-L1169 is the default command and arguments used. If you want to use something else then that could be a template to use.

ManuLinares commented 1 year ago
        /*
            We can play media for the following:

            - if we have a filename with a known content type
            - if we have a filename, and a specified contentType
            - if we have a filename with an unknown content type, and transcode is true
            -
        */

I have a "Chromecast HD", the max resolution it can play is 1080p. This function treats 2160p files as not needing transcoding.

This is an issue worth fixing, I would be glad thankful if an example to the "transcode" command could be provided.

vishen commented 1 year ago

The transcode command will take any arbitrary command and arguments you want. If you have an ffmpeg command or similar that will transcode to stdout, then you can plug that directly into go-chromecast transcode command. Using the example ffmpeg command I provided above, that would look like:

$ go-chromecast transcode ffmpeg -re -i <filename> -vcodec h264 -acodec aac -ac 2 -f mp4 -movflags frag_keyframe+faststart -strict -experimental pipe:1
ManuLinares commented 1 year ago

I should point out you forgot the "content-type" at the end

The command that worked for me is this one:

go-chromecast --first transcode --command "ffmpeg -i ${video_file} -c:v hevc_nvenc -c:a vorbis -ac 2 -vf scale=1920:-2,subtitles=${video_file}:stream_index=0:force_style=Fontname=LiberationSans -f matroska -movflags frag_keyframe+faststart -strict -2 pipe:1" --content-type "video/x-matroska"

vishen commented 1 year ago

Ah thanks, I forgot about that. Thanks for the working example. I think the --command option is probably the better approach.