FFmpeg: Choosing audio streams by language - ffmpeg

I am trying to transcode tv streams but with only the english audio stream included. I have tried using the -map 0:m:language:eng stream specifier, but I get:
"Automatic encoder selection failed for output stream #0:3. Default encoder for format mpegts (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:3"
This is despite including an encoder. I have tried all sorts of variations on this theme without success.
Full output for one attempt is below:
ffmpeg -i http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0: -ignore_unknown -map 0:a -map 0:m:language:eng -map 0:v -acodec aac -vcodec libx264 -b:v 1100000 -t 00:00:30 "somethin.ts" 2>output.txt
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts # 03db7b60] Could not find codec parameters for stream 17 (Unknown: none ([11][0][0][0] / 0x000B)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts # 03db7b60] Could not find codec parameters for stream 18 (Unknown: none ([11][0][0][0] / 0x000B)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0:':
Duration: N/A, start: 23690.732933, bitrate: N/A
Program 6321
Program 6322
Program 6338
Program 6301
Program 6302
Stream #0:0[0x13ec]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x13ee](NAR): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 224 kb/s
Stream #0:2[0x13ed](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 224 kb/s
Stream #0:3[0x13ef](eng,eng): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
Stream #0:4[0x13f0](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:5[0xf04]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:6[0xf03]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:7[0xf02]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:8[0xf01]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:9[0xf00]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:10[0x92a]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:11[0x913]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:12[0x912]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:13[0x911]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:14[0x919]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:15[0xf09]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:16[0xf08]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:17[0xf07]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:18[0xf06]: Unknown: none ([11][0][0][0] / 0x000B)
Program 6318
Program 6390
Program 6391
Program 6351
Program 6361
Program 6306
Program 6341
Automatic encoder selection failed for output stream #0:3. Default encoder for format mpegts (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:3
Any ideas on how to do this. I cant specify streams by number as I want to use it for lots of tv streams and the order is often different.
Thanks

Output stream 0:3 is a image-based subtitle stream. Since you've not specified an encoder for subtitles, ffmpeg is trying to pick one and fails since it doesn't have an image-based subtitle encoder. You can copy or drop the stream.
ffmpeg -i http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0: -ignore_unknown -c copy -map 0:a -map 0:m:language:eng -map 0:v -acodec aac -vcodec libx264 -b:v 1100000 -t 00:00:30 "somethin.ts" 2>output.txt
Of course, your primary aim is to map only the audio stream by language. Your command will map the video twice, as it is tagged as English.
To avoid this, you can use two ffmpeg commands:
ffmpeg -i http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0: -ignore_unknown -c copy -map 0:v:0 -map 0:m:language:eng -f mpegts - | ffmpeg -f mpegts -i - -map 0:v:0 -map 0:a:0 -c:a aac -c:v libx264 -b:v 1.1M out.ts

Related

ffmpeg convert rtmp audio/video stream to icecast2 audio/video stream

