Jump to content
Tuts 4 You
Sign in to follow this  
LCF-AT

FFmpeg - Audio bitrate not same

Recommended Posts

LCF-AT

Hi guys,

I found a new problem using FFmpeg to encode some video / audio streams.My goal was it to encode some diffrent parts of one video out using same audio bitrate but as result I have the parts out with diffrent bitrates what means I can not merge this parts together but for this I need exact same audio bitrate (only for audio needed).Thats a problem so far.I tried already all diffrent ffmpeg commands without success.I am using audio codec aac (nativ).On internet I found some infos about using libfdk_aac instead of acc what I tried too (Internet I found a static compiled build version what has this codec included which is not present in normal builds).I tried this one now and it still dosent match.

Example commands:

-i - -c:a libfdk_aac -b:a 128k -f mp4 -y "%(tempaudiofile)"

I just loaded a video in VirtualDub2 and using external encoders option where I can set commandline arguments.I just selected some video frames to encode from the beginning of the video and as result I got first a matching audio bitrate = good.Now I did selected some frames from the end of the video and did encode it and in this second file I got a audio bitrate which is higher.

44100Hz  128 kb/s tot (2 chnls) <-- of first video part
44100Hz  129 kb/s tot (2 chnls) <-- of second video part

So you see its only 1 bit more.

So my question is whether anyone knows some more specific commands I could use to get my desired constant audio bitrate out for acc codec?

Normaly I use VirtualDub tool to cut videos using Quick Time Plugin 2.6 loading mp4 videos.The good thing using this plugin is that I can cut videos and keeping the original audio stream.That pretty good.The disadvantage is that the plugin has some bad issues for the video stream what means frames are not same where there should be same.This is bad if you wanna cut exactly.Video handling bad / audio handling good.So to make a exact video cutting I need to load the video using FFmpeg input driver or Caching input driver (VirtualDub2) or DirectShow input driver so with these I get all video frames correctly to see without black frames or any other issues the QT plugin has.Problem with this drivers are the audio stream what needs to be encode and for that I wanna use FFmpeg as I told above but there I have that bitrate issues which dosent match.Maybe anyone could help to fix that issues. :)

Thank you

Share this post


Link to post
LCF-AT

Hi again,

I was now trying to use external encoder using just the copy method of ffmpeg in the audio encoder but this dosent work in VirtualDub. :( Thats pretty bad.

So I would like to keep the audio stream original without to re-encode it (using ffmpeg in VD).All seems to work good if I split any file using ffmpeg from commandline direct like this..

ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4

This new both files I can also merge together in VD.

Example: Lets say I do have 3 videos and wanna cut out some parts and merge them together.If I encode the audio stream like I told in my first post then I get diffrent bitrates out what means I cant merge them.How to handle that issue without to make a retour saving all audio streams as wav file.

greetz

Share this post


Link to post
LCF-AT

Hi again,

so I was playing around again testing diffrent video tools and found out that they all almost working very diffrent to merge / join videos and getting diffrent results out (mostly bad of course).

Good news first: I tried ffmpeg again to merge files like in my first post who having diffrent aac bitrates.So it works to merge them putting all files into extern txt file and using -f concat command.So with this I get successfully a complete correct file. :) The bad thing is I have no GUI yet for this (maybe I build any later).I also tried to tool called Avidemux what also works successfully to join such files.

Next I tried tools like MP4 Box GUI / VD2 and others what do merge these files too but they are not correctly merged = total bad result (not merged 2. file to first or second file sound isnt present in output file).

greetz

Share this post


Link to post
LCF-AT

Hi guys,

I have another question.Just wanna ask whether anyone knows how to re-encode diffrent video & audio streams into a new format?Lets say I have 3 video with audio and all 3 are diffrent.They using diffrent video & audio formats and now I wanna create one commandline to encode all in the one and same video / audio format.So I can do this one by one for example but I would like to know whether its also possible to do this at once (one commandline)?I was playing around and did check some commandline I found like this..

-c:v libx264 -r 25 -vf scale=854:480 -c:a aac -strict experimental -b:a 128k -ac 2 -ar 44100 -threads 2 -crf 20 -f mp4

...but audio isnt there in the second video (I tried it with 2 video in this case).Do you have any clues for that how to make more than one diffrent audio / video streams same in one commandline without to handle all videos one by one?

greetz

Share this post


Link to post
身勝手のごくい

Hi,

If i understand correctly u have 3 different type of videos with audio, u want to merge them to single video by following each timeline with its own audio.

