Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcode example in README #163

Open
Disonantemus opened this issue Jul 13, 2023 · 9 comments
Open

Transcode example in README #163

Disonantemus opened this issue Jul 13, 2023 · 9 comments

Comments

@Disonantemus
Copy link

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

#!/bin/bash
command="ffmpeg -hide_banner -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 pipe:1"
go-chromecast --verbose --first transcode --command "$command" --content-type video/mp4
  • Output:
    error: unable to transcode media: unable to change to appID "CC1AD845": context deadline exceeded

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:

  • go-chromecast
  • catt (no transcode)
  • castnow (abandoned)
  • mkchromecast
  • vlc (gui)

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
Copy link
Owner

vishen commented Jul 13, 2023

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
Copy link
Author

Disonantemus commented Jul 14, 2023

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
Copy link

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

@Disonantemus
Copy link
Author

  • Can someone please, put an example that works using transcode command from go-chromecast?
  • Maybe in README.md or here in this Issue at least, to test it with my device.
  • This could be really useful to do live transcode 4 files that are not compatible that are more frequent now (like: x265, AV1, vp9) , and not do 2 separated steps.

@vishen
Copy link
Owner

vishen commented Oct 28, 2023

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
Copy link

ManuLinares commented Oct 28, 2023

		/*
			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
Copy link
Owner

vishen commented Oct 28, 2023

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
Copy link

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"

  • I'm using hevc_nvenc as I have an nvidia gpu, but one could use h264
  • Using matroska seems to work better for the stream.
  • I'm burning in the subtitles (if found) because I didn't find a workaround by sending the stream with embedded srt, ass, vtt, they didn't display on chromecast.
  • I'm downscaling if ffprobe detects video larger than 1920x1080 as I have a "Chromecast HD".
  • I'm not using the -re ffmpeg flag as I've had better streaming experience without it, less stutters.

@vishen
Copy link
Owner

vishen commented Oct 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants