diff --git a/minimp4.h b/minimp4.h index 1fc01d2..0c009fc 100644 --- a/minimp4.h +++ b/minimp4.h @@ -331,7 +331,7 @@ typedef struct } mp4_h26x_writer_t; int mp4_h26x_write_init(mp4_h26x_writer_t *h, MP4E_mux_t *mux, int width, int height, int is_hevc); -int mp4_h26x_write_close(mp4_h26x_writer_t *h); +void mp4_h26x_write_close(mp4_h26x_writer_t *h); int mp4_h26x_write_nal(mp4_h26x_writer_t *h, const unsigned char *nal, int length, unsigned timeStamp90kHz_next); /************************************************************************/ @@ -2198,7 +2198,7 @@ int mp4_h26x_write_init(mp4_h26x_writer_t *h, MP4E_mux_t *mux, int width, int he return MP4E_STATUS_OK; } -int mp4_h26x_write_close(mp4_h26x_writer_t *h) +void mp4_h26x_write_close(mp4_h26x_writer_t *h) { #if MINIMP4_TRANSCODE_SPS_ID h264_sps_id_patcher_t *p = &h->sps_patcher; diff --git a/minimp4_test.c b/minimp4_test.c index b7c4b01..f9629a1 100644 --- a/minimp4_test.c +++ b/minimp4_test.c @@ -107,15 +107,28 @@ int demux(uint8_t *input_buf, ssize_t input_size, FILE *fout) unsigned frame_bytes, timestamp, duration; MP4D_file_offset_t ofs = MP4D_frame_offset(&mp4, ntrack, i, &frame_bytes, ×tamp, &duration); uint8_t *mem = input_buf + ofs; - mem[0] = 0; mem[1] = 0; mem[2] = 0; mem[3] = 1; sum_duration += duration; - fwrite(mem + USE_SHORT_SYNC, 1, frame_bytes - USE_SHORT_SYNC, fout); + while (frame_bytes) + { + uint32_t size = ((uint32_t)mem[0] << 24) | ((uint32_t)mem[1] << 16) | ((uint32_t)mem[2] << 8) | mem[3]; + size += 4; + mem[0] = 0; mem[1] = 0; mem[2] = 0; mem[3] = 1; + fwrite(mem + USE_SHORT_SYNC, 1, size - USE_SHORT_SYNC, fout); + if (frame_bytes < size) + { + printf("error: demux sample failed\n"); + exit(1); + } + frame_bytes -= size; + mem += size; + } } } MP4D_close(&mp4); if (input_buf) free(input_buf); + return 0; } int main(int argc, char **argv) diff --git a/scripts/test.sh b/scripts/test.sh index 2f0d9c6..5fe9695 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,7 +4,11 @@ CUR_DIR=$(cd $(dirname ${CUR_DIR}); pwd)/$(basename ${CUR_DIR})/ pushd $CUR_DIR/.. -./minimp4_x86 vectors/foreman.264 out.mp4 +test_executable() { + +EXEC=$1 + +$EXEC vectors/foreman.264 out.mp4 if ! cmp ./out.mp4 vectors/out_ref.mp4 >/dev/null 2>&1 then echo test failed @@ -12,7 +16,7 @@ then fi rm out.mp4 -./minimp4_x86 -s vectors/foreman.264 out.mp4 +$EXEC -s vectors/foreman.264 out.mp4 if ! cmp ./out.mp4 vectors/out_sequential_ref.mp4 >/dev/null 2>&1 then echo sequential test failed @@ -20,7 +24,7 @@ then fi rm out.mp4 -./minimp4_x86 -f vectors/foreman.264 out.mp4 +$EXEC -f vectors/foreman.264 out.mp4 if ! cmp ./out.mp4 vectors/out_fragmentation_ref.mp4 >/dev/null 2>&1 then echo fragmentation test failed @@ -28,7 +32,7 @@ then fi rm out.mp4 -./minimp4_x86 vectors/foreman_slices.264 out.mp4 +$EXEC vectors/foreman_slices.264 out.mp4 if ! cmp ./out.mp4 vectors/out_slices_ref.mp4 >/dev/null 2>&1 then echo slices test failed @@ -36,36 +40,33 @@ then fi rm out.mp4 -qemu-arm ./minimp4_arm_gcc vectors/foreman.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_ref.mp4 >/dev/null 2>&1 +$EXEC -d vectors/out_ref.mp4 out.h264 +if ! cmp ./out.h264 vectors/foreman.264 >/dev/null 2>&1 then - echo test failed + echo demux test failed exit 1 fi -rm out.mp4 +rm out.h264 -qemu-arm ./minimp4_arm_gcc -s vectors/foreman.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_sequential_ref.mp4 >/dev/null 2>&1 +$EXEC -d vectors/out_sequential_ref.mp4 out.h264 +if ! cmp ./out.h264 vectors/foreman.264 >/dev/null 2>&1 then - echo sequential test failed + echo demux sequential test failed exit 1 fi -rm out.mp4 +rm out.h264 -qemu-arm ./minimp4_arm_gcc -f vectors/foreman.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_fragmentation_ref.mp4 >/dev/null 2>&1 +$EXEC -d vectors/out_slices_ref.mp4 out.h264 +if ! cmp ./out.h264 vectors/foreman_slices.264 >/dev/null 2>&1 then - echo fragmentation test failed + echo demux slices test failed exit 1 fi -rm out.mp4 +rm out.h264 -qemu-arm ./minimp4_arm_gcc vectors/foreman_slices.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_slices_ref.mp4 >/dev/null 2>&1 -then - echo slices test failed - exit 1 -fi -rm out.mp4 +} + +test_executable ./minimp4_x86 +test_executable "qemu-arm ./minimp4_arm_gcc" echo test passed diff --git a/vectors/foreman.264 b/vectors/foreman.264 index c17064c..28927b2 100644 Binary files a/vectors/foreman.264 and b/vectors/foreman.264 differ diff --git a/vectors/foreman_slices.264 b/vectors/foreman_slices.264 index 6d6cb73..88e8896 100644 Binary files a/vectors/foreman_slices.264 and b/vectors/foreman_slices.264 differ