Create a .m4s file with ffmpeg - encoding

I'm rying to create .m4s files and I'm using this command with ffmpeg: ffmpeg -i input.mov -c:v copy output.m4s
The file can't be created.
Output: Unable to find a suitable output format for tempM4S.m4s tempM4S.m4s: Invalid argument
I'm guessing the file format .m4s is not supported by ffmpeg which is strange because ffmpeg can create .m4s files when trying to create segments for MPEG-DASH. Is there a workaround this problem? WIll I have to use other tools or check ffmpeg's source code for hints?

m4s files do not work by themselves as they do not contain a moov box required for playback. They require an initialization fragment as well.

I am guessing you want to create m4s to include it as part of m4s series. As #szatmary mentioned, these files are not independent. So you can try this:
Merge the m4s files to one mov file.
Merge your mov file with the step 1 output file.
Split again the output file of step 2 to m4s files.

Here's how I achieved this. My use case is an audio-only stream. The backend service ships MPEG-DASH files to static hosting. I upload the initializing .mp4 segment once, subsequently only uploading each new .m4s segment.
Also, the playlist .mpd is updated every segment, in order to tell a newly arriving listener where to begin playback. The listener will pick up an initializing .mp4 file for the desired bitrate, followed by the current and following .m4s segments.
My source material is a series of 10-second media segments in uncompressed .wav format.
I'll run ffmpeg once per each new media segment
I've specified a segment size of 11 seconds, to ensure that ffmpeg generates exactly 1 output .m4s segment for each source media segment.
ffmpeg \
-i pelicans-1234.wav \
-f hls \
-ac 2 \
-c:a aac \
-b:a 128k \
-minrate 128k \
-maxrate 128k \
-start_number 1234 \
-hls_fmp4_init_filename pelicans-128k-IS.mp4 \
-hls_segment_filename pelicans-128k-%d.m4s \
-hls_segment_type fmp4 \
-hls_time 11 \
temp.m3u8

Related

FFMPEG Streaming updated image in loop to FB Live Video

I am trying to stream image to fb live video using this command :
ffmpeg -loop 1 -re -i "input.jpg" -pix_fmt yuv420p -profile:v baseline -s 720x480 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -t 60 -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv "rtmp_link"
This command works perfectly for one single input file. But the problem is that I want ffmpeg to stream the latest and updated version of "input.jpg" file because my app is updating this "input.jpg" after every 2-3 seconds but the image that is streamed is the older version, not the updated one.
If I try to restart this loop, then streaming stops for approx. 4-5 seconds which is sufficient enough for FB live video to consider that streaming has been stopped and it then ends the live video.
So, is it possible to use the latest available version of input file for streaming in this loop? I don't know much about FFMPEG and I tried to search this issue but all in vain.
I have finally figured out a solution for this. When I was directly overwriting ‘input.jpg’ file using my rails app, this process was taking a few miliseconds but during this time too, ffmpeg was streaming this file which was incomplete for few miliseconds.
So, the solution for this issue is that first write the updated image to a temp file like ‘input.tmp.img’ and then move this file to the original file using script or using terminal like
mv input.tmp.img input.jpg
As moving process hardly takes any time, this solved the problem for me.

How to extract the bitstream from H.264 video?

I have a H.264 video and I want to extract the bitstream from it. In other words, I need to know the stream after encoding a video via H.264 standard. I am going to use the extracted stream in Matlab. How can I do this (extract the bitstream)? Is it possible to use ffmpeg?if so what is the command.
You can do this using
ffmpeg -i in.mp4 -c copy -f h264 stream.264
Depending on what MATLAB expects, you may need to add a bitstream filter
ffmpeg -i in.mp4 -c copy -f h264 -vbsf h264_mp4toannexb stream.264

FFMPEG corrupting audio data when trying to edit metadata

I'm trying to use FFMPEG to edit some metadata in Powershell. My problem is that FFMPEG simply outputs an audio file with the correct metadata, but the audio does not play. The length of the track is reduced to a fraction of a second. Here is the command I'm using in Powershell:
& $ffmpeg -y -i $flac.fullname -c copy -metadata track="$tracknumber" $flac.fullname
Previously, I tried having -map 0:0 in there too, but it didn't make a difference. Thanks for any help.
Edit: I'm not sure if this is intentional behavior or not, but if I change the output path to be a new destination (rather than saving over the old destination) it does work correctly. So as a workaround, I'm just using a temp folder as an output then moving the files back to where I want them.
FFmpeg does NOT do in-place editing. Destination has to be a new file.
ffmpeg -y -i file.flac -c copy -metadata track="$tracknumber" newfile.flac

Trim mp4 files without encoding it again

I have a .mp4 video file, I need to trim it, however no matter how I do it, trimmed video is being encoded again which results in noisy video.
What I've tried:
Open video with Matlab, read frames and write only the frames that I want to have in trimmed video, I use 'MPEG-4' option.
Trim video using Windows Movie Maker.
Trim video using VirtualDub.
In first 2 scenarios original mp4 movie is encoded again after trimming it. I couldn't get mp4 files open in VirtualDub.
So what would be the easiest way to trim a video without re-encdong it?
You can do the split and re-encode in one command.
Create a text file, list.txt,
like this
file 'in.mp4'
inpoint 48.101
outpoint 67.459
file 'in.mp4'
inpoint 76.178
outpoint 86.399
file 'in.mp4'
inpoint 112.140
outpoint 125.031
then run,
ffmpeg -f concat -i list.txt -an -crf 18 out_merged.mp4
I've solved it with the following commands:
ffmpeg.exe -ss 48.101 -t 19.358 -i in.mp4 -an out_part1.mp4
ffmpeg.exe -ss 76.178 -t 10.221 -i in.mp4 -an out_part2.mp4
ffmpeg.exe -ss 112.140 -t 12.891 -i in.mp4 -an out_part3.mp4
ffmpeg -i out_part1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt1.ts
ffmpeg -i out_part2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt2.ts
ffmpeg -i out_part3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt3.ts
ffmpeg -i "concat:intrmdt1.ts|intrmdt2.ts|intrmdt3.ts" -c copy out_merged.mp4
And some explanation:
Giving -ss (start time) and -t (duration) options before -i (input) option avoids unnecessary decoding.
Not using -c copy provides transcoding hence result more precise cut (got this from here).
I used -an because I didn't need the audio, if you need audio just omit this option.
Before concatenating the resulting trimmed videos I needed to transcode them to mpeg transport streams, to achieve lossless concatenation (for more details you can see this link).

copying several segments of the same video avconv

I am trying to copy several segments of one video file to a single output video file
I can do it for one segment only by using the following code:
avconv -i input.flv -ss 00:04:50 -t 00:04:00 -codec copy outputfile.flv
Is there any way to do it with several segments?