If thats the case in virtualdub u can use 'append avi segment' before u save them all might have some limitations i got no experience with it.

Im using virtualdub to create low size videos with decent quality from uncompressed files, mostly standard aac x265 and mkvmerge as multiplexer.

I would just queue every video in a job and then merge them (u might have to set same static size previously in the conversion to avoid stretching).

here are the exact cmdargs im running:

-q 0.67 -ignorelength -if - -of "%(tempaudiofile)"

--crf 24 --preset medium --input-res %(width)x%(height) --fps %(fps) -o "%(tempvideofile)" -

-o "%(outputname)" --default-duration 0:%(fpsnum)/%(fpsden)fps "%(tempvideofile)" "%(tempaudiofile)"

Hope it helps, regards.

  • Like 1

Share this post


Link to post
LCF-AT

Hello .....you,sorry I can't read your name. :)

Thanks for your answer so far.Yes I am also using VD/2 sometimes.

So about FFmpeg commandlines.In this case I just wanna do it alone with FFmpeg (without VD) and with only one whole cmd line if possible but anyhow I dont get it work yet also not if I am using the concat mode (extern file with paths of the videos I wanna handle).Its works if I handle all videos alone but not all at once you know.In this case I could setup the list of videos I wanna make same and start the process and go away and if I come back then all shouldbe finished.All this without to create any extra script or other tools between using ffmpeg.I am still not sure whether its possible but I am trying check another ffmpeg parameters or infos I found on internet.Will see.

greetz

Share this post


Link to post
身勝手のごくい

Hi, again!

I did some digging, concatating videos without have to re-encode can be done easily as found here https://trac.ffmpeg.org/wiki/Concatenate.

You can make it with a single command line.

I've made first a list of my video files using this:

(for %i in (*.mkv, *.avi, *.mp4) do @echo file '%i') > mylist.txt

then i run this:

ffmpeg -f concat -i mylist.txt -c copy output.mkv


(videos merged without losing any quality in single file, and the order was filename ascending)

In a previous version of ffmpeg i run this fully working example:

"C:\ffmpeg\ffmpeg.exe"  -y -t 70.19 -i C:\ffmpeg\v1.mkv -t 71.77 -i C:\ffmpeg\v2.mkv -t 12.10 -i C:\ffmpeg\v3.mkv -t 12.35 -i C:\ffmpeg\v4.mkv -t 16.92 -i C:\ffmpeg\v5.mkv -t 37.10 -i C:\ffmpeg\v6.mkv -t 70.19 -i C:\ffmpeg\v1.mkv -t 71.77 -i C:\ffmpeg\v2.mkv -t 12.10 -i C:\ffmpeg\v3.mkv -t 12.35 -i C:\ffmpeg\v4.mkv -t 16.92 -i C:\ffmpeg\v5.mkv -t 37.10 -i C:\ffmpeg\v6.mkv -filter_complex "[0:v] trim=end=70.19 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_0]; [1:v] trim=end=71.77 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_1]; [2:v] trim=end=12.10 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_2]; [3:v] trim=end=12.35 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_3]; [4:v] trim=end=16.92 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_4]; [5:v] trim=end=37.10 , scale=iw*min(1680/iw\,1050/ih):ih*min(1680/iw\,1050/ih) , pad=1680:1050:(1680-iw*min(1680/iw\,1050/ih))/2:(1050-ih*min(1680/iw\,1050/ih))/2 , setsar=1/1 [v_0_5]; [v_0_0][v_0_1][v_0_2][v_0_3][v_0_4][v_0_5] concat=n=6:v=1:a=0[v_0]; [6:a] atrim=end=70.19 [a_0_0]; [7:a] atrim=end=71.77 [a_0_1]; [8:a] atrim=end=12.10 [a_0_2]; [9:a] atrim=end=12.35 [a_0_3]; [10:a] atrim=end=16.92 [a_0_4]; [11:a] atrim=end=37.10 [a_0_5]; [a_0_0][a_0_1][a_0_2][a_0_3][a_0_4][a_0_5] concat=n=6:v=0:a=1[a_0]" -map [v_0] -map [a_0] -pix_fmt yuv420p -b:v 1844 -vcodec libx265 -crf 28 -preset ultrafast -aspect 16:10 -ab 192K -ac 2 -ar 44100 -acodec libfaac C:\ffmpeg\ouput.mp4

Its reencoding the videos and merging them to the specified output:
video:
1680x1050
1844 br
ultrafast preset
16:10 aspect ratio
yuv420 pixel format

