snobu / destreamer

Save Microsoft Stream videos for offline enjoyment.
MIT License
2.36k stars 441 forks source link

FFmpeg returned an error: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument #292

Closed pistachoo closed 3 years ago

pistachoo commented 3 years ago

OS: 10.15.7 Catalina (MacOS)

Launch command used: ./destreamer.sh -i "https://web.microsoftstream.com/video/VIDEO-1"

I am an elementary school teacher with enough tech savvy to follow instructions and copy-paste things into Terminal. (lol)

I'm trying to download a large (3h30m) video from MS Stream that our district shared for our last Pro-D day: I showed part of it (1h30m) to my class and a student has asked if I could post it in Teams. I only want to post the relevant section, and I thought finding a way to download it would be quicker than screen recording it... ha!

I got as far as reinstalling a newer version of ffmpeg but I don't know what to do with this latest error. I searched previous issues and found the same error code in a closed/resolved issue but it was for Linux, not Mac. So now I am stuck.

Hoping there is an easy fix so I don't have to screen record a 1h30m video this weekend!

Here's what I get when I try to download the video:

Downloading Video: Indigenous Education Focus Day Nov 27th

Spawning ffmpeg with access token and HLS URL. This may take a few seconds...

Then it shows me a pixely image of the video's title image, and then

