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

ffmpeg merging of stream tracks does not behave has expected when first stream has both audio & video tracks. #3935

Closed
WCVanHorne opened this issue Oct 12, 2014 · 5 comments

Comments

@WCVanHorne
Copy link

@WCVanHorne WCVanHorne commented Oct 12, 2014

It is an excellent feature to integrate ffmpeg muxing/merging (actually technically copying I guess) of audio and video tracks from separate streams. Really a necessity in the DASH era. However, not knowing the exact syntax being passed to ffmpeg, there seem to be certain assumptions made as the the track content when asking for "-f video+audio" to merge streams. This results in unexpected behavior.

Specifically if the first stream you want the video from has an audio track as well, the second stream's audio track is not copied in. E.G. "-f 22+141" does not result in the audio track being replaced in 22.

Curiously the hack of swapping to "-f audio+video" works, albeit with the side effect of naming the output with a .m4a extension. E.G. "-f 141+22" replaces the audio track in 22 with 141.

Of note is that the existing command does work properly if the second stream has both audio and video track. I.E. it copies in the audio only from the second stream and uses the video from the first. E.G. "-f 137+22" works as expected.

It seems that a more robust command syntax needs to be passed to ffmpeg to allow for mixed tracks on both the audio and video source and at least grab the first one of each when merging.

E.G.

ffmpeg -i "[Video Source File]" -i "[Audio Source File]" -c copy -map 1:v:0 -map 0:a:0 -shortest "[Output A/V File]"

I might also suggest the "-shortest" flag be used but that's possibly moot given the infinitesimal savings unless it occasionally prevents some odd audio or video overhang artifacts at the end.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Oct 12, 2014

Just for reference, you'll get the command line used for ffmpeg if you add the --vebose option:

$ youtube-dl -f bestvideo+bestaudio test:youtube -o 'example.%(ext)s' --verbose
...
[ffmpeg] Merging formats into "example.mp4"
[debug] ffmpeg command line: ffmpeg -y -i example.f137.mp4 -i example.f140.m4a -c copy example.mp4
@WCVanHorne
Copy link
Author

@WCVanHorne WCVanHorne commented Oct 12, 2014

Excellent. Well I'd then suggest that after "-c copy" the following be added:

-map 1:v:0 -map 0:a:0 -shortest

I'd take a crack at it myself but after having a peek at the code it seems some dev more familiar with the modular structure should drop it in. Assuming of course this is deemed "a good idea" (tm).

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Oct 12, 2014

Since we have usually told users to use -f bestvideo+bestaudio, shouldn't it be -map 0:v:0 -map 1:a:0 -shortest?

@WCVanHorne
Copy link
Author

@WCVanHorne WCVanHorne commented Oct 12, 2014

Whoops!! Reversed the order for legibility but of course forgot to switch the 0 & 1 which is what ffmpeg really cares about.

I.E. you are correct:

-map 0:v:0 -map 1:a:0 -shortest
@phihag
Copy link
Contributor

@phihag phihag commented Oct 13, 2014

Thank you for the report. Type youtube-dl -U to update to youtube-dl 2014.10.13 where this should be fixed.

By the way, if you want to post code here in the issue tracker, enclose the code in single backticks, as in

`foo bar`

or use fenced code blocks.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.