audio:
44100 sample rate
192K bitrate

In case u want this old ffmpeg version i will leave it here with a picture of how the output looks like.

Cheers (:

ffmpeg.zip

ffmpegOutput.png

  • Like 1

Share this post


Link to post
LCF-AT

Hi again,

I tried concat command using extra file with diffrent video paths inside.First problem I have....about the filenames...

file 'C:\123\test'video1.mp4'
file 'C:\123\test'video2.mp4'

...if the filename used a ' sign in the name itself then it does fail whats not happens if I just use -i paramters.Strange somehow.

Now lets talk again about encoding of diffrent video files (formats / resolutions / with and without audio streams etc).The filter_complex paramters is also very complex to understand so maybe its possible for you to write some less complex commands examples next time which I could test without trimming etc.

Example: I made a small pic of 2 video from my app I did added...

Vidinfo.png.b8a2ef7a8d37c42b4524b89244224df0.png

...now I wanna encode both to one same video & audio & container format and join them.All at once with one commandline.

First problem I see in this case that they have diffrent resolutions.

- How to make both video to same resolution like (-s hd720)

- How to set a same aspect ratio 16:9 without to make the video stretch into 16:9 (I mean it should keep original) = need to add a letterbox OR make a zoom OR Crop it.Something like that you know.

- How to handle the diffrent framerates?Can they keep same?I mean the sound stream needs to keep matching of course.

- How to do handle diffrent video & audio bitrates?I would like to tell ffmpeg to choose A.) the best bitrate of video & audio streams it can find in the files (if possible) so that all files will created with the best rate which is present in any file from the list of video I wanna handle all at once.

Something like this you know,so maybe you can make any examples I can check out.Later I would like to use them to make some diffrent profiles.

PS: I am just a basic FFmpeg user at the moment and I dont know all possible commands yet.

Thank you

Share this post


Link to post
LCF-AT

Hi,

I have a another question about FFmpeg.I am looking for any command to generate dynamic or random output file names.So I wanna that FFmpeg does just create any or a specific output filename without to overwrite any present filename.

Example:

file_01.mp3

file_02.mp3

file_03.mp3

Here I have 3 files in my folder.Now I would  like to setup FFmpeg output file paramter more specific like file_%0d.mp3 but it should not overwrite the already present file 01-03 so it should  now create file 04 in this case.You know?Something like this I am looking for.On internet I found only this info...

https://stackoverflow.com/questions/40576880/generating-random-filenames-in-ffmpeg-output

....not sure how or whether this could work.Not for me so far.Does anyone of you maybe know some dynamic paramter I can use for outputfile?

greetz

Share this post


Link to post
LCF-AT

Hi guys,

I have a new small question about ffmpeg and using custom request http header datas.I have test it and I dont get it working anymore so correctly and I just get it work with only one header paramter also if I am using more than one.So ffmpeg said this...

http AVOptions:
-headers           <string>     ED....... set custom HTTP headers, can override built in default headers

...so if I use this paramter -headers "User-Agent: test" then it works.So now I would like to use more than one but if I do that then only the last -headers paramter gets added to the header and all before gets ignored.So does anyone remember how to make it correctly to set more than one header paramters for a commandline I can enter in CMD window?Is there any issue with CLRF and if yes how to enter that in text form?Maybe anyone has any example for that.

Thanks

Share this post


Link to post
NeWOT
35 minutes ago, LCF-AT said:

Hi guys,

I have a new small question about ffmpeg and using custom request http header datas.I have test it and I dont get it working anymore so correctly and I just get it work with only one header paramter also if I am using more than one.So ffmpeg said this...


http AVOptions:
-headers           <string>     ED....... set custom HTTP headers, can override built in default headers

...so if I use this paramter -headers "User-Agent: test" then it works.So now I would like to use more than one but if I do that then only the last -headers paramter gets added to the header and all before gets ignored.So does anyone remember how to make it correctly to set more than one header paramters for a commandline I can enter in CMD window?Is there any issue with CLRF and if yes how to enter that in text form?Maybe anyone has any example for that.

Thanks

Hi @LCF-AT,

 

Try something like(tested):

ffmpeg -headers $'X-API-KEY: g\r\nuser-agent:3' ...

Edited by NeWOT (see edit history)
  • Like 1

Share this post


Link to post
LCF-AT

Hi,

