Custom ffmpeg transcoding to HLS with Subtitles not working

Here you can submit bugreports
Post Reply
dlebrero
Posts: 15
Joined: Thu Apr 06, 2017 3:01 pm

Custom ffmpeg transcoding to HLS with Subtitles not working

Post by dlebrero »

Hi all,
I'm having issues passing a subtitle file to a custom ffmpeg encoder that works just fine with a video file only but when adding a subtitle file with -i option ffastrans ends with an error.

Here is the custom ffmpeg command:

Code: Select all

-i "%s_original_drive%%s_original_folder%\%s_original_name%.srt" -filter_complex "[0:v]split=3[v1][v2][v3]; [v1]scale=w=1280:h=720[v1out]; [v2]scale=w=854:h=480[v2out]; [v3]scale=w=640:h=360[v3out]" -map [v1out] -c:v:0 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:0 1465k -maxrate:v:0 1465k -minrate:v:0 1465k -bufsize:v:0 3500k -preset fast -g 30 -sc_threshold 0 -keyint_min 30 -map [v2out] -c:v:1 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:1 964k -maxrate:v:1 964k -minrate:v:1 964k -bufsize:v:1 1800k -preset fast -g 30 -sc_threshold 0 -keyint_min 30 -map [v3out] -c:v:2 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:2 764k -maxrate:v:2 764k -minrate:v:2 764k -bufsize:v:2 1500k -preset fast -g 30 -sc_threshold 0 -keyint_min 30 -map a:0 -c:a:0 aac -b:a:0 128k -ac 2 -map a:0 -c:a:1 aac -b:a:1 96k -ac 2 -map a:0 -c:a:2 aac -b:a:2 48k -ac 2 -map 1 -c:s webvtt -f hls -hls_playlist_type 2 -var_stream_map "v:0,a:0,name:1465,s:0,sgroup:subtitle_group v:1,a:1,name:964 v:2,a:2,name:764" -master_pl_name index.m3u8 -hls_time 6 -hls_list_size 0 -hls_allow_cache 1 -start_number 1 -hls_segment_filename 
"P:\HLS\Outbox\%s_original_name%\%v_%05d.ts" -f hls -master_pl_name "index.m3u8" "P:\HLS\Outbox\%s_original_name%\%v.m3u8" -hls_subtitle_path P:\HLS\Outbox\%s_original_name%\%v.m3u8
At first, reading the logs found that I had to add a backslash between %s_original_folder%\%s_original_name% otherwise it was concatenating both variables without a backslash.

But that did not help either and still fails (see attached log)
I was able to compress the workflow and the log, but I cannot seems to be able to send the subtitle file (even compressed) it says the quota was exceeded.

As a side note, the ffmpeg command inside the log works just fine after removing all the escape characters (I guess those are needed when submitting the job inside FFAstrans)

Can you please help me find out what is going on?
Attachments
Archive.zip
(10.85 KiB) Downloaded 348 times
dlebrero
Posts: 15
Joined: Thu Apr 06, 2017 3:01 pm

Re: Custom ffmpeg transcoding to HLS with Subtitles not working

Post by dlebrero »

I found the problem, the custom ffmpeg command had an extra new line character, I found that on the log.

"cmd_line":

Code: Select all

"C:\\Windows\\system32\\cmd.exe \/u \/c \"\"P:\\FFASTRANS-2\\FFAStrans1.2.1\\processors\\FFMpeg\\x64\\ffmpeg.exe\"  -analyzeduration 33554432  -stats_period 1.2 -nostdin -hide_banner -i \"T:\\Processing_Area_Local\\Transcoding_Area\\1-ARC\\2-MOVIES\\1-ENGLISH\\THE_HOLIDAY\\UTUNI120820063905900\\UTUNI120820063905900.ts\"   -i \"T:\\Processing_Area_Local\\Transcoding_Area\\1-ARC\\2-MOVIES\\1-ENGLISH\\THE_HOLIDAY\\UTUNI120820063905900\\UTUNI120820063905900.srt\" -filter_complex \"[0:v]split=3[v1][v2][v3]; [v1]scale=w=1280:h=720[v1out]; [v2]scale=w=854:h=480[v2out]; [v3]scale=w=640:h=360[v3out]\" -map [v1out] -c:v:0 libx264 -x264-params \"nal-hrd=cbr:force-cfr=1\" -b:v:0 1465k -maxrate:v:0 1465k -minrate:v:0 1465k -bufsize:v:0 3500k -preset fast -g 30 -sc_threshold 0 -keyint_min 30 -map [v2out] -c:v:1 libx264 -x264-params \"nal-hrd=cbr:force-cfr=1\" -b:v:1 964k -maxrate:v:1 964k -minrate:v:1 964k -bufsize:v:1 1800k -preset fast -g 30 -sc_threshold 0 -keyint_min 30 -map [v3out] -c:v:2 libx264 -x264-params \"nal-hrd=cbr:force-cfr=1\" -b:v:2 764k -maxrate:v:2 764k -minrate:v:2 764k -bufsize:v:2 1500k -preset fast -g 30 -sc_threshold 0 -keyint_min 30 -map a:0 -c:a:0 aac -b:a:0 128k -ac 2 -map a:0 -c:a:1 aac -b:a:1 96k -ac 2 -map a:0 -c:a:2 aac -b:a:2 48k -ac 2 -map 1 -c:s webvtt -f hls -hls_playlist_type 2 -var_stream_map \"v:0,a:0,name:1465,s:0,sgroup:subtitle_group v:1,a:1,name:964 v:2,a:2,name:764\" -master_pl_name index.m3u8 -hls_time 6 -hls_list_size 0 -hls_allow_cache 1 -start_number 1 -hls_segment_filename \n\"P:\\HLS\\Outbox\\UTUNI120820063905900\\%v_%05d.ts\" -f hls -master_pl_name \"index.m3u8\" \"P:\\HLS\\Outbox\\UTUNI120820063905900\\%v.m3u8\" -hls_subtitle_path P:\\HLS\\Outbox\\UTUNI120820063905900\\%v.m3u8 -f NULL - \""
The error is on this part of the command hls_segment_filename \n\"P:\\HLS\\Outbox\\UTUNI120820063905900 between the filename and P:\

