ffmpeg Produces unplayable MP4 File From avi files - macos

A have a hand full of .avi files which I would like to convert to .mp4. Cobbling together everything I have found on the Internet, I end up with something like this:
ffmpeg -i something.avi -c:v copy -c:a copy something.mp4
What I get is playable on VLC player, but, of course, that will play anything I through at it. However, I cannot play it using QuickLook in the Finder or with the QuickTime player.
In some cases I get video, but no sound. In some other cases I get garbled video.
I am guessing that the audio or video codec inside the .avi file is incompatible with MacOS, and that the copy instruction above is not appropriate. In that case I guess that I would actually need to reencode the audio or video.
If this sounds incoherent, I admit I know very little about video files.
What would be the best settings to try to produce an MP4 which works natively on MacOS?

"What would be the best settings to try to produce an MP4 which works natively on MacOS?"
Check this useful guide.
You can try the below command as a starting point (audio track will / should be auto-detected & converted):
ffmpeg -i something.avi -c:v libx264 -crf 22 -pix_fmt yuv420p something.mp4

Related

Ffmpeg -c copy not carrying over audio track from mkv to hls stream

I am using ffmpeg to create an hls stream. The source is an mkv with multiple audio tracks. I have tried using -map to specify the audio stream as well. I also found that when I point ffmpeg to any other audio stream in the file it works. It's just the first audio stream that does not. At one point I replaced -c copy with -acodec aac -ac 6 on the first stream and I got sound which is great but I am only looking to copy the stream and not re-encode it. The next thing I tried was using other mkv videos I have. All are reflecting the same issue. The mkv's by itself play both audio and video fine in VLC. When playing the output.m3u8 in VLC the option to choose different audio tracks is greyed out. Here is the command I'm using:
ffmpeg -i "./video.mkv" -ss 00:00:00 -t 00:00:30 -c copy -f hls "output.m3u8"
I want the audio of my hls stream to reflect that of the mkv source:
Although what I get returned from the command above gives me no sound and shows me this in mediaInfo:
I've aslo noticed that hls does not support pcm. Is it possible dash could work with this stream because it is pcm?
HLS segments can be either MPEG-TS or fragmented MP4. Neither officially support PCM audio, so you'll have to convert it.
DASH uses fragmented MP4 as segment format.

How to use ffmpeg to split an audio file into HLS-compatible chunks? (mp3 format)

I've been looking all over the web & StackOverflow, and can't get this to work. I have an audio file that I'd like to split into mp3 files and generate a corresponding m3u8 file.
I've tried this, which was the closest:
ffmpeg -i sometrack.wav -c:a libmp3lame -b:a 256k -map 0:0 -f segment -segment_time 10 -segment_list outputlist.m3u8 -segment_format mpegts 'output%03d.mp3'
But all the mp3 files are garbled when I play them.
There are two issues here. FFmpeg normally looks at the extension of the output files to determine output container. However, when the output format is forced -segment_format for segment muxer or just -f format for most others, ffmpeg will pay heed to that and no longer look at the extension. In this case, segment_format is set to mpegts so that's what the output files will be. To ensure valid mp3 files, set segment_format to mp3.
The second issue is that since the extension is mp3, my guess is that hls.js is not able to correctly determine the format of the segments, or it assumes a wrong format and tries to parse them that way. Either way, there should be some messages in the browser console to that effect. See https://github.com/video-dev/hls.js/pull/1190 for issues that hls.js has had with format probing.

Change video file container to mp4

I have learned through Google, that to change video containers without losing quality I can run the following command:
ffmpeg -i videofile.mkv -codec copy videofile.mp4
This has worked great for a number of video files I have. However, I am having an issue with three of them (1 mkv file and 2 avi files). When I run that command against them, the video is there, but there is no sound. There is sound in the original video file.
Any ideas how to put the video in a new container while retaining the audio track?
Thanks. Brian
The .mp4 container is not compatible with the audio codecs of the problem files. This should be evident from the logs. So the audio channels of the problem files have to be transcoded to something allowed in .mp4, eg. aac:
ffmpeg -i videofile.mkv -c:v copy -c:a aac videofile.mp4
Maybe the container mp4 it doesn’t compatible whith codec of your input video mkv and avi
By the way, you can try
ffmpeg -i videofile.mkv -c:v copy -c:a copy videofile.mp4
Check this documentation.
https://en.m.wikipedia.org/wiki/Comparison_of_video_codecs
https://trac.ffmpeg.org/wiki/Map

How do I set buffer for MP4 in FFmpeg?

I convert videos to MP4 for my web player. My problem is: My videos don't buffer. I have to wait until the whole video is downloaded, and after that, I can play the video.
This is my exec() command:
ffmpeg -i uploaded_files/'.$le["file"].' -vcodec libx264 -pix_fmt yuv420p flash/'.$le["file"].'.mp4
Are there any options for buffering? My MP4 size and quality is good. But without buffering, it's bad.
Is this the fault of the exec() command I use?
My videos don't buffer. I have to wait until the whole video is downloaded, and after that, I can play the video.
Use the -movflags faststart option while encoding, e.g.
ffmpeg -i input.mp4 […] -movflags faststart output.mp4
Or, alternatively, run qt-faststart on the file.
The reason the files don't stream immediately is that their MOOV atom is at the end of the file, and in order to play it, the client needs to parse this info. qt-faststart will just move that atom and your files will start playing right away.

How to transcode video formats

We're converting a bunch of .RM files to .MP4 and wondered what the best way is. Here are the details:
Convert the files to H.264.
Keep the filename but add .mp4 to the end.
Also extract a JPG image of the video at about 5 seconds in for each file and name it the original filename + .jpg.
This is on a Windows system. Is there a free tool you recommend for this? Thank you.
ffmpeg is pretty much the defacto standard app for transcoding video.
http://www.ffmpeg.org/
Convert to h264/mp4:
ffmpeg.exe -i inputFile.rm -vcodec libx264 -s 320x240 -acodec libfaac outputFile.mp4

Resources