I found that info already but it dosent work.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\ffmpeg-4.0.1-win32-static\bin 1>ffmpeg -headers $'X-API-KEY: g\r\nuser-agent:3' -i "....m3u8" -v trace
ffmpeg version 4.0.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.1 (GCC) 20180710
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg -
-enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-
libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Splitting the commandline.
Reading option '-headers' ... matched as AVOption 'headers' with argument '$'X-API-KEY:'.
Reading option 'g\r\nuser-agent:3'' ... matched as output url.
Reading option '-i' ... matched as input url with argument '.....m3u8'.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url .....m3u8.
Successfully parsed a group of options.
Opening an input file: .....m3u8.
[NULL @ 0052f780] Opening '.....m3u8' for reading
[https @ 04943b80] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[https @ 04943b80] request: GET /....m3u8 HTTP/1.1
User-Agent: Lavf/58.12.100
Accept: */*
Range: bytes=0-
Connection: close
Host: .....net
Icy-MetaData: 1

Thats the problem.If I use -headers parameter once then it will add it below but I need to add many header paramters not only one.If I use more than one -headers xy then it only adds the last one.Any more clues?

greetz

Share this post


Link to post
LCF-AT

Hi again,

still dont get it.So it really  seems that its not possible to set more than one -headers xy paramters in commandline.

-headers $"X-API-KEY: g\r\nuser-agent:3"

[https @ 05253e40] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[https @ 05253e40] No trailing CRLF found in HTTP header.

User-Agent: Lavf/58.12.100
Accept: */*
Range: bytes=0-
Connection: close
Host: mcdn.daserste.de
Icy-MetaData: 1
$X-API-KEY: g\r\nuser-agent:3
-headers $'X-API-KEY: g\r\nuser-agent:3'

[https @ 0012ff00] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'

User-Agent: Lavf/58.12.100
Accept: */*
Range: bytes=0-
Connection: close
Host: mcdn.daserste.de
Icy-MetaData: 1
-headers "X-API-KEY: g"\r\n"user-agent:3"\r\n 

[https @ 00703e40] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[https @ 00703e40] No trailing CRLF found in HTTP header.

User-Agent: Lavf/58.12.100
Accept: */*
Range: bytes=0-
Connection: close
Host: mcdn.daserste.de
Icy-MetaData: 1
X-API-KEY: g\r\nuser-agent:3\r\n

What now?Anyone any idea or working commandline with minimum  2 header paramters?

greetz

Share this post


Link to post
LCF-AT

Hi again,

it seems that the command with using CLRF \r\n only works for Linux systems. 😕

Now I found also another problem trying to play some rtmp streams with FFmpeg + rtmp commands.FFmpeg always fails with application rejected but FFplay does play it using exactly the same ffmpeg rtmp commands (app / playpath / swfurl etc).Thats strange.

greetz

Share this post


Link to post
NeWOT
On 11/16/2018 at 8:59 PM, LCF-AT said:

Hi again,

it seems that the command with using CLRF \r\n only works for Linux systems. 😕

Now I found also another problem trying to play some rtmp streams with FFmpeg + rtmp commands.FFmpeg always fails with application rejected but FFplay does play it using exactly the same ffmpeg rtmp commands (app / playpath / swfurl etc).Thats strange.

greetz

I didn't experience with rtmp but do you have any url to test? If ffplay works then use it instead of ffmpeg

 

 

On 11/13/2018 at 9:42 PM, LCF-AT said:

Hi,

