I've got a problem with streaming audio on my website. I thought I could put the MP3 file inside an MP4 container with h264 codec, so I can use pseudo-streaming ability of mp4 codec.
The code I'm using to convert my files is:
ffmpeg -i 1.mp3 -y -b:a 32K -vn 1.mp4
Pseudo-streaming (seeking in not-loaded parts of media) now works in HTML5 player but not in any Flash media players such as JWPlayer or FlowPlayer.
I've tested my files on both Apache server with h264 module enabled and Nginx with mod_mp4 enabled, but without any lucks.
I tried MP4Box, QTIndexSwapper and even creating a real video file by mixing of an image loop and my audio file.
ffmpeg -y -i joojoo.png -i 2.mp3 -vcodec mjpeg havij.mp4
MP4Box -add havij.mp4 -isma havij_new.mp4
What am I doing wrong? What can I do to make it work?
You have to hint the file. Check out mp4box -hint
Related
I am attempting to generate an MP4 video by combining images and audio with FFmpeg-Kit-React-Native but it is not being displayed in web browsers.
For your reference I'm attaching the package link below:
ffmpeg-kit-react-native
The commands I utilized to produce the video are as follows:
-i ${imageFile} -i ${audioFile?.uri} -vf scale=480:360 -f mp4 ${outputFile}
-loop 1 -i ${imageFile} -i ${audioFile.uri} -shortest -acodec copy ${outputFile}
-i ${imageFile} -i ${audioFile?.uri} -b:v 2M -vf scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1 -pix_fmt yuv420p ${outputFile}
-i ${imageFile} -i ${audioFile?.uri} -vf scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1 -f mp4 ${outputFile}
I have attached a link to the video I generated using a single image and one audio file
Additionally, I am unable to install external encoding packages such as full-gpl, full, https-gpl, and min-gpl on the Android side.
You do not specify a video codec for your format (-f mp4). In that case ffmpeg uses 'a' default video codec. If i run ffprobe on your file, the output for the video stream is:
Video: mpeg4 (Simple Profile)
According to https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers#mpeg-4_mp4, firefox does not support this codec (as to the other browsers, please do your own research).
The solution is to use one of the supported video codecs, e.g. AVC (H.264) or VP9.
To specify the H.264 codec in ffmpeg use the argument -codec:v libx264.
To list all available encoders, run: ffmpeg -encoders
If the required codecs are not listed in the output, you have to configure ffmpeg and specify, e.g. --enable libx264.
See also: FFmpeg - H.264 Video Encoding Guide
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
I loop over some files and convert them with ffmpeg. I provide -vcodec h264. When the input video already is encoded with that codec: will the video stream be copied? How to make sure it's not reencoded in that case? Is it what -sameq was used previously?
You need to use -c:v copy if you want the raw H.264 stream to be passed on without re-encoding:
ffmpeg -i myh264file.mp4 -c:v copy -c:a copy myh264output.mp4
-c:a copy will also copy the audio
-c copy will copy both audio and video as in:
ffmpeg -i myh264file.mp4 -c copy myh264output.mp4
Detecting H.264 streams is not straight forward. You will need to code this.
For the -sameq settings please refer to this statement.
I would recommend upgrading to a recent version of ffmpeg if it is not already done as -vcodec is not used anymore, now it is -c:v.
The documentation on ffmpeg could help you.
i want convert video from any format to mp4. so i am using command:
ffmpeg -i ttt.mp4 -vcodec copy -acodec copy test.mp4
this is working perftectly but now i also add scale in this -s 320:240.
There also many other command for convert LIKE :
ffmpeg -i inputfile.avi -s 320x240 outputfile.avi
but after convert by this command video not play in html5 player
BUT this is not working so tell me in my command how i add scale;
So please provide me solution for this .
Thanks in advance.
You have several problems:
In your command, you have -vcodec copy you cannot scale video without reencoding.
In the command you randomly found on the Internet, they are using AVI, which is not HTML5-compatible.
What you should do is:
ffmpeg -i INPUT -s 320x240 -acodec copy OUT.mp4
Adding to Timothy_G:
Video copy will ignore the video filter chain of ffmpeg, so no scaling is available (man ffmpeg is a great source of information that you will not find on Google). Notice that once you start decoding-filtering-encoding (i.e., no copy) the process will be much slower (x100 time slower or even more). The libx264 is recommended if you want compatibility with all browsers.
$ ffmpeg -i INPUT -s 320x240 -threads 4 -c:a copy -c:v libx264 OUT.mp4
vp9 will provide nearly 50% extra bandwidth saving, but only for supported browsers (Firefox/Chrome), and the encoding will much slower compared to libx264 (that itself is much slower that v:c copy):
$ ffmpeg -i INPUT -s 320x240 -c:a copy -c:v vp9 OUT.webm
Notice that there is a set of formats (containers) accepted by browsers (most admit mp4, some also webm, ...) and for each format there is a set of audio/video codecs accepted. For example you can use mp3 or aac with an mp4 file (container), but not with webm files.
http://en.wikipedia.org/wiki/HTML5_video#Supported_video_formats
I'm trying to stream a .ts file containing H.264 and AAC as an RTP stream to an Android device.
I tried:
.\ffmpeg -fflags +genpts -re -i 1.ts -vcodec copy -an -f rtp rtp://127.0.0.1:10
000 -vn -acodec copy -f rtp rtp://127.0.0.1:20000 -newaudio
FFMPEG displays what should be in your SDP file and I copied this into an SDP file and tried playing from VLC and FFPLAY. VLC plays audio but just gives errors re: bad NAL unit types for video. FFPLAY doesn't play anything.
My best guess if that the FFMPEG H.264 RTP implementation is broken or at least it doesn't work in video passthru mode (i.e. using the -vcodec copy).
I need a fix for FFMPEG or an alternate simple open-source solution. I don't want to install FFMPEG in my Android client.
thanks.
Have you tried vlc?I once used vlc for streaming. You can have a look at here.