I've been using this command to convert my public rtmp audio/video stream to a local mp3 audio icecast2 stream, but I have been unable to do the same for both video and audio.
[Audio Only] (This works fine)
ffmpeg -re -i rtmp://162.142.xx.xxx:xxx/stream -vn -codec:a libmp3lame -b:a 128k -f mp3 -content_type audio/mpeg icecast://source:password#192.168.1.xxx:80/live
I've tried to re-write in order to support video, but I keep hitting dead ends
[Audio & Video Attempt] (this does not work)
ffmpeg -re -i rtmp://162.142.xx.xxx:xxx/stream -codec:v -f mpeg4 -b:v -f mpeg4 -content_type video/mpeg4 icecast://source:password#192.168.1.xxx:80/live
When I run this command, it gives me the error below asking for a suitable format.
$ ffmpeg -re -i rtmp://162.142.xx.xxx:xxx/stream -codec:v -f mpeg4 -b:v -f mpeg4 -content_type video/mpeg4 icecast://source:password#192.168.1.xxx:80/live
[h264 # 0x5598ffbb8980] co located POCs unavailable
[h264 # 0x5598ffbb8980] mmco: unref short failure
Input #0, flv, from 'rtmp://162.142.xx.xxx:xxx/stream':
Metadata:
|RtmpSampleAccess: true
Server : NGINX RTMP (github.com/sergey-dryabzhinsky/nginx-rtmp-module)
displayWidth : 1280
displayHeight : 720
fps : 48
videokeyframe_frequency: 0
profile :
level :
Duration: 00:00:00.00, start: 28117.779000, bitrate: N/A
Stream #0:0: Audio: aac (LC), 48000 Hz, stereo, fltp, 327 kb/s
Stream #0:1: Video: h264 (High), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 2560 kb/s, 48 fps, 48 tbr, 1k tbn
[NULL # 0x5598ffb8bec0] Unable to find a suitable output format for 'mpeg4'
mpeg4: Invalid argument
I am positive that icecast2 can support video streams, however on the few occasions that I was able to actively stream successfully to it, it only showed an empty video embed.
I've re-written the command for AV multiple times while referencing ffmpeg documentation, however my above attempt seems to be the closest (concept-wise) that I have gotten.
What flags/formatting might I be missing which are causing the stream not to work?

How does MPG determine its default audio track?

I have some mpg files that I transcoded from DVDs I bought a long time ago (maybe 20 years ago). ffprobe:
Input #0, mpeg, from 'da-orig.mpg':
Duration: 00:06:59.44, start: 0.044100, bitrate: 6354 kb/s
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 720x480 [SAR 8:9 DAR 4:3], Closed Captions, 31 fps, 59.94 tbr, 90k tbn
Side data:
cpb: bitrate max/min/avg: 7500000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:1[0x85]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:2[0x83]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:3[0x81]: Audio: ac3, 48000 Hz, mono, fltp, 192 kb/s
Stream #0:4[0x80]: Audio: ac3, 48000 Hz, mono, fltp, 192 kb/s
This shows there are 4 audio streams. When I play this file in VLC / QuickTime it seems that Audio Track 4 is the default. I'd like to understand how this is chosen. Is it something within the mpg container format or are players choosing the stream that has the lowest id (0x80) ?
More background, when I try to turn this into a mp4 file with the following command:
ffmpeg -i da-orig.mpg -c copy -map 0 da-copy.mp4
I get roughly the same size file, but the default audio track is stream #0:1[0x85].
What I want is an equivalent mp4 file (so the same audio track chosen).
as written in this guide
"The -map option is used to choose which streams from the input(s)
should be included in the output(s)."
in your case you have only one input so it would be -map 0
if you have 2 inputs and want video from one and audio from the other it would be -map 0:v -map 1:a
since your input is a container selecting the video would be -map 0:v
and the second audio stream would be -map 0:a:2
ffmpeg -i da-orig.mpg -map 0:v -c:v h264 -crf 17 -preset 'veryslow' -map 0:a:2 -c:a copy output.mp4
to answer to your comment the sequence can help you
after you rename your collection with sequential numbers 'collection-name_0000' then
ffmpeg -i collection_name_#04d.mpg -map 0:v -c:v h264 -crf 17 -preset 'veryslow' -map 0:a:2 -c:a copy output-#04d.mp4
this iterate through the videos if they have the same number of streams

ffmpeg can't transcode DVD ac3 audio stream, but VLC can play it

I'm attempting to transcode a DVD to a single MKV file. I've had success in the past with other DVDs, but I'm running into an error I haven't seen before.
First I concatenate the VOB files I want to transcode:
cat VTS_02_1.VOB VTS_02_2.VOB VTS_02_3.VOB > WMAV.VOB
ffprobe output:
$ ffprobe -analyzeduration 100M -probesize 100M WMAV.VOB Input #0, mpeg, from 'WMAV.VOB':
Duration: 01:05:19.42, start: 0.300300, bitrate: 5686 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, smpte170m, top first), 720x480 [SAR 32:27 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:2[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Unsupported codec with id 100357 for input stream 0
Then I run this command to transcode the file:
ffmpeg -analyzeduration 100M -probesize 100M \
-i WMAV.VOB \
-map 0:1 -map 0:2 \
-c:v libx264 -preset slow -tune film -crf 21 \
-c:a aac -b:a 192k \
wmav.mkv
However, when I include -c:a aac, I get thousands of errors like this:
Error while decoding stream #0:2: Error number -16976906 occurred
[ac3 # 000002bd24d8eec0] expacc 127 is out-of-range
[ac3 # 000002bd24d8eec0] error decoding the audio block
There doesn't seem to be any issue with the audio stream since it plays back fine in VLC. The transcode succeeds if I use -c:a copy.
What is causing this error and how could I fix the problem?

how to extract elementary stream from transport stream

i have .ts file looks like the following
Input #0, mpegts, from 'i.ts':
Duration: 00:00:36.32, start: 28752.398067, bitrate: 57694 kb/s
Program 50
Metadata:
service_name : aaa HD
service_provider:
Stream #0:51[0x1f5]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
Stream #0:52[0x1f6]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
Program 51
Metadata:
service_name : b Music HD
service_provider:
Stream #0:16[0x1ff]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
Stream #0:17[0x200]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
Program 52
Metadata:
service_name : c ch HD
service_provider:
Stream #0:14[0x209]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
Stream #0:15[0x20a]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
Program 1510
Metadata:
service_name : asd
service_provider: xyz
Stream #0:18[0x5e7]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
Stream #0:19[0x5e8]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
i need to extract one video stream and its audio stream from this file for example related to program 50 i tried
ffmpeg -i i.ts -map 0:51 output.mp4
but i got this error
Stream mapping:
Stream #0:51 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
Cannot determine format of input stream 0:51 after EOF
Error marking filters as finished
Conversion failed!
I found a solution here
For mapping the whole programs, the syntax is:
ffmpeg -i i.ts -c:v copy -c:a copy -map 0:p:51 output.mp4
I can't verify that solution is actually working with your .ts file.
I created the following sample, that builds a .ts file with two programs, and then extracts each program to .mp4 file:
ffmpeg -y -r 10 -f lavfi -i testsrc=rate=10:size=160x120 -f lavfi -i sine=frequency=1000 -t 5 -c:v libx264 -c:a aac in1.mp4
ffmpeg -y -r 10 -f lavfi -i mandelbrot=rate=10:size=160x120 -f lavfi -i sine=frequency=300 -t 5 -c:v libx264 -c:a aac in2.mp4
ffmpeg -y -i in1.mp4 -i in2.mp4 -map 0:0 -map 0:1 -map 1:0 -map 1:1 -program title=ProgOne:st=0:st=1 -program title=ProgTwo:st=2:st=3 -c:v copy -c:a copy in.ts
ffmpeg -y -i in.ts -c:v copy -c:a copy -map 0:p:1 output1.mp4
ffmpeg -y -i in.ts -c:v copy -c:a copy -map 0:p:2 output2.mp4
1st command builds video test pattern with high frequency beep (output: in1.mp4).
2nd command builds video Mandelbrot pattern with low frequency beep (output: in2.mp4).
3rd command builds transport stream with two programs (output: in.ts).
4th command extracts first program (output: output1.mp4).
5th command extracts second program (output: output2.mp4).

View MPEG-TS stream in browser

I want to create a webpage with a video player that can play a H264 mpeg-ts live stream. I can't find any web player that can do that.
I read that JWPlayer is capable of doing that, but only in the paid version.
The stream can be played in VLC and any other players.
What can I do? I tried using ffmpeg to convert the stream to something more useful, but no succes.
ffmpeg -i "http://localhost:9002/tv.ts" -vcodec libx264 -r 20 -s 320x240 -threads 2 -vprofile baseline -vpre zoom -strict experimental -acodec aac -ab 96000 -ar 48000 -ac 1 -f rtsp rtsp://192.168.0.28:1935/live/_definst_/c3
This is what I get:
Last message repeated 1 times
[h264 # 0xbb9500] decode_slice_header error
[h264 # 0xbb9500] no frame!
[mpegts # 0xbaa6e0] decoding for stream 1 failed
[mpegts # 0xbaa6e0] Could not find codec parameters for stream 1 (Video: h264 ([27][0][0][0] / 0x001B), none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'http://192.168.0.28:9002/tv.ts':
Duration: N/A, start: 30764.854700, bitrate: N/A
Program 1
Stream #0:0[0x44](???): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 128 kb/s
Stream #0:1[0x45]: Video: h264 ([27][0][0][0] / 0x001B), none, 25 fps, 25 tbr, 90k tbn, 180k tbc
File for preset 'zoom' not found
You can attempt to include hls.js player in your website. This player transmuxes your TS stream into MP4 fragments in order to be played in any browser. It is free and easily integrated.
Demo page https://video-dev.github.io/hls.js/demo/
Github page https://github.com/video-dev/hls.js/

Resources