progress [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 0 0s

[ERROR] FFmpeg returned an error: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

[FATAL ERROR] Unknown FFmpeg error

I don't know where to go from here.

Verbose log ``` PASTE VERBOSE LOG HERE ```
lukaarma commented 3 years ago

FFmpeg seem to be complaining about a codec error.. So you could try again (maybe even with a different output folder) and if the error happens again you could try to append --vcodec libx264 --acodec aac to your launch command to force a re encoding of the video (it will be slower but could possibly solve the issue)

PS: If the error happens again please run it with --verbose appended and paste here the output

snobu commented 3 years ago

For MacOS use the ffmpeg binary from brew (brew install ffmpeg), that has a much higher chance of working than cherry-picking binaries off the web.

pistachoo commented 3 years ago

snobu: Yes, I did use brew to install ffmpeg.

lukaarma: I will try that.

pistachoo commented 3 years ago

It didn't work.


./destreamer.sh -i "https://web.microsoftstream.com/video/98f45008-0c47-4307-8913-799eb213c2b2" --vcodec libx264 --acodec aac --verbose

[VERBOSE] Using ffmpeg version 2.8.1 Copyright (c) 2000-2015 the FFmpeg developers

Access token still good for 59 minutes.

[VERBOSE] Session and API info 
     API Gateway URL: https://cact-1.api.microsoftstream.com/api/
     API Gateway version: 1.4-private

Parsing video/group urls

[VERBOSE] List of GUIDs and corresponding output directory 
    https://web.microsoftstream.com/video/98f45008-0c47-4307-8913-799eb213c2b2 => videos 

Fetching videos info... 

Downloading Video: Indigenous Education Focus Day Nov 27th 

[VERBOSE] Extra video info 
     Video m3u8 playlist URL: https://cact-1.api.microsoftstream.com/api/videos/manifest?api-version=1.0&playbackurl=https://streamcact1su021.azureedge.net//2f3a7d4d-55ca-4c6d-84fc-a3e57e1a5851/1-h5m3zx6bnexf3aatbdvkw5z4md.ism/manifest(format=m3u8-aapl)
     Video tumbnail URL: https://cact-1-content.api.microsoftstream.com/api/thumbnails/2/d484f1cc-e62b-4b62-b86f-76b88d5960d3/MS1oNW0zeng2Ym5leGYzYWF0YmR2a3c1ejRtZF8xXzMyMHgxODAucG5n?validTill=2020-12-15T00%3a00%3a00.0000000Z&aadUserOId=f4f421e7-efd2-4f06-a807-78e3e78b21db&encoding=base64&api-version=1.4-private&signature=XCnD9QbSH1bif8LphO7KtroPHhFCHGS6HECLOnoGCZU%3d
     Video subtitle URL (may not exist): undefined
     Video total chunks: 207.33333333333334

Spawning ffmpeg with access token and HLS URL. This may take a few seconds...

progress [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 0 0s

[ERROR] FFmpeg returned an error: [aac @ 0x7f8eb1041800] Alternatively use the non experimental encoder 'libvo_aacenc'.

[FATAL ERROR] Unknown FFmpeg error 
lukaarma commented 3 years ago

Ffmpeg really doesn't like that video... I couldn't find much online about that error you got.. you could try again the same command removing --acoded aac and see what happens Or you could try the new faster branch that you can find here, you just need to download and install aria2c then the process is the same as using master: npm i; npm run build and the your command

pistachoo commented 3 years ago

Trying the same command without the --acoded aac didn't work either.

The second suggestion (new faster branch) is one I will have to learn how to do... I'll try to figure that one out tomorrow. :)



[VERBOSE] Using ffmpeg version 2.8.1 Copyright (c) 2000-2015 the FFmpeg developers

[WARNING] Access token has expired! 

Launching headless Chrome to perform the OpenID Connect dance...
Navigating to login page...
We are logged in.
Wrote access token to token cache.
At this point Chromium's job is done, shutting it down...

[VERBOSE] Session and API info 
     API Gateway URL: https://cact-1.api.microsoftstream.com/api/
     API Gateway version: 1.4-private

Parsing video/group urls

[VERBOSE] List of GUIDs and corresponding output directory 
    https://web.microsoftstream.com/video/98f45008-0c47-4307-8913-799eb213c2b2 => videos 

Fetching videos info... 

Fresh access token dropped into .token_cachen 

Downloading Video: Indigenous Education Focus Day Nov 27th 

[VERBOSE] Extra video info 
     Video m3u8 playlist URL: https://cact-1.api.microsoftstream.com/api/videos/manifest?api-version=1.0&playbackurl=https://streamcact1su021.azureedge.net//2f3a7d4d-55ca-4c6d-84fc-a3e57e1a5851/1-h5m3zx6bnexf3aatbdvkw5z4md.ism/manifest(format=m3u8-aapl)
     Video tumbnail URL: https://cact-1-content.api.microsoftstream.com/api/thumbnails/2/d484f1cc-e62b-4b62-b86f-76b88d5960d3/MS1oNW0zeng2Ym5leGYzYWF0YmR2a3c1ejRtZF8xXzMyMHgxODAucG5n?validTill=2020-12-15T00%3a00%3a00.0000000Z&aadUserOId=f4f421e7-efd2-4f06-a807-78e3e78b21db&encoding=base64&api-version=1.4-private&signature=XCnD9QbSH1bif8LphO7KtroPHhFCHGS6HECLOnoGCZU%3d
     Video subtitle URL (may not exist): undefined
     Video total chunks: 207.33333333333334

Spawning ffmpeg with access token and HLS URL. This may take a few seconds...

progress [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 0 0s

[ERROR] FFmpeg returned an error: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

[FATAL ERROR] Unknown FFmpeg error 
lukaarma commented 3 years ago

For the new branch it's same same as the one you are using now but you need aria2c installed on your PC and either on PATH or in Destreamer root folder

snobu commented 3 years ago

@pistachoo, looking at your verbose output, i see you're running a ffmpeg binary from 2015. That's not going to work for destreamer.

[VERBOSE] Using ffmpeg version 2.8.1 Copyright (c) 2000-2015 the FFmpeg developers

Not sure how you ended up with that from brew, so maybe remove it and just download a fresh binary somewhere in your $PATH or tinker with your brew installation to get you the current ffmpeg version (4.3.1).

You can find static ffmpeg MacOS binaries here - https://evermeet.cx/ffmpeg/

snobu commented 3 years ago

@lukaarma We should probably warn for aged ffmpeg binaries since it seems this is a common pitfall. Tracking here https://github.com/snobu/destreamer/issues/294

lukaarma commented 3 years ago

@pistachoo, looking at your verbose output, i see you're running a ffmpeg binary from 2015. That's not going to work for destreamer.

Nice catch!

@lukaarma We should probably warn for aged ffmpeg binaries since it seems this is a common pitfall. Tracking here #294

Further discussion moving there

pistachoo commented 3 years ago

Ok, how do I replace ffmpeg the ancient? Because I did run brew install ffmpeg so I thought I had the most recent one.

pistachoo commented 3 years ago

Alright, I went down the rabbit hole trying to figure out what bits to copy-paste into Terminal ;) and have successfully reinstalled homebrew and ffmpeg 4.3.1 – yay!

Am now running ./destreamer.sh -i "https://web.microsoftstream.com/video/98f45008-0c47-4307-8913-799eb213c2b2" --vcodec libx264 --acodec aac --verbose again, and this time the progress bar is moving. Fingers crossed it works! (It's a looooong video, so I assume it'll take a while)

pistachoo commented 3 years ago

It worked! (took until 2 a.m. apparently) Thanks for the help everyone!