I found that info already but it dosent work.


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\ffmpeg-4.0.1-win32-static\bin 1>ffmpeg -headers $'X-API-KEY: g\r\nuser-agent:3' -i "....m3u8" -v trace
ffmpeg version 4.0.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.1 (GCC) 20180710
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg -
-enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-
libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Splitting the commandline.
Reading option '-headers' ... matched as AVOption 'headers' with argument '$'X-API-KEY:'.
Reading option 'g\r\nuser-agent:3'' ... matched as output url.
Reading option '-i' ... matched as input url with argument '.....m3u8'.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url .....m3u8.
Successfully parsed a group of options.
Opening an input file: .....m3u8.
[NULL @ 0052f780] Opening '.....m3u8' for reading
[https @ 04943b80] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[https @ 04943b80] request: GET /....m3u8 HTTP/1.1
User-Agent: Lavf/58.12.100
Accept: */*
Range: bytes=0-
Connection: close
Host: .....net
Icy-MetaData: 1

Thats the problem.If I use -headers parameter once then it will add it below but I need to add many header paramters not only one.If I use more than one -headers xy then it only adds the last one.Any more clues?

greetz

i tested it on linux..

  • Like 1

Share this post


Link to post
LCF-AT

Hi again,

so it seems to depend on the FFmpeg versions with that rtmp stream issues.I tried version 3.3.3 latest ffmpeg with librtmp and this works with a rtmp stream what not works with later versions but where ffplay does work!=?Anyway,problem is I cant play all rtmp streams with FFmpeg XY with or without librtmp or/and libavformat which I can play with rtmpdump / librtmp included patches by KSV.

https://github.com/K-S-V/Scripts/releases

PS: Yes I thought already that you did testet the header stuff on Linux. :) Just bad that its not working for Windows.

greetz

Share this post


Link to post
LCF-AT

Hi guys,

I have some small new questions about FFmppeg & Co.

Following problem.I found some HLS video streaming sites using extra request paramters like cookies.Normaly no big problem using cookie entrys with FFmpeg or just using youtube-dl what already does use the cookie by itself.But some sites using some kind of timeout for their cookies like 1 minute +/- before it does expired.So this is a problem if the video download / stream does need more time (download speed to slow or filesize to large etc).In this case the whole download will fail and I only have maybe  the half of the video and not the complete video.Now I tried to find any posts on internet for FFmpeg & youtube-dl how to handle this situation but didnt found anything.For youtube-dl I found no commandline arguments I could use to refresh the http header entrys like cookies if the download gets the error response of 403 (forbidden) and to resume the download from last successfully segment download from a playlist.Found nothing about that to build any automatically download in such cases.So it seems I need to handle it manually in such cases.

First idea I had was to download the video in few parts using FFmpeg and commandline...

-ss time_off        set the start time offset
-to time_stop       record or transcode stop time

Example: -ss 00:00:00 -t 00:01:00
         -ss 00:01:00 -t 00:02:00

Download from start till 1 minute.Next download from 1 minute till 2 minute...etc

...I tried this to execute FFmpeg twice using actually working cookie in header.It does work but there is a problem.The first part I did download is fine but the second part not and  the video starts first with only the sound for few seconds before the video starts.Anyhow the sound track seems to be longer than video track.Also if I download like this using timestamps then its not really perfect.Also depends on segment lenght.

Now I thought it should be get better if I tell FFmpeg only to download the video ts segment files itself and to keep them without to do anything with them.Unfortunately I didnt found any commandline argument how to do this.Also not how to tell ffmpeg to start downloading from a specific segment X you know.Also not for youtube-dl.

Direct questions now: Are there any ffmpeg commandline arguments I could use for that?

Example: The video has a lenght of 10 minutes and is splitet into 100 numbered segments starting from 001-100.Now I wanna tell ffmpeg to download all segments if possible into folder XY and if the download dosent success because of error 403 ffmpeg should stop to resume the download.Lets say I have now segment 001-050 then I need to download the rest segments 051-100 in a second round.How to tell ffmpeg to do this?

Also the same question I have using youtube-dl.WIth this it would be easier so I dont need to use extra cookie header but I also found no commandline how to tell youtube-dl to download segment X-Y.Only found commandline --keep-fragments but this dosent help in this case.

Maybe anyone of you does know how to handle this situation and the right commandline arguments for ffmpeg & or youtube-dl.

Thank you

Share this post


Link to post
LCF-AT

Hi again,

I found command for FFmpeg called...

-protocol_whitelist "file,http,https,tcp,tls,crypto"

..I can use to read a modded playlist from local file.I did download the original playlist where I can see all 100 segments short paths.I did modded the list and created 2 new playlist with full URL paths to segment files.First playlist I just keep segment paths from 001-050 and in the second playlist I just keep 051-100.Ok.The main problem now is that FFmpeg dosent use the cookie header I did set in commandline and I get error 403 again.

All in all it dosent seems to work what I wanna do with ffmpeg or youtube-dl.Only thing I could do is to download all segments by myself and join them if I have them all together.

greetz

Share this post


Link to post
身勝手のごくい
Posted (edited)

Hello fella,

to kick things let me say a big thanks for your tool, i've used it few times but it has some issues(?).

I've used it to download a YT live while it was still playing, first time worked perfectly and it didnt gave me problems when the live got copyrighted(from music) it kept download the rest of it.
Video was complete and everything was good.

Second time i tried using it w/o closing the same app instance as before it wasnt sending any network packet, like it had unclosed connection from first time and no error handling?resulting to "select with timeout Error time limit expired!"<gif attached>

Gave it another chance and tried do the same thing, download a live YT stream which possibly would get copyrighted, the video didnt got any copyright but the download finished 6-8 hours later(i got terrible internet but not that much).
Trying again the exact same thing, monitoring the network and the filesize, ffmpeg had 2.4gb of network total receive while the filesize was ~300mb(weird) which i interuptted downloading.
By opening this video with different media players, none of them could start rendering anything and i wanted to use that ~300mb part since eventually got copyrighted.


about ur questions:
Part 2 audio and video are they the same time?Have u tried to extract audio and video in case they are unsync? Did u try to merge these 2 parts and see if the output works?
i would: copy /b 001-050.mp4 + 051-100.mp4 output.mp4(u can merge as much segments u want) and check or/and u can try this "kernel video repair" which seemed to created an output(not sure if worked) for one corrupted downloads of mine, unfortunately they ask for license even to try it so... "module": "licenseactivation.dll" <they load it dynamically on activation> "address": "0x38B4" i think is the last part u will look at(dont know if i can share such infos public here).

To get the total video length and use it with -ss u have to use either API for browserless option OR javascript OR have a server which will do that for the ffmpeg user afik.
Then you can download it in parts as 001-002 for the time u want and merge them later BUT the problem of using the YT API is that it doesnt split permissions, what i mean its 1 auth to retrieve the information and manage the full channel with uploads and downloads.

There was a service that got shutdown which was giving the time of videos and the oembed from yt doesnt return times(ex: https://www.youtube.com/oembed?url=YOUR_YT_LINK&format=json)


Hopefully i understood correctly and since youtube-dl works fine with non-live my blind guess is u ask for YT LIVES but even if not, someone else might find that information useful.
About the 403 and the cookie i have no clue, sorry.

this message became like an essay wow cheers

 

Spoiler

ffmpeg.gif

 

Edited by 身勝手のごくい (see edit history)
  • Like 1

Share this post


Link to post
LCF-AT

Hi,

so in my tool I did set a default timeout of 5 seconds to wait for an answer of the server / Url you do request.I thought 5 seconds would be enough to wait for and aboard then the request.Just added this option to prevent hanging loop ony any request etc.So you can also patch this value if you wanna try it.Just search for the connect functions in Olly and right above this function you can see a mov command putting value 5 into.This you can change to a higher value to wait some more seconds

So the video I wanna download is first a video (vod) no live stream.The problem is as I said before the cookie I need to use which gets expired after few minutes.If the download of this video does take to long (need more time as the cookie is valid) using YT-DL or FFmpeg then both tools do fail with http response error 403 (forbidden).So I only have a small time window what does allow me to access the video / playlist.Thats the main problem and I need to refresh the cookie/s.If the video is to large and or download speed access to the server is to low then I cant download the video at once.I also found no way / method / commandline arguments yet to tell FFmpeg or YT-DL to autorefresh the cookie and now I am looking for a method to download the video completely in seperated parts without any issues.

There is no commandline (or found not yet) to specify the .ts segments range to download of a playlist.Only command I found are to set the timestamp using -ss & -t or -to to set the timestamp/s only what is unfortunately not very good so I dont get the excat frames matching and get some frames missing or too much if I donwload some parts.It would be much better to have a commandline to specify the segment parts / range itself to download like this...

ffmpeg -segment_range 0:30

....0:30 = download first segment till segment 30 complete and then stop.

ffmpeg -segment_range 31:60

...30:60 = download segment 31 till segement 60 complete and then stop etc.

"Downloaded 2 files.Each file has 30 complete segments inside like I would download them one by one = 100 % match.Now I just need to merge  both files = done."

In this case the user could download whole segments of a playlist without to use / set / care about any timestamps using -ss commandline what makes problems as I told before and the video dosent get downloaded 1:1 if the timestamp starts / ends I did set into a segment file (keyframe issues) so it cant cut it right if I use the copy mode and I dont wanna re-encode the video you know.If I download all segments by itself manually then I got them all original and  just need to merge them togehter = 1:1 video but using timestamps its not doable.

Of course I did play around with FFmpeg using diffrent comandline lines to get some more or less good results but not perfect.Main goal for me is it to download the video for 100 % perfectly 1:1 with no overlapping or missing frames inside.Thats the tricky part now.Normaly no problem to do that with FFmpeg at once but in this case its not so easy if you need to refresh the cookies.

All in all I dont get work using FFmpeg to get the video 1:1.As I said,missing frames or overlapping of time etc.For example.Below a playlist example link to a video (not using cookies in this case) you can test / play with FFmpeg and commandline args xy and now try to download some segemnts using -ss timestamp -to timestamp commandlines like just few seconds.After this check the small file/s you did download with FFmpeg and load it into VirtualDub for example to see all frames and time / lenght of this part/s.

https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/index_776000_av.m3u8

I tried something like this...

ffmpeg -ss 00:00:01.000 -to 00:00:10.000 -accurate_seek -seek_timestamp 1 -i "https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/index_776000_av.m3u8" -c copy "Output.ts"

..as result I get a file what has a lenght of 8 seconds and 200 frames.Missing 1 second so it should be 9 seconds.If I do set a starttime of second 2 instead of 1 then I get a 8 seconds file = right.If I set a timecode start of only 0 I also get 8 seconds out and missing frames from the beginning of the video.If I only set this commandline..

-ss 00:00:00 -to 00:00:10

...then I get a video lenght of Frame 253 (0:00:10.120) = 120ms to large or 3 frames to much.Thats the bad thing using timestamps so somehow you dont get it really exact out and my thought to download segment ranges instead would be better but dont found any CL for this yet if there are any CL for it in FFmpeg.

The playlist inside with the ts files looks like this...

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10.000,
https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/segment1_776000_av.ts?null=0
#EXTINF:10.000,
https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/segment2_776000_av.ts?null=0
#EXTINF:10.000,
https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/segment3_776000_av.ts?null=0
#EXTINF:10.000,
https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/segment4_776000_av.ts?null=0
.........
#EXTINF:10.000,
https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/segment268_776000_av.ts?null=0
#EXTINF:3.440,
https://zdfvodde-vh.akamaihd.net/i/meta-files/zdf/smil/m3u8/300/16/11/161124_subwaylfalle_inf/6/161124_subwaylfalle_inf.smil/segment269_776000_av.ts?null=0
#EXT-X-ENDLIST

...the video has 269 segments.All segments having a lenght of 10 seconds except the last segment has a lenght of 3.44.So it seems to work if I use exact timestamps like this...

-to 00:00:10 -accurate_seek -seek_timestamp 1
-ss 00:00:10 -to 00:00:20 -accurate_seek -seek_timestamp 1
-ss 00:00:20 -to 00:00:30 -accurate_seek -seek_timestamp 1

....here I get 3 parts exactly right.But what is if the EXTINF lenght for each segments are diffrent and not mostly same = problem.Some are starting with unround lenght = need to do calc process etc.In  this case like that it would be easier to have any commandline to set ranges only as I said above to prevent to calc out some timestamps in the hope you do it right and get it out right too at the end you know.I dont know whether there are any commandline args for FFmepg or YT-DL to manage this so maybe anyone does know it and could post some infos / hints about that.

greetz

  • Thanks 1

Share this post


Link to post
LCF-AT

Hi guys,

I have a new small question.Lately I made some ffmpeg records from diffrent stream sites only using copy mode of ffmpeg + mp4 container format (extension) for video & audio.I found out that in some cases the records are broken.Thats pretty bad but I also dont know the reason why ffmpeg does produce such broken files.The problem is also that I cant read that created file with any video tool or ffmpeg itself and I only get the message "Invalid data found when processing input".What to do in this case?Is there any method to fix such broken files anyhow?The other question is how to prevent such broken files using ffmpeg?

What could be the problem?Is it that I am using only the copy mode of ffmpeg?Should I better use a video codec format instead?Or does it play a role how to quit the record in CMD window pressing the exit button of CMD window or using better strg+c?So as I said I am not sure what the problem can be for this broken records but I would like to prevent this and using a method I can trust for 100% using ffmpeg to be sure to got the record fine and working you know.Dont wanna get surprised after recording of some minutes that the record is broken again.Maybe anyone has some hints about that and how to prevent it with ffmpeg.

greetz

Share this post


Link to post
LCF-AT

Hi,

I still found no method or tool how to fix such broken mp4 records.The tools I found arent working = can forget that.Also using ffmpeg commands faststart is not working for such files but I found something else to maybe prevent such broken mp4 records.If I am using the command -movflags faststart on recording then it does add some extra moov atom at the top of the mp4 file header.I made some test records to see the diffrent in Hex editor and there are.The good thing is that I now also can cut parts away from the record at the end for example (some MB) and save it as new file.Now the file is still working (handable and no more invalid) and I can play / edit it etc and exactly this wasnt possible without using this command -movflags faststart for normal copy records.So those files are no more working if I cut something out.That seems to be the good news about it.I will test go on to see whether it keeps working like that.Just wonder why ffmpeg dosent add this command function already by itself.Anyway.

greetz

Share this post


Link to post
LCF-AT

Hi again,

ok,its still not working also with using the new command -movflags faststart in ffmpeg.Seems to be a ffmpeg bug (I am using 4.0.1).I made some diffrent test records just using copy mode.

Example:

ffmpeg -i "TVchannel.m3u8" -c copy -movflags faststart record.mp4

Some  recorded files was working and some not.Now if I check the header of working and not working records in Hex editor then I see the diffrents.In the working files ffmpeg did wrote a extra meta data header at the top of the video and in the not working files is this extra header missing.Look...below a pic of the header of a normal copy mode record which has a lenght of 30 hex bytes.

T.png.5c8128209e6daaf880cbe9913d515a40.png

Now when I am using -c copy -movflags faststart then ffmpeg does add a long header...

T2.png.94b96b481ee3fc75200f9dd437d6edcb.png

....but in my broken record files which I cant play / edit or do anything with them because of invalid data message by ffmpeg was this long header not added.This I dont understand why ffmpeg does it not always add if I am using this faststart command you know.Its again anyhow randomly.Sometimes yes sometimes no.This really sucks.

Anyhow its seems to be that there is no 100% working method to record a file in copy mode with ffmpeg.I also dont see any info on starting a record in ffmpeg cmd window whether all is fine or not with this record process and I can just check or see it if I finish the record.That totally bad.

All what I can do is using the mpegts format instead of mp4 like this...

ffmpeg -i "TVchannel.m3u8" -c copy -f mpegts record.mp4
or
ffmpeg -i "TVchannel.m3u8" -c copy record.ts

....so with this I can check whether the record is working (windows does show a video image thumb on fly) and I can also play the video in VLC player during a record just to verify whether something gets also recorded.

Anyway,so normaly I would use the mp4 container from the beginning without to set it extra after the record you know.So if anyone has some another ideas for this problem then feedbacks are welcome.

greetz

Share this post


Link to post
LCF-AT

Hi guys,

ok,it seems to work using mpegts format container instead of mp4 to prevent fail records.I also made again some test records using mp4 C-Format and I did lock the internet for few seconds during recording and unlocked it again.The results are broken / damage and not usable mp4 records I can  throw into trashcan.This dosent happens using mpegts instead and I can still edit / play etc this record.Good so far.Only disadvantage is that the ts files having very less keyframes what makes seeking of such files in player very slow.Anyway,seems there isnt any 100% solution for that task to record in ts format and change it to mp4 after recording on fly.Only can do this manually.

Example method I am using now...

ffmpeg -i "TVchannel_720.m3u8" -c copy -f mpegts output.mp4

ffmpeg -i output.mp4 -c copy output_b.mp4

...new file = mp4 container.Much keyframes and good play / edit / seekable.Little detour but anyway.I just can do this step via drag & drop.

greetz

Share this post


Link to post
LCF-AT

Hi again,

I have another ffmpeg question about HLS streams using AES 128 key URL in playlists.Normaly ffmpeg can handle this by itself if the key URL dosent need extra request paramters or if the URL is dynamic or just valid for a very small moment.Now I found a TV channel what used such key URL and I didnt got it working yet only using extra request paramters and get response 403.Also if I request the URL in browser a second time very quick.Now I checked the key which used and its the same one.

The question I have is whether there is any ffmpeg command to set the decryption key and using it and to pass the AES key URL in the playlist.I see diffrent commands but only for creating own playlists etc.

Example what I mean....

ffmpeg -i "https://TVchannel.m3u8" -c copy -keyfile.txt output.ts

...keyfile.txt are the bytes into what ffmpeg should use to decrypt the ts segments and not accessing the AES key URL anymore.Some command to tell ffmpeg just using my keyfile you know.In the past I modded such playlist for VOD streams what also works but its extra work always to change such playlists.For LIVE streams its bad of course.So I thought that in the meantime the ffmpeg guys did add any new commands for that to point directly to an own keyfile but didnt found any command for this yet (also dont wanna do that playlist modding anymore).So does anyone know more about new or any commands I can use for this task maybe?

Something like the...

  -hls_enc_key_url   <string>     E........ url to access the key to decrypt the segments

...command.

greetz

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...