I guess it got there by copying and pasting from "Mac OS Notes" into the custom processor. removing the \n fix the issue.
dlebrero
Posts: 15
Joined: Thu Apr 06, 2017 3:01 pm

Re: Custom ffmpeg transcoding to HLS with Subtitles not working

Post by dlebrero »

The only thing that is weird and difficult to figure out is the fact that I had to add a backslash between two variables, maybe my case was not considered.

Between %s_original_drive% and %s_original_folder% there is no need to add anything, but, between %s_original_folder% and %s_original_name% you need to add the backslash otherwise FFAstrans will concatenate both together.

Here is how I fixed it

"%s_original_drive%%s_original_folder%\%s_original_name%.srt"

Not sure if this is a bug, or it works like this intentionally.
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Custom ffmpeg transcoding to HLS with Subtitles not working

Post by emcodem »

dlebrero wrote: Tue Dec 07, 2021 7:51 pm between %s_original_folder% and %s_original_name% you need to add the backslash otherwise FFAstrans will concatenate both together.
Well we "concat" the 2 variables anyway, the only thing is that %s_original_folder% does not include the last backslash. In my mind, there should be a worldwide standard that folder strings should always be terminated with a slash or backslash, it is the only way for a program to know that it is about a folder.
Anyway, it is as it is now and we cannot change because it would most likely break existing workflows, sorry for that.
emcodem, wrapping since 2009 you got the rhyme?
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Custom ffmpeg transcoding to HLS with Subtitles not working

Post by emcodem »

by the way, nice example how to map subtitles into hls :D
emcodem, wrapping since 2009 you got the rhyme?
videodoctor
Posts: 1
Joined: Sun Oct 16, 2022 2:34 pm

Re: Custom ffmpeg transcoding to HLS with Subtitles not working

Post by videodoctor »

I have an issue somewhat related with subtitles not working. I'm trying to get a file with nine audio tracks and nine subtitles to output to HLS, and there's not a whole lot of documentation on proper key/value setups for sgroups with agroups. I think this syntax looks correct, but I'm getting an error:

Code: Select all

ffmpeg \
	-y \
	-i EJ5385032_combined.mkv   \
	-c:v libx264 \
	-c:a aac \
	-map 0:v \
	-map 0:a:0 \
	-map 0:a:1 \
	-map 0:a:2 \
	-map 0:a:3 \
	-map 0:a:4 \
	-map 0:a:5 \
	-map 0:a:6 \
	-map 0:a:7 \
	-map 0:a:8 \
	-map 0:s:0 \
	-map 0:s:1 \
	-map 0:s:2 \
	-map 0:s:3 \
	-map 0:s:4 \
	-map 0:s:5 \
	-map 0:s:6 \
	-map 0:s:7 \
	-map 0:s:8 \
	-f hls \
	-hls_flags independent_segments \
	-hls_segment_type mpegts \
	-hls_allow_cache 1 \
	-start_number 0 \
	-hls_time 10 \
	-hls_list_size 0 \
	-hls_segment_filename 'output/%v/file_%03d.ts' \
	-var_stream_map "v:0,agroup:audio,sgroup:subs,name:video a:0,s:0,default:yes,agroup:audio,sgroup:subs,language:eng,name:English a:1,s:1,agroup:audio,sgroup:subs,language:fra,name:French a:2,s:2,agroup:audio,sgroup:subs,language:ara,name:Arabic a:3,s:3,agroup:audio,sgroup:subs,language:deu,name:German a:4,s:4,agroup:audio,sgroup:subs,language:spa,name:Spanish a:5,s:5,agroup:audio,sgroup:subs,language:fre-ca,name:French-Canadian a:6,s:6,agroup:audio,sgroup:subs,language:jpn,name:Japanese a:7,s:7,agroup:audio,sgroup:subs,language:por-br,name:Portuguese-Brazilian a:8,s:8,agroup:audio,sgroup:subs,language:zho-cn,name:Chinese" \
	-master_pl_name master.m3u8 \
	-hls_subtitle_path output/sub-%v/index.m3u8 \
	output/%v/index.m3u8
Which produces:

Code: Select all

[mpegts @ 0x7ff29d97b000] Invalid packet stream index: -1
av_interleaved_write_frame(): Invalid argument
Segmentation fault: 11
Any suggestions would be greatly appreciated!
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Custom ffmpeg transcoding to HLS with Subtitles not working

Post by emcodem »

Hey @videodoctor, thank you for using FFAStrans (do you? :D)
Thats something for the #ffmpeg support channel on the Libera chat. I doubt that anyone here has lots of experience with the var_stream_map filter. Maybe it is even just ffmpeg not supporting the recognized subtitle codec? ...lots of possibilities :D
Basic help from me: simplify the command and locate where exactly in your stream_map the error occurs.
emcodem, wrapping since 2009 you got the rhyme?
Post Reply